TUIMessageCellData.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. // Created by Tencent on 2023/06/09.
  2. // Copyright © 2023 Tencent. All rights reserved.
  3. /**
  4. *
  5. * 本文件声明了 TUIMessageCellData 类。
  6. * - "消息单元"数据源作为多种细化数据源的父类,提供了各类"消息单元"数据源属性与行为的基本模板。
  7. * - 本文件中的"数据源类"是所有消息数据的基类,各个类型的数据源都继承与本类或者本类的子类。
  8. * - 当您想要自定义消息时,需要将自定义消息的数据源继承于本类或者本类的子类。
  9. *
  10. * This file declares the TUIMessageCellData class.
  11. * - The "message unit" data source, as the parent class of various detailed data sources, provides basic templates for the properties and behaviors of various
  12. * "message unit" data sources.
  13. * - The "data source class" in this document is the base class for all message data, and each type of data source inherits from this class or its subclasses.
  14. * - When you want to customize the message, you need to inherit the data source of the customized message from this class or a subclass of this class.
  15. */
  16. #import <TIMCommon/TIMCommonModel.h>
  17. #import <TIMCommon/TIMDefine.h>
  18. #import "TUIMessageCellLayout.h"
  19. NS_ASSUME_NONNULL_BEGIN
  20. typedef void (^TDownloadProgress)(NSInteger curSize, NSInteger totalSize);
  21. typedef void (^TDownloadResponse)(int code, NSString *desc, NSString *path);
  22. /**
  23. * 消息状态枚举
  24. *
  25. * The definition of message status
  26. */
  27. typedef NS_ENUM(NSUInteger, TMsgStatus) {
  28. Msg_Status_Init, // 消息创建, message initial
  29. Msg_Status_Sending, // 消息发送中, message sending
  30. Msg_Status_Sending_2, // 消息发送中_2,推荐使用,message sending, recommended
  31. Msg_Status_Succ, // 消息发送成功, message sent successfully
  32. Msg_Status_Fail, // 消息发送失败, Failed to send message
  33. };
  34. /**
  35. * 消息方向枚举
  36. * 消息方向影响气泡图标、气泡位置等 UI 风格。
  37. *
  38. * The definition of message direction
  39. * Message direction affects UI styles such as bubble icons, bubble positions, etc.
  40. */
  41. typedef NS_ENUM(NSUInteger, TMsgDirection) {
  42. MsgDirectionIncoming, // 消息接收
  43. MsgDirectionOutgoing, // 消息发送
  44. };
  45. /**
  46. * 【模块名称】TUIMessageCellData
  47. * 【功能说明】聊天消息单元数据源,配合消息控制器实现消息收发的业务逻辑。
  48. * - 用于存储消息管理与逻辑实现所需要的各类数据与信息。包括消息状态、消息发送者 ID 与头像等一系列数据。
  49. * - 聊天信息数据单元整合并调用了 IM SDK,能够通过 SDK 提供的接口实现消息的业务逻辑。
  50. *
  51. * 【Module name】TUIMessageCellData
  52. * 【Function description】The data source of the chat message unit cooperates with the message controller to realize the business logic of message sending and
  53. * receiving.
  54. * - It is used to store various data and information required for message management and logic implementation. Including a series of data such as message
  55. * status, message sender ID and avatar.
  56. * - The chat information data unit integrates and calls the IM SDK, and can implement the business logic of the message through the interface provided by the
  57. * SDK.
  58. */
  59. @interface TUIMessageCellData : TUICommonCellData
  60. /**
  61. * Getting cellData according to message
  62. */
  63. + (TUIMessageCellData *)getCellData:(V2TIMMessage *)message;
  64. /**
  65. * Getting the display string according to the message
  66. */
  67. + (NSString *)getDisplayString:(V2TIMMessage *)message;
  68. /**
  69. * 获取消息回复自定义引用的布局及其数据的类
  70. * Class to get the layout of the message reply custom reference and its data
  71. */
  72. - (Class)getReplyQuoteViewDataClass;
  73. - (Class)getReplyQuoteViewClass;
  74. /**
  75. * Message unique id
  76. */
  77. @property(nonatomic, strong) NSString *msgID;
  78. /**
  79. * Message sender ID
  80. */
  81. @property(nonatomic, strong) NSString *identifier;
  82. /**
  83. * Sender's avatar url
  84. */
  85. @property(nonatomic, strong) NSURL *__nullable avatarUrl;
  86. /**
  87. * Sender's avatar
  88. */
  89. @property(nonatomic, strong) UIImage *__nullable avatarImage __attribute__((deprecated("not supported")));
  90. /**
  91. * Whether to use the receiver's avatar, default is NO
  92. */
  93. @property(nonatomic, assign) BOOL isUseMsgReceiverAvatar;
  94. /**
  95. * 信息发送者昵称
  96. * 昵称与 ID 不一定相同,在聊天界面默认展示昵称。
  97. *
  98. * Sender's nickname
  99. * The nickname and ID are not necessarily the same, and the nickname is displayed by default in the chat interface.
  100. */
  101. @property(nonatomic, strong) NSString *name;
  102. /**
  103. * 名称展示 flag
  104. * - 好友聊天时,默认不在消息中展示昵称。
  105. * - 群组聊天时,对于群组内其他用户发送的信息,展示昵称。
  106. * - YES:展示昵称;NO:不展示昵称。
  107. *
  108. * The flag of showing name
  109. * - In 1 vs 1 chat, the nickname is not displayed in the message by default.
  110. * - In group chat, the nickname is displayed for messages sent by other users in the group.
  111. * - YES: showing nickname; NO: hidden nickname
  112. */
  113. @property(nonatomic, assign) BOOL showName;
  114. /**
  115. * 头像展示
  116. * Display user avatar
  117. */
  118. @property(nonatomic, assign) BOOL showAvatar;
  119. /**
  120. * 当前消息是否和下一条消息发送者一样
  121. * Whether the current message is the same as the sender of the next message
  122. */
  123. @property(nonatomic, assign) BOOL sameToNextMsgSender;
  124. /**
  125. * 显示消息多选 flag
  126. * - 消息列表中,默认不显示选择按钮,当长按消息弹出多选按钮并点击后,消息列表变为可多选状态
  127. * - YES: 可多选,展示多选视图;NO:不可多选,展示默认视图
  128. *
  129. * The flag of showing message multiple selection
  130. * - In the message list, the selection button is not displayed by default. When you long press the message to pop up the multi-select button and click it, the
  131. * message list becomes multi-selectable.
  132. * - YES: Enable multiple selection, multiple selection views are displayed; NO: Disable multiple selection, the default view is displayed.
  133. */
  134. @property(nonatomic, assign) BOOL showCheckBox;
  135. /**
  136. * 显示是否选中 flag
  137. * The flag of selected
  138. */
  139. @property(nonatomic, assign) BOOL selected;
  140. /**
  141. * 消息 @ 用户列表
  142. * The user list in at message
  143. */
  144. @property(nonatomic, strong) NSMutableArray<NSString *> *atUserList;
  145. /**
  146. * 消息方向
  147. * - 消息方向影响气泡图标、气泡位置等 UI 风格。
  148. *
  149. * Message direction
  150. * - Message direction affects UI styles such as bubble icons, bubble positions, etc.
  151. */
  152. @property(nonatomic, assign) TMsgDirection direction;
  153. /**
  154. * 消息状态
  155. * Message status
  156. */
  157. @property(nonatomic, assign) TMsgStatus status;
  158. /**
  159. * 内层消息
  160. * IM SDK 提供的消息对象。内含各种获取消息信息的成员函数,包括获取优先级、获取元素索引、获取离线消息配置信息等。
  161. * 详细信息请参考 TXIMSDK__Plus_iOS\Frameworks\ImSDK_Plus.framework\Headers\V2TIMMessage.h
  162. *
  163. * IMSDK message
  164. * The Message object provided by IM SDK. Contains various member functions for obtaining message information, including obtaining priority, obtaining element
  165. * index, obtaining offline message configuration information, etc. For details, please refer to
  166. * TXIMSDK__Plus_iOS\Frameworks\ImSDK_Plus.framework\Headers\V2TIMMessage.h
  167. */
  168. @property(nonatomic, strong) V2TIMMessage *innerMessage;
  169. /**
  170. * 消息单元布局
  171. * 包括消息边距、气泡内边距、头像边距、头像大小等 UI 布局。
  172. * 详细信息请参考 Section\Chat\CellLayout\TUIMessageCellLayout.h
  173. *
  174. * Message unit layout
  175. * It includes UI information such as message margins, bubble padding, avatar margins, and avatar size.
  176. * For details, please refer to Section\Chat\CellLayout\TUIMessageCellLayout.h
  177. */
  178. @property(nonatomic, strong) TUIMessageCellLayout *cellLayout;
  179. /**
  180. * 是否显示已读回执
  181. *
  182. * The flag of whether showing read receipts.
  183. */
  184. @property(nonatomic, assign) BOOL showReadReceipt;
  185. /**
  186. * 是否显示消息时间
  187. *
  188. * The flag of whether showing message time.
  189. */
  190. @property(nonatomic, assign) BOOL showMessageTime;
  191. /**
  192. * 是否显示消息编辑 x 人回复按钮
  193. *
  194. * The flag of whether showing the button which indicated how many people modiffied.
  195. */
  196. @property(nonatomic, assign) BOOL showMessageModifyReplies;
  197. /**
  198. * 高亮关键字,当改关键字不为空时,会短暂高亮显示,主要用在消息搜索场景中
  199. *
  200. * Highlight keywords, when the keyword is not empty, it will be highlighted briefly, mainly used in message search scenarios.
  201. */
  202. @property(nonatomic, copy) NSString *__nullable highlightKeyword;
  203. /**
  204. * 消息已读回执
  205. *
  206. * Message read receipt
  207. */
  208. @property(nonatomic, strong) V2TIMMessageReceipt *messageReceipt;
  209. /**
  210. * 当前消息的「回复消息」列表
  211. *
  212. * List of Reply Messages for the current message
  213. */
  214. @property(nonatomic, strong) NSArray *messageModifyReplies;
  215. /**
  216. * 「表情互动消息」的用户信息
  217. * key: emoji key value: user_id
  218. *
  219. * User information of "Emoji Interactive Message"
  220. */
  221. @property(nonatomic, strong) NSDictionary *messageModifyReacts;
  222. @property(nonatomic, assign) CGSize messageModifyReactsSize;
  223. /**
  224. * 当前会话参与消息编辑(回复、表情回应)的好友信息
  225. * Information about friends who participate in message editing (reply, emoticon react) in the current conversation
  226. */
  227. @property(nonatomic, strong) NSDictionary *messageModifyUserInfos;
  228. /// Size for bottom container.
  229. @property(nonatomic, assign) CGSize bottomContainerSize;
  230. /// Placeholder data, to be replaced after data preparation is completed.
  231. @property(nonatomic, strong) TUIMessageCellData* _Nullable placeHolderCellData;
  232. /// Video transcoding progress
  233. @property(nonatomic, assign) CGFloat videoTranscodingProgress;
  234. /// If cell content can be forwarded.
  235. - (BOOL)canForward;
  236. /**
  237. * 根据消息方向(收/发)初始化消息单元
  238. * - 除了基本消息的初始化外,还包括根据方向设置方向变量、昵称字体等。
  239. * - 同时为子类提供可继承的行为。
  240. *
  241. * Initialize the message unit according to the message direction (receive/sent)
  242. * - In addition to the initialization of basic messages, it also includes setting direction variables, nickname fonts, etc. according to the direction.
  243. * - Also provides inheritable behavior for subclasses.
  244. */
  245. - (instancetype)initWithDirection:(TMsgDirection)direction NS_DESIGNATED_INITIALIZER;
  246. - (instancetype)init NS_UNAVAILABLE;
  247. @property(nonatomic, assign) CGSize msgStatusSize;
  248. @end
  249. NS_ASSUME_NONNULL_END
  250. /**
  251. * 【模块名称】TUIMessageCellDataFileUploadProtocol
  252. * 【功能说明】文件类型的消息, 统一上传(发送)进度字段
  253. *
  254. * 【Module name】TUIMessageCellDataFileUploadProtocol
  255. * 【Function description】File type message, unified upload (send) progress field
  256. */
  257. @protocol TUIMessageCellDataFileUploadProtocol <NSObject>
  258. @required
  259. /**
  260. * 上传(发送)进度
  261. *
  262. * The progress of uploading (sending)
  263. */
  264. @property(nonatomic, assign) NSUInteger uploadProgress;
  265. @end
  266. @protocol TUIMessageCellDataFileDownloadProtocol <NSObject>
  267. @required
  268. /**
  269. * 下载(接收)进度
  270. *
  271. * The progress of downloading (receving)
  272. */
  273. @property(nonatomic, assign) NSUInteger downladProgress;
  274. /**
  275. * 下载标识符
  276. * YES:正在下载;NO:未在下载
  277. *
  278. * The flag of whether is downloading
  279. * YES: downloading; NO: not download
  280. */
  281. @property(nonatomic, assign) BOOL isDownloading;
  282. @end