TIMElem+ShowAPIs.m 47.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341
//
//  TIMElem+ShowAPIs.m
//  CNLiveNetAdd
//
//  Created by iOS on 2018/1/17.
//  Copyright © 2018年 cnlive. All rights reserved.
//

#import "TIMElem+ShowAPIs.h"
#import "IMAMsg+UITableViewCell.h"
#import <CNLiveBusinessTools/CNLiveBusinessTools.h>
@implementation TIMElem (ShowAPIs)

- (Class)showCellClassOf:(IMAMsg *)msg
{
    
    return [NSClassFromString(@"CNOrderConfirmCell") class];
}

- (CGSize)sizeInWidth:(CGFloat)width atMsg:(IMAMsg *)packMsg
{
    return CGSizeMake(width, 32);
}

@end

@implementation TIMTextElem (ShowAPIs)

- (Class)showCellClassOf:(IMAMsg *)msg
{
    return [NSClassFromString(@"CNTextMessageCell") class];
}
- (CGSize)sizeInWidth:(CGFloat)width atMsg:(IMAMsg *)packMsg
{
    NSMutableAttributedString *attStr = [CNLiveBusinessTools replaceNativeQQemojiWithCustomText:[NSString stringWithFormat:@"%@%@",self.text,[self  getSpecialSpaceCharactCerS]]];
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
    paragraphStyle.lineSpacing = 5;  //行高度
    NSMutableAttributedString *attributes = [[NSMutableAttributedString alloc] initWithAttributedString:attStr];
    [attributes addAttribute:NSFontAttributeName value:UIFontCNMake(contentLabelFontSize) range:NSMakeRange(0, attributes.length)];
    [attributes addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, attributes.length)];
    packMsg.showChatAttributedText = attributes;
    
    //获取高度
    CGSize attSize = [attributes boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading |NSStringDrawingUsesDeviceMetrics context:nil].size;
    //注*要向上取整!!!!!!!
    NSInteger minH = 16*RATIO; //最小高度
    attSize.width = ceil(attSize.width);
    attSize.height = ceil(attSize.height);
    if (attSize.height < minH) {
        attSize.height = minH;
    }
    packMsg.showContentSizeInChat = attSize;
    //计算cell 的size
    CGSize cellSize = attSize;
    if ([packMsg isGroupMsg] && ![packMsg isMineMsg]) {
        cellSize.height += 17*RATIO;  //17:昵称高度12,与气泡间距5
    }
    cellSize.height += 24*RATIO;    //24:文字距离气泡上下的高度
    return cellSize;
}

/// 获取特殊空白字符
- (NSString *)getSpecialSpaceCharactCerS{
    int asciiCode = 8197;
    NSString *string1 = [NSString stringWithFormat:@"%C", (unichar)asciiCode];
    return string1;
}
@end



@implementation TIMImageElem (ShowAPIs)

- (CGSize)getThumbShowSizeInMsg:(IMAMsg *)packMsg;
{
    NSInteger tw = [packMsg integerForKey:kIMAMSG_Image_ThumbWidth];
    NSInteger th = [packMsg integerForKey:kIMAMSG_Image_ThumbHeight];
    
    if (tw == 0 || th == 0)
    {
        BOOL succ = NO;
        for (TIMImage *timImage in self.imageList)
        {
            if (timImage.type == TIM_IMAGE_TYPE_THUMB)
            {
                // 解析大小
                CGFloat scale = 1;
                scale = MIN(kChatPicThumbMaxHeight/timImage.height, kChatPicThumbMaxWidth/timImage.width);
                tw = (NSInteger)(timImage.width * scale + 1);
                th =  (NSInteger)(timImage.height * scale + 1);
               
                [packMsg addInteger:tw forKey:kIMAMSG_Image_ThumbWidth];
                [packMsg addInteger:th forKey:kIMAMSG_Image_ThumbHeight];
                succ = YES;
                break;
            }
        }
    }
    NSInteger minW = 50;
    NSInteger minH = 50;
    if (tw < minW) {
        tw = minW;
        th = minW*2.4;
    }
    if (th<50) {
        th = minH;
    }
    return CGSizeMake(tw, th);
}


- (Class)showCellClassOf:(IMAMsg *)msg
{
    return [NSClassFromString(@"CNImageMessageCell") class];
}

- (CGSize)sizeInWidth:(CGFloat)width atMsg:(IMAMsg *)packMsg
{
    NSInteger tw = [packMsg integerForKey:kIMAMSG_Image_ThumbWidth];
    NSInteger th = [packMsg integerForKey:kIMAMSG_Image_ThumbHeight];
    
    if (tw ==0 || th ==0)
    {
        BOOL succ = NO;
        for (TIMImage *timImage in self.imageList)
        {
            if (timImage.type == TIM_IMAGE_TYPE_THUMB)
            {
                // 解析大小
                CGFloat scale = 1;
                scale = MIN(kChatPicThumbMaxHeight/timImage.height, kChatPicThumbMaxWidth/timImage.width);
                tw = (NSInteger)(timImage.width * scale + 1);
                th =  (NSInteger)(timImage.height * scale + 1);
        
                [packMsg addInteger:tw forKey:kIMAMSG_Image_ThumbWidth];
                [packMsg addInteger:th forKey:kIMAMSG_Image_ThumbHeight];
                succ = YES;
                break;
            }
        }
        
        if (!succ)
        {
            
            
            
            //    int num = (arc4random() % 10000);
            NSFileManager *fileManager = [NSFileManager defaultManager];
            //之前旧逻辑是以msgId命名文件名的,新的逻辑以uniqueId 命名文件名,以防以后版本msgId又发生改变
               //先取以msgId命名的文件是否存在
            NSString *fileName = [NSString stringWithFormat:@"%@_image_file", packMsg.msg.msgId];
            NSString *filePath = [CNLiveBusinessTools chatImagePathByConversationId:self.conversationId imageName:fileName isRead:YES isThumb:NO imageElem_path_lastPathComponent:self.path.lastPathComponent];
            if ([NSString isEmpty:filePath]) {
                //以msgId 命名的文件不存在,取以uniqueId命名的文件
                fileName = [NSString stringWithFormat:@"%llu_image_file", packMsg.msg.uniqueId];
                filePath = [CNLiveBusinessTools chatImagePathByConversationId:self.conversationId imageName:fileName isRead:YES isThumb:NO imageElem_path_lastPathComponent:self.path.lastPathComponent];
            }
            NSInteger thumbWidth = kChatPicThumbMaxWidth;
            NSInteger thumbHeight = kChatPicThumbMaxHeight;
            if (![NSString isEmpty:filePath])
            {
                // NSString *filePath = [NSString stringWithFormat:@"%@uploadFile%3.f_Size_%d_%d", nsTmpDIr, [NSDate timeIntervalSinceReferenceDate], (int)picThumbWidth, (int)picThumbHeight];
                // 检查本地是否存储了
                BOOL exist = [PathUtility isExistFile:filePath];
                if (exist)
                {

                    // 获取原图
                    UIImage *image = [[UIImage alloc] initWithContentsOfFile:filePath];
                    // TODO:是否能过加载的图片再算
                    
                    CGFloat scale = 1;
                    scale = MIN(kChatPicThumbMaxHeight/image.size.height, kChatPicThumbMaxWidth/image.size.width);
                    
                    CGFloat picHeight = image.size.height;
                    CGFloat picWidth = image.size.width;
                    NSInteger picThumbHeight = (NSInteger) (picHeight * scale + 1);
                    NSInteger picThumbWidth = (NSInteger) (picWidth * scale + 1);
                    
//                    CGFloat scale = 1;
//                    scale = MIN(kChatPicThumbMaxHeight/image.size.height, kChatPicThumbMaxWidth/image.size.width);
//
//                    CGFloat picHeight = image.size.height;
//                    CGFloat picWidth = image.size.width;
//                    thumbWidth = (NSInteger)(picHeight * scale + 1);
//                    thumbHeight = (NSInteger)(picWidth * scale + 1);
                    
                    tw = picThumbWidth;
                    th = picThumbHeight;
                    
                    [packMsg addInteger:th forKey:kIMAMSG_Image_ThumbHeight];
                    [packMsg addInteger:tw forKey:kIMAMSG_Image_ThumbWidth];
                }
                else
                {
                    DebugLog(@"程序异常退出,导致本地缓存图片不存在");
                }
            }
            else
            {
                DebugLog(@"理论不可达区域");
            }
        }
    }
    
    
    NSInteger minW = 50;
    NSInteger minH = 50;
    if (tw < minW) {
        tw = minW;
        th = minW*2.4;
    }
    if (th<50) {
        th = minH;
    }
    
    if (tw > width)
    {
        th = (NSInteger)(th * width/tw);
        tw = width;
    }
    packMsg.showContentSizeInChat = CGSizeMake(tw, th);
    //计算cell size
    CGSize cellSize = CGSizeMake(tw, th);
    if ([packMsg isGroupMsg] && ![packMsg isMineMsg]) {
        cellSize.height += 17*RATIO;  //17:昵称高度12,与气泡间距5
    }
    return cellSize;
}

@end

@implementation TIMFileElem (ShowAPIs)


- (Class)showCellClassOf:(IMAMsg *)msg
{
    return [NSClassFromString(@"CNFileMessageTableViewCell") class];
}

- (CGSize)sizeInWidth:(CGFloat)width atMsg:(IMAMsg *)packMsg
{
    packMsg.showContentSizeInChat = CGSizeMake(width, 70*RATIO);
    //计算cell size
    CGSize cellSize = CGSizeMake(width, 70*RATIO);
    if ([packMsg isGroupMsg] && ![packMsg isMineMsg]) {
        cellSize.height += 17*RATIO;  //17:昵称高度12,与气泡间距5
    }
    return cellSize;
}
@end

@implementation TIMSoundElem (ShowAPIs)

- (Class)showCellClassOf:(IMAMsg *)msg
{
    return [NSClassFromString(@"CNVoiceMessageCell") class];
}

- (CGSize)sizeInWidth:(CGFloat)width atMsg:(IMAMsg *)packMsg
{
    NSInteger minWidth = 70;
    
    NSInteger uni = (width - minWidth)/60;
    
    NSInteger w = minWidth + self.second * uni;
    if (w > width)
    {
        w = width;
    }
    packMsg.showContentSizeInChat = CGSizeMake(w, 40*RATIO);
    //计算cell size
    CGSize cellSize = CGSizeMake(w, 40*RATIO);
    if ([packMsg isGroupMsg] && ![packMsg isMineMsg]) {
        cellSize.height += 17*RATIO;  //17:昵称高度12,与气泡间距5
    }
    return cellSize;
}

@end

@implementation TIMFaceElem (ShowAPIs)

- (Class)showCellClassOf:(IMAMsg *)msg
{
    return [NSClassFromString(@"CNUnknownMsgCell") class];
}

// 是否是系统表情(QQ自带的表情)
- (BOOL)isSystemFace
{
    // 目前没有做自定义表情,所以全问都是系统表情
    // 用户可根据自身业务逻辑修改此处
    return YES;
}
- (CGSize)sizeInWidth:(CGFloat)width atMsg:(IMAMsg *)packMsg
{
    packMsg.showContentSizeInChat = CGSizeMake(width, 100*RATIO);
    //计算cell size
    CGSize cellSize = CGSizeMake(width, 100*RATIO);
    if ([packMsg isGroupMsg] && ![packMsg isMineMsg]) {
        cellSize.height += 17*RATIO;  //17:昵称高度12,与气泡间距5
    }
    return cellSize;
}
@end

@implementation TIMLocationElem (ShowAPIs)
- (Class)showCellClassOf:(IMAMsg *)msg
{
    return [NSClassFromString(@"CNUnknownMsgCell") class];
}
- (CGSize)sizeInWidth:(CGFloat)width atMsg:(IMAMsg *)packMsg
{
    packMsg.showContentSizeInChat = CGSizeMake(width, 100*RATIO);
    //计算cell size
    CGSize cellSize = CGSizeMake(width, 100*RATIO);;
    if ([packMsg isGroupMsg] && ![packMsg isMineMsg]) {
        cellSize.height += 17*RATIO;  //17:昵称高度12,与气泡间距5
    }
    return cellSize;
}
@end

@implementation TIMGroupTipsElem (ShowAPIs)

- (Class)showCellClassOf:(IMAMsg *)msg
{
    return [NSClassFromString(@"CNChatGroupTipTableViewCell") class];
}

- (CGSize)sizeInWidth:(CGFloat)width atMsg:(IMAMsg *)packMsg
{
    TIMGroupTipsElem *elem = (TIMGroupTipsElem *)self;
    CGSize size = [[elem tipText] textSizeIn:CGSizeMake(width, MAXFLOAT) font:UIFontCNMake(12)];
    packMsg.showContentSizeInChat = CGSizeMake(size.width, size.height*RATIO);

    //计算cell size
    CGSize cellSize = CGSizeMake(size.width, size.height*RATIO);
    if ([packMsg isGroupMsg] && ![packMsg isMineMsg]) {
        cellSize.height += 6*RATIO;  //留出文字与消息气泡的上下间距
    }
    return cellSize;
}

@end

@implementation TIMVideoElem (ShowAPIs)

- (Class)showCellClassOf:(IMAMsg *)msg
{
    return [NSClassFromString(@"CNVideoMessageCell") class];
}

- (CGSize)sizeInWidth:(CGFloat)width atMsg:(IMAMsg *)packMsg
{
    
    NSInteger tw = [packMsg integerForKey:kIMAMSG_Image_ThumbWidth];
    NSInteger th = [packMsg integerForKey:kIMAMSG_Image_ThumbHeight];
    
    TIMSnapshot *shot = self.snapshot;
    // 解析大小
    CGFloat scale = 1;
    scale = MIN(kChatPicThumbMaxHeight/shot.height, kChatPicThumbMaxWidth/shot.width);
    tw = (NSInteger)(shot.width * scale + 1);
    th =  (NSInteger)(shot.height * scale + 1);
    
    [packMsg addInteger:tw forKey:kIMAMSG_Image_ThumbWidth];
    [packMsg addInteger:th forKey:kIMAMSG_Image_ThumbHeight];
    
    if (tw > width) {
        th = (NSInteger)(th * width/tw);
        tw = width;
    }
    packMsg.showContentSizeInChat = CGSizeMake(tw, th);
    //计算cell size
    CGSize cellSize = CGSizeMake(tw, th);
    if ([packMsg isGroupMsg] && ![packMsg isMineMsg]) {
        cellSize.height += 17*RATIO;  //17:昵称高度12,与气泡间距5
    }
    return cellSize;
    
}

@end


@implementation TIMCustomElem (ShowAPIs)


- (Class)showCellClassOf:(IMAMsg *)msg
{
    if (msg.type == EIMAMSG_TimeTip)
    {
        return [NSClassFromString(@"CNChatTimeTipTableViewCell") class];
    }
    else if (msg.type == EIMAMSG_SaftyTip)
    {
        return [NSClassFromString(@"CNChatSaftyTipTableViewCell") class];
    }
    else if (msg.type == EIMAMSG_OrderConfirm)
    {
        // DODO!!! 电商订单消息修改
        return [NSClassFromString(@"CNOrderConfirmCell") class];
//        return [CNE_BusinessOrderConfirmCell class];
    }
    else if (msg.type == EIMAMSG_OrderCnee)
    {
        return [NSClassFromString(@"CNCneeInfoCell") class];
    }
    else if (msg.type == EIMAMSG_OrderStatus)
    {
        //DODO!!! 电商订单消息修改
        return [NSClassFromString(@"CNOrderStatusTableViewCell") class];
    }
    else if (msg.type == EIMAMSG_NewLiveVideo)
    {
        return [NSClassFromString(@"CNOrderStatusTableViewCell") class];
    }
    else if (msg.type == EIMAMSG_FriendshipVerify)
    {
        return [NSClassFromString(@"CNFriendshipVerifyCell") class];
    }
    else if (msg.type == EIMAMSG_AddFriend)
    {
        return [NSClassFromString(@"CNAddFriendSuccessCell") class];
    }
    else if (msg.type == EIMAMSG_AgreeApply)
    {
        return [NSClassFromString(@"CNAgreeApplyCell") class];
    }
    else if (msg.type == EIMAMSG_SendAddFriendInvitation)
    {
        return [NSClassFromString(@"CNSendAddFriendInvitationCell") class];
    }
    else if (msg.type == EIMAMSG_AiteStatus)
    {
        return [NSClassFromString(@"CNTextMessageCell") class];
    }
    else if (msg.type == EIMAMSG_Receipt)
    {
        return [NSClassFromString(@"CNActivityPayCell") class];
    }
    else if (msg.type == EIMAMSG_Payment)
    {
        return [NSClassFromString(@"CNPaymentLinkCell") class];
    }
    else if (msg.type == EIMAMSG_ShareLink)
    {
        return [NSClassFromString(@"CNTShareLinkCell") class];
    }
    else if (msg.type == EIMAMSG_ShareGoods)
    {
        return [NSClassFromString(@"CNShareGoodsCell") class];
    }
    else if(msg.type == EIMAMSG_ShopGoodsInfo)
    {
        return [NSClassFromString(@"CNShopGoodsInfoCell") class];
    }
    else if(msg.type == EIMAMSG_ShopOrderDetail)
    {
        return [NSClassFromString(@"CNShopOrderDetailCell") class];
    }
    else if (msg.type == EIMAMSG_DissolveGroup)
    {
        return [NSClassFromString(@"CNDissolveGroupCell") class];
    }
    else if (msg.type == EIMAMSG_ShareGift)
    {
        return [NSClassFromString(@"CNShareGiftCell") class];
    }
    else if (msg.type == EIMAMSG_SendGiftSuccess)
    {
        return [NSClassFromString(@"CNAddGiftAddressSuccCell") class];

    }
    else if (msg.type == EIMAMSG_ReceviedGiftSuccess)
    {
        return [NSClassFromString(@"CNAddGiftAddressSuccCell") class];
        
    }
    else if (msg.type == EIMAMSG_GroupPaySuccess)
    {
        return [NSClassFromString(@"CNGroupPaymentSuccessCell") class];
    }
    else if (msg.type == EIMAMSG_BlackTip)
    {
        return [NSClassFromString(@"CNChatBlackTipTableViewCell") class];
    }
    else if (msg.type == EIMAMSG_CustomFace)
    {
        return [NSClassFromString(@"CNGifFaceMessageCell") class];
    }
    else if (msg.type == EIMAMSG_SendCard)
    {
        return [NSClassFromString(@"CNCardMessageTableViewCell") class];
    }
    else if (msg.type == EIMAMSG_TransferBalance)
    {
        return [NSClassFromString(@"CNTransferBalanceCell") class];
    }
    else if(msg.type == EIMAMSG_VoiceWords)
    {
        return [NSClassFromString(@"CNVoiceToWordsTableViewCell") class];
    }else if (msg.type == EIMAMSG_SendCurrentlocation){
        return [NSClassFromString(@"CNSendCurrentLocationCell") class];
    }
    else if (msg.type == EIMAMSG_OutRoom)
    {
        return [NSClassFromString(@"CNVideoOrAudioMssageCell") class];
    }
    else if (msg.type == EIMAMSG_ReceiveE_BusinessOrder)
    {
        return [NSClassFromString(@"CNE_BusinessOrderConfirmCell") class];
    }
    else if (msg.type == EIMAMSG_E_BusinessOrderPaySuceess)
    {
        return [NSClassFromString(@"CNOrderPaySuccessCell") class];
    }
    else if (msg.type == EIMAMSG_ShareSubGroup)
    {
        return [NSClassFromString(@"CNShareSubGroupTableViewCell") class];
    }
    else if (msg.type == EIMAMSG_FamilyHealthyStep)
    {
        return [NSClassFromString(@"CNFamilyHealthyStepCell") class];
    }
    else if (msg.type == EIMAMSG_OrederPaySuccess)
    {
        return [NSClassFromString(@"CNOrderPayCell") class];
    }
    else if (msg.type == EIMAMSG_OrederRepast)
    {
        return [NSClassFromString(@"CNOrderPayCell") class];
    }
    else if (msg.type == EIMAMSG_OrederRepastReceipt)
    {
        return [NSClassFromString(@"CNOrderPayCell") class];
    }
    else if (msg.type == EIMAMSG_OrederApplyForRefund)
    {
        return [NSClassFromString(@"CNOrderPayCell") class];
    }
    else if (msg.type == EIMAMSG_OrederReminder)
    {
        return [NSClassFromString(@"CNOrderPayCell") class];
    }
    else if (msg.type == EIMAMSG_NewOrderRemind)
    {
        return [NSClassFromString(@"CNOrderRemindCell") class];
    }
    else if (msg.type == EIMAMSG_LiveRemind)
    {
        return [NSClassFromString(@"CNSeviceNoticeCell") class];
    }
    else if (msg.type == EIMAMSG_CommuntyOrder)
    {
        return [NSClassFromString(@"CNCommuntyMessageCell") class];
    }
    else if (msg.type == EIMAMSG_PhotoAlbumDynamic)
    {
        return [NSClassFromString(@"CNPhotoAlbumDynamicMessageCell") class];
    }
    else if (msg.type == EIMAMSG_FamilyGift)
    {
        return [NSClassFromString(@"CNFamilyGiftMessageCell") class];
    }
    else if (msg.type == EIMAMSG_ShareGoodsToHome)
    {
        return [NSClassFromString(@"CNShareGoodsToHomeMessageCell") class];
    }
    else if (msg.type == EIMAMSG_ShareCoupon)
    {
        return [NSClassFromString(@"CNCouponMessageCell") class];
    }
    else
    {
        return [NSClassFromString(@"CNUnknownMsgCell") class];
    }
}


- (CGSize)sizeInWidth:(CGFloat)width atMsg:(IMAMsg *)packMsg
{
    switch (packMsg.type) {
        case EIMAMSG_AiteStatus:
        {
            return [self aitMsgInWith:width atMsg:packMsg];
        }
            break;
        case EIMAMSG_OrderConfirm:
        {
            //订单核实cell高度
            CGSize orderSize = CGSizeMake(width, HUGE_VALF);
            orderSize.height = [self orderConfirmMsgHeight:packMsg];
            return orderSize;
        }
            break;
        case EIMAMSG_ReceiveE_BusinessOrder:
        {
            CGSize orderSize = CGSizeMake(width, HUGE_VALF);
            orderSize.height = (217 + 15)*RATIO;
            return orderSize;
        }
            break;
        case EIMAMSG_E_BusinessOrderPaySuceess:
        {
            CGSize orderSize = CGSizeMake(width, HUGE_VALF);
            orderSize.height = [self e_businessOrderPaySuccess:packMsg];
            return orderSize;
        }
            break;
        case EIMAMSG_OrderCnee:
        {
            //收货人信息cell高度
            CGSize orderSize = CGSizeMake(width, HUGE_VALF);
            orderSize = [self cneeContentSizeInWidth:width atMsg:packMsg];
            return orderSize;
        }
            break;
        case EIMAMSG_OrderStatus:
        {
            //订单状态cell高度
            CGSize orderSize = CGSizeMake(width, HUGE_VALF);
            orderSize.height = [self orderStatusMsgHeight:packMsg];
            return orderSize;
        }
            break;
        case EIMAMSG_NewLiveVideo:
        {
            // sp特群有新的直播消息 高度
            return [self spGroupNewLiveMsgHeight:packMsg];
        }
            break;
        case EIMAMSG_CustomFace:
        {
            //自定义表情cell高度
            CGSize size = CGSizeMake(width, HUGE_VALF);
            if (packMsg.isGroupMsg && ![packMsg isMineMsg]) {
                size.height = 150*RATIO;
            }
            else
                size.height =130*RATIO;
            return size;
        }
            break;
        case EIMAMSG_TimeTip:
        case EIMAMSG_SaftyTip:
        case EIMAMSG_BlackTip:
        {
            CGSize size = CGSizeMake(width, 20*RATIO);
            return size;
        }
            break;
        case EIMAMSG_Payment:
        case EIMAMSG_DissolveGroup:
        {
            return CGSizeMake(width, 100*RATIO);
        }
            break;
        case EIMAMSG_Receipt:
        {
            return CGSizeMake(width, 110*RATIO);
        }
            break;
        case EIMAMSG_ShareLink:
        {
            
            NSDictionary *shareFriendData = [packMsg.customMsgData objectForKey:@"shareFriendData"];
            NSString *titleStr = shareFriendData[@"title"];
            CGSize titleSize = [titleStr boundingRectWithSize:CGSizeMake(241-18-17, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : UIFontCNMake(15)} context:nil].size;
            if (titleSize.height > 36) {
                titleSize.height = 36;
            }
            if (packMsg.isGroupMsg && ![packMsg isMineMsg]) {
                return CGSizeMake(width, (95 + titleSize.height)*RATIO);
            }
            return CGSizeMake(width, (80 + titleSize.height)*RATIO);
        }
            break;
        case EIMAMSG_SendCard:
        {
            if (packMsg.isGroupMsg && ![packMsg isMineMsg]) {
                return CGSizeMake(width, 110*RATIO);
            }
            return CGSizeMake(width, 90*RATIO);
        }
            break;
        case EIMAMSG_TransferBalance:
        {
            if (packMsg.isGroupMsg && ![packMsg isMineMsg]) {
                return CGSizeMake(width, 110*RATIO);
            }
            return CGSizeMake(width, 95*RATIO);
        }
            break;
        case EIMAMSG_ShareGoods:
        {
            if (packMsg.isGroupMsg && ![packMsg isMineMsg])
            {
                return CGSizeMake(width, 120*RATIO);
            }
            return CGSizeMake(width, 110*RATIO);
        }
            break;
        case EIMAMSG_ShopGoodsInfo:
        {
            if (packMsg.isGroupMsg && ![packMsg isMineMsg])
            {
                return CGSizeMake(width, 360*RATIO);
            }
            return CGSizeMake(width, 360*RATIO);
        }
            break;
        case EIMAMSG_ShopOrderDetail:
        {
            if (![packMsg isMineMsg])
            {
                return CGSizeMake(width, 180*RATIO);
            }
            return CGSizeMake(width, 200*RATIO);
        }
            break;
        case EIMAMSG_ShareGift:
        {
            if (packMsg.isGroupMsg && ![packMsg isMineMsg]) {
                return CGSizeMake(width, 135*RATIO);
            }
            return CGSizeMake(width, 120*RATIO);
        }
            break;
        case EIMAMSG_SendGiftSuccess:
        {
            return CGSizeMake(width, 20*RATIO);
        }
            break;
        case EIMAMSG_ReceviedGiftSuccess:
        {
            return CGSizeMake(width, 20*RATIO);
        }
            break;
        case EIMAMSG_Unknown:
        {
            CGSize size = [self unknownMsgCellHeight:packMsg];
            //24:为文字距离气泡上下的高度  17:昵称高度
            if (packMsg.isGroupMsg && ![packMsg isMineMsg]) {
                size.height += (24+17)*RATIO;
            }
            else
                size.height += 24*RATIO;
            return size;
        }
            break;
        case EIMAMSG_VoiceWords:
        {
            return [self voiceWordsMsgHandle:packMsg];
        }
            break;
        case EIMAMSG_SendCurrentlocation:
        {
            CGSize size = CGSizeMake(width, HUGE_VALF);
            if (packMsg.isGroupMsg && ![packMsg isMineMsg])
            {
                size.height = 10+7+7+(16+12)*RATIO+95+24;
            }
            else
                size.height = 10+7+7+(16+12)*RATIO+95;
            return size;
        }
            break;
        case EIMAMSG_OutRoom:
        {
            return CGSizeMake(width, 50*RATIO);
        }
            break;
        case EIMAMSG_ShareSubGroup:
        {
            if (packMsg.isGroupMsg && ![packMsg isMineMsg]) {
                return CGSizeMake(width, 120*RATIO);
            }
            return CGSizeMake(width, 106*RATIO);
        }
            break;
        case EIMAMSG_FamilyHealthyStep:
        {
            
            NSDictionary *familyHealthyStepTotalData = [packMsg.customMsgData objectForKey:@"familyHealthyStepTotalData"];
            NSString *totalStep = [NSString stringWithFormat:@"%@",familyHealthyStepTotalData[@"totalStep"]];
            if ([totalStep integerValue] == 0) {
                return CGSizeMake(width, 110*RATIO);
            }
            else
                return CGSizeMake(width, 153*RATIO);
        }
            break;
        case EIMAMSG_AgreeApply:
        case EIMAMSG_FriendshipVerify:
        case EIMAMSG_AddFriend:
        case EIMAMSG_SendAddFriendInvitation:
        {
            CGSize size = [self friendshipChangedSizeInWidth:width atMsg:packMsg];
            return size;
        }
            break;
        case EIMAMSG_GroupPaySuccess:
        {
            return CGSizeMake(width, (19+10)*RATIO);
        }
            break;
        case  EIMAMSG_OrederPaySuccess:
        case  EIMAMSG_OrederApplyForRefund:
        case  EIMAMSG_OrederReminder :
        {
            TIMCustomElem * element = (TIMCustomElem *)[packMsg.msg getElem:0];
            NSDictionary * jsonDic = element.data.jsonValueDecoded;
            NSDictionary * foodsGoodsOrderInfo = [jsonDic objectForKey:@"foodsGoodsOrderInfo"];
            NSString *selectTime = foodsGoodsOrderInfo[@"selectTime"];
            NSArray *goodsDetailArray = foodsGoodsOrderInfo[@"detail"];
            
           //处理一个订单多笔商品时的高度显示问题,最多显示3个
            CGFloat goodsH = 0;
            if (goodsDetailArray.count < 4) {
                goodsH = 40 * goodsDetailArray.count;
            }
            else
                goodsH = 40 * 3;
            
            if (selectTime || selectTime.length) {
                //餐厅订单高度增加
                return CGSizeMake(width, (230 + goodsH + 10)*RATIO);
            }
            return CGSizeMake(width, (120 + goodsH + 10)*RATIO);
        }
            break;
        case  EIMAMSG_OrederRepast   :
        case  EIMAMSG_OrederRepastReceipt  :
        {
            return CGSizeMake(width, (200+10)*RATIO);
        }
            break;
        case EIMAMSG_NewOrderRemind:
        {
            return CGSizeMake(width, (180+10)*RATIO);
        }
            break;
        case EIMAMSG_LiveRemind:
        {
            return CGSizeMake(width, (180+10)*RATIO);
        }
            break;
        case EIMAMSG_CommuntyOrder:
        {
            NSDictionary * repairOrderDict = [packMsg.customMsgData objectForKey:@"repairOrder"];
            //地址动态高度
            NSString *addrss = [NSString stringWithFormat:@"%@",[repairOrderDict stringValueForKey:@"address" default:@""]];
            CGFloat addrssH = [addrss boundingRectWithSize:CGSizeMake(kScreenWidth*0.6 - 50, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil].size.height;
            
            //订单id动态高度
            NSString *idStr = [NSString stringWithFormat:@"%@",[repairOrderDict stringValueForKey:@"id" default:@""]];
            CGFloat idStrH = [idStr boundingRectWithSize:CGSizeMake(kScreenWidth*0.6 - 95, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil].size.height;
            
            //基础高度
            CGFloat baseH = 170;
            return CGSizeMake(width, (baseH + addrssH +idStrH +10)*RATIO);
        }
            break;
        case EIMAMSG_PhotoAlbumDynamic:
        {
            NSDictionary *photoDic = packMsg.customMsgData[@"photoAlbumData"];
            NSString *des = photoDic[@"text"];
            if ([NSString isEmpty:des]) {
                return CGSizeMake(width, (180 + 10)*RATIO);
            }
            
            return CGSizeMake(width, (220 + 10)*RATIO);
        }
            break;
        case EIMAMSG_FamilyGift:
        {
            return CGSizeMake(width, (36 +10)*RATIO);
        }
            break;
        case EIMAMSG_ShareGoodsToHome:
        {
            return CGSizeMake(width, [self shareGoodsMessageContentHeightWithMsg:packMsg] + 10*RATIO);
        }
            break;
        case EIMAMSG_ShareCoupon:
        {
            return CGSizeMake(width, 160);
        }
            break;
        case EIMAMSG_Illegal:
        {
            NSDictionary *illegalData = packMsg.customMsgData[@"illegalData"];
            CGSize contentSize = [self sizeWithText:illegalData[@"content"] lineSpacing:5 width:width fontSize:14];
            
            return CGSizeMake(contentSize.width, contentSize.height + 100);
        }
            break;
        case EIMAMSG_PersonageCerSuccess:
        {
            NSDictionary *personageCerSuccessData = packMsg.customMsgData[@"personageCerSuccessData"];
            CGSize contentSize = [self sizeWithText:personageCerSuccessData[@"content"] lineSpacing:5 width:width fontSize:14];
            return CGSizeMake(contentSize.width, contentSize.height + 100);
        }
            break;
        case EIMAMSG_PersonageCerFail:
        {
            NSDictionary *personageCerFailData = packMsg.customMsgData[@"personageCerFailData"];
            CGSize contentSize = [self sizeWithText:personageCerFailData[@"content"] lineSpacing:5 width:width fontSize:14];
            return CGSizeMake(contentSize.width, contentSize.height + 100);
        }
            break;
        case EIMAMSG_OrganizationCerSuccess:
        {
            NSDictionary *organizationCerSuccessData = packMsg.customMsgData[@"organizationCerSuccessData"];

            CGSize contentSize = [self sizeWithText:organizationCerSuccessData[@"content"] lineSpacing:5 width:width fontSize:14];
            return CGSizeMake(contentSize.width, contentSize.height + 100);
            
        }
            break;
        case EIMAMSG_OrganizationCerFail:
        {
            NSDictionary *organizationCerFailData = packMsg.customMsgData[@"organizationCerFailData"];
            
            CGSize contentSize = [self sizeWithText:organizationCerFailData[@"content"] lineSpacing:5 width:width fontSize:14];
            return CGSizeMake(contentSize.width, contentSize.height + 100);
        }
            break;
        default:
            break;
    }
    return CGSizeZero;
}

/// 获取@消息高度
/// @param width 最大宽
/// @param packMsg 消息
- (CGSize)aitMsgInWith:(CGFloat)width atMsg:(IMAMsg *)packMsg
{

    NSDictionary *groupAitDic = [packMsg.customMsgData objectForKey:@"groupAit"];
    //    NSString* content = customElem.desc;
    NSString *content = groupAitDic[@"aitDesc"];
    
    NSMutableAttributedString *attStr = [CNLiveBusinessTools replaceNativeQQemojiWithCustomText:[NSString stringWithFormat:@"%@%@",content,[self getSpecialSpaceCharactCerS]]];
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
    paragraphStyle.lineSpacing = 5;  //行高度
    NSMutableAttributedString *attributes = [[NSMutableAttributedString alloc] initWithAttributedString:attStr];
    [attributes addAttribute:NSFontAttributeName value:UIFontCNMake(contentLabelFontSize) range:NSMakeRange(0, attributes.length)];
    [attributes addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, attributes.length)];
    packMsg.showChatAttributedText = attributes;
    
    //获取高度
    CGSize attSize = [attributes boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading |NSStringDrawingUsesDeviceMetrics context:nil].size;
    
    NSInteger minH = 16; //最小高度
    attSize.width = ceil(attSize.width);
    attSize.height = ceil(attSize.height);
    if (attSize.height < minH) {
        attSize.height = minH;
    }
    packMsg.showContentSizeInChat = attSize;
    //计算cell 的size
    CGSize cellSize = attSize;
    if ([packMsg isGroupMsg] && ![packMsg isMineMsg]) {
        cellSize.height += 17*RATIO;  //17:昵称高度12,与气泡间距5
    }
    cellSize.height += 24*RATIO;    //24:文字距离气泡上下的高度
    return cellSize;
}
/// 获取特殊空白字符
- (NSString *)getSpecialSpaceCharactCerS{
    int asciiCode = 8197;
    NSString *string1 = [NSString stringWithFormat:@"%C", (unichar)asciiCode];
    return string1;
}
/// 核对订单cell内容高度计算
/// @param packMsg 消息
- (CGFloat)orderConfirmMsgHeight:(IMAMsg *)packMsg {
    

    NSDictionary *orderCheckData = packMsg.customMsgData[@"orderCheckData"];
    NSArray *goodsInfo = orderCheckData[@"goodsInfo"];
    CGFloat validWidth = KScreenWidth-28;

    /**
     *  goodsCount = 1 ,为了适配老版本(老版本没有goodsInfo字段)
     */
    NSInteger goodsCount = 0;
    if (goodsInfo && goodsInfo.count>0) {
        goodsCount = [goodsInfo count];
    } else {
        goodsCount = 1;
    }
    packMsg.showContentSizeInChat = CGSizeMake(validWidth, 46+(goodsCount*80)*RATIO+89+15);  //大概
    
    return 46+(goodsCount*80)*RATIO+89+15;
}
/// 电商订单支付成功cell 高度
/// @param packMsg 消息
- (CGFloat)e_businessOrderPaySuccess:(IMAMsg *)packMsg
{
   
    NSDictionary *dataDic = [packMsg.customMsgData objectForKey:@"payData"];
    NSDictionary *orderInfoDic = [dataDic objectForKey:@"orderInfo"];
    if (orderInfoDic) {
        NSArray *goodsInfo = orderInfoDic[@"goodsInfo"];
        CGFloat height = 61; // 初始化高度
        height += goodsInfo.count*61;//61 为 每个商品详情的高度
        height += 50; // 50 为底部view 高度
        return height;
    }
    else
        return 0;
}

/// 收货人地址cell内容计算(弃用, 已改为由用户端添加收货人信息)
/// @param width 宽
/// @param packMsg 消息
- (CGSize)cneeContentSizeInWidth:(CGFloat)width atMsg:(IMAMsg *)packMsg{
    
    NSInteger max = [packMsg contentMaxWidth];
    if (width > max) {
        width = max;
    }
    
    NSDictionary *dic  = packMsg.customMsgData;
    
    NSString *str1 = [NSString stringWithFormat:@"收货地址: %@",dic[@"orderReceiverInfoData"][@"contactAddress"]];
    NSString *str2 = [NSString stringWithFormat:@"收货人: %@",dic[@"orderReceiverInfoData"][@"contactName"]];
    NSString *str3 = [NSString stringWithFormat:@"联系电话: %@",dic[@"orderReceiverInfoData"][@"contactPhone"]];

    NSString *tempStr = [NSString stringWithFormat:@"%@\n%@\n%@", str2, str3,str1];

    NSMutableAttributedString *ats = [self attributedStringWithText:tempStr font:14];
    CGSize attSize = [ats boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil].size;
    
    //注*要向上取整!!!!!!!
    attSize.width = ceil(attSize.width);
    attSize.height = ceil(attSize.height);
    
    packMsg.showContentSizeInChat = CGSizeMake(attSize.width+10, attSize.height+24);
    return CGSizeMake(attSize.width, attSize.height+24+6); // 24:消息内容距离气泡间距24,6:label间距3
    
}
- (NSMutableAttributedString *)attributedStringWithText:(NSString *)text font:(CGFloat)font {
    
    NSMutableAttributedString *ats = [[NSMutableAttributedString alloc] initWithString:text];
    ats.yy_font = UIFontCNMake(font);
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
    [ats addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, ats.length)];
    return ats;
}
/// 订单状态cell内容高度计算
/// @param packMsg 消息
- (CGFloat)orderStatusMsgHeight:(IMAMsg *)packMsg {
    
    NSString *text = packMsg.customMsgData[@"alertMsg"];
    if ([packMsg isMineMsg] && [text containsString:@"开启了全员禁言"]) {
        text = @"你开启了全员禁言";
    }
    else if ([packMsg isMineMsg] && [text containsString:@"关闭了全员禁言"])
    {
        text = @"你关闭了全员禁言";
    }
    CGSize size = [text textSizeIn:CGSizeMake(KScreenWidth-20, HUGE_VAL) font:UIFontCNMake(14)];

    packMsg.showContentSizeInChat = size;
    size.height += 10; //文字距离底部和底部的高度和
    return size.height;
    
}
/// 特群新直播消息提醒
/// @param packMsg 消息
- (CGSize)spGroupNewLiveMsgHeight:(IMAMsg *)packMsg
{
    
    NSString *text = packMsg.customMsgData[@"alertMsg"];
    CGSize size = [text textSizeIn:CGSizeMake(KScreenWidth-20, HUGE_VAL) font:UIFontCNMake(14)];
    packMsg.showContentSizeInChat = size;
    size.height += 10;
    return size;
}

/// 未知消息高度
/// @param packMsg 消息
- (CGSize )unknownMsgCellHeight:(IMAMsg *)packMsg
{
    NSString *str = @"当前版本过低,暂不支持查看此消息,请升级网家家最新版本查看消息。";
    NSMutableAttributedString *attStr = [CNLiveBusinessTools replaceNativeQQemojiWithCustomText:[NSString stringWithFormat:@"%@",str]];
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
    paragraphStyle.lineSpacing = 5;  //行高度
    NSMutableAttributedString *attributes = [[NSMutableAttributedString alloc] initWithAttributedString:attStr];
    [attributes addAttribute:NSFontAttributeName value:UIFontCNMake(15) range:NSMakeRange(0, attributes.length)];
    [attributes addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, attributes.length)];
    packMsg.showChatAttributedText = attributes;
    
    //获取高度
    CGSize attSize = [attributes boundingRectWithSize:CGSizeMake([packMsg contentMaxWidth], MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading |NSStringDrawingUsesDeviceMetrics context:nil].size;
    //注*要向上取整!!!!!!!
    NSInteger minH = 16*RATIO; //最小高度
    attSize.width = ceil(attSize.width);
    attSize.height = ceil(attSize.height);
    if (attSize.height < minH) {
        attSize.height = minH;
    }
    packMsg.showContentSizeInChat = attSize;
    return attSize;
}

/// 语音转成文字的消息高度
/// @param msg 消息
- (CGSize)voiceWordsMsgHandle:(IMAMsg *)msg
{
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
    paragraphStyle.lineSpacing = 5;  //行高度
    NSMutableAttributedString *attributes = [[NSMutableAttributedString alloc] initWithString:msg.voiceText];
    [attributes addAttribute:NSFontAttributeName value:UIFontCNMake(contentLabelFontSize) range:NSMakeRange(0, attributes.length)];
    [attributes addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, attributes.length)];
    CGFloat maxWith = kScreenWidth * 0.6;
    //获取高度
    CGSize attSize = [attributes boundingRectWithSize:CGSizeMake(maxWith, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading |NSStringDrawingUsesDeviceMetrics context:nil].size;
    CGFloat minWith =  80;
    CGFloat minHeight = 35;
    
    attSize.height += 10 + 10;
    attSize.width += 10 + 10 + 8;
    if (msg.vioceToWordStatus == CNVoiceToWordsStatusFinish) {
        attSize.height += 20;

    }
    
    if (attSize.height < minHeight) {
        attSize.height = minHeight;
    }
    if (attSize.width < minWith) {
        attSize.width = minWith;
    }
    if (attSize.width > maxWith ) {
        attSize.width = maxWith;
    }
    return attSize;
}
//好友关系改变
- (CGSize)friendshipChangedSizeInWidth:(CGFloat)width atMsg:(IMAMsg *)packMsg{
    
    CGSize size = CGSizeMake(width, HUGE_VALF);

    //好友验证
    if (packMsg.type == EIMAMSG_FriendshipVerify) {
        
        size.height = [self friendshipVerifyCellHeight:packMsg];
        return size;
    }
    //单项好友发送添加对方为好友
    if (packMsg.type == EIMAMSG_SendAddFriendInvitation) {
        size.height = [self addFriend:packMsg];
        return size;
    }
    //好友验证(同意添加好友)
    if (packMsg.type == EIMAMSG_AgreeApply) {
        
        size.height = [self agreeApplyCellHeight:packMsg];
        return size;
    }
    
    //添加好友成功
    if (packMsg.type == EIMAMSG_AddFriend) {
        
        size.height = [self addFriendSuccessCellHeight:packMsg];
        return size;
    }
    
    return CGSizeZero;
    
}
//发送好友验证cell内容高度计算
- (CGFloat)friendshipVerifyCellHeight:(IMAMsg *)packMsg {

    TIMCustomElem *elem = (TIMCustomElem *)[packMsg.msg getElem:0];
    NSString *text = [NSString stringWithFormat:@"%@ 发送朋友验证", elem.desc];
    CGSize size = [text textSizeIn:CGSizeMake(KScreenWidth-60, HUGE_VAL) font:UIFontCNMake(13)];
    
    packMsg.showContentSizeInChat = CGSizeMake(size.width, size.height + 20);
    return size.height+20;

}
//添加对方为好友
- (CGFloat)addFriend:(IMAMsg *)packMsg
{
    TIMCustomElem *elem = (TIMCustomElem *)[packMsg.msg getElem:0];
    NSString *text = [NSString stringWithFormat:@"%@", elem.desc];
    CGSize size = [text textSizeIn:CGSizeMake(KScreenWidth-60, HUGE_VAL) font:UIFontCNMake(13)];
    
    packMsg.showContentSizeInChat = CGSizeMake(size.width, size.height);
    return size.height+20;
}
//添加好友成功
- (CGFloat)addFriendSuccessCellHeight:(IMAMsg *)packMsg {
    
    TIMCustomElem *elem = (TIMCustomElem *)[packMsg.msg getElem:0];
    NSString *text = [NSString stringWithFormat:@"%@", elem.desc];
    CGSize size = [text textSizeIn:CGSizeMake(KScreenWidth-60, HUGE_VAL) font:UIFontCNMake(13)];
    
    packMsg.showContentSizeInChat = CGSizeMake(size.width, size.height);
    return size.height+20;
    
}

/// 同意添加好友
- (CGFloat)agreeApplyCellHeight:(IMAMsg *)packMsg {
    
    TIMCustomElem *elem = (TIMCustomElem *)[packMsg.msg getElem:0];
    NSString *text = [NSString stringWithFormat:@"%@ 同意", elem.desc];
    CGSize size = [text textSizeIn:CGSizeMake(KScreenWidth-60, HUGE_VAL) font:UIFontCNMake(13)];
    
    packMsg.showContentSizeInChat = CGSizeMake(size.width, size.height);
    return size.height+20;
    
}
///返回商品共享到家园的消息高度
- (CGFloat)shareGoodsMessageContentHeightWithMsg:(IMAMsg *)packMsg
{
    NSDictionary *shareGoodsDic = packMsg.customMsgData[@"shareGoodsData"];
    
    NSString *contentStr = [NSString stringWithFormat:@"“%@”将“%@”共享至“%@”中,点击查看",shareGoodsDic[@"userName"], shareGoodsDic[@"goodsName"], shareGoodsDic[@"showName"]];
    
    NSMutableAttributedString *contentAtt = [[NSMutableAttributedString alloc] initWithString:contentStr];
    
    [contentAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14*RATIO] range:NSMakeRange(0, contentStr.length)];
    [contentAtt addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#666666"] range:NSMakeRange(0, contentStr.length)];
    [contentAtt addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(contentStr.length - 4, 4)];

    //插入图片
    NSTextAttachment *attchment = [[NSTextAttachment alloc]init];
    attchment.bounds = CGRectMake(0, 0, 7, 9);//设置frame
    attchment.image = [UIImage imageNamed:@"more_icon"];//设置图片
    NSAttributedString *imageString = [NSAttributedString attributedStringWithAttachment:(NSTextAttachment *)(attchment)];
    [contentAtt appendAttributedString:imageString];
    
    //保存内容文本
    packMsg.showChatAttributedText = contentAtt;
    
    //获取高度
    CGSize attSize = [contentAtt boundingRectWithSize:CGSizeMake(kScreenWidth*0.6 - 30, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin context:nil].size;
    //注*要向上取整!!!!!!!
    NSInteger minH = 16; //最小高度
    attSize.width = ceil(attSize.width);
    attSize.height = ceil(attSize.height);
    if (attSize.height < minH) {
        attSize.height = minH;
    }
    attSize = CGSizeMake(attSize.width, attSize.height + 5);
    //设置内容的size
    packMsg.showContentSizeInChat = attSize;
    return attSize.height;
}
/// 获取一段文本高度
/// @param content     文本内容
/// @param lineSpacing 行间距
/// @param width       最大宽度
/// @param fontSize    字体大小
- (CGSize)sizeWithText:(NSString *)content lineSpacing:(CGFloat)lineSpacing width:(CGFloat)width fontSize:(CGFloat)fontSize
{
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:content];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
    paragraphStyle.lineSpacing = lineSpacing;  //行高度
    NSMutableAttributedString *attributes = [[NSMutableAttributedString alloc] initWithAttributedString:attStr];
    [attributes addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:fontSize] range:NSMakeRange(0, attributes.length)];
    [attributes addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, attributes.length)];
    
    //获取高度
    CGSize attSize = [attributes boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading |NSStringDrawingUsesDeviceMetrics context:nil].size;
    //注*要向上取整!!!!!!!
    NSInteger minH = 16; //最小高度
    attSize.width = ceil(attSize.width);
    attSize.height = ceil(attSize.height);
    if (attSize.height < minH) {
        attSize.height = minH;
    }
    return attSize;
}
@end


@implementation TIMGroupSystemElem (ShowAPIs)

- (Class)showCellClassOf:(IMAMsg *)msg
{
    return [NSClassFromString(@"CNUnknownMsgCell") class];
}

- (CGSize)sizeInWidth:(CGFloat)width atMsg:(IMAMsg *)packMsg
{
    CGSize size = [[self showDescriptionOf:packMsg] textSizeIn:CGSizeMake(KScreenWidth-60, HUGE_VAL) font:UIFontCNMake(12)];
    return size;
}

@end

@implementation TIMSNSSystemElem (ShowAPIs)
- (Class)showCellClassOf:(IMAMsg *)msg
{
    return [NSClassFromString(@"CNUnknownMsgCell") class];
}
- (CGSize)sizeInWidth:(CGFloat)width atMsg:(IMAMsg *)packMsg
{
    
    return CGSizeMake(width, 100);
}
@end

@implementation TIMProfileSystemElem (ShowAPIs)
- (Class)showCellClassOf:(IMAMsg *)msg
{
    return [NSClassFromString(@"CNUnknownMsgCell") class];
}
// 显示描述
- (NSString *)showDescriptionOf:(IMAMsg *)msg
{
    // 后面转成对应的描述信息
    return @"[资料变更消息]";
}
- (CGSize)sizeInWidth:(CGFloat)width atMsg:(IMAMsg *)packMsg
{
    
    return CGSizeMake(width, 100);
}
@end