浏览代码

收到图片消息无缩略图时,当查看大图后自动生成缩略图

heavyrian2012 2 年之前
父节点
当前提交
dde1497f2b

+ 2 - 0
.gitignore

@@ -11,3 +11,5 @@ wfclient/WFChatClient/Proto/libssl_arm64
 wfclient/WFChatClient/Proto/libssl_arm64_sim.a
 wfclient/WFChatClient/Proto/libcrypto_arm64.a
 wfclient/WFChatClient/Proto/libssl_arm64.a
+wfclient/build
+wfuikit/build

+ 1 - 1
wfclient/WFChatClient/Messages/WFCCImageMessageContent.h

@@ -43,7 +43,7 @@
 /**
  图片尺寸
  */
-@property (nonatomic, assign, readonly)CGSize size;
+@property (nonatomic, assign)CGSize size;
 
 /**
  图片缩略图参数

+ 0 - 6
wfclient/WFChatClient/Messages/WFCCImageMessageContent.m

@@ -12,9 +12,6 @@
 #import "WFCCUtilities.h"
 #import "Common.h"
 
-@interface WFCCImageMessageContent ()
-@property (nonatomic, assign)CGSize size;
-@end
 
 @implementation WFCCImageMessageContent
 + (instancetype)contentFrom:(UIImage *)image cachePath:(NSString *)path {
@@ -125,9 +122,6 @@
     return WFCCPersistFlag_PERSIST_AND_COUNT;
 }
 
-
-
-
 + (void)load {
     [[WFCCIMService sharedWFCIMService] registerMessageContent:self];
 }

+ 2 - 0
wfuikit/WFChatUIKit/MessageList/ViewController/WFCUMessageListViewController.m

@@ -3433,10 +3433,12 @@
     if([msg.content isKindOfClass:[WFCCImageMessageContent class]]) {
         WFCCImageMessageContent *imgCnt = (WFCCImageMessageContent *)msg.content;
         MWPhoto *photo = [MWPhoto photoWithURL:[NSURL URLWithString:imgCnt.remoteUrl]];
+        photo.message = msg;
         return photo;
     } else if([msg.content isKindOfClass:[WFCCVideoMessageContent class]]) {
         WFCCVideoMessageContent *videoCnt = (WFCCVideoMessageContent *)msg.content;
         MWPhoto *photo = [MWPhoto videoWithURL:[NSURL URLWithString:videoCnt.remoteUrl]];
+        photo.message = msg;
         return photo;
     }
     return nil;

+ 3 - 0
wfuikit/WFChatUIKit/Vendor/MWPhotoBrowser/MWPhoto.h

@@ -14,12 +14,15 @@
 // If you want to handle photos, caching, decompression
 // yourself then you can simply ensure your custom data model
 // conforms to MWPhotoProtocol
+@class WFCCMessage;
+
 @interface MWPhoto : NSObject <MWPhoto>
 
 @property (nonatomic, strong) NSString *caption;
 @property (nonatomic, strong) NSURL *videoURL;
 @property (nonatomic) BOOL emptyImage;
 @property (nonatomic) BOOL isVideo;
+@property (nonatomic, strong)WFCCMessage* message;
 
 + (MWPhoto *)photoWithImage:(UIImage *)image;
 + (MWPhoto *)photoWithURL:(NSURL *)url;

+ 19 - 0
wfuikit/WFChatUIKit/Vendor/MWPhotoBrowser/MWPhoto.m

@@ -12,6 +12,9 @@
 #import <AssetsLibrary/AssetsLibrary.h>
 #import "MWPhoto.h"
 #import "MWPhotoBrowser.h"
+#import <WFChatClient/WFCChatClient.h>
+#import "WFCUConfigManager.h"
+
 
 @interface MWPhoto () {
 
@@ -319,6 +322,22 @@
     _loadingInProgress = NO;
     // Notify on next run loop
     [self performSelector:@selector(postCompleteNotification) withObject:nil afterDelay:0];
+    
+    if(self.underlyingImage && [self.message.content isKindOfClass:[WFCCImageMessageContent class]]) {
+        WFCCImageMessageContent *imgCnt = (WFCCImageMessageContent *)self.message.content;
+        if(!imgCnt.localPath.length) {
+            UInt64 recordTime = [[NSDate date] timeIntervalSince1970]*1000;
+            NSString *cacheDir = [[WFCUConfigManager globalManager] cachePathOf:self.message.conversation mediaType:Media_Type_IMAGE];
+            NSString *path = [cacheDir stringByAppendingPathComponent:[NSString stringWithFormat:@"img%lld.jpg", recordTime]];
+            NSData *imgData = UIImageJPEGRepresentation(self.underlyingImage, 0.85);
+            if([imgData writeToFile:path atomically:YES]) {
+                imgCnt.localPath = path;
+                imgCnt.size = self.underlyingImage.size;
+                imgCnt.thumbnail = [WFCCUtilities generateThumbnail:self.underlyingImage withWidth:120 withHeight:120];
+                [[WFCCIMService sharedWFCIMService] updateMessage:self.message.messageId content:imgCnt];
+            }
+        }
+    }
 }
 
 - (void)postCompleteNotification {