TUIMergeMessageCellData.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // TUIMergeMessageCellData.m
  3. // Pods
  4. //
  5. // Created by harvy on 2020/12/9.
  6. // Copyright © 2023 Tencent. All rights reserved.
  7. //
  8. #import "TUIMergeMessageCellData.h"
  9. #import <TIMCommon/TIMDefine.h>
  10. #import "TUITextMessageCellData.h"
  11. #import <TIMCommon/NSString+TUIEmoji.h>
  12. @implementation TUIMergeMessageCellData
  13. + (TUIMessageCellData *)getCellData:(V2TIMMessage *)message {
  14. V2TIMMergerElem *elem = message.mergerElem;
  15. if (elem.layersOverLimit) {
  16. TUITextMessageCellData *limitCell = [[TUITextMessageCellData alloc] initWithDirection:(message.isSelf ? MsgDirectionOutgoing : MsgDirectionIncoming)];
  17. limitCell.content = TIMCommonLocalizableString(TUIKitRelayLayerLimitTips);
  18. return limitCell;
  19. }
  20. TUIMergeMessageCellData *mergeData = [[TUIMergeMessageCellData alloc] initWithDirection:(message.isSelf ? MsgDirectionOutgoing : MsgDirectionIncoming)];
  21. mergeData.title = elem.title;
  22. mergeData.abstractList = [NSArray arrayWithArray:elem.abstractList];
  23. mergeData.abstractSendDetailList = [self.class formatAbstractSendDetailList:elem.abstractList];
  24. mergeData.mergerElem = elem;
  25. mergeData.reuseId = TMergeMessageCell_ReuserId;
  26. return mergeData;
  27. }
  28. + (NSString *)getDisplayString:(V2TIMMessage *)message {
  29. return [NSString stringWithFormat:@"[%@]", TIMCommonLocalizableString(TUIKitRelayChatHistory)];
  30. }
  31. - (Class)getReplyQuoteViewDataClass {
  32. return NSClassFromString(@"TUIMergeReplyQuoteViewData");
  33. }
  34. - (Class)getReplyQuoteViewClass {
  35. return NSClassFromString(@"TUIMergeReplyQuoteView");
  36. }
  37. - (NSAttributedString *)abstractAttributedString {
  38. NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
  39. style.lineSpacing = 4;
  40. style.alignment = isRTL()? NSTextAlignmentRight:NSTextAlignmentLeft;
  41. NSDictionary *attribute = @{
  42. NSForegroundColorAttributeName : [UIColor colorWithRed:187 / 255.0 green:187 / 255.0 blue:187 / 255.0 alpha:1 / 1.0],
  43. NSFontAttributeName : [UIFont systemFontOfSize:12.0],
  44. NSParagraphStyleAttributeName : style
  45. };
  46. NSMutableAttributedString *abstr = [[NSMutableAttributedString alloc] initWithString:@""];
  47. int i = 0;
  48. for (NSString *ab in self.abstractList) {
  49. if (i >= 4) {
  50. break;
  51. }
  52. NSString *resultStr = [NSString stringWithFormat:@"%@\n", ab];
  53. NSString *str = resultStr;
  54. [abstr appendAttributedString:[[NSAttributedString alloc] initWithString:str attributes:attribute]];
  55. i++;
  56. }
  57. return abstr;
  58. }
  59. + (NSMutableArray *)formatAbstractSendDetailList:(NSArray *)originAbstractList {
  60. NSMutableArray *array = [NSMutableArray arrayWithCapacity:3];
  61. NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
  62. style.alignment = isRTL()? NSTextAlignmentRight:NSTextAlignmentLeft;
  63. style.lineBreakMode = NSLineBreakByTruncatingTail;
  64. NSDictionary *attribute = @{
  65. NSForegroundColorAttributeName : [UIColor colorWithRed:187 / 255.0 green:187 / 255.0 blue:187 / 255.0 alpha:1 / 1.0],
  66. NSFontAttributeName : [UIFont systemFontOfSize:12.0],
  67. NSParagraphStyleAttributeName : style
  68. };
  69. int i = 0;
  70. for (NSString *ab in originAbstractList) {
  71. if (i >= 4) {
  72. break;
  73. }
  74. NSString *str = ab;
  75. NSString * splitStr = @":";
  76. if ([str tui_containsString:@"\u202C:"]) {
  77. splitStr = @"\u202C:";
  78. }
  79. NSArray<NSString *> *result = [str componentsSeparatedByString:splitStr];
  80. NSString *sender = result[0];
  81. NSString *detail = result[1];
  82. sender = [NSString stringWithFormat:@"%@",sender];
  83. detail = [NSString stringWithFormat:@"%@",detail.getLocalizableStringWithFaceContent];
  84. NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:3];
  85. if(sender.length>0 ){
  86. NSMutableAttributedString *abstr = [[NSMutableAttributedString alloc] initWithString:@""];
  87. [abstr appendAttributedString:[[NSAttributedString alloc] initWithString:sender attributes:attribute]];
  88. [dic setObject:abstr forKey:@"sender"];
  89. }
  90. if(detail.length>0 ){
  91. NSMutableAttributedString *abstr = [[NSMutableAttributedString alloc] initWithString:@""];
  92. [abstr appendAttributedString:[[NSAttributedString alloc] initWithString:detail attributes:attribute]];
  93. [dic setObject:abstr forKey:@"detail"];
  94. }
  95. [array addObject:dic];
  96. i++;
  97. }
  98. return array;
  99. }
  100. - (BOOL)isArString:(NSString *)text {
  101. NSString *isoLangCode = (__bridge_transfer NSString *)CFStringTokenizerCopyBestStringLanguage((__bridge CFStringRef)text, CFRangeMake(0, text.length));
  102. if ([isoLangCode isEqualToString:@"ar"]) {
  103. return YES;
  104. }
  105. return NO;
  106. }
  107. @end