Commit 18c84b081e74a897bab81bd698944f8f0173a277
1 parent
8b9cd574
0.3.0 版本 自定义消息数据解析后进行缓存处理
Showing
5 changed files
with
60 additions
and
79 deletions
CNLiveNewIMAManagerKit.podspec
CNLiveNewIMAManagerKit/Classes/TIMCategory/TIMElem+ShowAPIs.m
| ... | ... | @@ -648,9 +648,8 @@ |
| 648 | 648 | break; |
| 649 | 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 | 653 | NSString *titleStr = shareFriendData[@"title"]; |
| 655 | 654 | CGSize titleSize = [titleStr boundingRectWithSize:CGSizeMake(241-18-17, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : UIFontCNMake(15)} context:nil].size; |
| 656 | 655 | if (titleSize.height > 36) { |
| ... | ... | @@ -767,9 +766,8 @@ |
| 767 | 766 | break; |
| 768 | 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 | 771 | NSString *totalStep = [NSString stringWithFormat:@"%@",familyHealthyStepTotalData[@"totalStep"]]; |
| 774 | 772 | if ([totalStep integerValue] == 0) { |
| 775 | 773 | return CGSizeMake(width, 110*RATIO); |
| ... | ... | @@ -834,10 +832,8 @@ |
| 834 | 832 | /// @param packMsg 消息 |
| 835 | 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 | 837 | // NSString* content = customElem.desc; |
| 842 | 838 | NSString *content = groupAitDic[@"aitDesc"]; |
| 843 | 839 | |
| ... | ... | @@ -879,12 +875,8 @@ |
| 879 | 875 | /// @param packMsg 消息 |
| 880 | 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 | 880 | NSArray *goodsInfo = orderCheckData[@"goodsInfo"]; |
| 889 | 881 | CGFloat validWidth = KScreenWidth-28; |
| 890 | 882 | |
| ... | ... | @@ -905,12 +897,8 @@ |
| 905 | 897 | /// @param packMsg 消息 |
| 906 | 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 | 902 | NSDictionary *orderInfoDic = [dataDic objectForKey:@"orderInfo"]; |
| 915 | 903 | if (orderInfoDic) { |
| 916 | 904 | NSArray *goodsInfo = orderInfoDic[@"goodsInfo"]; |
| ... | ... | @@ -933,8 +921,7 @@ |
| 933 | 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 | 926 | NSString *str1 = [NSString stringWithFormat:@"收货地址: %@",dic[@"orderReceiverInfoData"][@"contactAddress"]]; |
| 940 | 927 | NSString *str2 = [NSString stringWithFormat:@"收货人: %@",dic[@"orderReceiverInfoData"][@"contactName"]]; |
| ... | ... | @@ -966,12 +953,7 @@ |
| 966 | 953 | /// @param packMsg 消息 |
| 967 | 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 | 957 | if ([packMsg isMineMsg] && [text containsString:@"开启了全员禁言"]) { |
| 976 | 958 | text = @"你开启了全员禁言"; |
| 977 | 959 | } |
| ... | ... | @@ -990,12 +972,8 @@ |
| 990 | 972 | /// @param packMsg 消息 |
| 991 | 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 | 977 | CGSize size = [text textSizeIn:CGSizeMake(KScreenWidth-20, HUGE_VAL) font:UIFontCNMake(14)]; |
| 1000 | 978 | packMsg.showContentSizeInChat = size; |
| 1001 | 979 | size.height += 10; | ... | ... |
CNLiveNewIMAManagerKit/Classes/TIMModel/MSG/IMAMsg.h
| ... | ... | @@ -270,6 +270,9 @@ typedef NS_ENUM(NSInteger, CNVoiceToWordsStatus){ |
| 270 | 270 | /// 消息状态 |
| 271 | 271 | @property (nonatomic, readonly) NSInteger status; |
| 272 | 272 | |
| 273 | +/// 自定义消息 json数据解析后的数据 | |
| 274 | +@property (nonatomic, readonly, strong) NSDictionary *customMsgData; | |
| 275 | + | |
| 273 | 276 | /// 是否正在播放语音 |
| 274 | 277 | @property (nonatomic, assign) BOOL isPlayingSuond; |
| 275 | 278 | |
| ... | ... | @@ -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 | 305 | /// 根据 TIMMessage 生成 IMAMsg 对象 | ... | ... |
CNLiveNewIMAManagerKit/Classes/TIMModel/MSG/IMAMsg.m
| ... | ... | @@ -26,6 +26,21 @@ |
| 26 | 26 | _msg = msg; |
| 27 | 27 | _type = type; |
| 28 | 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 | 45 | return self; |
| 31 | 46 | } |
| ... | ... | @@ -520,17 +535,6 @@ |
| 520 | 535 | { |
| 521 | 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 | 538 | else if ([dic[@"type"] integerValue] == CustomMsgTypeSendCard || [dic[@"type"] integerValue] == CustomMsgTypeSendDarenCard) |
| 535 | 539 | { |
| 536 | 540 | type = EIMAMSG_SendCard; |
| ... | ... | @@ -955,9 +959,7 @@ |
| 955 | 959 | //对转余额消息进行特殊处理 |
| 956 | 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 | 963 | /**type 1:待收款, 2:已收款, 3:被退还*/ |
| 962 | 964 | NSString *type = [NSString stringWithFormat:@"%@",transferBalanceData[@"type"]]; |
| 963 | 965 | NSString *fromId = transferBalanceData[@"fromId"]; |
| ... | ... | @@ -1046,11 +1048,8 @@ |
| 1046 | 1048 | |
| 1047 | 1049 | } else { |
| 1048 | 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 | 1054 | NSDictionary *groupAitDic = dic[@"groupAit"]; |
| 1056 | 1055 | |
| ... | ... | @@ -1203,12 +1202,8 @@ |
| 1203 | 1202 | else if (self.type == EIMAMSG_ShareGift) |
| 1204 | 1203 | { |
| 1205 | 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 | 1207 | if ([giftInfoData[@"toType"] integerValue] == 1) { |
| 1213 | 1208 | if (![self isWithdrawMsg]) { |
| 1214 | 1209 | //发送礼物 | ... | ... |
CNLiveNewIMAManagerKit/Classes/TIMShow/TIMElem+ShowDescription.m
| ... | ... | @@ -711,8 +711,8 @@ static NSString *const kGroupTypeKey = @"kGroupTypeKey"; |
| 711 | 711 | |
| 712 | 712 | if ([NSString isEmpty:self.desc]) { |
| 713 | 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 | 716 | NSString *des = [NSString stringWithFormat:@"%@", groupAit[@"aitDesc"]]; |
| 717 | 717 | return des; |
| 718 | 718 | } |
| ... | ... | @@ -733,8 +733,8 @@ static NSString *const kGroupTypeKey = @"kGroupTypeKey"; |
| 733 | 733 | else if (msg.type == EIMAMSG_SendCard) |
| 734 | 734 | { |
| 735 | 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 | 738 | if ([msg isMineMsg]) { |
| 739 | 739 | des = [NSString stringWithFormat:@"你推荐了%@",businessCardDataDic[@"name"]]; |
| 740 | 740 | } |
| ... | ... | @@ -744,21 +744,21 @@ static NSString *const kGroupTypeKey = @"kGroupTypeKey"; |
| 744 | 744 | } |
| 745 | 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 | 749 | NSString *des = giftInfoData[@"goodsTitle"]; |
| 750 | 750 | return des; |
| 751 | 751 | } |
| 752 | 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 | 756 | return des; |
| 757 | 757 | } |
| 758 | 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 | 762 | return des; |
| 763 | 763 | } |
| 764 | 764 | else if (msg.type == EIMAMSG_OrderStatus) |
| ... | ... | @@ -775,8 +775,8 @@ static NSString *const kGroupTypeKey = @"kGroupTypeKey"; |
| 775 | 775 | } |
| 776 | 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 | 780 | NSString *type = [NSString stringWithFormat:@"%@",transferBalanceData[@"type"]]; |
| 781 | 781 | NSString *fromId = transferBalanceData[@"fromId"]; |
| 782 | 782 | if ([fromId isEqualToString:CNUserShareModel.uid]) { | ... | ... |