Няма описание

EMConversation.h 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. /*!
  2. * \~chinese
  3. * @header EMConversation.h
  4. * @abstract 聊天会话
  5. * @author Hyphenate
  6. * @version 3.00
  7. *
  8. * \~english
  9. * @header EMConversation.h
  10. * @abstract Chat conversation
  11. * @author Hyphenate
  12. * @version 3.00
  13. */
  14. #import <Foundation/Foundation.h>
  15. #import "EMMessageBody.h"
  16. /*
  17. * \~chinese
  18. * 会话类型
  19. *
  20. * \~english
  21. * Conversation type
  22. */
  23. typedef enum{
  24. EMConversationTypeChat = 0, /*! \~chinese 单聊会话 \~english one to one chat room type */
  25. EMConversationTypeGroupChat, /*! \~chinese 群聊会话 \~english Group chat room type */
  26. EMConversationTypeChatRoom /*! \~chinese 聊天室会话 \~english Chatroom chat room type */
  27. } EMConversationType;
  28. /*
  29. * \~chinese
  30. * 消息搜索方向
  31. *
  32. * \~english
  33. * Message search direction
  34. */
  35. typedef enum{
  36. EMMessageSearchDirectionUp = 0, /*! \~chinese 向上搜索 \~english Search older messages */
  37. EMMessageSearchDirectionDown /*! \~chinese 向下搜索 \~english Search newer messages */
  38. } EMMessageSearchDirection;
  39. @class EMMessage;
  40. @class EMError;
  41. /*!
  42. * \~chinese
  43. * 聊天会话
  44. *
  45. * \~english
  46. * Chat conversation
  47. */
  48. @interface EMConversation : NSObject
  49. /*!
  50. * \~chinese
  51. * 会话唯一标识
  52. *
  53. * \~english
  54. * Unique identifier of conversation
  55. */
  56. @property (nonatomic, copy, readonly) NSString *conversationId;
  57. /*!
  58. * \~chinese
  59. * 会话类型
  60. *
  61. * \~english
  62. * Conversation type
  63. */
  64. @property (nonatomic, assign, readonly) EMConversationType type;
  65. /*!
  66. * \~chinese
  67. * 会话未读消息数量
  68. *
  69. * \~english
  70. * Count of unread messages
  71. */
  72. @property (nonatomic, assign, readonly) int unreadMessagesCount;
  73. /*!
  74. * \~chinese
  75. * 会话扩展属性
  76. *
  77. * \~english
  78. * Conversation extension property
  79. */
  80. @property (nonatomic, copy) NSDictionary *ext;
  81. /*!
  82. * \~chinese
  83. * 会话最新一条消息
  84. *
  85. * \~english
  86. * Conversation latest message
  87. */
  88. @property (nonatomic, strong, readonly) EMMessage *latestMessage;
  89. /*!
  90. * \~chinese
  91. * 插入一条消息,消息的conversationId应该和会话的conversationId一致,消息会被插入DB,并且更新会话的latestMessage等属性
  92. *
  93. * @param aMessage 消息实例
  94. * @param pError 错误信息
  95. *
  96. * \~english
  97. * Insert a message to a conversation. ConversationId of the message should be the same as conversationId of the conversation in order to insert the message into the conversation correctly.
  98. *
  99. * @param aMessage Message
  100. * @param pError Error
  101. */
  102. - (void)insertMessage:(EMMessage *)aMessage
  103. error:(EMError **)pError;
  104. /*!
  105. * \~chinese
  106. * 插入一条消息到会话尾部,消息的conversationId应该和会话的conversationId一致,消息会被插入DB,并且更新会话的latestMessage等属性
  107. *
  108. * @param aMessage 消息实例
  109. * @param pError 错误信息
  110. *
  111. * \~english
  112. * Insert a message to the end of a conversation. ConversationId of the message should be the same as conversationId of the conversation in order to insert the message into the conversation correctly.
  113. *
  114. * @param aMessage Message
  115. * @param pError Error
  116. *
  117. */
  118. - (void)appendMessage:(EMMessage *)aMessage
  119. error:(EMError **)pError;
  120. /*!
  121. * \~chinese
  122. * 删除一条消息
  123. *
  124. * @param aMessageId 要删除消失的ID
  125. * @param pError 错误信息
  126. *
  127. * \~english
  128. * Delete a message
  129. *
  130. * @param aMessageId MessageId of the message to be deleted
  131. * @param pError Error
  132. *
  133. */
  134. - (void)deleteMessageWithId:(NSString *)aMessageId
  135. error:(EMError **)pError;
  136. /*!
  137. * \~chinese
  138. * 删除该会话所有消息
  139. * @param pError 错误信息
  140. *
  141. * \~english
  142. * Delete all message of a conversation
  143. * @param pError Error
  144. */
  145. - (void)deleteAllMessages:(EMError **)pError;
  146. /*!
  147. * \~chinese
  148. * 更新一条消息,不能更新消息ID,消息更新后,会话的latestMessage等属性进行相应更新
  149. *
  150. * @param aMessage 要更新的消息
  151. * @param pError 错误信息
  152. *
  153. * \~english
  154. * Update a local message, conversation's latestMessage and other properties will be updated accordingly. Please note that messageId can not be updated.
  155. *
  156. * @param aMessage Message
  157. * @param pError Error
  158. *
  159. */
  160. - (void)updateMessageChange:(EMMessage *)aMessage
  161. error:(EMError **)pError;
  162. /*!
  163. * \~chinese
  164. * 将消息设置为已读
  165. *
  166. * @param aMessageId 要设置消息的ID
  167. * @param pError 错误信息
  168. *
  169. * \~english
  170. * Mark a message as read
  171. *
  172. * @param aMessageId MessageID
  173. * @param pError Error
  174. *
  175. */
  176. - (void)markMessageAsReadWithId:(NSString *)aMessageId
  177. error:(EMError **)pError;
  178. /*!
  179. * \~chinese
  180. * 将所有未读消息设置为已读
  181. *
  182. * @param pError 错误信息
  183. *
  184. * \~english
  185. * Mark all message as read
  186. *
  187. * @param pError Error
  188. *
  189. */
  190. - (void)markAllMessagesAsRead:(EMError **)pError;
  191. /*!
  192. * \~chinese
  193. * 获取指定ID的消息
  194. *
  195. * @param aMessageId 消息ID
  196. * @param pError 错误信息
  197. *
  198. * \~english
  199. * Get a message with the ID
  200. *
  201. * @param aMessageId MessageID
  202. * @param pError Error
  203. *
  204. */
  205. - (EMMessage *)loadMessageWithId:(NSString *)aMessageId
  206. error:(EMError **)pError;
  207. /*!
  208. * \~chinese
  209. * 收到的对方发送的最后一条消息
  210. *
  211. * @result 消息实例
  212. *
  213. * \~english
  214. * Get last received message
  215. *
  216. * @result Message instance
  217. */
  218. - (EMMessage *)lastReceivedMessage;
  219. #pragma mark - Async method
  220. /*!
  221. * \~chinese
  222. * 从数据库获取指定数量的消息,取到的消息按时间排序,并且不包含参考的消息,如果参考消息的ID为空,则从最新消息取
  223. *
  224. * @param aMessageId 参考消息的ID
  225. * @param count 获取的条数
  226. * @param aDirection 消息搜索方向
  227. * @param aCompletionBlock 完成的回调
  228. *
  229. * \~english
  230. * Load messages from a specified message, returning messages are sorted by receiving timestamp. If the aMessageId is nil, return the latest received messages.
  231. *
  232. * @param aMessageId Reference message's ID
  233. * @param aCount Count of messages to load
  234. * @param aDirection Message search direction
  235. * @param aCompletionBlock The callback block of completion
  236. *
  237. */
  238. - (void)loadMessagesStartFromId:(NSString *)aMessageId
  239. count:(int)aCount
  240. searchDirection:(EMMessageSearchDirection)aDirection
  241. completion:(void (^)(NSArray *aMessages, EMError *aError))aCompletionBlock;
  242. /*!
  243. * \~chinese
  244. * 从数据库获取指定类型的消息,取到的消息按时间排序,如果参考的时间戳为负数,则从最新消息取,如果aCount小于等于0当作1处理
  245. *
  246. * @param aType 消息类型
  247. * @param aTimestamp 参考时间戳
  248. * @param aCount 获取的条数
  249. * @param aUsername 消息发送方,如果为空则忽略
  250. * @param aDirection 消息搜索方向
  251. * @param aCompletionBlock 完成的回调
  252. *
  253. * \~english
  254. * Load messages with specified type, returning messages are sorted by receiving timestamp. If reference timestamp is negative, load from the latest messages; if message count is negative, count deal with 1 and load one message that meet the condition.
  255. *
  256. * @param aType Message type to load
  257. * @param aTimestamp Reference timestamp
  258. * @param aLimit Count of messages to load
  259. * @param aUsername Message sender (optional)
  260. * @param aDirection Message search direction
  261. * @param aCompletionBlock The callback block of completion
  262. *
  263. */
  264. - (void)loadMessagesWithType:(EMMessageBodyType)aType
  265. timestamp:(long long)aTimestamp
  266. count:(int)aCount
  267. fromUser:(NSString*)aUsername
  268. searchDirection:(EMMessageSearchDirection)aDirection
  269. completion:(void (^)(NSArray *aMessages, EMError *aError))aCompletionBlock;
  270. /*!
  271. * \~chinese
  272. * 从数据库获取包含指定内容的消息,取到的消息按时间排序,如果参考的时间戳为负数,则从最新消息向前取,如果aCount小于等于0当作1处理
  273. *
  274. * @param aKeywords 搜索关键字,如果为空则忽略
  275. * @param aTimestamp 参考时间戳
  276. * @param aCount 获取的条数
  277. * @param aSender 消息发送方,如果为空则忽略
  278. * @param aDirection 消息搜索方向
  279. * @param aCompletionBlock 完成的回调
  280. *
  281. * \~english
  282. * Load messages with specified keyword, returning messages are sorted by receiving timestamp. If reference timestamp is negative, load from the latest messages; if message count is negative, count deal with 1 and load one message that meet the condition.
  283. *
  284. * @param aKeywords Search content, will ignore it if it's empty
  285. * @param aTimestamp Reference timestamp
  286. * @param aCount Count of messages to load
  287. * @param aSender Message sender (optional)
  288. * @param aDirection Message search direction
  289. * @param aCompletionBlock The callback block of completion
  290. *
  291. */
  292. - (void)loadMessagesWithKeyword:(NSString*)aKeyword
  293. timestamp:(long long)aTimestamp
  294. count:(int)aCount
  295. fromUser:(NSString*)aSender
  296. searchDirection:(EMMessageSearchDirection)aDirection
  297. completion:(void (^)(NSArray *aMessages, EMError *aError))aCompletionBlock;
  298. /*!
  299. * \~chinese
  300. * 从数据库获取指定时间段内的消息,取到的消息按时间排序,为了防止占用太多内存,用户应当制定加载消息的最大数
  301. *
  302. * @param aStartTimestamp 毫秒级开始时间
  303. * @param aEndTimestamp 结束时间
  304. * @param aCount 加载消息最大数
  305. * @param aCompletionBlock 完成的回调
  306. *
  307. * \~english
  308. * Load messages within specified time range, retruning messages are sorted by receiving timestamp
  309. *
  310. * @param aStartTimestamp Start time's timestamp in miliseconds
  311. * @param aEndTimestamp End time's timestamp in miliseconds
  312. * @param aCount Message search direction
  313. * @param aCompletionBlock The callback block of completion
  314. *
  315. */
  316. - (void)loadMessagesFrom:(long long)aStartTimestamp
  317. to:(long long)aEndTimestamp
  318. count:(int)aCount
  319. completion:(void (^)(NSArray *aMessages, EMError *aError))aCompletionBlock;
  320. #pragma mark - Deprecated methods
  321. /*!
  322. * \~chinese
  323. * 插入一条消息,消息的conversationId应该和会话的conversationId一致,消息会被插入DB,并且更新会话的latestMessage等属性
  324. *
  325. * @param aMessage 消息实例
  326. *
  327. * @result 是否成功
  328. *
  329. * \~english
  330. * Insert a message to a conversation. ConversationId of the message should be the same as conversationId of the conversation in order to insert the message into the conversation correctly.
  331. *
  332. * @param aMessage Message
  333. *
  334. * @result Message insert result, return YES or success, return No for failure.
  335. */
  336. - (BOOL)insertMessage:(EMMessage *)aMessage __deprecated_msg("Use -insertMessage:error:");
  337. /*!
  338. * \~chinese
  339. * 插入一条消息到会话尾部,消息的conversationId应该和会话的conversationId一致,消息会被插入DB,并且更新会话的latestMessage等属性
  340. *
  341. * @param aMessage 消息实例
  342. *
  343. * @result 是否成功
  344. *
  345. * \~english
  346. * Insert a message to the tail of conversation, message's conversationId should equle to conversation's conversationId, message will be inserted to DB, and update conversation's property
  347. *
  348. * @param aMessage Message
  349. *
  350. * @result Message insert result, YES: success, No: fail
  351. */
  352. - (BOOL)appendMessage:(EMMessage *)aMessage __deprecated_msg("Use -appendMessage:error:");
  353. /*!
  354. * \~chinese
  355. * 删除一条消息
  356. *
  357. * @param aMessageId 要删除消失的ID
  358. *
  359. * @result 是否成功
  360. *
  361. * \~english
  362. * Delete a message
  363. *
  364. * @param aMessageId Message's ID who will be deleted
  365. *
  366. * @result Message delete result, YES: success, No: fail
  367. */
  368. - (BOOL)deleteMessageWithId:(NSString *)aMessageId __deprecated_msg("Use -deleteMessageWithId:error:");
  369. /*!
  370. * \~chinese
  371. * 删除该会话所有消息
  372. *
  373. * @result 是否成功
  374. *
  375. * \~english
  376. * Delete all message of the conversation
  377. *
  378. * @result Delete result, YES: success, No: fail
  379. */
  380. - (BOOL)deleteAllMessages __deprecated_msg("Use -deleteAllMessages:");
  381. /*!
  382. * \~chinese
  383. * 更新一条消息,不能更新消息ID,消息更新后,会话的latestMessage等属性进行相应更新
  384. *
  385. * @param aMessage 要更新的消息
  386. *
  387. * @result 是否成功
  388. *
  389. * \~english
  390. * Update a message, can't update message's messageId, conversation's latestMessage and so on properties will update after update the message
  391. *
  392. * @param aMessage Message
  393. *
  394. * @result Message update result, YES: success, No: fail
  395. */
  396. - (BOOL)updateMessage:(EMMessage *)aMessage __deprecated_msg("Use -updateMessageChange:error:");
  397. /*!
  398. * \~chinese
  399. * 将消息设置为已读
  400. *
  401. * @param aMessageId 要设置消息的ID
  402. *
  403. * @result 是否成功
  404. *
  405. * \~english
  406. * Mark a message as read
  407. *
  408. * @param aMessageId Message's ID who will be set read status
  409. *
  410. * @result Result of mark message as read, YES: success, No: fail
  411. */
  412. - (BOOL)markMessageAsReadWithId:(NSString *)aMessageId __deprecated_msg("Use -markMessageAsReadWithId:error:");
  413. /*!
  414. * \~chinese
  415. * 将所有未读消息设置为已读
  416. *
  417. * @result 是否成功
  418. *
  419. * \~english
  420. * Mark all message as read
  421. *
  422. * @result Result of mark all message as read, YES: success, No: fail
  423. */
  424. - (BOOL)markAllMessagesAsRead __deprecated_msg("Use -markAllMessagesAsRead:");
  425. /*!
  426. * \~chinese
  427. * 更新会话扩展属性到DB
  428. *
  429. * @result 是否成功
  430. *
  431. * \~english
  432. * Update conversation extend properties to DB
  433. *
  434. * @result Extend properties update result, YES: success, No: fail
  435. */
  436. - (BOOL)updateConversationExtToDB __deprecated_msg("setExt: will update extend properties to DB");
  437. /*!
  438. * \~chinese
  439. * 获取指定ID的消息
  440. *
  441. * @param aMessageId 消息ID
  442. *
  443. * @result 消息
  444. *
  445. * \~english
  446. * Get a message with the ID
  447. *
  448. * @param aMessageId Message's id
  449. *
  450. * @result Message instance
  451. */
  452. - (EMMessage *)loadMessageWithId:(NSString *)aMessageId __deprecated_msg("Use -loadMessageWithId:error:");
  453. /*!
  454. * \~chinese
  455. * 从数据库获取指定数量的消息,取到的消息按时间排序,并且不包含参考的消息,如果参考消息的ID为空,则从最新消息向前取
  456. *
  457. * @param aMessageId 参考消息的ID
  458. * @param aLimit 获取的条数
  459. * @param aDirection 消息搜索方向
  460. *
  461. * @result 消息列表<EMMessage>
  462. *
  463. * \~english
  464. * Get more messages from DB, result messages are sorted by receive time, and NOT include the reference message, if reference messag's ID is nil, will fetch message from latest message
  465. *
  466. * @param aMessageId Reference message's ID
  467. * @param aLimit Count of messages to load
  468. * @param aDirection Message search direction
  469. *
  470. * @result Message list<EMMessage>
  471. */
  472. - (NSArray *)loadMoreMessagesFromId:(NSString *)aMessageId
  473. limit:(int)aLimit
  474. direction:(EMMessageSearchDirection)aDirection __deprecated_msg("Use -loadMessagesStartFromId:count:searchDirection:completion:");
  475. /*!
  476. * \~chinese
  477. * 从数据库获取指定类型的消息,取到的消息按时间排序,如果参考的时间戳为负数,则从最新消息向前取,如果aLimit是负数,则获取所有符合条件的消息
  478. *
  479. * @param aType 消息类型
  480. * @param aTimestamp 参考时间戳
  481. * @param aLimit 获取的条数
  482. * @param aSender 消息发送方,如果为空则忽略
  483. * @param aDirection 消息搜索方向
  484. *
  485. * @result 消息列表<EMMessage>
  486. *
  487. * \~english
  488. * Get more messages with specified type from DB, result messages are sorted by received time, if reference timestamp is negative, will fetch message from latest message, andd will fetch all messages that meet the condition if aLimit is negative
  489. *
  490. * @param aType Message type to load
  491. * @param aTimestamp Reference timestamp
  492. * @param aLimit Count of messages to load
  493. * @param aSender Message sender, will ignore it if it's empty
  494. * @param aDirection Message search direction
  495. *
  496. * @result Message list<EMMessage>
  497. */
  498. - (NSArray *)loadMoreMessagesWithType:(EMMessageBodyType)aType
  499. before:(long long)aTimestamp
  500. limit:(int)aLimit
  501. from:(NSString*)aSender
  502. direction:(EMMessageSearchDirection)aDirection __deprecated_msg("Use -loadMessagesWithType:timestamp:count:fromUser:searchDirection:completion:");
  503. /*!
  504. * \~chinese
  505. * 从数据库获取包含指定内容的消息,取到的消息按时间排序,如果参考的时间戳为负数,则从最新消息向前取,如果aLimit是负数,则获取所有符合条件的消息
  506. *
  507. * @param aKeywords 搜索关键字,如果为空则忽略
  508. * @param aTimestamp 参考时间戳
  509. * @param aLimit 获取的条数
  510. * @param aSender 消息发送方,如果为空则忽略
  511. * @param aDirection 消息搜索方向
  512. *
  513. * @result 消息列表<EMMessage>
  514. *
  515. * \~english
  516. * Get more messages contain specified keywords from DB, result messages are sorted by received time, if reference timestamp is negative, will fetch message from latest message, andd will fetch all messages that meet the condition if aLimit is negative
  517. *
  518. * @param aKeywords Search content, will ignore it if it's empty
  519. * @param aTimestamp Reference timestamp
  520. * @param aLimit Count of messages to load
  521. * @param aSender Message sender, will ignore it if it's empty
  522. * @param aDirection Message search direction
  523. *
  524. * @result Message list<EMMessage>
  525. */
  526. - (NSArray *)loadMoreMessagesContain:(NSString*)aKeywords
  527. before:(long long)aTimestamp
  528. limit:(int)aLimit
  529. from:(NSString*)aSender
  530. direction:(EMMessageSearchDirection)aDirection __deprecated_msg("Use -loadMessagesContainKeywords:timestamp:count:fromUser:searchDirection:completion:");
  531. /*!
  532. * \~chinese
  533. * 从数据库获取指定时间段内的消息,取到的消息按时间排序,为了防止占用太多内存,用户应当制定加载消息的最大数
  534. *
  535. * @param aStartTimestamp 毫秒级开始时间
  536. * @param aEndTimestamp 结束时间
  537. * @param aMaxCount 加载消息最大数
  538. *
  539. * @result 消息列表<EMMessage>
  540. *
  541. * \~english
  542. * Load messages from DB in duration, result messages are sorted by receive time, user should limit the max count to load to avoid memory issue
  543. *
  544. * @param aStartTimestamp Start time's timestamp in miliseconds
  545. * @param aEndTimestamp End time's timestamp in miliseconds
  546. * @param aMaxCount Message search direction
  547. *
  548. * @result Message list<EMMessage>
  549. */
  550. - (NSArray *)loadMoreMessagesFrom:(long long)aStartTimestamp
  551. to:(long long)aEndTimestamp
  552. maxCount:(int)aMaxCount __deprecated_msg("Use -loadMessagesFrom:to:count:completion:");
  553. /*!
  554. * \~chinese
  555. * 收到的对方发送的最后一条消息
  556. *
  557. * @result 消息实例
  558. *
  559. * \~english
  560. * Get latest message that received from others
  561. *
  562. * @result Message instance
  563. */
  564. - (EMMessage *)latestMessageFromOthers __deprecated_msg("Use -lastReceivedMessage");
  565. @end