EMConversation.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  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. #import "EMCursorResult.h"
  17. /**
  18. * \~chinese
  19. * 会话枚举类型。
  20. *
  21. * \~english
  22. * The conversation types.
  23. */
  24. typedef NS_ENUM(NSInteger, EMConversationType) {
  25. EMConversationTypeChat = 0, /** \~chinese 单聊。 \~english One-to-one chat. */
  26. EMConversationTypeGroupChat, /** \~chinese 群聊。 \~english Group chat.*/
  27. EMConversationTypeChatRoom, /** \~chinese 聊天室。 \~english Chat room.*/
  28. };
  29. /**
  30. * \~chinese
  31. * 消息搜索方向枚举类型。
  32. *
  33. * 消息搜索基于消息中包含的 Unix 时间戳。每个消息中包含两个 Unix 时间戳:
  34. * - 消息创建的 Unix 时间戳;
  35. * - 服务器接收消息的 Unix 时间戳。
  36. * 消息搜索基于哪个 Unix 时间戳取决于 {@link EMOptions#sortMessageByServerTime} 的设置。
  37. *
  38. * \~english
  39. * The message search directions.
  40. *
  41. * The message research is based on the Unix timestamp included in messages. Each message contains two Unix timestamps:
  42. * - The Unix timestamp when the message is created;
  43. * - The Unix timestamp when the message is received by the server.
  44. *
  45. * Which Unix timestamp is used for message search depends on the setting of {@link EMOptions#sortMessageByServerTime}.
  46. */
  47. typedef NS_ENUM(NSInteger, EMMessageSearchDirection) {
  48. EMMessageSearchDirectionUp = 0, /** \~chinese 按消息中的时间戳的倒序搜索。 \~english Messages are retrieved in the descending order of the timestamp included in them.*/
  49. EMMessageSearchDirectionDown /** \~chinese 按消息中的时间戳的顺序搜索。 \~english The Messages are retrieved in the ascending order of the timestamp included in them.*/
  50. };
  51. @class EMChatMessage;
  52. @class EMError;
  53. /**
  54. * \~chinese
  55. * 聊天会话类。
  56. *
  57. * \~english
  58. * The chat conversation class.
  59. */
  60. @interface EMConversation : NSObject
  61. /**
  62. * \~chinese
  63. * 会话 ID。
  64. * - 单聊:会话 ID 为对方的用户 ID。
  65. * - 群聊:会话 ID 为群组 ID。
  66. * - 聊天室:会话 ID 为聊天室的 ID。
  67. *
  68. * \~english
  69. * The conversation ID.
  70. * - One-to-one chat: The conversation ID is the user ID of the peer user.
  71. * - Group chat: The conversation ID is the group ID.
  72. * - Chat room: The conversation ID is the chat room ID.
  73. */
  74. @property (nonatomic, copy, readonly) NSString *conversationId;
  75. /**
  76. * \~chinese
  77. * 会话类型。
  78. *
  79. * \~english
  80. * The conversation type.
  81. */
  82. @property (nonatomic, assign, readonly) EMConversationType type;
  83. /**
  84. * \~chinese
  85. * 会话中未读取的消息数量。
  86. *
  87. * \~english
  88. * The number of unread messages in the conversation.
  89. */
  90. @property (nonatomic, assign, readonly) int unreadMessagesCount;
  91. /**
  92. * \~chinese
  93. * 会话中的消息数量。
  94. *
  95. * \~english
  96. * The message count in the conversation.
  97. */
  98. @property (nonatomic, assign, readonly) int messagesCount;
  99. /**
  100. * \~chinese
  101. * 会话扩展属性。
  102. *
  103. * 子区功能目前版本暂不可设置。
  104. *
  105. * \~english
  106. * The conversation extension attribute.
  107. *
  108. * This attribute is not available for thread conversations.
  109. */
  110. @property (nonatomic, copy) NSDictionary *ext;
  111. /*!
  112. * \~chinese
  113. * 是否为 thread 会话:
  114. * - `YES`:是
  115. * - `NO`:否
  116. *
  117. * \~english
  118. * Whether the conversation is a thread conversation:
  119. * - `YES`:Yes
  120. * - `NO`:No
  121. */
  122. @property (nonatomic, assign) BOOL isChatThread;
  123. /*!
  124. * \~chinese
  125. * 是否为置顶会话:
  126. * - `YES`:是
  127. * - `NO`:否
  128. *
  129. * \~english
  130. * Whether the conversation is pinned:
  131. * - `YES`:Yes
  132. * - `NO`:No
  133. */
  134. @property (readonly) BOOL isPinned;
  135. /*!
  136. * \~chinese
  137. * 会话置顶的 UNIX 时间戳,单位为毫秒。未置顶时值为 `0`。
  138. *
  139. * \~english
  140. * The UNIX timestamp when the conversation is pinned. The unit is millisecond. This value is `0` when the conversation is not pinned.
  141. */
  142. @property (readonly) int64_t pinnedTime;
  143. /*!
  144. * \~chinese
  145. * 会话中的最新一条消息。
  146. *
  147. * \~english
  148. * The latest message in the conversation.
  149. */
  150. @property (nonatomic, strong, readonly) EMChatMessage *latestMessage;
  151. /**
  152. * \~chinese
  153. * 收到的对方发送的最后一条消息。
  154. *
  155. * @result 消息实例。
  156. *
  157. * \~english
  158. * Gets the last received message.
  159. *
  160. * @result The message instance.
  161. */
  162. - (EMChatMessage * _Nullable)lastReceivedMessage;
  163. /**
  164. * \~chinese
  165. * 插入一条消息在 SDK 本地数据库
  166. *
  167. * 消息的会话 ID 应与会话的 ID 保持一致。
  168. *
  169. * 消息会根据消息里的时间戳被插入 SDK 本地数据库,SDK 会更新会话的 `latestMessage` 等属性。
  170. *
  171. * @param aMessage 消息实例。
  172. * @param pError 错误信息。
  173. *
  174. * \~english
  175. * Inserts a message to a conversation in the local database.
  176. *
  177. * To insert the message correctly, ensure that the conversation ID of the message is the same as that of the conversation.
  178. *
  179. * The message is inserted based on timestamp and the SDK will automatically update attributes of the conversation, including `latestMessage`.
  180. *
  181. *
  182. * @param aMessage The message instance.
  183. * @param pError The error information if the method fails: Error.
  184. */
  185. - (void)insertMessage:(EMChatMessage *_Nonnull)aMessage
  186. error:(EMError ** _Nullable)pError;
  187. /**
  188. * \~chinese
  189. * 插入一条消息到 SDK 本地数据库会话尾部。
  190. *
  191. * 消息的 conversationId 应该和会话的 conversationId 一致。
  192. *
  193. * 消息会被插入 SDK 本地数据库,并且更新会话的 `latestMessage` 等属性。
  194. *
  195. * @param aMessage 消息实例。
  196. * @param pError 错误信息。
  197. *
  198. * \~english
  199. * Inserts a message to the end of a conversation in local database.
  200. *
  201. * To insert the message correctly, ensure that the conversation ID of the message is the same as that of the conversation.
  202. *
  203. * After a message is inserted, the SDK will automatically update attributes of the conversation, including `latestMessage`.
  204. *
  205. * @param aMessage The message instance.
  206. * @param pError The error information if the method fails: Error.
  207. *
  208. */
  209. - (void)appendMessage:(EMChatMessage *_Nonnull)aMessage
  210. error:(EMError **_Nullable)pError;
  211. /**
  212. * \~chinese
  213. * 从 SDK 本地数据库删除一条消息。
  214. *
  215. * @param aMessageId 要删除的 ID。
  216. * @param pError 错误信息。
  217. *
  218. * \~english
  219. * Deletes a message from the local database.
  220. *
  221. * @param aMessageId The ID of the message to be deleted.
  222. * @param pError The error information if the method fails: Error.
  223. *
  224. */
  225. - (void)deleteMessageWithId:(NSString *_Nonnull)aMessageId
  226. error:(EMError ** _Nullable)pError;
  227. /**
  228. * \~chinese
  229. * 清除内存和数据库中指定会话中的消息。
  230. *
  231. * @param pError 错误信息。
  232. *
  233. * \~english
  234. * Deletes all the messages in the conversation from the memory and local database.
  235. *
  236. * @param pError The error information if the method fails: Error.
  237. */
  238. - (void)deleteAllMessages:(EMError ** _Nullable)pError;
  239. /**
  240. * \~chinese
  241. * 从会话中删除消息(包括本地存储和服务器存储)。
  242. *
  243. * @param messageIds 要删除消息 ID 字符串数组。
  244. * @param completion 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  245. *
  246. * \~english
  247. * Removes messages from the conversation by timestamp.
  248. *
  249. * This method deletes messages from both local storage and server.
  250. *
  251. * @param messageIds The list of IDs of messages to be removed form the current conversation.
  252. * @param completion The completion block, which contains the error message if the method fails.
  253. *
  254. */
  255. - (void)removeMessagesFromServerMessageIds:(NSArray <__kindof NSString*>*_Nonnull)messageIds completion:(void (^ _Nullable)(EMError * _Nullable aError))aCompletionBlock;
  256. /**
  257. * \~chinese
  258. * 从会话中删除消息(包括本地存储和服务器存储)。
  259. *
  260. * @param beforeTimeStamp UNIX 时间戳,单位为毫秒。若消息的 UNIX 时间戳小于设置的值,则会被删除。
  261. * @param completion 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  262. *
  263. * \~english
  264. * Removes messages from the conversation by message ID.
  265. *
  266. * This method deletes messages from both local storage and server.
  267. *
  268. * @param messageIds The message timestamp in millisecond. Messages with the timestamp smaller than the specified one will be removed from the current conversation.
  269. * @param completion The completion block, which contains the error message if the method fails.
  270. *
  271. */
  272. - (void)removeMessagesFromServerWithTimeStamp:(NSTimeInterval)beforeTimeStamp completion:(void (^ _Nullable)(EMError * _Nullable aError))aCompletionBlock;
  273. /**
  274. * \~chinese
  275. * 更新 SDK 本地数据库的消息。
  276. *
  277. * 消息更新时,消息 ID 不会修改。
  278. *
  279. * 消息更新后,SDK 会自动更新会话的 `latestMessage` 等属性。
  280. *
  281. * @param aMessage 要更新的消息。
  282. * @param pError 错误信息。
  283. *
  284. * \~english
  285. * Updates a message in the local database.
  286. *
  287. * After you update a message, the message ID remains unchanged and the SDK automatically updates attributes of the conversation, like `latestMessage`.
  288. *
  289. * @param aMessage The message to be updated.
  290. * @param pError The error information if the method fails: Error.
  291. *
  292. */
  293. - (void)updateMessageChange:(EMChatMessage *_Nonnull)aMessage
  294. error:(EMError ** _Nullable)pError;
  295. /**
  296. * \~chinese
  297. * 将 SDK 本地数据库中的指定消息设置为已读。
  298. *
  299. * @param aMessageId 要设置消息的 ID。
  300. * @param pError 错误信息。
  301. *
  302. * \~english
  303. * Marks a message in the local database as read.
  304. *
  305. * @param aMessageId The message ID.
  306. * @param pError The error information if the method fails: Error.
  307. *
  308. */
  309. - (void)markMessageAsReadWithId:(NSString *_Nonnull)aMessageId
  310. error:(EMError ** _Nullable)pError;
  311. /**
  312. * \~chinese
  313. * 将 SDK 本地数据库所有未读消息设置为已读。
  314. *
  315. * @param pError 错误信息。
  316. *
  317. * \~english
  318. * Marks all messages in the local database as read.
  319. *
  320. * @param pError The error information if the method fails: Error.
  321. *
  322. */
  323. - (void)markAllMessagesAsRead:(EMError ** _Nullable)pError;
  324. #pragma mark - Load Messages Methods
  325. /**
  326. * \~chinese
  327. * 从 SDK 本地数据库获取指定 ID 的消息。
  328. *
  329. * @param aMessageId 消息 ID。
  330. * @param pError 错误信息。
  331. *
  332. * \~english
  333. * Gets a message with the specified message ID from the local database.
  334. *
  335. * @param aMessageId The message ID.
  336. * @param pError The error information if the method fails: Error.
  337. *
  338. */
  339. - (EMChatMessage * _Nullable)loadMessageWithId:(NSString * _Nonnull)aMessageId
  340. error:(EMError ** _Nullable)pError;
  341. /**
  342. * \~chinese
  343. * 从 SDK 本地数据库获取指定数量的消息。
  344. *
  345. * 同步方法,会阻塞当前线程。
  346. *
  347. * @param aMessageId 查询的起始消息 ID。该参数设置后,SDK 从指定的消息 ID 开始按消息检索方向加载。
  348. * 如果传入消息的 ID 为空,SDK 忽略该参数,按搜索方向查询消息:
  349. * - 若 `aDirection` 为 `UP`,SDK 从最新消息开始,按消息时间戳的倒序获取;
  350. * - 若 `aDirection` 为 `DOWN`,SDK 从最早消息开始,按消息时间戳的正序获取。
  351. * @param aCount 每次获取的消息条数。如果设为小于等于 0,SDK 获取 1 条消息。
  352. * @param aDirection 消息搜索方向,详见 {@link EMMessageSearchDirection}。
  353. *
  354. * @result 消息列表。
  355. *
  356. * \~english
  357. * Loads the messages from the local database, starting from a specific message ID.
  358. *
  359. * This is a synchronous method and blocks the current thread.
  360. *
  361. * @param aMessageId The starting message ID for query. After this parameter is set, the SDK retrieves messages, from the specified one, according to the message search direction.
  362. * If this parameter is set as `nil`, the SDK retrieves messages according to the search direction while ignoring this parameter.
  363. * - If `aDirection` is set as `UP`, the SDK retrieves messages, starting from the latest one, in the descending order of the timestamp included in them.
  364. * - If `aDirection` is set as `DOWN`, the SDK retrieves messages, starting from the oldest one, in the ascending order of the timestamp included in them.
  365. * @param aCount The number of messages to load each time. If you set this parameter to a value less than 1, the SDK retrieves one message.
  366. * @param aDirection The message search direction. See {@link EMMessageSearchDirection}.
  367. *
  368. * @result EMChatMessage The message instance.
  369. *
  370. */
  371. - (NSArray<EMChatMessage *> * _Nullable)loadMessagesStartFromId:(NSString * _Nullable)aMessageId
  372. count:(int)aCount
  373. searchDirection:(EMMessageSearchDirection)aDirection;
  374. /**
  375. * \~chinese
  376. * 从 SDK 本地数据库获取指定数量的消息。
  377. *
  378. * @param aMessageId 查询的起始消息 ID。该参数设置后,SDK 从指定的消息 ID 开始按消息检索方向加载。
  379. * 如果传入消息的 ID 为空,SDK 忽略该参数,按搜索方向查询消息:
  380. * - 若 `aDirection` 为 `UP`,SDK 从最新消息开始,按消息时间戳的倒序获取;
  381. * - 若 `aDirection` 为 `DOWN`,SDK 从最早消息开始,按消息时间戳的正序获取。
  382. * @param aCount 每次获取的消息条数。如果设为小于等于 0,SDK 获取 1 条消息。
  383. * @param aDirection 消息搜索方向,详见 {@link EMMessageSearchDirection}。
  384. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  385. *
  386. * \~english
  387. * Loads messages starting from the specified message ID from local database.
  388. *
  389. * Returning messages are sorted by receiving timestamp based on EMMessageSearchDirection. If the aMessageId is nil, will return starting from the latest message.
  390. *
  391. * @param aMessageId The starting message ID for query. After this parameter is set, the SDK retrieves messages, from the specified one, according to the message search direction.
  392. * If this parameter is set as `nil`, the SDK retrieves messages according to the search direction while ignoring this parameter.
  393. * - If `aDirection` is set as `UP`, the SDK retrieves messages, starting from the latest one, in the descending order of the timestamp included in them.
  394. * - If `aDirection` is set as `DOWN`, the SDK retrieves messages, starting from the oldest one, in the ascending order of the timestamp included in them.
  395. * @param aCount The number of messages to load each time. If you set this parameter to a value less than 1, the SDK retrieves one message.
  396. * @param aDirection The message search direction. See {@link EMMessageSearchDirection}.
  397. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  398. *
  399. */
  400. - (void)loadMessagesStartFromId:(NSString * _Nullable)aMessageId
  401. count:(int)aCount
  402. searchDirection:(EMMessageSearchDirection)aDirection
  403. completion:(void (^ _Nullable)(NSArray<EMChatMessage *> * _Nullable aMessages, EMError * _Nullable aError))aCompletionBlock;
  404. /**
  405. * \~chinese
  406. * 从本地数据库中获取会话中指定用户发送的一定数量的特定类型的消息。
  407. *
  408. * 同步方法,会阻塞当前线程。
  409. *
  410. * @param aType 消息类型,txt:文本消息,img:图片消息,loc:位置消息,audio:语音消息,video:视频消息,file:文件消息,cmd: 透传消息。
  411. * @param aTimestamp 当前传入消息的设备时间戳,单位为毫秒。如果该参数设置的时间戳为负数,则从最新消息向前获取。
  412. * @param aCount 每次获取的消息条数。如果设为小于等于 0,SDK 会获取 1 条消息。
  413. * @param aUsername 消息发送方。设为 NIL 表示忽略该参数。
  414. * @param aDirection 消息搜索方向,详见 {@link EMMessageSearchDirection}。
  415. *
  416. * @result 消息列表。
  417. *
  418. * \~english
  419. * Gets messages of certain types that a specified user sends in the conversation.
  420. *
  421. * This is a synchronous method and blocks the current thread.
  422. *
  423. * @param aType The message type to load. Types include txt (text message), img (image message), loc (location message), audio (audio message), video (video message), file (file message), and cmd (command message).
  424. * @param aTimestamp The starting Unix timestamp in the message for query. The unit is millisecond. If you set this parameter as a negative value, the SDK loads messages from the latest one.
  425. * @param aCount The number of messages to load each time. If you set this parameter to a value less than 1, the SDK retrieves one message.
  426. * @param aUsername The message sender. Setting it as NIL means that the SDK ignores this parameter.
  427. * @param aDirection The message search direction. See {@link EMMessageSearchDirection}.
  428. *
  429. * @result EMChatMessage The message instance.
  430. *
  431. */
  432. - (NSArray<EMChatMessage *> * _Nullable)loadMessagesWithType:(EMMessageBodyType)aType
  433. timestamp:(long long)aTimestamp
  434. count:(int)aCount
  435. fromUser:(NSString* _Nullable)aUsername
  436. searchDirection:(EMMessageSearchDirection)aDirection;
  437. /**
  438. * \~chinese
  439. * 从本地数据库中获取会话中指定用户发送的一定数量的特定类型的消息。
  440. *
  441. * @param aType 消息类型,txt:文本消息,img:图片消息,loc:位置消息,audio:语音消息,video:视频消息,file:文件消息,cmd: 透传消息。
  442. * @param aTimestamp 当前传入消息的设备时间戳,单位为毫秒。如果该参数设置的时间戳为负数,则从最新消息向前获取。
  443. * @param aCount 每次获取的消息条数。如果设为小于等于 0,SDK 会获取 1 条消息。
  444. * @param aUsername 消息发送方。设为 NIL 表示忽略该参数。
  445. * @param aDirection 消息搜索方向,详见 {@link EMMessageSearchDirection}。
  446. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  447. *
  448. * \~english
  449. * Gets messages of certain types that a specified user sends in the conversation.
  450. *
  451. * @param aType The message type to load. Types include txt (text message), img (image message), loc (location message), audio (audio message), video (video message), file (file message), and cmd (command message).
  452. * @param aTimestamp The starting Unix timestamp in the message for query. The unit is millisecond. If you set this parameter as a negative value, the SDK loads messages from the latest one.
  453. * @param aCount The number of messages to load each time. If you set this parameter to a value less than 1, the SDK retrieves one message.
  454. * @param aUsername (Optional) The message sender. Setting it as NIL means that the SDK ignores this parameter.
  455. * @param aDirection The message search direction. See {@link EMMessageSearchDirection}.
  456. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  457. *
  458. */
  459. - (void)loadMessagesWithType:(EMMessageBodyType)aType
  460. timestamp:(long long)aTimestamp
  461. count:(int)aCount
  462. fromUser:(NSString* _Nullable)aUsername
  463. searchDirection:(EMMessageSearchDirection)aDirection
  464. completion:(void (^ _Nullable)(NSArray<EMChatMessage *> * _Nullable aMessages, EMError * _Nullable aError))aCompletionBlock;
  465. /**
  466. * \~chinese
  467. * 从本地数据库获取会话中的指定用户发送的包含特定关键词的消息。
  468. *
  469. * 同步方法,会阻塞当前线程。
  470. *
  471. * @param aKeywords 搜索关键词,设为 NIL 表示忽略该参数。
  472. * @param aTimestamp 查询的起始消息 Unix 时间戳,单位为毫秒。该参数设置后,SDK 从指定时间戳的消息开始,按消息搜索方向获取。
  473. * 如果该参数设置为负数,SDK 从当前时间开始搜索。
  474. * @param aCount 每次获取的消息条数。如果设为小于等于 0,SDK 会获取 1 条消息。
  475. * @param aSender 消息发送方,设为 NIL 表示忽略该参数。
  476. * @param aDirection 消息搜索方向,详见 {@link EMMessageSearchDirection}。
  477. *
  478. * @result 消息列表。
  479. *
  480. * \~english
  481. * Loads messages with keywords that the specified user sends in the conversation.
  482. *
  483. * This is a synchronous method and blocks the current thread.
  484. *
  485. * @param aKeyword The keywords for query. Setting it as NIL means that the SDK ignores this parameter.
  486. * @param aTimestamp The starting Unix timestamp for search. The unit is millisecond.
  487. * If this parameter is set as a negative value, the SDK retrieves from the current time.
  488. * @param aCount The number of messages to load each time. If you set this parameter to a value less than 1, the SDK retrieves one message.
  489. * @param aSender (Optional) The message sender. Setting it as NIL means that the SDK ignores this parameter.
  490. * @param aDirection The message search direction. See {@link EMMessageSearchDirection}.
  491. *
  492. * @result EMChatMessage The message list.
  493. *
  494. */
  495. - (NSArray<EMChatMessage *> * _Nullable)loadMessagesWithKeyword:(NSString* _Nullable)aKeyword
  496. timestamp:(long long)aTimestamp
  497. count:(int)aCount
  498. fromUser:(NSString* _Nullable)aSender
  499. searchDirection:(EMMessageSearchDirection)aDirection;
  500. /**
  501. * \~chinese
  502. * 从本地数据库获取会话中的指定用户发送的包含特定关键词的消息。
  503. *
  504. * @param aKeywords 关键词。设为 NIL 表示忽略该参数。
  505. * @param aTimestamp 传入的 Unix 时间戳,单位为毫秒。如果该参数设置的时间戳为负数,则从最新消息向前获取。
  506. * @param aCount 每次获取的消息条数。如果设为小于等于 0,SDK 会获取 1 条消息。
  507. * @param aSender 消息发送方。设为 NIL 表示忽略该参数。
  508. * @param aDirection 消息搜索方向,详见 {@link EMMessageSearchDirection}。
  509. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  510. *
  511. * \~english
  512. * Loads messages with specified keyword from local database. Returning messages are sorted by receiving timestamp based on EMMessageSearchDirection. If reference timestamp is negative, load from the latest messages; if message count is negative, will be handled as count=1
  513. *
  514. * @param aKeyword The keywords for query. Setting it as NIL means that the SDK ignores this parameter.
  515. * @param aTimestamp The starting Unix timestamp for search. The unit is millisecond.
  516. * If this parameter is set as a negative value, the SDK retrieves from the current time.
  517. * @param aCount The number of messages to load each time. If you set this parameter to a value less than 1, the SDK retrieves one message.
  518. * @param aSender (Optional) The message sender. Setting it as NIL means that the SDK ignores this parameter.
  519. * @param aDirection The message search direction. See {@link EMMessageSearchDirection}.
  520. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  521. *
  522. */
  523. - (void)loadMessagesWithKeyword:(NSString* _Nullable)aKeyword
  524. timestamp:(long long)aTimestamp
  525. count:(int)aCount
  526. fromUser:(NSString* _Nullable)aSender
  527. searchDirection:(EMMessageSearchDirection)aDirection
  528. completion:(void (^ _Nullable)(NSArray<EMChatMessage *> * _Nullable aMessages, EMError * _Nullable aError))aCompletionBlock;
  529. /**
  530. * \~chinese
  531. * 从本地数据库获取会话中的指定用户发送的包含特定关键词的自定义消息。
  532. *
  533. * 同步方法,会阻塞当前线程。
  534. *
  535. * @param aKeywords 关键词。设为 NIL 表示忽略该参数。
  536. * @param aTimestamp 传入的时间戳,单位为毫秒。如果该参数设置的时间戳为负数,则从最新消息向前获取。
  537. * @param aCount 每次获取的消息条数。如果设为小于等于 0,SDK 会获取 1 条消息。
  538. * @param aSender 消息发送方。设为 NIL 表示忽略该参数。
  539. * @param aDirection 消息搜索方向,详见 {@link EMMessageSearchDirection}。
  540. *
  541. * @result 消息列表。
  542. *
  543. *
  544. * \~english
  545. * Loads custom messages with keywords that the specified user sends in the conversation.
  546. *
  547. * This is a synchronous method and blocks the current thread.
  548. *
  549. * @param aKeyword The keywords for query. Setting it as NIL means that the SDK ignores this parameter.
  550. * @param aTimestamp The starting Unix timestamp in the message for query. The unit is millisecond. After this parameter is set, the SDK retrieves messages, starting from the specified one, according to the message search direction.
  551. * If this parameter is set as a negative value, the SDK retrieves from the current time.
  552. * @param aCount The number of messages to load each time. If you set this parameter to a value less than 1, the SDK retrieves one message.
  553. * @param aSender The message sender. Setting it as NIL means that the SDK ignores this parameter.
  554. * @param aDirection The message search direction. See {@link EMMessageSearchDirection}.
  555. * @result EMChatMessage The message list.
  556. *
  557. */
  558. - (NSArray<EMChatMessage *> * _Nullable)loadCustomMsgWithKeyword:(NSString*)aKeyword
  559. timestamp:(long long)aTimestamp
  560. count:(int)aCount
  561. fromUser:(NSString* _Nullable)aSender
  562. searchDirection:(EMMessageSearchDirection)aDirection;
  563. /**
  564. * \~chinese
  565. * 从本地数据库获取会话中的指定用户发送的包含特定关键词的自定义消息。
  566. *
  567. * @param aKeywords 关键词。设为 NIL 表示忽略该参数。
  568. * @param aTimestamp 传入的 Unix 时间戳,单位为毫秒。如果该参数设置的时间戳为负数,则从最新消息向前获取。
  569. * @param aCount 每次获取的消息条数。如果设为小于等于 0,SDK 会获取 1 条消息。
  570. * @param aSender 消息发送方。设为 NIL 表示忽略该参数。
  571. * @param aDirection 消息搜索方向,详见 {@link EMMessageSearchDirection}。
  572. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  573. *
  574. * \~english
  575. * Loads custom messages with keywords that the specified user sends in the conversation.
  576. *
  577. * @param aKeyword The keyword for searching the messages. Setting it as NIL means that the SDK ignores this parameter.
  578. * @param aTimestamp The starting Unix timestamp in the message for query. The unit is millisecond. After this parameter is set, the SDK retrieves messages, starting from the specified one, according to the message search direction.
  579. * If this parameter is set as a negative value, the SDK retrieves from the current time.
  580. * @param aCount The number of messages to load each time. If you set this parameter to a value less than 1, the SDK retrieves one message.
  581. * @param aSender The message sender. Setting it as NIL means that the SDK ignores this parameter.
  582. * @param aDirection The message search direction. See {@link EMMessageSearchDirection}.
  583. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  584. *
  585. */
  586. - (void)loadCustomMsgWithKeyword:(NSString* _Nullable)aKeyword
  587. timestamp:(long long)aTimestamp
  588. count:(int)aCount
  589. fromUser:(NSString* _Nullable)aSender
  590. searchDirection:(EMMessageSearchDirection)aDirection
  591. completion:(void (^ _Nullable)(NSArray<EMChatMessage *> * _Nullable aMessages, EMError * _Nullable aError))aCompletionBlock;
  592. /**
  593. * \~chinese
  594. * 从本地数据库中搜索指定时间段内发送或接收的一定数量的消息。
  595. *
  596. * 该方法返回的消息按时间正序排列。
  597. *
  598. * 同步方法,会阻塞当前线程。
  599. *
  600. * @param aStartTimestamp 搜索的起始时间戳。单位为毫秒。
  601. * @param aEndTimestamp 搜索的结束时间戳。单位为毫秒。
  602. * @param aCount 每次获取的消息条数。如果设为小于等于 0,SDK 会获取 1 条消息。
  603. *
  604. * @result 消息列表。
  605. *
  606. *
  607. * \~english
  608. * Loads a certain quantity of messages sent or received in a certain period from the local database.
  609. *
  610. * Messages are retrieved in the ascending order of the timestamp included in them.
  611. *
  612. * This is a synchronous method and blocks the current thread.
  613. *
  614. * @param aStartTimestamp The starting Unix timestamp in the message for query. The unit is millisecond.
  615. * @param aEndTimestamp The ending Unix timestamp in the message for query. The unit is millisecond.
  616. * @param aCount The number of messages to load each time. If you set this parameter to a value less than 1, the SDK retrieves one message.
  617. *
  618. * @result EMChatMessage The message list.
  619. *
  620. */
  621. - (NSArray<EMChatMessage *> * _Nullable)loadMessagesFrom:(long long)aStartTimestamp
  622. to:(long long)aEndTimestamp
  623. count:(int)aCount;
  624. /**
  625. * \~chinese
  626. * 从本地数据库中搜索指定时间段内发送或接收的一定数量的消息。
  627. *
  628. * @param aStartTimestamp 搜索的起始时间戳。单位为毫秒。
  629. * @param aEndTimestamp 搜索的结束时间戳。单位为毫秒。
  630. * @param aCount 每次获取的消息条数。如果设为小于等于 0,SDK 会获取 1 条消息。
  631. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  632. *
  633. * \~english
  634. * Loads a certain quantity of messages sent or received in a certain period from the local database.
  635. *
  636. * @param aStartTimestamp The starting Unix timestamp in the message for query. The unit is millisecond.
  637. * @param aEndTimestamp The ending Unix timestamp in the message for query. The unit is millisecond.
  638. * @param aCount The number of messages to load each time. If you set this parameter to a value less than 1, the SDK retrieves one message.
  639. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  640. *
  641. */
  642. - (void)loadMessagesFrom:(long long)aStartTimestamp
  643. to:(long long)aEndTimestamp
  644. count:(int)aCount
  645. completion:(void (^ _Nullable)(NSArray<EMChatMessage *> * _Nullable aMessages, EMError * _Nullable aError))aCompletionBlock;
  646. /**
  647. * \~chinese
  648. * 从本地数据库中删除指定时间段内的消息。
  649. *
  650. * @param aStartTimestamp 删除消息的起始时间。UNIX 时间戳,单位为毫秒。
  651. * @param aEndTimestamp 删除消息的结束时间。UNIX 时间戳,单位为毫秒。
  652. * @return EMError 消息是否删除成功:
  653. - 若操作成功,返回 `nil`。
  654. - 若操作失败,返回错误原因,例如参数错误或数据库操作失败。
  655. *
  656. * \~english
  657. * Deletes messages sent or received in a certain period from the local database.
  658. *
  659. * @param aStartTimestamp The starting UNIX timestamp for message deletion. The unit is millisecond.
  660. * @param aEndTimestamp The end UNIX timestamp for message deletion. The unit is millisecond.
  661. * @return EMError Whether the message deletion succeeds:
  662. * - If the operation succeeds, the SDK returns `nil`.
  663. * - If the operation fails, the SDK returns the failure reason such as the parameter error or database operation failure.
  664. *
  665. */
  666. - (EMError* _Nullable)removeMessagesStart:(NSInteger)aStartTimestamp
  667. to:(NSInteger)aEndTimestamp;
  668. @end