|
|
@@ -113,10 +113,10 @@
|
|
|
// 其他自定义字段...
|
|
|
self.readStatus = [self getReadStatus];
|
|
|
|
|
|
- BOOL contain = [[NSFileManager defaultManager] fileExistsAtPath:self.localurl];
|
|
|
NSString *localPath = [self checkHasLocalPath];
|
|
|
- if (!contain && localPath.length) {
|
|
|
+ if (localPath.length) {
|
|
|
self.localurl = localPath;
|
|
|
+ [self updateFileSizeString];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -347,7 +347,6 @@
|
|
|
//下载视频文件
|
|
|
-(void)downloadFileIfNeed:(void(^)(NSInteger persent))loading{
|
|
|
if ([[NSFileManager defaultManager] fileExistsAtPath:self.localurl]){
|
|
|
- self.customFileSize = [self getFileSize];
|
|
|
if (loading) {
|
|
|
loading(100);
|
|
|
}
|
|
|
@@ -355,28 +354,6 @@
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- 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];
|
|
|
- if ([[NSFileManager defaultManager] fileExistsAtPath:documentsDirectoryURL.path]){
|
|
|
- NSLog(@"downloadFileIfNeed 1: %@", 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];
|
|
|
- self.customFileSize = [self getFileSize];
|
|
|
- if (loading) {
|
|
|
- loading(100);
|
|
|
- }
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
if (![self.url hasPrefix:@"http"]) {
|
|
|
NSLog(@"文件URL异常:%@", self.formerMessage);
|
|
|
return;
|
|
|
@@ -391,7 +368,7 @@
|
|
|
self.localurl = res[@"filePath"];
|
|
|
NSDictionary *NewMsg = [mutableDict copy];
|
|
|
[ChatsStore.shareInstance reciveMsg:NewMsg];
|
|
|
- self.customFileSize = [self getFileSize];
|
|
|
+ [self updateFileSizeString];
|
|
|
if (loading) {
|
|
|
loading(100);
|
|
|
}
|
|
|
@@ -427,7 +404,7 @@
|
|
|
|
|
|
#pragma mark - 消息状态管理
|
|
|
|
|
|
-- (NSString *)getFileSize {
|
|
|
+- (void)updateFileSizeString {
|
|
|
NSString *filePath = self.localurl;
|
|
|
|
|
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
|
@@ -450,31 +427,31 @@
|
|
|
NSLog(@"文件大小: %.2f KB (%.2f MB)", fileSizeKB, fileSizeMB);
|
|
|
string = [NSString stringWithFormat:@"%.2fMB", fileSizeMB];
|
|
|
}
|
|
|
- return string;
|
|
|
+ _customFileSize = string;
|
|
|
}
|
|
|
|
|
|
-- (NSString *)customFileSize {
|
|
|
- if (!_customFileSize) {
|
|
|
- _customFileSize = [self getFileSize];
|
|
|
- }
|
|
|
- return _customFileSize;
|
|
|
-}
|
|
|
|
|
|
- (NSString *)checkHasLocalPath {
|
|
|
- if ([[NSFileManager defaultManager] fileExistsAtPath:self.localurl]){
|
|
|
- self.customFileSize = [self getFileSize];
|
|
|
- NSLog(@"checkHasLocalPath 0: %@", self.localurl);
|
|
|
- return self.localurl;
|
|
|
+ if (!self.isUploadFile) {
|
|
|
+ return nil;
|
|
|
}
|
|
|
|
|
|
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];
|
|
|
- NSString *path = [documentsDirectoryURL URLByAppendingPathComponent:newfileName].path;
|
|
|
+
|
|
|
+ NSString *fileName;
|
|
|
+ NSURL *localURL = [NSURL URLWithString:self.localurl];
|
|
|
+ if (localURL) {
|
|
|
+ fileName = localURL.lastPathComponent;
|
|
|
+ } else {
|
|
|
+ fileName = [NSURL URLWithString:self.url].lastPathComponent;
|
|
|
+ }
|
|
|
+ if (fileName.length == 0) {
|
|
|
+ return nil;
|
|
|
+ }
|
|
|
+
|
|
|
+ NSString *path = [documentsDirectoryURL URLByAppendingPathComponent:fileName].path;
|
|
|
if ([[NSFileManager defaultManager] fileExistsAtPath:path]){
|
|
|
- NSLog(@"checkHasLocalPath 0: %@", path);
|
|
|
+ NSLog(@"checkHasLocalPath: %@", path);
|
|
|
return path;
|
|
|
}
|
|
|
return nil;
|