diff --git a/ChatKit-OC/ChatKit-OC.xcodeproj/project.pbxproj b/ChatKit-OC/ChatKit-OC.xcodeproj/project.pbxproj index 457f64e4..11dadb85 100644 --- a/ChatKit-OC/ChatKit-OC.xcodeproj/project.pbxproj +++ b/ChatKit-OC/ChatKit-OC.xcodeproj/project.pbxproj @@ -830,7 +830,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; 5852033203B0746EE8645654 /* 📦 Copy Pods Resources */ = { diff --git a/ChatKit-OC/Podfile.lock b/ChatKit-OC/Podfile.lock index 679465a2..0b545296 100644 --- a/ChatKit-OC/Podfile.lock +++ b/ChatKit-OC/Podfile.lock @@ -9,7 +9,7 @@ PODS: - AVOSCloudIM/_NOARC (= 8.2.0) - AVOSCloudIM/_NOARC (8.2.0): - AVOSCloud (= 8.2.0) - - ChatKit (2.0.3): + - ChatKit (2.1.0): - AVOSCloud (~> 8.2.0) - AVOSCloudIM (~> 8.2.0) - CYLDeallocBlockExecutor (~> 1.1.2) @@ -62,12 +62,12 @@ DEPENDENCIES: EXTERNAL SOURCES: ChatKit: - :path: ../ + :path: "../" SPEC CHECKSUMS: AVOSCloud: c28318404ce474e722e09c8ac103fc58b2610074 AVOSCloudIM: 62c0d6307df41ce682f7cf11463254cc49318e24 - ChatKit: 4ae53ec69e88025a529b7e7b5e95a2f68564e2e5 + ChatKit: e0c626e492a9abba73b77462ac4570183a82e3ec CYLDeallocBlockExecutor: ecf39e45dcead9e120f460df5668b8f5093d178e CYLTabBarController: 8d99fccf22866fe18c978c5ff863dc6051da45ff DACircularProgress: 4dd437c0fc3da5161cb289e07ac449493d41db71 @@ -90,4 +90,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: d16020c2760c0b23c86274a3c4bed9aa620de53a -COCOAPODS: 1.3.1 +COCOAPODS: 1.2.0 diff --git a/ChatKit-OC/README.md b/ChatKit-OC/README.md new file mode 100644 index 00000000..e7039b9d --- /dev/null +++ b/ChatKit-OC/README.md @@ -0,0 +1,10 @@ +# 解决之前发送长方形图片接收之后cell高度显示不对的bug + +# 解决图片在加载之后闪一下的bug + +直线之后对比: + +![before](http://oahmyhzk1.bkt.clouddn.com/2018-01-27-before.gif) + + ![afte](http://oahmyhzk1.bkt.clouddn.com/2018-01-27-after.gif) + diff --git a/ChatKit-OC/after.gif b/ChatKit-OC/after.gif new file mode 100644 index 00000000..67139d0a Binary files /dev/null and b/ChatKit-OC/after.gif differ diff --git a/ChatKit-OC/before.gif b/ChatKit-OC/before.gif new file mode 100644 index 00000000..f8e3dd64 Binary files /dev/null and b/ChatKit-OC/before.gif differ diff --git a/ChatKit/Class/Model/LCCKMessage.h b/ChatKit/Class/Model/LCCKMessage.h index b1ff1c3e..3ac4f308 100644 --- a/ChatKit/Class/Model/LCCKMessage.h +++ b/ChatKit/Class/Model/LCCKMessage.h @@ -14,6 +14,13 @@ @interface LCCKMessage : NSObject +/// Width of the image in pixels. +@property(nonatomic, assign, readonly) int photoWidth; + +/// Height of the image in pixels. +@property(nonatomic, assign, readonly) int photoHeight; + + @property (nonatomic, copy, readonly) NSString *text; @property (nonatomic, copy, readonly) NSString *systemText; @property (nonatomic, strong, readwrite) UIImage *photo; @@ -55,8 +62,8 @@ @property (nonatomic, copy, readonly) NSString *localDisplayName; - (instancetype)initWithText:(NSString *)text - senderId:(NSString *)senderId - sender:(id)sender + senderId:(NSString *)senderId + sender:(id)sender timestamp:(NSTimeInterval)timestamp serverMessageId:(NSString *)serverMessageId; @@ -69,6 +76,8 @@ * 初始化图片类型的消息 * * @param photo 目标图片 + * @param photoWidth 图片的实际宽度 + * @param photoHeight 图片的实际高度 * @param photePath 目标图片的本地路径 * @param thumbnailURL 目标图片在服务器的缩略图地址 * @param originPhotoURL 目标图片在服务器的原图地址 @@ -78,11 +87,13 @@ * @return 返回Message model 对象 */ - (instancetype)initWithPhoto:(UIImage *)photo + photoWidth:(uint)photoWidth + photoHeight:(uint)photoHeight thumbnailPhoto:(UIImage *)thumbnailPhoto photoPath:(NSString *)photoPath thumbnailURL:(NSURL *)thumbnailURL originPhotoURL:(NSURL *)originPhotoURL - senderId:(NSString *)senderId + senderId:(NSString *)senderId sender:(id)sender timestamp:(NSTimeInterval)timestamp serverMessageId:(NSString *)serverMessageId; @@ -101,8 +112,8 @@ - (instancetype)initWithVideoConverPhoto:(UIImage *)videoConverPhoto videoPath:(NSString *)videoPath videoURL:(NSURL *)videoURL - senderId:(NSString *)senderId - sender:(id)sender + senderId:(NSString *)senderId + sender:(id)sender timestamp:(NSTimeInterval)timestamp serverMessageId:(NSString *)serverMessageId; @@ -120,8 +131,8 @@ - (instancetype)initWithVoicePath:(NSString *)voicePath voiceURL:(NSURL *)voiceURL voiceDuration:(NSString *)voiceDuration - senderId:(NSString *)senderId - sender:(id)sender + senderId:(NSString *)senderId + sender:(id)sender timestamp:(NSTimeInterval)timestamp serverMessageId:(NSString *)serverMessageId; @@ -140,20 +151,21 @@ - (instancetype)initWithVoicePath:(NSString *)voicePath voiceURL:(NSURL *)voiceURL voiceDuration:(NSString *)voiceDuration - senderId:(NSString *)senderId - sender:(id)sender + senderId:(NSString *)senderId + sender:(id)sender timestamp:(NSTimeInterval)timestamp - hasRead:(BOOL)hasRead + hasRead:(BOOL)hasRead serverMessageId:(NSString *)serverMessageId; - (instancetype)initWithLocalPositionPhoto:(UIImage *)localPositionPhoto geolocations:(NSString *)geolocations location:(CLLocation *)location - senderId:(NSString *)senderId - sender:(id)sender + senderId:(NSString *)senderId + sender:(id)sender timestamp:(NSTimeInterval)timestamp serverMessageId:(NSString *)serverMessageId; + (id)messageWithAVIMTypedMessage:(AVIMTypedMessage *)message; @end + diff --git a/ChatKit/Class/Model/LCCKMessage.m b/ChatKit/Class/Model/LCCKMessage.m index 3561febd..f4e7c363 100644 --- a/ChatKit/Class/Model/LCCKMessage.m +++ b/ChatKit/Class/Model/LCCKMessage.m @@ -5,7 +5,6 @@ // v0.8.5 Created by ElonChan on 16/3/21. // Copyright © 2016年 LeanCloud. All rights reserved. // - #import "LCCKMessage.h" #import "LCCKSessionService.h" #import "LCCKUserSystemService.h" @@ -61,8 +60,8 @@ @implementation LCCKMessage @synthesize ownerType = _ownerType; - (instancetype)initWithText:(NSString *)text - senderId:(NSString *)senderId - sender:(id)sender + senderId:(NSString *)senderId + sender:(id)sender timestamp:(NSTimeInterval)timestamp serverMessageId:(NSString *)serverMessageId { self = [super init]; @@ -148,16 +147,20 @@ + (instancetype)localFeedbackText:(NSString *)localFeedbackText { } - (instancetype)initWithPhoto:(UIImage *)photo + photoWidth:(uint)photoWidth + photoHeight:(uint)photoHeight thumbnailPhoto:(UIImage *)thumbnailPhoto photoPath:(NSString *)photoPath thumbnailURL:(NSURL *)thumbnailURL originPhotoURL:(NSURL *)originPhotoURL - senderId:(NSString *)senderId - sender:(id)sender + senderId:(NSString *)senderId + sender:(id)sender timestamp:(NSTimeInterval)timestamp serverMessageId:(NSString *)serverMessageId { self = [super init]; if (self) { + _photoWidth = photoWidth; + _photoHeight = photoHeight; _photo = photo; _thumbnailPhoto = thumbnailPhoto; _photoPath = photoPath; @@ -175,8 +178,8 @@ - (instancetype)initWithPhoto:(UIImage *)photo - (instancetype)initWithVideoConverPhoto:(UIImage *)videoConverPhoto videoPath:(NSString *)videoPath videoURL:(NSURL *)videoURL - senderId:(NSString *)senderId - sender:(id)sender + senderId:(NSString *)senderId + sender:(id)sender timestamp:(NSTimeInterval)timestamp serverMessageId:(NSString *)serverMessageId { self = [super init]; @@ -196,8 +199,8 @@ - (instancetype)initWithVideoConverPhoto:(UIImage *)videoConverPhoto - (instancetype)initWithVoicePath:(NSString *)voicePath voiceURL:(NSURL *)voiceURL voiceDuration:(NSString *)voiceDuration - senderId:(NSString *)senderId - sender:(id)sender + senderId:(NSString *)senderId + sender:(id)sender timestamp:(NSTimeInterval)timestamp serverMessageId:(NSString *)serverMessageId { @@ -207,11 +210,11 @@ - (instancetype)initWithVoicePath:(NSString *)voicePath - (instancetype)initWithVoicePath:(NSString *)voicePath voiceURL:(NSURL *)voiceURL voiceDuration:(NSString *)voiceDuration - senderId:(NSString *)senderId - sender:(id)sender + senderId:(NSString *)senderId + sender:(id)sender timestamp:(NSTimeInterval)timestamp - hasRead:(BOOL)hasRead - serverMessageId:(NSString *)serverMessageId { + hasRead:(BOOL)hasRead + serverMessageId:(NSString *)serverMessageId { self = [super init]; if (self) { _voicePath = voicePath; @@ -257,8 +260,8 @@ - (instancetype)initWithVoicePath:(NSString *)voicePath - (instancetype)initWithLocalPositionPhoto:(UIImage *)localPositionPhoto geolocations:(NSString *)geolocations location:(CLLocation *)location - senderId:(NSString *)senderId - sender:(id)sender + senderId:(NSString *)senderId + sender:(id)sender timestamp:(NSTimeInterval)timestamp serverMessageId:(NSString *)serverMessageId { self = [super init]; @@ -328,7 +331,7 @@ + (id)messageWithAVIMTypedMessage:(AVIMTypedMessage *)message { if ([fileManager fileExistsAtPath:pathForFile]){ imagePath = imageMsg.file.localPath; } - lcckMessage = [[LCCKMessage alloc] initWithPhoto:nil thumbnailPhoto:nil photoPath:imagePath thumbnailURL:nil originPhotoURL:[NSURL URLWithString:imageMsg.file.url] senderId:senderId sender:sender timestamp:time serverMessageId:serverMessageId]; + lcckMessage = [[LCCKMessage alloc] initWithPhoto:nil photoWidth:imageMsg.width photoHeight: imageMsg.height thumbnailPhoto:nil photoPath:imagePath thumbnailURL:nil originPhotoURL:[NSURL URLWithString:imageMsg.file.url] senderId:senderId sender:sender timestamp:time serverMessageId:serverMessageId]; break; } @@ -346,7 +349,7 @@ + (id)messageWithAVIMTypedMessage:(AVIMTypedMessage *)message { default: { NSString *degradeContent; @try { - degradeContent = [message.attributes objectForKey:LCCKCustomMessageDegradeKey]; + degradeContent = [message.attributes objectForKey:LCCKCustomMessageDegradeKey]; } @catch (NSException *exception) {} @finally { if (!degradeContent) { degradeContent = LCCKLocalizedStrings(@"unknownMessage"); @@ -364,7 +367,7 @@ + (id)messageWithAVIMTypedMessage:(AVIMTypedMessage *)message { lcckMessage.ownerType = LCCKMessageOwnerTypeOther; } lcckMessage.sendStatus = (LCCKMessageSendState)message.status; - + return lcckMessage; } @@ -404,7 +407,7 @@ - (id)initWithCoder:(NSCoder *)aDecoder { _conversationId = [aDecoder decodeObjectForKey:@"conversationId"]; _mediaType = [aDecoder decodeIntForKey:@"mediaType"]; -// _messageGroupType = [aDecoder decodeIntForKey:@"messageGroupType"]; + // _messageGroupType = [aDecoder decodeIntForKey:@"messageGroupType"]; _messageReadState = [aDecoder decodeIntForKey:@"messageReadState"]; _ownerType = [aDecoder decodeIntForKey:@"ownerType"]; _read = [aDecoder decodeBoolForKey:@"read"]; @@ -445,7 +448,7 @@ - (void)encodeWithCoder:(NSCoder *)aCoder { [aCoder encodeObject:self.conversationId forKey:@"conversationId"]; [aCoder encodeInt:self.mediaType forKey:@"mediaType"]; -// [aCoder encodeInt:self.messageGroupType forKey:@"messageGroupType"]; + // [aCoder encodeInt:self.messageGroupType forKey:@"messageGroupType"]; [aCoder encodeInt:self.messageReadState forKey:@"messageReadState"]; [aCoder encodeInt:self.ownerType forKey:@"ownerType"]; [aCoder encodeBool:self.read forKey:@"read"]; @@ -462,8 +465,8 @@ - (id)copyWithZone:(NSZone *)zone { switch (self.mediaType) { case kAVIMMessageMediaTypeText: { message = [[[self class] allocWithZone:zone] initWithText:[self.text copy] - senderId:[self.senderId copy] - sender:[self.sender copyWithZone:nil] + senderId:[self.senderId copy] + sender:[self.sender copyWithZone:nil] timestamp:self.timestamp serverMessageId:[self.serverMessageId copy]]; @@ -471,55 +474,57 @@ - (id)copyWithZone:(NSZone *)zone { break; case kAVIMMessageMediaTypeImage: { message = [[[self class] allocWithZone:zone] initWithPhoto:[self.photo copy] + photoWidth:self.photoWidth + photoHeight:self.photoHeight thumbnailPhoto:[self.thumbnailPhoto copy] photoPath:[self.photoPath copy] thumbnailURL:[self.thumbnailURL copy] originPhotoURL:[self.originPhotoURL copy] - senderId:[self.senderId copy] - sender:[self.sender copyWithZone:nil] + senderId:[self.senderId copy] + sender:[self.sender copyWithZone:nil] timestamp:self.timestamp serverMessageId:[self.serverMessageId copy]]; - + } break; case kAVIMMessageMediaTypeVideo: { message = [[[self class] allocWithZone:zone] initWithVideoConverPhoto:[self.videoConverPhoto copy] videoPath:[self.videoPath copy] videoURL:[self.videoURL copy] - senderId:[self.senderId copy] - sender:[self.sender copyWithZone:nil] + senderId:[self.senderId copy] + sender:[self.sender copyWithZone:nil] timestamp:self.timestamp serverMessageId:[self.serverMessageId copy]]; - + } break; case kAVIMMessageMediaTypeAudio: { message = [[[self class] allocWithZone:zone] initWithVoicePath:[self.voicePath copy] voiceURL:[self.voiceURL copy] voiceDuration:[self.voiceDuration copy] - senderId:[self.senderId copy] - sender:[self.sender copyWithZone:nil] + senderId:[self.senderId copy] + sender:[self.sender copyWithZone:nil] timestamp:self.timestamp serverMessageId:[self.serverMessageId copy]]; - + } break; -// case LCCKMessageTypeEmotion: { -// message = [[[self class] allocWithZone:zone] initWithEmotionPath:[self.emotionPath copy] -// emotionName:[self.emotionName copy] -// senderId:[self.senderId copy] -// sender:[self.sender copyWithZone:nil] -// timestamp:self.timestamp -// serverMessageId:[self.serverMessageId copy]]; -// -// } -// break; + // case LCCKMessageTypeEmotion: { + // message = [[[self class] allocWithZone:zone] initWithEmotionPath:[self.emotionPath copy] + // emotionName:[self.emotionName copy] + // senderId:[self.senderId copy] + // sender:[self.sender copyWithZone:nil] + // timestamp:self.timestamp + // serverMessageId:[self.serverMessageId copy]]; + // + // } + // break; case kAVIMMessageMediaTypeLocation: { message = [[[self class] allocWithZone:zone] initWithLocalPositionPhoto:[self.localPositionPhoto copy] geolocations:[self.geolocations copy] location:[self.location copy] - senderId:[self.senderId copy] - sender:[self.sender copyWithZone:nil] + senderId:[self.senderId copy] + sender:[self.sender copyWithZone:nil] timestamp:self.timestamp serverMessageId:[self.serverMessageId copy]]; } @@ -539,7 +544,7 @@ - (id)copyWithZone:(NSZone *)zone { message.localMessageId = [self.localMessageId copy]; message.conversationId = [self.conversationId copy]; message.mediaType = self.mediaType; -// message.messageGroupType = self.messageGroupType; + // message.messageGroupType = self.messageGroupType; message.messageReadState = self.messageReadState; message.sendStatus = self.sendStatus; message.read = self.read; @@ -547,3 +552,4 @@ - (id)copyWithZone:(NSZone *)zone { } @end + diff --git a/ChatKit/Class/Module/Conversation/Controller/LCCKConversationViewController.m b/ChatKit/Class/Module/Conversation/Controller/LCCKConversationViewController.m index 3e02f9ca..d6acd39e 100644 --- a/ChatKit/Class/Module/Conversation/Controller/LCCKConversationViewController.m +++ b/ChatKit/Class/Module/Conversation/Controller/LCCKConversationViewController.m @@ -314,6 +314,8 @@ - (void)sendImageMessageData:(NSData *)imageData { UIImage *thumbnailPhoto = [representationImage lcck_imageByScalingAspectFill]; if (error == nil) { LCCKMessage *message = [[LCCKMessage alloc] initWithPhoto:representationImage + photoWidth:nil + photoHeight:nil thumbnailPhoto:thumbnailPhoto photoPath:path thumbnailURL:nil diff --git a/ChatKit/Class/Module/Conversation/View/ChatMessageCell/LCCKChatImageMessageCell.m b/ChatKit/Class/Module/Conversation/View/ChatMessageCell/LCCKChatImageMessageCell.m index 3520e122..dce284d7 100644 --- a/ChatKit/Class/Module/Conversation/View/ChatMessageCell/LCCKChatImageMessageCell.m +++ b/ChatKit/Class/Module/Conversation/View/ChatMessageCell/LCCKChatImageMessageCell.m @@ -10,9 +10,9 @@ #import "UIImage+LCCKExtension.h" #if __has_include() - #import +#import #else - #import "UIImageView+WebCache.h" +#import "UIImageView+WebCache.h" #endif @interface LCCKChatImageMessageCell () @@ -92,15 +92,42 @@ - (void)configureCellWithData:(LCCKMessage *)message { message.thumbnailPhoto = resizedImage; break; } - // requied! if (message.originPhotoURL) { - [self.messageImageView sd_setImageWithURL:message.originPhotoURL placeholderImage:[self imageInBundleForImageName:@"Placeholder_Image"] + UIImage *image = [self imageInBundleForImageName:@"Placeholder_Image"]; + CGSize photoSize = CGSizeMake(message.photoWidth, message.photoHeight); + UIImage *newImage = [image lcck_imageByScalingAspectFillWithOriginSize:photoSize]; + self.messageImageView.contentMode = UIViewContentModeScaleAspectFit; + + UIEdgeInsets edgeMessageBubbleCustomize; + if (message.ownerType == LCCKMessageOwnerTypeSelf) { + UIEdgeInsets rightEdgeMessageBubbleCustomize = [LCCKSettingService sharedInstance].rightHollowEdgeMessageBubbleCustomize; + edgeMessageBubbleCustomize = rightEdgeMessageBubbleCustomize; + } else { + UIEdgeInsets leftEdgeMessageBubbleCustomize = [LCCKSettingService sharedInstance].leftHollowEdgeMessageBubbleCustomize; + edgeMessageBubbleCustomize = leftEdgeMessageBubbleCustomize; + } + + if (message.ownerType == LCCKMessageOwnerTypeSelf) { + [self.messageImageView mas_updateConstraints:^(MASConstraintMaker *make) { + make.edges.equalTo(self.messageContentView).with.insets(edgeMessageBubbleCustomize); + make.height.mas_equalTo(newImage.size.height); + make.width.mas_equalTo(newImage.size.width); + }]; + }else { + [self.messageImageView mas_updateConstraints:^(MASConstraintMaker *make) { + make.edges.equalTo(self.messageContentView).with.insets(edgeMessageBubbleCustomize); + make.height.mas_equalTo(newImage.size.height); + make.width.mas_equalTo(newImage.size.width); + }]; + } + + [self.messageImageView sd_setImageWithURL:message.originPhotoURL placeholderImage:newImage completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { dispatch_async(dispatch_get_main_queue(),^{ if (image){ message.photo = image; - message.thumbnailPhoto = [image lcck_imageByScalingAspectFill]; + message.thumbnailPhoto = [image lcck_imageByScalingAspectFillWithOriginSize:photoSize]; if ([self.delegate respondsToSelector:@selector(fileMessageDidDownload:)]) { [self.delegate fileMessageDidDownload:self]; } @@ -115,6 +142,8 @@ - (void)configureCellWithData:(LCCKMessage *)message { } while (NO); } + + - (UIImage *)imageInBundleForImageName:(NSString *)imageName { return ({ UIImage *image = [UIImage lcck_imageNamed:imageName bundleName:@"Placeholder" bundleForClass:[self class]]; @@ -143,7 +172,7 @@ - (void)setMessageSendState:(LCCKMessageSendState)messageSendState { - (void)removeProgressView { [self.messageProgressView removeFromSuperview]; - [[self.messageProgressView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)]; + [[self.messageProgressView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)]; self.messageProgressView = nil; self.messageProgressLabel = nil; } @@ -154,7 +183,7 @@ - (UIImageView *)messageImageView { if (!_messageImageView) { _messageImageView = [[UIImageView alloc] init]; //FIXME:这一行可以不需要 - _messageImageView.contentMode = UIViewContentModeScaleAspectFill; + _messageImageView.contentMode = UIViewContentModeScaleAspectFit; } return _messageImageView; @@ -187,3 +216,4 @@ + (AVIMMessageMediaType)classMediaType { } @end +