EMChatMessage.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. /**
  2. * \~chinese
  3. * @header EMChatMessage.h
  4. * @abstract 聊天消息
  5. * @author Hyphenate
  6. * @version 3.00
  7. *
  8. * \~english
  9. * @header EMChatMessage.h
  10. * @abstract Chat message
  11. * @author Hyphenate
  12. * @version 3.00
  13. */
  14. #import <Foundation/Foundation.h>
  15. #import "EMMessageBody.h"
  16. #import "EMMessageReaction.h"
  17. /**
  18. * \~chinese
  19. * 聊天类型。
  20. *
  21. * \~english
  22. * Chat types.
  23. */
  24. typedef NS_ENUM(NSInteger, EMChatType) {
  25. EMChatTypeChat = 0, /** \~chinese 单聊。 \~english One-to-one chat. */
  26. EMChatTypeGroupChat, /** \~chinese 群聊。 \~english Group chat. */
  27. EMChatTypeChatRoom, /** \~chinese 聊天室。 \~english Chat room. */
  28. };
  29. /**
  30. * \~chinese
  31. * 消息发送状态。
  32. *
  33. * \~english
  34. * The message delivery states.
  35. */
  36. typedef NS_ENUM(NSInteger, EMMessageStatus) {
  37. EMMessageStatusPending = 0, /** \~chinese 发送未开始。 \~english The message delivery is pending.*/
  38. EMMessageStatusDelivering, /** \~chinese 正在发送。 \~english The message is being delivered.*/
  39. EMMessageStatusSucceed, /** \~chinese 发送成功。 \~english The message is successfully delivered.*/
  40. EMMessageStatusFailed, /** \~chinese 发送失败。 \~english The message fails to be delivered.*/
  41. };
  42. /**
  43. * \~chinese
  44. * 消息方向类型。
  45. *
  46. * \~english
  47. * The message directions.
  48. */
  49. typedef NS_ENUM(NSInteger, EMMessageDirection) {
  50. EMMessageDirectionSend = 0, /** \~chinese 该消息是当前用户发送出去的。\~english This message is sent from the local client.*/
  51. EMMessageDirectionReceive, /** \~chinese 该消息是当前用户接收到的。 \~english The message is received by the local client.*/
  52. };
  53. /**
  54. * \~chinese
  55. * 聊天室消息的送达优先级。
  56. *
  57. * \~english
  58. * The chat room message priorities.
  59. */
  60. typedef NS_ENUM(NSInteger, EMChatRoomMessagePriority) {
  61. EMChatRoomMessagePriorityHigh = 0, /* \~chinese 高。 \~english High. */
  62. EMChatRoomMessagePriorityNormal, /* \~chinese 中。 \~english Normal. */
  63. EMChatRoomMessagePriorityLow, /* \~chinese 低。 \~english Low. */
  64. };
  65. @class EMChatThread;
  66. /**
  67. * \~chinese
  68. * 聊天消息类。
  69. *
  70. * \~english
  71. * The chat message class.
  72. */
  73. @interface EMChatMessage : NSObject
  74. /**
  75. * \~chinese
  76. * 消息 ID,是消息的唯一标识。
  77. *
  78. * \~english
  79. * The message ID, which is the unique identifier of the message.
  80. */
  81. @property (nonatomic, copy) NSString * _Nonnull messageId;
  82. /**
  83. * \~chinese
  84. * 会话 ID,是会话的唯一标识。
  85. *
  86. * \~english
  87. * The conversation ID, which is the unique identifier of the conversation.
  88. */
  89. @property (nonatomic, copy) NSString * _Nonnull conversationId;
  90. /**
  91. * \~chinese
  92. * 消息的方向。
  93. *
  94. * \~english
  95. * The message delivery direction.
  96. */
  97. @property (nonatomic) EMMessageDirection direction;
  98. /**
  99. * \~chinese
  100. * 消息的发送方。
  101. *
  102. * \~english
  103. * The user sending the message.
  104. */
  105. @property (nonatomic, copy) NSString * _Nonnull from;
  106. /**
  107. * \~chinese
  108. * 消息的接收方。
  109. *
  110. * \~english
  111. * The user receiving the message.
  112. */
  113. @property (nonatomic, copy) NSString * _Nonnull to;
  114. /**
  115. * \~chinese
  116. * 服务器收到该消息的 Unix 时间戳,单位为毫秒。
  117. *
  118. * \~english
  119. * The Unix timestamp for the chat server receiving the message.
  120. *
  121. * The unit is second.
  122. */
  123. @property (nonatomic) long long timestamp;
  124. /**
  125. * \~chinese
  126. * 客户端发送或收到此消息的时间。
  127. *
  128. * 单位为毫秒。
  129. *
  130. * \~english
  131. * The Unix timestamp for the local client sending or receiving the message.
  132. *
  133. * The unit is millisecond.
  134. */
  135. @property (nonatomic) long long localTime;
  136. /**
  137. * \~chinese
  138. * 聊天类型。
  139. *
  140. * \~english
  141. * The chat type.
  142. */
  143. @property (nonatomic) EMChatType chatType;
  144. /**
  145. * \~chinese
  146. * 消息发送状态。详见 {@link EMMessageStatus}。
  147. *
  148. * \~english
  149. * The message delivery status. See {@link EMMessageStatus}.
  150. */
  151. @property (nonatomic) EMMessageStatus status;
  152. /*!
  153. * \~chinese
  154. * 是否为在线消息:
  155. * - `YES`: 在线消息。
  156. * - `NO`: 离线消息。
  157. *
  158. * 消息的在线状态在本地数据库不存储。
  159. *
  160. * 从数据库读取或拉取的漫游消息默认值为在线。
  161. *
  162. * \~english
  163. *
  164. * Whether the message is an online message:
  165. * - `YES`: online message.
  166. * - `NO`: offline message.
  167. *
  168. * This message status is not stored in the local database.
  169. *
  170. * Messages read from the database or pulled from the server are regarded as online.
  171. *
  172. *
  173. */
  174. @property (nonatomic, readonly) BOOL onlineState;
  175. /**
  176. * \~chinese
  177. * 是否(消息接收方)已发送或(消息发送方)已收到消息已读回执。
  178. *
  179. * - `YES`: 是;
  180. * - `NO`: 否。
  181. *
  182. * \~english
  183. * Whether the message read receipt is sent (from the message recipient) or received (by the message sender).
  184. *
  185. * - `YES`: Yes;
  186. * - `NO`: No.
  187. */
  188. @property (nonatomic) BOOL isReadAcked;
  189. /**
  190. * \~chinese
  191. * 是否是在子区内发送的消息:
  192. *
  193. * - `YES`: 是;
  194. * - `NO`: 否。
  195. *
  196. * \~english
  197. * Whether this message is sent within a thread:
  198. *
  199. * - `YES`: Yes;
  200. * - `NO`: No.
  201. */
  202. @property (nonatomic) BOOL isChatThreadMessage;
  203. /**
  204. * \~chinese
  205. * 是否需要发送群组已读消息回执:
  206. *
  207. * - `YES`: 是;
  208. * - `NO`: 否。
  209. *
  210. * \~english
  211. * Whether read receipts are required for group messages.
  212. *
  213. * - `YES`: Yes;
  214. * - `NO`: No.
  215. */
  216. @property (nonatomic) BOOL isNeedGroupAck;
  217. /**
  218. * \~chinese
  219. * 收到的群组已读消息回执数量。
  220. *
  221. * \~english
  222. * The number of read receipts received for group messages.
  223. */
  224. @property (nonatomic, readonly) int groupAckCount;
  225. /**
  226. * \~chinese
  227. * 是否已发送或收到消息送达回执。
  228. *
  229. * - `YES`: 是;
  230. * - `NO`: 否。
  231. *
  232. * 对于消息发送方,该属性表示是否已收到送达回执。
  233. *
  234. * 对于消息接收方,该属性表示是否已发送送达回执。
  235. *
  236. * 如果你将 `EMOptions` 中的 `enableDeliveryAck` 设为 `YES`,则 SDK 在收到消息后会自动发送送法回执。
  237. *
  238. * \~english
  239. * Whether the delivery receipt is sent or received:
  240. *
  241. * - `YES`: Yes;
  242. * - `NO`: No.
  243. * For the message sender, this attribute indicates whether the delivery receipt is received.
  244. *
  245. * For the message recipient, this attribute indicates whether the delivery receipt is sent.
  246. *
  247. * If you set `enableDeliveryAck` in `EMOptions` as `YES`, the SDK automatically sends the delivery receipt after receiving a message.
  248. */
  249. @property (nonatomic) BOOL isDeliverAcked;
  250. /**
  251. * \~chinese
  252. * 消息是否已读。
  253. *
  254. * - `YES`: 是;
  255. * - `NO`: 否。
  256. *
  257. * \~english
  258. * Whether the message is read.
  259. *
  260. * - `YES`: Yes;
  261. * - `NO`: No.
  262. */
  263. @property (nonatomic) BOOL isRead;
  264. /**
  265. * \~chinese
  266. * 语音消息是否已播放。
  267. *
  268. * - `YES`: 是;
  269. * - `NO`: 否。
  270. *
  271. * \~english
  272. * Whether the voice message is played.
  273. *
  274. * - `YES`: Yes;
  275. * - `NO`: No.
  276. */
  277. @property (nonatomic) BOOL isListened;
  278. /**
  279. * \~chinese
  280. * 消息体。
  281. *
  282. * \~english
  283. * The message body.
  284. */
  285. @property (nonatomic, strong) EMMessageBody * _Nonnull body;
  286. /**
  287. * \~chinese
  288. * Reaction 列表。
  289. *
  290. * \~english
  291. * The Reaction list.
  292. */
  293. @property (nonatomic, readonly) NSArray <EMMessageReaction *>* _Nullable reactionList;
  294. /**
  295. * \~chinese
  296. * 根据 Reaction ID 获取 Reaction 内容。
  297. *
  298. * @param reaction Reaction ID。
  299. *
  300. * @result Reaction 内容。
  301. *
  302. * \~english
  303. * Gets the Reaction content by the Reaction ID.
  304. *
  305. * @param reaction The Reaction ID.
  306. *
  307. * @result The Reaction content.
  308. */
  309. - (EMMessageReaction *_Nullable)getReaction:(NSString * _Nonnull)reaction;
  310. /**
  311. * \~chinese
  312. * 自定义消息扩展。
  313. *
  314. * 该参数数据形式是一个 Key-Value 的键值对,其中 Key 为 NSString 型,Value 为 NSString、NSNumber 类型的 Bool、Int、Unsigned int、long long 或 double.
  315. *
  316. * \~english
  317. * The custom message extension.
  318. *
  319. * This data is in the key-value format, where the key is the extension field name of the NSString type, and the value must be of the NSString or NSNumber (Bool, Int, unsigned int, long long, double) type.
  320. */
  321. @property (nonatomic, copy) NSDictionary * _Nullable ext;
  322. /**
  323. * \~chinese
  324. * 获取消息内的 thread 概览。
  325. *
  326. * 目前仅群组消息支持。
  327. *
  328. * \~english
  329. * Gets an overview of the thread in the message.
  330. *
  331. * Currently, this attribute is valid only for group messages.
  332. */
  333. @property (readonly) EMChatThread * _Nullable chatThread;
  334. /**
  335. * \~chinese
  336. *
  337. * 设置聊天室消息的到达优先级。
  338. *
  339. * 目前,该属性仅支持聊天室消息。默认值为 `normal`,表示普通优先级。
  340. *
  341. * \~english
  342. * Sets the priority of a chat room message.
  343. *
  344. * Currently, this attribute is valid only for chat room messages.
  345. *
  346. * The default value is `normal`, indicating the normal priority.
  347. */
  348. @property (nonatomic) EMChatRoomMessagePriority priority;
  349. /**
  350. * \~chinese
  351. *
  352. * 消息是否只投递给在线用户:
  353. * - `YES`:只有消息接收方在线时才能投递成功。若接收方离线,消息不投递。
  354. * - (默认)`NO`:无论接收方在线或离线,消息均投递。
  355. *
  356. *
  357. * \~english
  358. *
  359. * Whether the message is delivered only when the recipient(s) is/are online:
  360. * - `YES`:The message is delivered only when the recipient(s) is/are online. If the recipient is offline, the message is not delivered.
  361. * - (Default) `NO`:The message is delivered to the recipients regardless of whether they are online or offline.
  362. */
  363. @property (nonatomic) BOOL deliverOnlineOnly;
  364. /**
  365. * \~chinese
  366. *
  367. * 定向消息的接收方。
  368. *
  369. * 该属性仅对群组和聊天室中的消息有效。若传入 `nil`,则消息发送给群组或聊天室的所有成员。
  370. *
  371. * \~english
  372. *
  373. * The recipient list of a targeted message.
  374. *
  375. * This property is used only for messages in groups and chat rooms. If you pass in `nil`, the messages are sent to all members in the group or chat room.
  376. */
  377. @property (nonatomic,strong) NSArray<NSString*>* _Nullable receiverList;
  378. /**
  379. * \~chinese
  380. * 初始化消息实例。
  381. *
  382. * @param aConversationId 会话 ID。
  383. * @param aFrom 消息发送方。
  384. * @param aTo 消息接收方。
  385. * @param aBody 消息体实例。
  386. * @param aExt 扩展信息。
  387. *
  388. * @result 消息实例。
  389. *
  390. * \~english
  391. * Initializes a message instance.
  392. *
  393. * @param aConversationId The conversation ID.
  394. * @param aFrom The user that sends the message.
  395. * @param aTo The user that receives the message.
  396. * @param aBody The message body.
  397. * @param aExt The message extention.
  398. *
  399. * @result The message instance.
  400. */
  401. - (instancetype _Nonnull)initWithConversationID:(NSString *_Nonnull)aConversationId
  402. from:(NSString *_Nonnull)aFrom
  403. to:(NSString *_Nonnull)aTo
  404. body:(EMMessageBody *_Nonnull)aBody
  405. ext:(NSDictionary *_Nullable)aExt;
  406. /**
  407. * \~chinese
  408. * 初始化消息实例。
  409. *
  410. * @param aConversationId 会话 ID。
  411. * @param aBody 消息体实例。
  412. * @param aExt 扩展信息。
  413. *
  414. * @result 消息实例。
  415. *
  416. * \~english
  417. * Initializes a message instance.
  418. *
  419. * @param aConversationId The conversation ID.
  420. * @param aBody The message body.
  421. * @param aExt The message extention.
  422. *
  423. * @result The message instance.
  424. */
  425. - (instancetype _Nonnull)initWithConversationID:(NSString *_Nonnull)aConversationId
  426. body:(EMMessageBody *_Nonnull)aBody
  427. ext:(NSDictionary *_Nullable)aExt;
  428. @end