TUISystemMessageCellData.m 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // TUISystemMessageCellData.m
  3. // TXIMSDK_TUIKit_iOS
  4. //
  5. // Created by annidyfeng on 2019/5/21.
  6. // Copyright © 2023 Tencent. All rights reserved.
  7. //
  8. #import "TUISystemMessageCellData.h"
  9. #import <TIMCommon/TIMDefine.h>
  10. #import "TUIRelationUserModel.h"
  11. @implementation TUISystemMessageCellData
  12. - (instancetype)initWithDirection:(TMsgDirection)direction {
  13. self = [super initWithDirection:direction];
  14. if (self) {
  15. self.showAvatar = NO;
  16. _contentFont = [UIFont systemFontOfSize:13];
  17. _contentColor = [UIColor d_systemGrayColor];
  18. self.cellLayout = [TUIMessageCellLayout systemMessageLayout];
  19. }
  20. return self;
  21. }
  22. - (NSMutableAttributedString *)attributedString {
  23. __block BOOL forceRefresh = NO;
  24. [self.additionalUserInfoResult enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, TUIRelationUserModel * _Nonnull obj, BOOL * _Nonnull stop) {
  25. NSString *str = [NSString stringWithFormat:@"{%@}", key];
  26. NSString *showName = obj.userID;
  27. if (obj.nameCard.length > 0) {
  28. showName = obj.nameCard;
  29. } else if (obj.friendRemark.length > 0) {
  30. showName = obj.friendRemark;
  31. } else if (obj.nickName.length > 0) {
  32. showName = obj.nickName;
  33. }
  34. if ([self.content containsString:str]) {
  35. self.content = [self.content stringByReplacingOccurrencesOfString:str withString:showName];
  36. forceRefresh = YES;
  37. }
  38. }];
  39. if (forceRefresh || (_attributedString == nil && self.content.length > 0)) {
  40. NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:self.content];
  41. NSDictionary *attributeDict = @{NSForegroundColorAttributeName : [UIColor d_systemGrayColor]};
  42. [attributeString setAttributes:attributeDict range:NSMakeRange(0, attributeString.length)];
  43. if (self.supportReEdit) {
  44. NSString *reEditStr = TIMCommonLocalizableString(TUIKitMessageTipsReEditMessage);
  45. [attributeString appendAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@", reEditStr]]];
  46. NSDictionary *attributeDict = @{NSForegroundColorAttributeName : [UIColor d_systemBlueColor]};
  47. [attributeString setAttributes:attributeDict range:NSMakeRange(self.content.length + 1, reEditStr.length)];
  48. [attributeString addAttribute:NSUnderlineStyleAttributeName
  49. value:[NSNumber numberWithInteger:NSUnderlineStyleNone]
  50. range:NSMakeRange(self.content.length + 1, reEditStr.length)];
  51. }
  52. _attributedString = attributeString;
  53. }
  54. return _attributedString;
  55. }
  56. - (NSArray<NSString *> *)requestForAdditionalUserInfo {
  57. NSMutableArray *result = [NSMutableArray arrayWithArray:[super requestForAdditionalUserInfo]];
  58. if (self.replacedUserIDList) {
  59. [result addObjectsFromArray:self.replacedUserIDList];
  60. }
  61. return result;
  62. }
  63. static UIFont *gTextFont;
  64. + (void)setTextFont:(UIFont *)textFont {
  65. gTextFont = textFont;
  66. }
  67. + (UIFont *)textFont {
  68. return gTextFont;
  69. }
  70. static UIColor *gTextColor;
  71. + (void)setTextColor:(UIColor *)textColor {
  72. gTextColor = textColor;
  73. }
  74. + (UIColor *)textColor {
  75. return gTextColor;
  76. }
  77. static UIColor *gTextBackgroundColor;
  78. + (void)setTextBackgroundColor:(UIColor *)textBackgroundColor {
  79. gTextBackgroundColor = textBackgroundColor;
  80. }
  81. + (UIColor *)textBackgroundColor {
  82. return gTextBackgroundColor;
  83. }
  84. @end