zwp 5 месяцев назад
Родитель
Сommit
bcacdfda53

+ 1 - 0
AIIM/Common/CommonUI/TopPopupView.h

@@ -15,6 +15,7 @@ typedef void (^PopupClickBlock)(void);
 @property (nonatomic, copy) PopupClickBlock clickBlock;
 @property (nonatomic, copy) PopupClickBlock clickBlock;
 
 
 + (void)showWithNickname:(NSString *)nickname
 + (void)showWithNickname:(NSString *)nickname
+                  avatar:(NSString *)avatar
                 message:(NSString *)message
                 message:(NSString *)message
                 chatId:(NSString *)chatId
                 chatId:(NSString *)chatId
                 type:(NSInteger)type
                 type:(NSInteger)type

+ 5 - 15
AIIM/Common/CommonUI/TopPopupView.m

@@ -25,7 +25,7 @@ static const NSTimeInterval kPopupDisplayTime = 3.0;
 
 
 @implementation TopPopupView
 @implementation TopPopupView
 
 
-+ (void)showWithNickname:(NSString *)nickname message:(NSString *)message chatId:(nonnull NSString *)chatId type:(NSInteger)type clickBlock:(PopupClickBlock)clickBlock {
++ (void)showWithNickname:(NSString *)nickname avatar:(nonnull NSString *)avatar message:(NSString *)message chatId:(nonnull NSString *)chatId type:(NSInteger)type clickBlock:(PopupClickBlock)clickBlock {
     // 确保在主线程执行
     // 确保在主线程执行
     dispatch_async(dispatch_get_main_queue(), ^{
     dispatch_async(dispatch_get_main_queue(), ^{
         // 移除可能已经存在的弹窗
         // 移除可能已经存在的弹窗
@@ -39,7 +39,7 @@ static const NSTimeInterval kPopupDisplayTime = 3.0;
         // 创建新弹窗
         // 创建新弹窗
         TopPopupView *popup = [[TopPopupView alloc] initWithFrame:CGRectMake(20, -kPopupHeight, keyWindow.bounds.size.width - 40, kPopupHeight)];
         TopPopupView *popup = [[TopPopupView alloc] initWithFrame:CGRectMake(20, -kPopupHeight, keyWindow.bounds.size.width - 40, kPopupHeight)];
         popup.clickBlock = clickBlock;
         popup.clickBlock = clickBlock;
-        [popup setupWithNickname:nickname message:message chatId:chatId type:type];
+        [popup setupWithNickname:nickname avatar:avatar message:message chatId:chatId type:type];
         [keyWindow addSubview:popup];
         [keyWindow addSubview:popup];
         
         
         // 显示动画
         // 显示动画
@@ -92,21 +92,11 @@ static const NSTimeInterval kPopupDisplayTime = 3.0;
     [self addGestureRecognizer:swipe];
     [self addGestureRecognizer:swipe];
 }
 }
 
 
-- (void)setupWithNickname:(NSString *)nickname message:(NSString *)message chatId:(NSString *)chatId type:(NSInteger)type{
+- (void)setupWithNickname:(NSString *)nickname avatar:(nonnull NSString *)avatar message:(NSString *)message chatId:(NSString *)chatId type:(NSInteger)type{
     self.nicknameLabel.text = nickname;
     self.nicknameLabel.text = nickname;
     self.messageLabel.text = message;
     self.messageLabel.text = message;
-    if (type == 0) {
-        [self.avatar sd_setImageWithURL:getURL(chatId)];
-    }else{
-        [GroupNetApi getGroupInfo:chatId succ:^(int code, NSDictionary * _Nullable result) {
-            NSDictionary * userinfo=result[@"data"];
-            if (userinfo[@"avatar"]) {
-                [self.avatar sd_setImageWithURL:getURL(userinfo[@"avatar"])];
-                self.nicknameLabel.text = [NSString stringWithFormat:@"%@(%@)",nickname,userinfo[@"name"]];
-            }
-        } fail:^(NSError * _Nonnull error) {
-            
-        }];
+    if (avatar) {
+        [self.avatar sd_setImageWithURL:getURL(avatar)];
     }
     }
     
     
     // 布局
     // 布局

+ 1 - 1
AIIM/Common/Network/GBaseNetApi.m

@@ -524,7 +524,7 @@
         NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
         NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
         NSString *fileName = [response suggestedFilename];
         NSString *fileName = [response suggestedFilename];
         NSString *fileExtension = [fileName pathExtension];
         NSString *fileExtension = [fileName pathExtension];
-        NSString *newfileName = [NSString stringWithFormat:@"%@.%@", [[NSUUID UUID] UUIDString],fileExtension];
+        NSString *newfileName = [NSString stringWithFormat:@"%@.%@", thrid,fileExtension];
         documentsDirectoryURL = [documentsDirectoryURL URLByAppendingPathComponent:newfileName];
         documentsDirectoryURL = [documentsDirectoryURL URLByAppendingPathComponent:newfileName];
         return documentsDirectoryURL;
         return documentsDirectoryURL;
     } completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) {
     } completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) {

+ 25 - 3
AIIM/Common/Network/aliOSS/OSSManager.h

@@ -11,21 +11,43 @@
 
 
 NS_ASSUME_NONNULL_BEGIN
 NS_ASSUME_NONNULL_BEGIN
 
 
-@interface OSSManager : NSObject
 
 
+@protocol OSSManagerDelegate <NSObject>
+@optional
+- (void)stateChange:(NSDictionary *_Nullable)changeMsg;
+@end
+
+
+@interface OSSManager : NSObject
+@property (nonatomic,weak) id <OSSManagerDelegate> delegate;
 @property (nonatomic, strong) OSSClient *defaultClient;
 @property (nonatomic, strong) OSSClient *defaultClient;
 
 
 @property (nonatomic, strong) OSSClient *imageClient;
 @property (nonatomic, strong) OSSClient *imageClient;
 @property (nonatomic, strong) NSDictionary *OSSInfo;
 @property (nonatomic, strong) NSDictionary *OSSInfo;
+@property (nonatomic,strong) NSMutableArray * _Nullable uploadTanck;
 
 
 + (instancetype)sharedManager;
 + (instancetype)sharedManager;
 
 
 -(void)getOSSInfo;
 -(void)getOSSInfo;
 //普通上传
 //普通上传
-- (void)asyncPutFile:(NSString *)objectKey localFilePath:(NSString *)filePath thrid:(NSString *)strtime progress:(void (^)(NSInteger,NSString *))progress success:(void (^)(id _Nullable,NSString *))success failure:(void (^)(NSError * _Nonnull,NSString *))failure;
+- (void)asyncPutFile:(NSString *)objectKey localFilePath:(NSString *)filePath thrid:(NSString *)strtime;
 
 
 //断点续传
 //断点续传
-- (void)asyncResumableUploadFile:(NSString *)objectKey localFilePath:(NSString *)filePath thrid:(NSString *)strtime progress:(void (^)(NSInteger,NSString *))prgress success:(void (^)(id _Nullable,NSString *))success failure:(void (^)(NSError * _Nonnull,NSString *))failure;
+- (void)asyncResumableUploadFile:(NSString *)objectKey localFilePath:(NSString *)filePath thrid:(NSString *)strtime;
+
+
+
+
+-(void)addUploadTanckobj:(OSSTask *)task thrid:(NSString *)thrid;
+
+
+
+-(BOOL)isuploadTanck:(NSString *)thrid;
+
+-(void)removeUploadTanckobj:(NSString *)thrid;
+
+-(void)stopUploadTanck:(NSString *)thrid;
+
 
 
 @end
 @end
 
 

+ 200 - 16
AIIM/Common/Network/aliOSS/OSSManager.m

@@ -9,6 +9,9 @@
 #import "OSSManager.h"
 #import "OSSManager.h"
 #import "OssNetApi.h"
 #import "OssNetApi.h"
 #import <AliyunOSSiOS/OSSService.h>
 #import <AliyunOSSiOS/OSSService.h>
+#import "ChatsStore.h"
+#import "GDBManager.h"
+#import "GWebSocket.h"
 
 
 // yourEndpoint填写Bucket所在地域对应的Endpoint。以华东1(杭州)为例,Endpoint填写为https://oss-cn-hangzhou.aliyuncs.com。
 // yourEndpoint填写Bucket所在地域对应的Endpoint。以华东1(杭州)为例,Endpoint填写为https://oss-cn-hangzhou.aliyuncs.com。
 #define endpoint @"https://oss-ap-southeast-1.aliyuncs.com"//生产服务器
 #define endpoint @"https://oss-ap-southeast-1.aliyuncs.com"//生产服务器
@@ -35,8 +38,18 @@
     return _manager;
     return _manager;
 }
 }
 
 
+- (instancetype)init {
+    if (self = [super init]) {
+        _uploadTanck = [NSMutableArray new];
+    }
+    return self;
+}
+
+
 -(void)getOSSInfo{
 -(void)getOSSInfo{
-    
+    if (!_uploadTanck) {
+        _uploadTanck = [NSMutableArray new];
+    }
     NSDictionary *dic = [UDManager.shareInstance getDDManager:nkOSSinfo];
     NSDictionary *dic = [UDManager.shareInstance getDDManager:nkOSSinfo];
     if(dic){
     if(dic){
         self.OSSInfo = dic.copy;
         self.OSSInfo = dic.copy;
@@ -90,7 +103,7 @@
 
 
 
 
 //普通上传
 //普通上传
-- (void)asyncPutFile:(NSString *)objectKey localFilePath:(NSString *)filePath thrid:(NSString *)strtime progress:(void (^)(NSInteger,NSString *))prgress success:(void (^)(id _Nullable,NSString *))success failure:(void (^)(NSError * _Nonnull,NSString *))failure{
+- (void)asyncPutFile:(NSString *)objectKey localFilePath:(NSString *)filePath thrid:(NSString *)strtime{
     if([OSSManager sharedManager].defaultClient==nil){
     if([OSSManager sharedManager].defaultClient==nil){
         [MBProgressHUD showWithText:@"OSS文件服务初始化失败!請重試"];
         [MBProgressHUD showWithText:@"OSS文件服务初始化失败!請重試"];
         [self getOSSInfo];
         [self getOSSInfo];
@@ -98,7 +111,14 @@
     }
     }
     if (![objectKey oss_isNotEmpty]) {
     if (![objectKey oss_isNotEmpty]) {
         NSError *error = [NSError errorWithDomain:NSInvalidArgumentException code:0 userInfo:@{NSLocalizedDescriptionKey: @"objectKey should not be nil"}];
         NSError *error = [NSError errorWithDomain:NSInvalidArgumentException code:0 userInfo:@{NSLocalizedDescriptionKey: @"objectKey should not be nil"}];
-        failure(error,strtime);
+        if(self.delegate){
+            NSDictionary *dic=@{
+                @"state":@"3",
+                @"pcent":@"",
+                @"thrid":strtime
+            };
+            [self.delegate stateChange:dic];
+        }
         return;
         return;
     }
     }
     
     
@@ -108,13 +128,19 @@
     _normalUploadRequest.objectKey = objectKey;
     _normalUploadRequest.objectKey = objectKey;
     _normalUploadRequest.uploadingFileURL = [NSURL fileURLWithPath:filePath];
     _normalUploadRequest.uploadingFileURL = [NSURL fileURLWithPath:filePath];
     _normalUploadRequest.isAuthenticationRequired = YES;
     _normalUploadRequest.isAuthenticationRequired = YES;
+    weakSelf(self);
     _normalUploadRequest.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) {
     _normalUploadRequest.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) {
         CGFloat progress = 1.f * totalByteSent / totalBytesExpectedToSend;
         CGFloat progress = 1.f * totalByteSent / totalBytesExpectedToSend;
 //        NSLog(@"上传文件进度: %f", progress);
 //        NSLog(@"上传文件进度: %f", progress);
         NSInteger pcent =progress*100;
         NSInteger pcent =progress*100;
-        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-            prgress(pcent,strtime);
-        });
+        if(weakself.delegate){
+            NSDictionary *dic=@{
+                @"state":@"1",
+                @"pcent":[NSString stringWithFormat:@"%ld",(long)pcent],
+                @"thrid":strtime
+            };
+            [weakself.delegate stateChange:dic];
+        }
         
         
     };
     };
     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
@@ -122,10 +148,26 @@
         [task continueWithBlock:^id(OSSTask *task) {
         [task continueWithBlock:^id(OSSTask *task) {
             dispatch_async(dispatch_get_main_queue(), ^{
             dispatch_async(dispatch_get_main_queue(), ^{
                 if (task.error) {
                 if (task.error) {
-                    failure(task.error,strtime);
+                    [self updataFileMsg:strtime state:@"1"];
+                    if(self.delegate){
+                        NSDictionary *dic=@{
+                            @"state":@"3",
+                            @"pcent":@"",
+                            @"thrid":strtime
+                        };
+                        [self.delegate stateChange:dic];
+                    }
                 } else {
                 } else {
-                    success(task,strtime);
                     NSLog(@"上传文件完成");
                     NSLog(@"上传文件完成");
+                    [self updataFileMsg:strtime state:@"2"];
+                    if(self.delegate){
+                        NSDictionary *dic=@{
+                            @"state":@"2",
+                            @"pcent":@"",
+                            @"thrid":strtime
+                        };
+                        [self.delegate stateChange:dic];
+                    }
                 }
                 }
             });
             });
             
             
@@ -135,7 +177,7 @@
 }
 }
 
 
 //断点续传
 //断点续传
-- (void)asyncResumableUploadFile:(NSString *)objectKey localFilePath:(NSString *)filePath thrid:(NSString *)strtime progress:(void (^)(NSInteger,NSString *))prgress success:(void (^)(id _Nullable,NSString *))success failure:(void (^)(NSError * _Nonnull,NSString *))failure{
+- (void)asyncResumableUploadFile:(NSString *)objectKey localFilePath:(NSString *)filePath thrid:(NSString *)strtime{
     
     
     if([OSSManager sharedManager].defaultClient==nil){
     if([OSSManager sharedManager].defaultClient==nil){
         [MBProgressHUD showWithText:@"OSS文件服务初始化失败!請重試"];
         [MBProgressHUD showWithText:@"OSS文件服务初始化失败!請重試"];
@@ -154,9 +196,19 @@
         CGFloat progress = 1.f * totalByteSent / totalBytesExpectedToSend;
         CGFloat progress = 1.f * totalByteSent / totalBytesExpectedToSend;
 //        NSLog(@"上传文件进度: %f", progress);
 //        NSLog(@"上传文件进度: %f", progress);
         NSInteger pcent =progress*100;
         NSInteger pcent =progress*100;
-        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-            prgress(pcent,strtime);
-        });
+        
+        if(self.delegate){
+            NSDictionary *dic=@{
+                @"state":@"1",
+                @"pcent":[NSString stringWithFormat:@"%ld",(long)pcent],
+                @"thrid":strtime
+            };
+            [self.delegate stateChange:dic];
+        }
+        
+//        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+//            prgress(pcent,strtime);
+//        });
     };
     };
     NSString *cachesDir = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
     NSString *cachesDir = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
     // 设置断点记录保存路径。
     // 设置断点记录保存路径。
@@ -166,23 +218,155 @@
 
 
     resumableUpload.uploadingFileURL = [NSURL fileURLWithPath:filePath];
     resumableUpload.uploadingFileURL = [NSURL fileURLWithPath:filePath];
     OSSTask * resumeTask = [[OSSManager sharedManager].defaultClient resumableUpload:resumableUpload];
     OSSTask * resumeTask = [[OSSManager sharedManager].defaultClient resumableUpload:resumableUpload];
+    [self addUploadTanckobj:resumeTask thrid:strtime];
     [resumeTask continueWithBlock:^id(OSSTask *task) {
     [resumeTask continueWithBlock:^id(OSSTask *task) {
         if (task.error) {
         if (task.error) {
             NSLog(@"error: %@", task.error);
             NSLog(@"error: %@", task.error);
             if ([task.error.domain isEqualToString:OSSClientErrorDomain] && task.error.code == OSSClientErrorCodeCannotResumeUpload) {
             if ([task.error.domain isEqualToString:OSSClientErrorDomain] && task.error.code == OSSClientErrorCodeCannotResumeUpload) {
                 // 此任务无法续传,需获取新的uploadId重新上传。
                 // 此任务无法续传,需获取新的uploadId重新上传。
-                failure(task.error,strtime);
             }
             }
+            [self updataFileMsg:strtime state:@"3"];
+//            if(self.delegate){
+//                NSDictionary *dic=@{
+//                    @"state":@"3",
+//                    @"pcent":@"",
+//                    @"thrid":strtime
+//                };
+//                [self.delegate stateChange:dic];
+//            }
         } else {
         } else {
             NSLog(@"Upload file success");
             NSLog(@"Upload file success");
-            success(task,strtime);
+            [self updataFileMsg:strtime state:@"2"];
+//            if(self.delegate){
+//                NSDictionary *dic=@{
+//                    @"state":@"2",
+//                    @"pcent":@"",
+//                    @"thrid":strtime
+//                };
+//                [self.delegate stateChange:dic];
+//            }
         }
         }
         return nil;
         return nil;
     }];
     }];
+//    [resumeTask waitUntilFinished];
+//    [resumableUpload cancel];
+}
 
 
-    // [resumeTask waitUntilFinished];
 
 
-    // [resumableUpload cancel];
+
+-(void)addUploadTanckobj:(OSSTask *)task thrid:(NSString *)thrid{
+    NSDictionary *item = @{
+        @"task":task,
+        @"thrid":thrid
+    };
+    [_uploadTanck addObject:item];
+}
+
+
+
+-(BOOL)isuploadTanck:(NSString *)thrid{
+//    NSLog(@"stopUploadTanck-------------2");
+    if(_uploadTanck.count>0){
+        for (NSDictionary *item in _uploadTanck) {
+            NSString *th = item[@"thrid"];
+            NSLog(@"stopUploadTanck-------------3");
+            if([th isEqualToString:thrid]){
+                NSLog(@"stopUploadTanck-------------4");
+                return true;
+            }
+        }
+    }
+    return false;
+}
+
+-(void)removeUploadTanckobj:(NSString *)thrid{
+    if(_uploadTanck.count>0){
+        for (NSDictionary *item in _uploadTanck) {
+            NSString *th = item[@"thrid"];
+            if([th isEqualToString:thrid]){
+                [_uploadTanck removeObject:item];
+                return;
+            }
+        }
+    }
+}
+
+-(void)stopUploadTanck:(NSString *)thrid{
+    NSLog(@"stopUploadTanck-------------2");
+    if(_uploadTanck.count>0){
+        for (NSDictionary *item in _uploadTanck) {
+            NSString *th = item[@"thrid"];
+            NSLog(@"stopUploadTanck-------------3");
+            if([th isEqualToString:thrid]){
+                OSSTask *task = item[@"task"];
+                NSLog(@"stopUploadTanck-------------4");
+                //[task cancel];取消传输
+              
+                return;
+            }
+        }
+    }
+}
+
+
+-(void)updataFileMsg:(NSString *)thrid state:(NSString *)state{
+    
+    
+    [GDBManager.shareInstance selectLocalmsgWithLocaltime:thrid succ:^(NSArray * _Nullable array) {
+        NSLog(@"selectLocalmsgWithLocaltime:%@",array);
+        
+        if(array){
+            if(array.count>0){
+                NSDictionary *msg =array[0];
+                NSString *msgtype = msg[@"messageType"];
+                
+                if (([msgtype isEqualToString:MessageType_Del]||[msgtype isEqualToString:MessageType_CallBack2])) {
+                    return;
+                }
+                
+                NSDictionary *extend=msg[@"extend"];
+                NSMutableDictionary *mextend = [extend mutableCopy];
+                NSMutableDictionary *mmsg = [msg mutableCopy];
+                
+                if([state isEqualToString:@"2"]){
+                    NSString *localPath =extend[@"localurl"];
+                    NSURL *loaclUrl = [NSURL URLWithString:localPath];
+                    NSString *url = [NSString stringWithFormat:@"http://oss.abtim-my.com/%@",loaclUrl.lastPathComponent];
+                    [mextend setObject:url forKey:@"url"];
+                    
+                    [mmsg setObject:mextend forKey:@"extend"];
+                    [mmsg setObject:@"" forKey:@"id"];
+                }
+                else if([state isEqualToString:@"3"]){
+                    [mextend setObject:@"" forKey:@"url"];
+                    [mextend setObject:@"" forKey:@"fileName"];
+                    [mextend setObject:[NSNumber numberWithInt:1] forKey:@"fileError"];
+                    
+                    [mmsg setObject:mextend forKey:@"extend"];
+                    [mmsg setObject:@"" forKey:@"id"];
+                }
+                
+                
+                NSDictionary *sendInfo = @{
+                    @"code":@"2",
+                    @"message":mmsg,
+                };
+                NSError *error;
+                NSData *jsonData = [NSJSONSerialization dataWithJSONObject:sendInfo options:0 error:&error];
+                if (!jsonData) {
+                    NSLog(@"Got an error: %@", error);
+                } else {
+                    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
+//                    NSLog(@"%@", jsonString);
+                    NSLog(@"----发送文件消息2----");
+                    [GWebSocket.shareInstance sendMsg:jsonString];
+                }
+                
+            }
+        }
+    } fail:^(NSString * _Nullable error) {
+        ;
+    }];
 }
 }
 
 
 
 

+ 154 - 161
AIIM/Controller/chat/ChatController.m

@@ -46,7 +46,7 @@
 #import "OSSManager.h"
 #import "OSSManager.h"
 
 
 static const CGFloat kQuoteViewHeight = 46.0f;
 static const CGFloat kQuoteViewHeight = 46.0f;
-@interface ChatController()<UITextViewDelegate,ChatsStoreDelegate,UITableViewDelegate,UITableViewDataSource,chatpopViewDelegate,PHPickerViewControllerDelegate,UINavigationControllerDelegate,UIDocumentPickerDelegate,UIScrollViewDelegate>
+@interface ChatController()<UITextViewDelegate,ChatsStoreDelegate,UITableViewDelegate,UITableViewDataSource,chatpopViewDelegate,PHPickerViewControllerDelegate,UINavigationControllerDelegate,UIDocumentPickerDelegate,UIScrollViewDelegate,OSSManagerDelegate>
 
 
 @property (weak, nonatomic) IBOutlet UILabel *titlelb;
 @property (weak, nonatomic) IBOutlet UILabel *titlelb;
 @property (weak, nonatomic) IBOutlet UITableView *_tableView;
 @property (weak, nonatomic) IBOutlet UITableView *_tableView;
@@ -194,6 +194,8 @@ static const CGFloat kQuoteViewHeight = 46.0f;
     ChatsStore.shareInstance.userid =self.userId;
     ChatsStore.shareInstance.userid =self.userId;
     ChatListStore.shareInstance.chatId = self.chatId;
     ChatListStore.shareInstance.chatId = self.chatId;
     [ChatsStore.shareInstance getchatReadTime:self.chatId];
     [ChatsStore.shareInstance getchatReadTime:self.chatId];
+    [OSSManager sharedManager].delegate = self;
+    
     _showLoading = YES;
     _showLoading = YES;
     NSString *type=@"";
     NSString *type=@"";
     if(self.type==0){
     if(self.type==0){
@@ -228,6 +230,7 @@ static const CGFloat kQuoteViewHeight = 46.0f;
     _titlelb.text = self.titlename;
     _titlelb.text = self.titlename;
     
     
     ChatsStore.shareInstance.delegate = self;
     ChatsStore.shareInstance.delegate = self;
+    [OSSManager sharedManager].delegate = self;
     ChatsStore.shareInstance.chatId = self.chatId;
     ChatsStore.shareInstance.chatId = self.chatId;
     ChatsStore.shareInstance.userid =self.userId;
     ChatsStore.shareInstance.userid =self.userId;
     ChatListStore.shareInstance.chatId = self.chatId;
     ChatListStore.shareInstance.chatId = self.chatId;
@@ -263,6 +266,7 @@ static const CGFloat kQuoteViewHeight = 46.0f;
     [self.preloader stopMonitoring];
     [self.preloader stopMonitoring];
     [[NSNotificationCenter defaultCenter] removeObserver:self];
     [[NSNotificationCenter defaultCenter] removeObserver:self];
     ChatsStore.shareInstance.delegate = nil;
     ChatsStore.shareInstance.delegate = nil;
+    [OSSManager sharedManager].delegate = nil;
     ChatsStore.shareInstance.chatId = nil;
     ChatsStore.shareInstance.chatId = nil;
 }
 }
 -(void)viewDidAppear:(BOOL)animated{
 -(void)viewDidAppear:(BOOL)animated{
@@ -442,7 +446,7 @@ static const CGFloat kQuoteViewHeight = 46.0f;
 }
 }
 
 
 -(void)ChatsChange:(NSArray *)msgList type:(NSInteger)typpe{
 -(void)ChatsChange:(NSArray *)msgList type:(NSInteger)typpe{
-    NSLog(@"msgList:%@",msgList);
+//    NSLog(@"msgList:%@",msgList);
     if([msgList count]==0){
     if([msgList count]==0){
         return;
         return;
     }
     }
@@ -1338,28 +1342,13 @@ static const CGFloat kQuoteViewHeight = 46.0f;
 
 
 -(void)TimerAction{
 -(void)TimerAction{
     //处理重发事件
     //处理重发事件
-    NSDate *now = [NSDate date];
-    NSTimeInterval trt = [now timeIntervalSince1970];
 //    NSLog(@"self.msgList:%@",self.msgList);
 //    NSLog(@"self.msgList:%@",self.msgList);
     for(NSDictionary *dis in self.msgList){
     for(NSDictionary *dis in self.msgList){
         NSString *mine = dis[@"mine"];
         NSString *mine = dis[@"mine"];
         if(mine.boolValue){
         if(mine.boolValue){
             if([dis[@"id"] isEqualToString:dis[@"localtime"]]){
             if([dis[@"id"] isEqualToString:dis[@"localtime"]]){
-                NSNumber *tt =dis[@"localtime"];
-//                NSLog(@"NSTimeInterval:%f  ,%ld",trt,(long)tt.integerValue);
-                if((trt-tt.integerValue/1000)>40){
-                    //发送失败
-                    NSLog(@"发送失败-------");
-                    continue;
-                }
-                if((trt-tt.integerValue/1000)>9){
-                    NSLog(@"重发-------:%@",dis);
-                    //重发
-                    [self resendMsg:dis.copy];
-                }
+                [self resendMsg:dis.copy];
             }
             }
-            [self fileUploadState:dis];
-            
         }
         }
     }
     }
 }
 }
@@ -1367,20 +1356,57 @@ static const CGFloat kQuoteViewHeight = 46.0f;
 -(BOOL)canResend:(NSDictionary *)msg{
 -(BOOL)canResend:(NSDictionary *)msg{
     NSLog(@"canResend:%@",msg);
     NSLog(@"canResend:%@",msg);
     NSString *localtime = msg[@"localtime"];
     NSString *localtime = msg[@"localtime"];
-    for (NSDictionary *item in self.msgList) {
-        NSString *itlocaltime =item[@"localtime"];
-        if([localtime isEqualToString:itlocaltime]){
-            NSLog(@"canResend2:%@",item);
-            if(![item[@"id"] isEqualToString:item[@"localtime"]]){
-                return false;
+    NSString *messageType = msg[@"messageType"];
+    if([messageType isEqualToString:MessageType_text]){
+        for (NSDictionary *item in self.msgList) {
+            NSString *itlocaltime =item[@"localtime"];
+            if([localtime isEqualToString:itlocaltime]){
+                NSLog(@"canResend2:%@",item);
+                if(![item[@"id"] isEqualToString:item[@"localtime"]]){
+                    return false;
+                }
+                NSDate *now = [NSDate date];
+                NSTimeInterval trt = [now timeIntervalSince1970];
+                NSNumber *tt =msg[@"localtime"];
+                if((trt-tt.integerValue/1000)>40){
+                    //发送失败
+                    NSLog(@"发送失败-------");
+                    return false;
+                }
+                
             }
             }
         }
         }
     }
     }
+    else{
+        [self fileUploadState:msg];
+        return false;
+    }
+    
     return YES;
     return YES;
 }
 }
 
 
 -(void)fileUploadState:(NSDictionary *)msg{
 -(void)fileUploadState:(NSDictionary *)msg{
-    
+    NSString *localtime = msg[@"localtime"];
+    NSString *messageType = msg[@"messageType"];
+    if([messageType isEqualToString:MessageType_file]||[messageType isEqualToString:MessageType_image]||[messageType isEqualToString:MessageType_video]) {
+        for (NSDictionary *item in self.msgList) {
+            
+            if([OSSManager.sharedManager isuploadTanck:localtime]){
+                return;
+            }
+            NSDictionary *extend =item[@"extend"];
+            NSString *url =extend[@"url"];
+            if([url isEqualToString:@""]){
+                NSString *savedPath =extend[@"localurl"];
+                NSURL * fileUrl = [NSURL fileURLWithPath:savedPath];
+                ChatFileModel * model = [[ChatFileModel alloc] initWithURL:fileUrl];
+                model.fileURL = fileUrl;
+                model.filePath = savedPath;
+                [self OSSuploadFile:model thrid:localtime];
+                NSLog(@"重发文件");
+            }
+        }
+    }
 }
 }
 
 
 
 
@@ -1468,57 +1494,55 @@ static const CGFloat kQuoteViewHeight = 46.0f;
         NSItemProvider *itemProvider = result.itemProvider;
         NSItemProvider *itemProvider = result.itemProvider;
         NSString *typeIdentifier = result.itemProvider.registeredTypeIdentifiers.firstObject;
         NSString *typeIdentifier = result.itemProvider.registeredTypeIdentifiers.firstObject;
         if ([result.itemProvider canLoadObjectOfClass:[UIImage class]]) {
         if ([result.itemProvider canLoadObjectOfClass:[UIImage class]]) {
-            [itemProvider loadObjectOfClass:[UIImage class] completionHandler:^(__kindof id<NSItemProviderReading>  _Nullable object, NSError * _Nullable error) {
-                if (!error) {
-                    UIImage *selectedImage = (UIImage *)object;
-                    
-                    // 保存图片到本地
-                    NSString *savedPath = [self saveImageToSandbox:selectedImage];
-                    if ([[NSFileManager defaultManager] fileExistsAtPath:savedPath]) {
-                        NSLog(@"-----找得到文件------");
-                    }
+            
+            [result.itemProvider loadFileRepresentationForTypeIdentifier:typeIdentifier completionHandler:^(NSURL * _Nullable url, NSError * _Nullable error) {
+                if (error) {
+                    NSLog(@"Error loading file: %@", error);
+                    return;
+                }
+                NSLog(@"File URL: %@", url); // 这里就是文件的 URL 路径
+                // 你可以使用这个 URL 进行进一步处理,例如读取文件内容或者将其复制到应用沙盒中的其他位置。
+                NSString *savedPath = [self saveFileToDocumentsDirectory:url];
+                if(savedPath.length>0){
                     NSURL * fileUrl = [NSURL fileURLWithPath:savedPath];
                     NSURL * fileUrl = [NSURL fileURLWithPath:savedPath];
                     ChatFileModel * model = [[ChatFileModel alloc] initWithURL:fileUrl];
                     ChatFileModel * model = [[ChatFileModel alloc] initWithURL:fileUrl];
-                    
-//                    ChatFileModel * model = [[ChatFileModel alloc] initWithName:[FileInfoUtils getFileNameWithURL:fileUrl] size:[FileInfoUtils getFileSizeStringWithURL:fileUrl error:nil] isOversize:[FileInfoUtils isFileGreaterThan100MB:fileUrl error:nil]];
                     model.fileURL = fileUrl;
                     model.fileURL = fileUrl;
                     model.filePath = savedPath;
                     model.filePath = savedPath;
-                    
                     [fileArray addObject:model];
                     [fileArray addObject:model];
                     if (fileArray.count==results.count) {
                     if (fileArray.count==results.count) {
-//                        [self handleMediaData:fileArray];
                         dispatch_async(dispatch_get_main_queue(), ^{
                         dispatch_async(dispatch_get_main_queue(), ^{
                             [self handleMediaData:fileArray];
                             [self handleMediaData:fileArray];
                         });
                         });
                     }
                     }
                 }
                 }
+                else{
+                    NSLog(@"-----找不到文件------");
+                }
             }];
             }];
+
         }else{
         }else{
-            
-            [result.itemProvider loadDataRepresentationForTypeIdentifier:typeIdentifier completionHandler:^(NSData * _Nullable data, NSError * _Nullable error) {
-                if (data) {
-                    NSString *savedPath = [self saveVideoDataToDocumentsDirectory:data];
-                    dispatch_async(dispatch_get_main_queue(), ^{
-                        
-                        if ([[NSFileManager defaultManager] fileExistsAtPath:savedPath]) {
-                            NSLog(@"-----找得到文件------");
-                        }
-                        NSURL * fileUrl = [NSURL fileURLWithPath:savedPath];
-                        ChatFileModel * model = [[ChatFileModel alloc] initWithURL:fileUrl];
-//                        ChatFileModel * model = [[ChatFileModel alloc] initWithName:[FileInfoUtils getFileNameWithURL:fileUrl] size:[FileInfoUtils getFileSizeStringWithURL:fileUrl error:nil] isOversize:[FileInfoUtils isFileGreaterThan100MB:fileUrl error:nil]];
-                        model.fileURL = fileUrl;
-                        model.filePath = savedPath;
-                        [fileArray addObject:model];
-                        if (fileArray.count==results.count) {
-                            dispatch_async(dispatch_get_main_queue(), ^{
-                                [self handleMediaData:fileArray];
-                            });
-//                            [self handleMediaData:fileArray];
-                        }
-                    });
-                    
-                }else{
-                    NSLog(@"%@",error);
+            [result.itemProvider loadFileRepresentationForTypeIdentifier:typeIdentifier completionHandler:^(NSURL * _Nullable url, NSError * _Nullable error) {
+                if (error) {
+                    NSLog(@"Error loading file: %@", error);
+                    return;
+                }
+                NSLog(@"File URL: %@", url); // 这里就是文件的 URL 路径
+                // 你可以使用这个 URL 进行进一步处理,例如读取文件内容或者将其复制到应用沙盒中的其他位置。
+                NSString *savedPath = [self saveFileToDocumentsDirectory:url];
+                if(savedPath.length>0){
+                    NSURL * fileUrl = [NSURL fileURLWithPath:savedPath];
+                    ChatFileModel * model = [[ChatFileModel alloc] initWithURL:fileUrl];
+                    model.fileURL = fileUrl;
+                    model.filePath = savedPath;
+                    [fileArray addObject:model];
+                    if (fileArray.count==results.count) {
+                        dispatch_async(dispatch_get_main_queue(), ^{
+                            [self handleMediaData:fileArray];
+                        });
+                    }
+                }
+                else{
+                    NSLog(@"-----找不到文件------");
                 }
                 }
             }];
             }];
         }
         }
@@ -1570,6 +1594,30 @@ static const CGFloat kQuoteViewHeight = 46.0f;
     return filePath;
     return filePath;
 }
 }
 
 
+- (NSString *)saveFileToDocumentsDirectory:(NSURL *)fromePath {
+    NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
+    NSString *destinationPath = [documentsDirectory stringByAppendingPathComponent:fromePath.lastPathComponent]; // 目标文件路径
+    
+    NSFileManager *fileManager = [NSFileManager defaultManager];
+    NSError *error = nil;
+    
+    if([[NSFileManager defaultManager] fileExistsAtPath:destinationPath]){
+        return destinationPath;
+    }
+    else{
+        BOOL success = [fileManager copyItemAtPath:fromePath.path toPath:destinationPath error:&error];
+        if (success) {
+            NSLog(@"文件成功复制到本地");
+            return destinationPath;
+        } else {
+            NSLog(@"文件复制失败: %@", error.localizedDescription);
+            return @"";
+        }
+    }
+}
+
+
+
 #pragma mark -文件选择和处理
 #pragma mark -文件选择和处理
 -(void)showfilePicker{
 -(void)showfilePicker{
     // 创建文档选择器
     // 创建文档选择器
@@ -1620,28 +1668,6 @@ static const CGFloat kQuoteViewHeight = 46.0f;
             NSString *strtime = [self getLocalTime];
             NSString *strtime = [self getLocalTime];
             [self uploadFile:[NSString stringWithFormat:@"%@",model.fileURL] fpath:model.filePath state:1 act:1 localtime:strtime];
             [self uploadFile:[NSString stringWithFormat:@"%@",model.fileURL] fpath:model.filePath state:1 act:1 localtime:strtime];
             [self OSSuploadFile:model thrid:strtime];
             [self OSSuploadFile:model thrid:strtime];
-////            NSLog(@"------fileSize:%@",model.fileSize);
-//            [self uploadFile:[NSString stringWithFormat:@"%@",model.fileURL] fpath:model.filePath state:1 act:1 localtime:strtime];
-//            //dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-////            [FileNetApi uploadWithFilePath:model.fileURL thrid:strtime progress:^(NSString *_Nullable thrid,NSProgress * _Nullable uploadProgress) {
-//                [FileNetApi OSSuploadWithFilePath:model.fileURL thrid:strtime progress:^(NSString *_Nullable thrid,NSProgress * _Nullable uploadProgress) {
-//                    NSLog(@"thrid:%@,%@",thrid,uploadProgress);
-//                    [self updatajidu:thrid uploadProgress:uploadProgress];
-//                } succ:^(int code, NSString *_Nullable thrid,NSDictionary * _Nullable dis) {
-//                    NSString *reCode =dis[@"code"];
-//                    if(reCode.intValue==200){
-//                        NSLog(@"上传成功:%@",dis[@"url"]);
-//                        [self uploadFile:dis[@"url"] fpath:model.filePath state:1 act:2 localtime:thrid];
-//                    }
-//                    else{
-//                        NSLog(@"上传失败");
-//                        [self uploadFilefail:thrid];
-//                    }
-//                } fail:^(NSString *_Nullable thrid,NSError * _Nonnull error) {
-//                    NSLog(@"上传失败");
-//                    [self uploadFilefail:thrid];
-//                }];
-//            //});
         }
         }
 }
 }
 
 
@@ -1649,73 +1675,48 @@ static const CGFloat kQuoteViewHeight = 46.0f;
 
 
 
 
 -(void)OSSuploadFile:(ChatFileModel *)model thrid:(NSString *)strtime{
 -(void)OSSuploadFile:(ChatFileModel *)model thrid:(NSString *)strtime{
-//    普通上传
-//    [OSSManager.sharedManager asyncPutFile:model.fileURL.lastPathComponent localFilePath:model.filePath thrid:strtime progress:^(NSInteger pcent, NSString * loacaltime) {
-//        [self Ossupdatajidu:loacaltime uploadProgress:pcent];
-//    } success:^(id res, NSString * loacaltime) {
-//        [self uploadFile:model.fileURL.lastPathComponent fpath:model.filePath state:1 act:2 localtime:loacaltime];
-//    } failure:^(NSError * error, NSString * loacaltime) {
-//        [self uploadFilefail:loacaltime];
-//    }];
+
    
    
+    NSString * tempChatId = self.chatId.mutableCopy;
+    [ChatsStore shareInstance].chatId = tempChatId;
+    [ChatsStore shareInstance].delegate = self;
+    
 //    断点续传
 //    断点续传
-    [OSSManager.sharedManager asyncResumableUploadFile:model.fileURL.lastPathComponent localFilePath:model.filePath thrid:strtime progress:^(NSInteger pcent, NSString * loacaltime) {
-        [self Ossupdatajidu:loacaltime uploadProgress:pcent];
-    } success:^(id res, NSString * loacaltime) {
-        [self uploadFile:model.fileURL.lastPathComponent fpath:model.filePath state:1 act:2 localtime:loacaltime];
-    } failure:^(NSError * error, NSString * loacaltime) {
-        [self uploadFilefail:loacaltime];
-    }];
+    [OSSManager.sharedManager asyncResumableUploadFile:model.fileURL.lastPathComponent localFilePath:model.filePath thrid:strtime];
+
+}
+
+-(void)stateChange:(NSDictionary *)changeMsg{
+    NSString *loacaltime = changeMsg[@"thrid"];
+    NSString *pcent = changeMsg[@"pcent"];
+    NSString *state = changeMsg[@"state"];
+    if([state isEqualToString:@"1"]){
+        [self Ossupdatajidu:loacaltime uploadProgress:pcent.intValue];
+    }
+//    if([state isEqualToString:@"2"]){
+//        [self Ossupdatajidu:loacaltime uploadProgress:pcent.intValue];
+//    }
     
     
 }
 }
 
 
 -(void)resendFile:(ChatMessageModel *)msg{
 -(void)resendFile:(ChatMessageModel *)msg{
     
     
     NSString *strtime = [NSString stringWithFormat:@"%ld",(long)msg.localtime];
     NSString *strtime = [NSString stringWithFormat:@"%ld",(long)msg.localtime];
-    NSString *loaclFile = [NSString stringWithFormat:@"file://%@",msg.localurl];
-    NSURL *fileURL = [NSURL URLWithString:loaclFile];
-    
-    [FileNetApi OSSuploadWithFilePath:fileURL thrid:strtime progress:^(NSString *_Nullable thrid,NSProgress * _Nullable uploadProgress) {
-        NSLog(@"thrid:%@,%@",thrid,uploadProgress);
-        [self updatajidu:thrid uploadProgress:uploadProgress];
-    } succ:^(int code, NSString *_Nullable thrid,NSDictionary * _Nullable dis) {
-        NSString *reCode =dis[@"code"];
-        if(reCode.intValue==200){
-            NSLog(@"上传成功:%@",dis[@"url"]);
-            [self uploadFile:dis[@"url"] fpath:msg.localurl state:1 act:2 localtime:thrid];
-        }
-        else{
-            NSLog(@"上传失败");
-            [self uploadFilefail:thrid];
-        }
-    } fail:^(NSString *_Nullable thrid,NSError * _Nonnull error) {
-        NSLog(@"上传失败");
-        [self uploadFilefail:thrid];
-    }];
+    NSString *loaclFile = [NSString stringWithFormat:@"%@",msg.localurl];
+    
+    if(![[NSFileManager defaultManager] fileExistsAtPath:loaclFile]){
+        [MBProgressHUD showWithText:@"文件不存在,請重新選擇"];
+        return;
+    }
+    
+   
+    NSURL * fileUrl = [NSURL fileURLWithPath:loaclFile];
+    ChatFileModel * model = [[ChatFileModel alloc] initWithURL:fileUrl];
+    model.fileURL = fileUrl;
+    model.filePath = loaclFile;
+    
+    [self OSSuploadFile:model thrid:strtime];
     
     
-    [GDBManager.shareInstance selectLocalmsgWithLocaltime:strtime succ:^(NSArray * _Nullable array) {
-        NSLog(@"selectLocalmsgWithLocaltime:%@",array);
-        
-        if(array){
-            if(array.count>0){
-                NSDictionary *msg =array[0];
-                NSString *msgtype = msg[@"messageType"];
-                
-                if (([msgtype isEqualToString:MessageType_Del]||[msgtype isEqualToString:MessageType_CallBack2])) {
-                    return;
-                }
-                NSString *strtime = [self getLocalTime];
-                NSDictionary *extend=msg[@"extend"];
-                NSMutableDictionary *mextend = [extend mutableCopy];
-                [mextend setObject:[NSNumber numberWithInt:0] forKey:@"fileError"];
-                NSMutableDictionary *mmsg = [msg mutableCopy];
-                [mmsg setObject:mextend forKey:@"extend"];
-                [ChatsStore.shareInstance reciveMsg:mmsg];
-            }
-        }
-    } fail:^(NSString * _Nullable error) {
-        ;
-    }];
 }
 }
 
 
 
 
@@ -1940,9 +1941,7 @@ static const CGFloat kQuoteViewHeight = 46.0f;
     NSInteger time = trt*1000;
     NSInteger time = trt*1000;
     _AudiofileName = [NSString stringWithFormat:@"%ld.mp4",(long)time];
     _AudiofileName = [NSString stringWithFormat:@"%ld.mp4",(long)time];
     
     
-    if(!_AudiofilePath){
-        _AudiofilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:_AudiofileName];
-    }
+    _AudiofilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:_AudiofileName];
     
     
     NSError *error = nil;
     NSError *error = nil;
     AVAudioSession *audioSession = [AVAudioSession sharedInstance];
     AVAudioSession *audioSession = [AVAudioSession sharedInstance];
@@ -1993,6 +1992,7 @@ static const CGFloat kQuoteViewHeight = 46.0f;
         return;
         return;
     }
     }
     NSLog(@"_AudiofilePath:%@",_AudiofilePath);
     NSLog(@"_AudiofilePath:%@",_AudiofilePath);
+    
     NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
     NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
     NSString *destinationPath = [documentsDirectory stringByAppendingPathComponent:yuanfileURL.lastPathComponent]; // 目标文件路径
     NSString *destinationPath = [documentsDirectory stringByAppendingPathComponent:yuanfileURL.lastPathComponent]; // 目标文件路径
     
     
@@ -2000,8 +2000,10 @@ static const CGFloat kQuoteViewHeight = 46.0f;
     NSError *error = nil;
     NSError *error = nil;
     BOOL success = [fileManager copyItemAtPath:_AudiofilePath toPath:destinationPath error:&error];
     BOOL success = [fileManager copyItemAtPath:_AudiofilePath toPath:destinationPath error:&error];
     if (success) {
     if (success) {
+        [[NSFileManager defaultManager] removeItemAtURL:yuanfileURL error:nil];
         NSLog(@"文件成功复制到本地");
         NSLog(@"文件成功复制到本地");
     } else {
     } else {
+        [[NSFileManager defaultManager] removeItemAtURL:yuanfileURL error:nil];
         NSLog(@"文件复制失败: %@", error.localizedDescription);
         NSLog(@"文件复制失败: %@", error.localizedDescription);
     }
     }
     NSLog(@"destinationPath:%@",destinationPath);
     NSLog(@"destinationPath:%@",destinationPath);
@@ -2013,18 +2015,9 @@ static const CGFloat kQuoteViewHeight = 46.0f;
     model.fileURL = fileURL;
     model.fileURL = fileURL;
     model.filePath = destinationPath;
     model.filePath = destinationPath;
     NSString *strtime = [self getLocalTime];
     NSString *strtime = [self getLocalTime];
-    //普通上传
+
     [self sendYuyinMsg:model.fileURL.lastPathComponent filePth:destinationPath localtime:strtime state:0];
     [self sendYuyinMsg:model.fileURL.lastPathComponent filePth:destinationPath localtime:strtime state:0];
-    [OSSManager.sharedManager asyncPutFile:model.fileURL.lastPathComponent localFilePath:model.filePath thrid:strtime progress:^(NSInteger pcent, NSString * loacaltime) {
-//        [self Ossupdatajidu:loacaltime uploadProgress:pcent];
-    } success:^(id res, NSString * loacaltime) {
-        [self sendYuyinMsg:model.fileURL.lastPathComponent filePth:destinationPath localtime:loacaltime state:1];
-        [[NSFileManager defaultManager] removeItemAtURL:yuanfileURL error:nil];
-    } failure:^(NSError * error, NSString * loacaltime) {
-//        [self sendYuyinMsg:model.fileURL.lastPathComponent localtime:loacaltime state:2];
-        [[NSFileManager defaultManager] removeItemAtURL:yuanfileURL error:nil];
-    }];
-   
+    [self OSSuploadFile:model thrid:strtime];
     
     
     [self.heatBeat invalidate];
     [self.heatBeat invalidate];
     self.heatBeat = nil;
     self.heatBeat = nil;
@@ -2183,7 +2176,7 @@ static const CGFloat kQuoteViewHeight = 46.0f;
     }
     }
     [favoritesDict setValue:extend forKey:@"extend"];
     [favoritesDict setValue:extend forKey:@"extend"];
     [UserNetApi addFavorites:favoritesDict succ:^(int code, NSDictionary * _Nullable res) {
     [UserNetApi addFavorites:favoritesDict succ:^(int code, NSDictionary * _Nullable res) {
-        NSLog(@"------result:%@",res);
+//        NSLog(@"------result:%@",res);
         NSString *ecode = res[@"code"];
         NSString *ecode = res[@"code"];
         if(ecode.intValue==200){
         if(ecode.intValue==200){
             if ([res jk_hasKey:@"msg"] && ![res[@"msg"] isKindOfClass:NSNull.class]) {
             if ([res jk_hasKey:@"msg"] && ![res[@"msg"] isKindOfClass:NSNull.class]) {
@@ -2490,9 +2483,9 @@ static const CGFloat kQuoteViewHeight = 46.0f;
                     return;
                     return;
                 }
                 }
             }
             }
-//            NSLog(@"othersChatMessageAlert---3:%@",message);
-            weakSelf(self);
-            [TopPopupView showWithNickname:message.nickName message:message.content chatId:message.type == 0 ? message.avatar : message.chatId type:message.type clickBlock:^{
+            NSLog(@"othersChatMessageAlert---3:%@",message.avatar);
+//            weakSelf(self);
+            [TopPopupView showWithNickname:message.nickName avatar:message.avatar message:message.content chatId:message.chatId type:message.type clickBlock:^{
 //                weakself.chatId = message.chatId;
 //                weakself.chatId = message.chatId;
 //                weakself.type = message.type;
 //                weakself.type = message.type;
 //                weakself.titlename = message.nickName;
 //                weakself.titlename = message.nickName;

+ 44 - 21
AIIM/Controller/chat/chetCell/ChatMessageModel.m

@@ -96,6 +96,7 @@
         self.fileError = fileError;
         self.fileError = fileError;
     }
     }
     
     
+    
     //合并转发
     //合并转发
     self.forwardMsgArray = extend[@"messageList"] ?:@[];
     self.forwardMsgArray = extend[@"messageList"] ?:@[];
     
     
@@ -277,7 +278,7 @@
     
     
     NSURL *videoURL = nil;
     NSURL *videoURL = nil;
     if (self.localurl.length != 0 && [[NSFileManager defaultManager] fileExistsAtPath:self.localurl]) {
     if (self.localurl.length != 0 && [[NSFileManager defaultManager] fileExistsAtPath:self.localurl]) {
-//        NSLog(@"generateThumbnailWithCompletion localurl:%@",self.localurl);
+        NSLog(@"generateThumbnailWithCompletion localurl:%@",self.localurl);
         videoURL = [NSURL fileURLWithPath:self.localurl];
         videoURL = [NSURL fileURLWithPath:self.localurl];
         dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
         dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
             AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];
             AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];
@@ -354,30 +355,52 @@
         else{
         else{
 //            NSLog(@"文件不存在");
 //            NSLog(@"文件不存在");
             if(self.url&&self.url.length != 0){
             if(self.url&&self.url.length != 0){
-                [FileNetApi downLoadWToken:getURL(self.url) thrid:self.msgId succ:^(int code, NSDictionary * res) {
-    //                NSLog(@"11---downLoadWToken:%d",code);
-                    if(res!=nil){
-                        NSMutableDictionary *mutableDict = [self.formerMessage mutableCopy];
-                        NSMutableDictionary *extend = [self.formerMessage[@"extend"] mutableCopy];
-                        [extend setObject:res[@"filePath"] forKey:@"localurl"];
-                        [mutableDict setObject:extend forKey:@"extend"];
-                        self.localurl = res[@"filePath"];
-                        NSDictionary *NewMsg = [mutableDict copy];
-                        [ChatsStore.shareInstance reciveMsg:NewMsg];
-                        if (loading) {
-                            loading(100);
-                        }
+                
+                NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
+                NSURL *tempUrl = [NSURL URLWithString:self.url];
+                NSString *fileName = tempUrl.lastPathComponent;
+                NSString *fileExtension = [fileName pathExtension];
+                NSString *newfileName = [NSString stringWithFormat:@"%@.%@", self.msgId,fileExtension];
+                documentsDirectoryURL = [documentsDirectoryURL URLByAppendingPathComponent:newfileName];
+                NSLog(@"文件已经存在本地1-:%@",documentsDirectoryURL.path);
+                if ([[NSFileManager defaultManager] fileExistsAtPath:documentsDirectoryURL.path]){
+                    NSLog(@"文件已经存在本地2-:%@",documentsDirectoryURL.path);
+                    NSMutableDictionary *mutableDict = [self.formerMessage mutableCopy];
+                    NSMutableDictionary *extend = [self.formerMessage[@"extend"] mutableCopy];
+                    [extend setObject:documentsDirectoryURL.path forKey:@"localurl"];
+                    [mutableDict setObject:extend forKey:@"extend"];
+                    self.localurl = documentsDirectoryURL.path;
+                    NSDictionary *NewMsg = [mutableDict copy];
+                    [ChatsStore.shareInstance reciveMsg:NewMsg];
+                    if (loading) {
+                        loading(100);
                     }
                     }
-                    else{
-                        if (code>=0&&code<200) {
+                }
+                else{
+                    [FileNetApi downLoadWToken:getURL(self.url) thrid:self.msgId succ:^(int code, NSDictionary * res) {
+                        if(res!=nil){
+                            NSMutableDictionary *mutableDict = [self.formerMessage mutableCopy];
+                            NSMutableDictionary *extend = [self.formerMessage[@"extend"] mutableCopy];
+                            [extend setObject:res[@"filePath"] forKey:@"localurl"];
+                            [mutableDict setObject:extend forKey:@"extend"];
+                            self.localurl = res[@"filePath"];
+                            NSDictionary *NewMsg = [mutableDict copy];
+                            [ChatsStore.shareInstance reciveMsg:NewMsg];
                             if (loading) {
                             if (loading) {
-                                loading(code);
+                                loading(100);
                             }
                             }
                         }
                         }
-                    }
-                } fail:^(NSError * _Nonnull error) {
-                    NSLog(@"error:%@",error);
-                }];
+                        else{
+                            if (code>=0&&code<200) {
+                                if (loading) {
+                                    loading(code);
+                                }
+                            }
+                        }
+                    } fail:^(NSError * _Nonnull error) {
+                        NSLog(@"error:%@",error);
+                    }];
+                }
             }
             }
             else{
             else{
                 if (loading) {
                 if (loading) {

+ 5 - 2
AIIM/Controller/chat/chetCell/chatCellView.m

@@ -697,7 +697,9 @@ static const CGFloat kMediaCornerRadius = 4.0f;
         [_textLbl yb_addAttributeTapActionWithStrings:array tapClicked:^(UILabel *label, NSString *string, NSRange range, NSInteger index) {
         [_textLbl yb_addAttributeTapActionWithStrings:array tapClicked:^(UILabel *label, NSString *string, NSRange range, NSInteger index) {
             NSLog(@"%ld:%@",(long)index,self->_matchesArray[index]);
             NSLog(@"%ld:%@",(long)index,self->_matchesArray[index]);
             NSTextCheckingResult *match=self->_matchesArray[index];
             NSTextCheckingResult *match=self->_matchesArray[index];
-            [[UIApplication sharedApplication] openURL:match.URL options:@{} completionHandler:nil];
+//            [[UIApplication sharedApplication] openURL:match.URL options:@{} completionHandler:nil];
+            // 点击后的操作
+            [FilePreviewer.shared previewFileWithLocalPath:@"" remoteURL:match.URL fromViewController:self.parentViewController];
         }];
         }];
     }
     }
     else{
     else{
@@ -1107,7 +1109,8 @@ static const CGFloat kMediaCornerRadius = 4.0f;
         NSString * recordString = @"";
         NSString * recordString = @"";
         switch ([messageType integerValue]) {
         switch ([messageType integerValue]) {
             case 0:
             case 0:
-                recordString = [NSString stringWithFormat:@"%@:%@\n",nickName,dict[@"content"]?:@""];//[NSString stringWithFormat:@"%@:%@\n",nickName,[CryptoAES.shareInstance decryptDataL:dict[@"content"]]];
+//                recordString = [NSString stringWithFormat:@"%@:%@\n",nickName,dict[@"content"]?:@""];
+                recordString = [NSString stringWithFormat:@"%@:%@\n",nickName,[CryptoAES.shareInstance decryptDataL:dict[@"content"]]];
                 break;
                 break;
             case 1:
             case 1:
                 recordString = [NSString stringWithFormat:@"%@:【图片】\n",nickName];;
                 recordString = [NSString stringWithFormat:@"%@:【图片】\n",nickName];;