Commit 18c84b081e74a897bab81bd698944f8f0173a277

Authored by daojian
1 parent 8b9cd574

0.3.0 版本 自定义消息数据解析后进行缓存处理

CNLiveNewIMAManagerKit.podspec
@@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
8 8
9 Pod::Spec.new do |s| 9 Pod::Spec.new do |s|
10 s.name = 'CNLiveNewIMAManagerKit' 10 s.name = 'CNLiveNewIMAManagerKit'
11 - s.version = '0.2.9' 11 + s.version = '0.3.0'
12 s.summary = 'A short description of CNLiveNewIMAManagerKit.' 12 s.summary = 'A short description of CNLiveNewIMAManagerKit.'
13 13
14 #s.description = <<-DESC 14 #s.description = <<-DESC
CNLiveNewIMAManagerKit/Classes/TIMCategory/TIMElem+ShowAPIs.m
@@ -648,9 +648,8 @@ @@ -648,9 +648,8 @@
648 break; 648 break;
649 case EIMAMSG_ShareLink: 649 case EIMAMSG_ShareLink:
650 { 650 {
651 - TIMCustomElem *elem = (TIMCustomElem *)[packMsg.msg getElem:0];  
652 - NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:elem.data options:NSJSONReadingMutableContainers error:nil];  
653 - NSDictionary *shareFriendData = [dic objectForKey:@"shareFriendData"]; 651 +
  652 + NSDictionary *shareFriendData = [packMsg.customMsgData objectForKey:@"shareFriendData"];
654 NSString *titleStr = shareFriendData[@"title"]; 653 NSString *titleStr = shareFriendData[@"title"];
655 CGSize titleSize = [titleStr boundingRectWithSize:CGSizeMake(241-18-17, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : UIFontCNMake(15)} context:nil].size; 654 CGSize titleSize = [titleStr boundingRectWithSize:CGSizeMake(241-18-17, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : UIFontCNMake(15)} context:nil].size;
656 if (titleSize.height > 36) { 655 if (titleSize.height > 36) {
@@ -767,9 +766,8 @@ @@ -767,9 +766,8 @@
767 break; 766 break;
768 case EIMAMSG_FamilyHealthyStep: 767 case EIMAMSG_FamilyHealthyStep:
769 { 768 {
770 - TIMCustomElem *customElem = (TIMCustomElem *)[packMsg.msg getElem:0];  
771 - NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:customElem.data options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];  
772 - NSDictionary *familyHealthyStepTotalData = [dic objectForKey:@"familyHealthyStepTotalData"]; 769 +
  770 + NSDictionary *familyHealthyStepTotalData = [packMsg.customMsgData objectForKey:@"familyHealthyStepTotalData"];
773 NSString *totalStep = [NSString stringWithFormat:@"%@",familyHealthyStepTotalData[@"totalStep"]]; 771 NSString *totalStep = [NSString stringWithFormat:@"%@",familyHealthyStepTotalData[@"totalStep"]];
774 if ([totalStep integerValue] == 0) { 772 if ([totalStep integerValue] == 0) {
775 return CGSizeMake(width, 110*RATIO); 773 return CGSizeMake(width, 110*RATIO);
@@ -834,10 +832,8 @@ @@ -834,10 +832,8 @@
834 /// @param packMsg 消息 832 /// @param packMsg 消息
835 - (CGSize)aitMsgInWith:(CGFloat)width atMsg:(IMAMsg *)packMsg 833 - (CGSize)aitMsgInWith:(CGFloat)width atMsg:(IMAMsg *)packMsg
836 { 834 {
837 - TIMCustomElem *customElem = (TIMCustomElem *)[packMsg.msg getElem:0];  
838 - NSData *data = [customElem data];  
839 - NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];  
840 - NSDictionary *groupAitDic = [dic objectForKey:@"groupAit"]; 835 +
  836 + NSDictionary *groupAitDic = [packMsg.customMsgData objectForKey:@"groupAit"];
841 // NSString* content = customElem.desc; 837 // NSString* content = customElem.desc;
842 NSString *content = groupAitDic[@"aitDesc"]; 838 NSString *content = groupAitDic[@"aitDesc"];
843 839
@@ -879,12 +875,8 @@ @@ -879,12 +875,8 @@
879 /// @param packMsg 消息 875 /// @param packMsg 消息
880 - (CGFloat)orderConfirmMsgHeight:(IMAMsg *)packMsg { 876 - (CGFloat)orderConfirmMsgHeight:(IMAMsg *)packMsg {
881 877
882 - TIMCustomElem *elem = (TIMCustomElem *)[packMsg.msg getElem:0];  
883 - NSError *err;  
884 - NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:elem.data  
885 - options:NSJSONReadingMutableContainers  
886 - error:&err];  
887 - NSDictionary *orderCheckData = dic[@"orderCheckData"]; 878 +
  879 + NSDictionary *orderCheckData = packMsg.customMsgData[@"orderCheckData"];
888 NSArray *goodsInfo = orderCheckData[@"goodsInfo"]; 880 NSArray *goodsInfo = orderCheckData[@"goodsInfo"];
889 CGFloat validWidth = KScreenWidth-28; 881 CGFloat validWidth = KScreenWidth-28;
890 882
@@ -905,12 +897,8 @@ @@ -905,12 +897,8 @@
905 /// @param packMsg 消息 897 /// @param packMsg 消息
906 - (CGFloat)e_businessOrderPaySuccess:(IMAMsg *)packMsg 898 - (CGFloat)e_businessOrderPaySuccess:(IMAMsg *)packMsg
907 { 899 {
908 - TIMCustomElem *elem = (TIMCustomElem *)[packMsg.msg getElem:0];  
909 - NSError *err;  
910 - NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:elem.data  
911 - options:NSJSONReadingMutableContainers  
912 - error:&err];  
913 - NSDictionary *dataDic = [dic objectForKey:@"payData"]; 900 +
  901 + NSDictionary *dataDic = [packMsg.customMsgData objectForKey:@"payData"];
914 NSDictionary *orderInfoDic = [dataDic objectForKey:@"orderInfo"]; 902 NSDictionary *orderInfoDic = [dataDic objectForKey:@"orderInfo"];
915 if (orderInfoDic) { 903 if (orderInfoDic) {
916 NSArray *goodsInfo = orderInfoDic[@"goodsInfo"]; 904 NSArray *goodsInfo = orderInfoDic[@"goodsInfo"];
@@ -933,8 +921,7 @@ @@ -933,8 +921,7 @@
933 width = max; 921 width = max;
934 } 922 }
935 923
936 - TIMCustomElem *elem = (TIMCustomElem *)[packMsg.msg getElem:0];  
937 - NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:elem.data options:NSJSONReadingMutableContainers error:nil];; 924 + NSDictionary *dic = packMsg.customMsgData;
938 925
939 NSString *str1 = [NSString stringWithFormat:@"收货地址: %@",dic[@"orderReceiverInfoData"][@"contactAddress"]]; 926 NSString *str1 = [NSString stringWithFormat:@"收货地址: %@",dic[@"orderReceiverInfoData"][@"contactAddress"]];
940 NSString *str2 = [NSString stringWithFormat:@"收货人: %@",dic[@"orderReceiverInfoData"][@"contactName"]]; 927 NSString *str2 = [NSString stringWithFormat:@"收货人: %@",dic[@"orderReceiverInfoData"][@"contactName"]];
@@ -966,12 +953,7 @@ @@ -966,12 +953,7 @@
966 /// @param packMsg 消息 953 /// @param packMsg 消息
967 - (CGFloat)orderStatusMsgHeight:(IMAMsg *)packMsg { 954 - (CGFloat)orderStatusMsgHeight:(IMAMsg *)packMsg {
968 955
969 - TIMCustomElem *elem = (TIMCustomElem *)[packMsg.msg getElem:0];  
970 - NSError *err;  
971 - NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:elem.data  
972 - options:NSJSONReadingMutableContainers  
973 - error:&err];  
974 - NSString *text = dic[@"alertMsg"]; 956 + NSString *text = packMsg.customMsgData[@"alertMsg"];
975 if ([packMsg isMineMsg] && [text containsString:@"开启了全员禁言"]) { 957 if ([packMsg isMineMsg] && [text containsString:@"开启了全员禁言"]) {
976 text = @"你开启了全员禁言"; 958 text = @"你开启了全员禁言";
977 } 959 }
@@ -990,12 +972,8 @@ @@ -990,12 +972,8 @@
990 /// @param packMsg 消息 972 /// @param packMsg 消息
991 - (CGSize)spGroupNewLiveMsgHeight:(IMAMsg *)packMsg 973 - (CGSize)spGroupNewLiveMsgHeight:(IMAMsg *)packMsg
992 { 974 {
993 - TIMCustomElem *elem = (TIMCustomElem *)[packMsg.msg getElem:0];  
994 - NSError *err;  
995 - NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:elem.data  
996 - options:NSJSONReadingMutableContainers  
997 - error:&err];  
998 - NSString *text = dic[@"alertMsg"]; 975 +
  976 + NSString *text = packMsg.customMsgData[@"alertMsg"];
999 CGSize size = [text textSizeIn:CGSizeMake(KScreenWidth-20, HUGE_VAL) font:UIFontCNMake(14)]; 977 CGSize size = [text textSizeIn:CGSizeMake(KScreenWidth-20, HUGE_VAL) font:UIFontCNMake(14)];
1000 packMsg.showContentSizeInChat = size; 978 packMsg.showContentSizeInChat = size;
1001 size.height += 10; 979 size.height += 10;
CNLiveNewIMAManagerKit/Classes/TIMModel/MSG/IMAMsg.h
@@ -270,6 +270,9 @@ typedef NS_ENUM(NSInteger, CNVoiceToWordsStatus){ @@ -270,6 +270,9 @@ typedef NS_ENUM(NSInteger, CNVoiceToWordsStatus){
270 /// 消息状态 270 /// 消息状态
271 @property (nonatomic, readonly) NSInteger status; 271 @property (nonatomic, readonly) NSInteger status;
272 272
  273 +/// 自定义消息 json数据解析后的数据
  274 +@property (nonatomic, readonly, strong) NSDictionary *customMsgData;
  275 +
273 /// 是否正在播放语音 276 /// 是否正在播放语音
274 @property (nonatomic, assign) BOOL isPlayingSuond; 277 @property (nonatomic, assign) BOOL isPlayingSuond;
275 278
@@ -287,11 +290,16 @@ typedef NS_ENUM(NSInteger, CNVoiceToWordsStatus){ @@ -287,11 +290,16 @@ typedef NS_ENUM(NSInteger, CNVoiceToWordsStatus){
287 290
288 /** -------语音转文字时用的的一些属性--------*/ 291 /** -------语音转文字时用的的一些属性--------*/
289 292
290 -@property (nonatomic, assign) BOOL isVoiceToWords; //是语音转文字  
291 -@property (nonatomic, strong) IMAMsg *voiceMsg; //被转成文字的语音消息  
292 -@property (nonatomic, copy) NSString *voiceText; // 语音文字  
293 -@property (nonatomic, assign) CNVoiceToWordsStatus vioceToWordStatus; //语音转文字状态  
294 -@property (nonatomic, copy) NSString *vioceToWordErrorMsg; // 语音文字 293 +/// 是语音转文字
  294 +@property (nonatomic, assign) BOOL isVoiceToWords;
  295 +/// 被转成文字的语音消息
  296 +@property (nonatomic, strong) IMAMsg *voiceMsg;
  297 +/// 语音文字
  298 +@property (nonatomic, copy) NSString *voiceText;
  299 +///语音转文字状态
  300 +@property (nonatomic, assign) CNVoiceToWordsStatus vioceToWordStatus;
  301 +/// 语音文字
  302 +@property (nonatomic, copy) NSString *vioceToWordErrorMsg;
295 303
296 304
297 /// 根据 TIMMessage 生成 IMAMsg 对象 305 /// 根据 TIMMessage 生成 IMAMsg 对象
CNLiveNewIMAManagerKit/Classes/TIMModel/MSG/IMAMsg.m
@@ -26,6 +26,21 @@ @@ -26,6 +26,21 @@
26 _msg = msg; 26 _msg = msg;
27 _type = type; 27 _type = type;
28 _status = EIMAMsg_Init; 28 _status = EIMAMsg_Init;
  29 +
  30 + TIMElem *elem = [msg getElem:0];
  31 +
  32 + /**判断是否是自定义消息*/
  33 + if ([elem isKindOfClass:[TIMCustomElem class]]) {
  34 +
  35 + //解析自定义消息,并把解析后的数据赋值给 _customMsgData
  36 + TIMCustomElem *cusElem = (TIMCustomElem *)elem;
  37 + NSError *err;
  38 + NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:cusElem.data
  39 + options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves
  40 + error:&err];
  41 +
  42 + _customMsgData = dic;
  43 + }
29 } 44 }
30 return self; 45 return self;
31 } 46 }
@@ -520,17 +535,6 @@ @@ -520,17 +535,6 @@
520 { 535 {
521 type = EIMAMSG_SendCurrentlocation; 536 type = EIMAMSG_SendCurrentlocation;
522 } 537 }
523 -// else if([dic[@"type"] integerValue] == CustomMsgTypeInitiatingSharedLocation)  
524 -// {  
525 -// type = EIMAMSG_Sharelocation;  
526 -// }else if([dic[@"type"] integerValue] == CustomMsgTypeCurrentSharedLocation)  
527 -// {  
528 -// type = EIMAMSG_Currentlocation;  
529 -// }  
530 -// else if([dic[@"type"] integerValue] == CustomMsgTypeSharedLocationEndTip)  
531 -// {  
532 -// type = EIMAMSG_SharelocationEndTip;  
533 -// }  
534 else if ([dic[@"type"] integerValue] == CustomMsgTypeSendCard || [dic[@"type"] integerValue] == CustomMsgTypeSendDarenCard) 538 else if ([dic[@"type"] integerValue] == CustomMsgTypeSendCard || [dic[@"type"] integerValue] == CustomMsgTypeSendDarenCard)
535 { 539 {
536 type = EIMAMSG_SendCard; 540 type = EIMAMSG_SendCard;
@@ -955,9 +959,7 @@ @@ -955,9 +959,7 @@
955 //对转余额消息进行特殊处理 959 //对转余额消息进行特殊处理
956 attStr = [[NSMutableAttributedString alloc] initWithString:[elem showDescriptionOf:self] attributes:@{NSFontAttributeName : UIFontCNMake(14), NSForegroundColorAttributeName : KGray101Color}]; 960 attStr = [[NSMutableAttributedString alloc] initWithString:[elem showDescriptionOf:self] attributes:@{NSFontAttributeName : UIFontCNMake(14), NSForegroundColorAttributeName : KGray101Color}];
957 /**对打款方收到对方已收款或者已退还消息,会话列表对“【转余额】” 文字颜色改为红色*/ 961 /**对打款方收到对方已收款或者已退还消息,会话列表对“【转余额】” 文字颜色改为红色*/
958 - TIMCustomElem *customElem = (TIMCustomElem *)elem;  
959 - NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:customElem.data options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];  
960 - NSDictionary *transferBalanceData = dic[@"transferBalanceData"]; 962 + NSDictionary *transferBalanceData = self.customMsgData[@"transferBalanceData"];
961 /**type 1:待收款, 2:已收款, 3:被退还*/ 963 /**type 1:待收款, 2:已收款, 3:被退还*/
962 NSString *type = [NSString stringWithFormat:@"%@",transferBalanceData[@"type"]]; 964 NSString *type = [NSString stringWithFormat:@"%@",transferBalanceData[@"type"]];
963 NSString *fromId = transferBalanceData[@"fromId"]; 965 NSString *fromId = transferBalanceData[@"fromId"];
@@ -1046,11 +1048,8 @@ @@ -1046,11 +1048,8 @@
1046 1048
1047 } else { 1049 } else {
1048 if (self.type == EIMAMSG_AiteStatus && ![_msg isReaded]) { 1050 if (self.type == EIMAMSG_AiteStatus && ![_msg isReaded]) {
1049 - TIMCustomElem *elem = (TIMCustomElem *)[self.msg getElem:0];  
1050 - NSError *err;  
1051 - NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:elem.data  
1052 - options:NSJSONReadingMutableContainers  
1053 - error:&err]; 1051 +
  1052 + NSDictionary *dic = self.customMsgData;
1054 1053
1055 NSDictionary *groupAitDic = dic[@"groupAit"]; 1054 NSDictionary *groupAitDic = dic[@"groupAit"];
1056 1055
@@ -1203,12 +1202,8 @@ @@ -1203,12 +1202,8 @@
1203 else if (self.type == EIMAMSG_ShareGift) 1202 else if (self.type == EIMAMSG_ShareGift)
1204 { 1203 {
1205 NSString *redTipStr = @""; 1204 NSString *redTipStr = @"";
1206 - TIMCustomElem *elem = (TIMCustomElem *)[self.msg getElem:0];  
1207 - NSError *err;  
1208 - NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:elem.data  
1209 - options:NSJSONReadingMutableContainers  
1210 - error:&err];  
1211 - NSDictionary *giftInfoData = dic[@"giftInfoData"]; 1205 +
  1206 + NSDictionary *giftInfoData = self.customMsgData[@"giftInfoData"];
1212 if ([giftInfoData[@"toType"] integerValue] == 1) { 1207 if ([giftInfoData[@"toType"] integerValue] == 1) {
1213 if (![self isWithdrawMsg]) { 1208 if (![self isWithdrawMsg]) {
1214 //发送礼物 1209 //发送礼物
CNLiveNewIMAManagerKit/Classes/TIMShow/TIMElem+ShowDescription.m
@@ -711,8 +711,8 @@ static NSString *const kGroupTypeKey = @&quot;kGroupTypeKey&quot;; @@ -711,8 +711,8 @@ static NSString *const kGroupTypeKey = @&quot;kGroupTypeKey&quot;;
711 711
712 if ([NSString isEmpty:self.desc]) { 712 if ([NSString isEmpty:self.desc]) {
713 //对desc 为空做处理 713 //对desc 为空做处理
714 - NSDictionary *customDic = [NSJSONSerialization JSONObjectWithData:self.data options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];  
715 - NSDictionary *groupAit = customDic[@"groupAit"]; 714 +
  715 + NSDictionary *groupAit = msg.customMsgData[@"groupAit"];
716 NSString *des = [NSString stringWithFormat:@"%@", groupAit[@"aitDesc"]]; 716 NSString *des = [NSString stringWithFormat:@"%@", groupAit[@"aitDesc"]];
717 return des; 717 return des;
718 } 718 }
@@ -733,8 +733,8 @@ static NSString *const kGroupTypeKey = @&quot;kGroupTypeKey&quot;; @@ -733,8 +733,8 @@ static NSString *const kGroupTypeKey = @&quot;kGroupTypeKey&quot;;
733 else if (msg.type == EIMAMSG_SendCard) 733 else if (msg.type == EIMAMSG_SendCard)
734 { 734 {
735 NSString *des = @""; 735 NSString *des = @"";
736 - NSDictionary *customDic = [NSJSONSerialization JSONObjectWithData:self.data options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];  
737 - NSDictionary *businessCardDataDic = [customDic objectForKey:@"businessCardData"]; 736 +
  737 + NSDictionary *businessCardDataDic = [msg.customMsgData objectForKey:@"businessCardData"];
738 if ([msg isMineMsg]) { 738 if ([msg isMineMsg]) {
739 des = [NSString stringWithFormat:@"你推荐了%@",businessCardDataDic[@"name"]]; 739 des = [NSString stringWithFormat:@"你推荐了%@",businessCardDataDic[@"name"]];
740 } 740 }
@@ -744,21 +744,21 @@ static NSString *const kGroupTypeKey = @&quot;kGroupTypeKey&quot;; @@ -744,21 +744,21 @@ static NSString *const kGroupTypeKey = @&quot;kGroupTypeKey&quot;;
744 } 744 }
745 else if (msg.type == EIMAMSG_ShareGift) 745 else if (msg.type == EIMAMSG_ShareGift)
746 { 746 {
747 - NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:self.data options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];  
748 - NSDictionary *giftInfoData = dic[@"giftInfoData"]; 747 +
  748 + NSDictionary *giftInfoData = msg.customMsgData[@"giftInfoData"];
749 NSString *des = giftInfoData[@"goodsTitle"]; 749 NSString *des = giftInfoData[@"goodsTitle"];
750 return des; 750 return des;
751 } 751 }
752 else if (msg.type == EIMAMSG_SendGiftSuccess) 752 else if (msg.type == EIMAMSG_SendGiftSuccess)
753 { 753 {
754 - NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:self.data options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];  
755 - NSString *des = dic[@"alertMsg"]; 754 +
  755 + NSString *des = msg.customMsgData[@"alertMsg"];
756 return des; 756 return des;
757 } 757 }
758 else if (msg.type == EIMAMSG_ReceviedGiftSuccess) 758 else if (msg.type == EIMAMSG_ReceviedGiftSuccess)
759 { 759 {
760 - NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:self.data options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];  
761 - NSString *des = dic[@"alertMsg"]; 760 +
  761 + NSString *des = msg.customMsgData[@"alertMsg"];
762 return des; 762 return des;
763 } 763 }
764 else if (msg.type == EIMAMSG_OrderStatus) 764 else if (msg.type == EIMAMSG_OrderStatus)
@@ -775,8 +775,8 @@ static NSString *const kGroupTypeKey = @&quot;kGroupTypeKey&quot;; @@ -775,8 +775,8 @@ static NSString *const kGroupTypeKey = @&quot;kGroupTypeKey&quot;;
775 } 775 }
776 else if(msg.type == EIMAMSG_TransferBalance) 776 else if(msg.type == EIMAMSG_TransferBalance)
777 { 777 {
778 - NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:self.data options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];  
779 - NSDictionary *transferBalanceData = dic[@"transferBalanceData"]; 778 +
  779 + NSDictionary *transferBalanceData = msg.customMsgData[@"transferBalanceData"];
780 NSString *type = [NSString stringWithFormat:@"%@",transferBalanceData[@"type"]]; 780 NSString *type = [NSString stringWithFormat:@"%@",transferBalanceData[@"type"]];
781 NSString *fromId = transferBalanceData[@"fromId"]; 781 NSString *fromId = transferBalanceData[@"fromId"];
782 if ([fromId isEqualToString:CNUserShareModel.uid]) { 782 if ([fromId isEqualToString:CNUserShareModel.uid]) {