TUIFoldConversationListDataProvider.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //
  2. // TUIFoldConversationListDataProvider.m
  3. // TUIConversation
  4. //
  5. // Created by wyl on 2022/11/22.
  6. // Copyright © 2023 Tencent. All rights reserved.
  7. //
  8. #import "TUIFoldConversationListDataProvider.h"
  9. #import <TIMCommon/TIMDefine.h>
  10. #import <TUICore/TUICore.h>
  11. #import "TUIConversationCellData.h"
  12. #import <TIMCommon/NSString+TUIEmoji.h>
  13. @implementation TUIFoldConversationListDataProvider
  14. - (Class)getConversationCellClass {
  15. return [TUIConversationCellData class];
  16. }
  17. - (NSString *)getDisplayStringFromService:(V2TIMMessage *)msg {
  18. NSDictionary *param = @{TUICore_TUIChatService_GetDisplayStringMethod_MsgKey : msg};
  19. return [TUICore callService:TUICore_TUIChatService method:TUICore_TUIChatService_GetDisplayStringMethod param:param];
  20. }
  21. - (NSMutableAttributedString *)getLastDisplayString:(V2TIMConversation *)conv {
  22. /**
  23. * If has group-at message, the group-at information will be displayed first
  24. */
  25. NSString *atStr = [self getGroupAtTipString:conv];
  26. NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:atStr];
  27. NSDictionary *attributeDict = @{NSForegroundColorAttributeName : [UIColor d_systemRedColor]};
  28. [attributeString setAttributes:attributeDict range:NSMakeRange(0, attributeString.length)];
  29. /**
  30. * If there is a draft box, the draft box information will be displayed first
  31. */
  32. if (conv.draftText.length > 0) {
  33. NSAttributedString *draft = [[NSAttributedString alloc] initWithString:TIMCommonLocalizableString(TUIKitMessageTypeDraftFormat)
  34. attributes:@{NSForegroundColorAttributeName : RGB(250, 81, 81)}];
  35. [attributeString appendAttributedString:draft];
  36. NSString *draftContentStr = [self getDraftContent:conv];
  37. NSMutableAttributedString *draftContent = [draftContentStr getAdvancedFormatEmojiStringWithFont:[UIFont systemFontOfSize:16.0]
  38. textColor:TUIChatDynamicColor(@"chat_input_text_color", @"#000000")
  39. emojiLocations:nil];
  40. [attributeString appendAttributedString:draftContent];
  41. } else {
  42. /**
  43. * No drafts, show conversation lastMsg information
  44. */
  45. NSString *lastMsgStr = @"";
  46. /**
  47. * Attempt to get externally customized display information
  48. */
  49. if (self.delegate && [self.delegate respondsToSelector:@selector(getConversationDisplayString:)]) {
  50. lastMsgStr = [self.delegate getConversationDisplayString:conv];
  51. }
  52. /**
  53. * If there is no external customization, get the lastMsg display information through the message module
  54. */
  55. if (lastMsgStr.length == 0 && conv.lastMessage) {
  56. NSDictionary *param = @{TUICore_TUIChatService_GetDisplayStringMethod_MsgKey : conv.lastMessage};
  57. lastMsgStr = [TUICore callService:TUICore_TUIChatService method:TUICore_TUIChatService_GetDisplayStringMethod param:param];
  58. }
  59. /**
  60. * If there is no lastMsg display information and no draft information, return nil directly
  61. */
  62. if (lastMsgStr.length == 0) {
  63. return nil;
  64. }
  65. [attributeString appendAttributedString:[[NSAttributedString alloc] initWithString:lastMsgStr]];
  66. }
  67. /**
  68. *
  69. * If do-not-disturb is set, the message do-not-disturb state is displayed
  70. * The default state of the meeting type group is V2TIM_RECEIVE_NOT_NOTIFY_MESSAGE, and the UI does not process it.
  71. */
  72. if ([self isConversationNotDisturb:conv] && conv.unreadCount > 0) {
  73. NSAttributedString *unreadString = [[NSAttributedString alloc]
  74. initWithString:[NSString stringWithFormat:@"[%d %@] ", conv.unreadCount, TIMCommonLocalizableString(TUIKitMessageTypeLastMsgCountFormat)]];
  75. [attributeString insertAttributedString:unreadString atIndex:0];
  76. }
  77. /**
  78. * If the status of the lastMsg of the conversation is sending or failed, display the sending status of the message (the draft box does not need to display
  79. * the sending status)
  80. */
  81. if (!conv.draftText && (V2TIM_MSG_STATUS_SENDING == conv.lastMessage.status || V2TIM_MSG_STATUS_SEND_FAIL == conv.lastMessage.status)) {
  82. UIFont *textFont = [UIFont systemFontOfSize:14];
  83. NSAttributedString *spaceString = [[NSAttributedString alloc] initWithString:@" " attributes:@{NSFontAttributeName : textFont}];
  84. NSTextAttachment *attchment = [[NSTextAttachment alloc] init];
  85. UIImage *image = nil;
  86. if (V2TIM_MSG_STATUS_SENDING == conv.lastMessage.status) {
  87. image = TUIConversationCommonBundleImage(@"msg_sending_for_conv");
  88. } else {
  89. image = TUIConversationCommonBundleImage(@"msg_error_for_conv");
  90. }
  91. attchment.image = image;
  92. attchment.bounds = CGRectMake(0, -(textFont.lineHeight - textFont.pointSize) / 2, textFont.pointSize, textFont.pointSize);
  93. NSAttributedString *imageString = [NSAttributedString attributedStringWithAttachment:(NSTextAttachment *)(attchment)];
  94. [attributeString insertAttributedString:spaceString atIndex:0];
  95. [attributeString insertAttributedString:imageString atIndex:0];
  96. }
  97. return attributeString;
  98. }
  99. @end