IEMChatManager.h 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236
  1. /**
  2. * \~chinese
  3. * @header IEMChatManager.h
  4. * @abstract 聊天相关操作代理协议。
  5. * @author Hyphenate
  6. * @version 3.00
  7. *
  8. * \~english
  9. * @header IEMChatManager.h
  10. * @abstract This protocol defines the operations of chat.
  11. * @author Hyphenate
  12. * @version 3.00
  13. */
  14. #import <Foundation/Foundation.h>
  15. #import "EMCommonDefs.h"
  16. #import "EMChatManagerDelegate.h"
  17. #import "EMConversation.h"
  18. #import "EMChatMessage.h"
  19. #import "EMTextMessageBody.h"
  20. #import "EMLocationMessageBody.h"
  21. #import "EMCmdMessageBody.h"
  22. #import "EMFileMessageBody.h"
  23. #import "EMImageMessageBody.h"
  24. #import "EMVoiceMessageBody.h"
  25. #import "EMVideoMessageBody.h"
  26. #import "EMCustomMessageBody.h"
  27. #import "EMCursorResult.h"
  28. #import "EMGroupMessageAck.h"
  29. #import "EMTranslateLanguage.h"
  30. #import "EMFetchServerMessagesOption.h"
  31. /**
  32. * \~chinese
  33. * 漫游消息的拉取方向枚举类型。
  34. *
  35. * \~english
  36. * The directions in which historical messages are retrieved from the server.
  37. */
  38. typedef NS_ENUM(NSUInteger, EMMessageFetchHistoryDirection) {
  39. EMMessageFetchHistoryDirectionUp = 0, /** \~chinese SDK 按消息中的时间戳的逆序查询。 \~english The SDK retrieves messages in the descending order of the timestamp included in them.*/
  40. EMMessageFetchHistoryDirectionDown /** \~chinese SDK 按消息中的时间戳的正序查询。 \~english The SDK retrieves messages in the ascending order of the timestamp included in them.
  41. **/
  42. };
  43. @class EMError;
  44. /**
  45. * \~chinese
  46. * 聊天相关操作代理协议。
  47. *
  48. * 消息都是从本地数据库中加载,不是从服务端加载。
  49. *
  50. * \~english
  51. * This protocol that defines the operations of chat.
  52. *
  53. * Messages are loaded from the local database, not from the server.
  54. */
  55. @protocol IEMChatManager <NSObject>
  56. @required
  57. #pragma mark - Delegate
  58. /**
  59. * \~chinese
  60. * 添加回调代理。
  61. *
  62. * @param aDelegate 实现代理协议的对象。
  63. * @param aQueue 执行代理方法的队列。若在主线程上运行 app,将该参数设置为空。
  64. *
  65. * \~english
  66. * Adds a delegate.
  67. *
  68. * @param aDelegate The object that implements the protocol.
  69. * @param aQueue (optional) The queue of calling delegate methods. If you want to run the app on the main thread, set this parameter as nil.
  70. */
  71. - (void)addDelegate:(id<EMChatManagerDelegate> _Nullable)aDelegate
  72. delegateQueue:(dispatch_queue_t _Nullable)aQueue;
  73. /**
  74. * \~chinese
  75. * 移除回调代理。
  76. *
  77. * @param aDelegate 要移除的代理。
  78. *
  79. * \~english
  80. * Removes a delegate.
  81. *
  82. * @param aDelegate The delegate to be removed.
  83. */
  84. - (void)removeDelegate:(id<EMChatManagerDelegate> _Nonnull)aDelegate;
  85. #pragma mark - Conversation
  86. /**
  87. * \~chinese
  88. * 获取本地所有会话。
  89. *
  90. * 该方法会先从内存中获取,如果未找到任何会话,从本地数据库获取。
  91. *
  92. * @result 会话列表,NSArray<EMConversation *> * 类型。
  93. *
  94. * \~english
  95. * Gets all local conversations.
  96. *
  97. * The SDK loads the conversations from the memory first. If no conversation is found in the memory, the SDK loads from the local database.
  98. *
  99. * @result The conversation list of the NSArray<EMConversation *> * type.
  100. */
  101. - (NSArray<EMConversation *> * _Nullable)getAllConversations;
  102. /**
  103. * \~chinese
  104. * 获取本地所有会话。
  105. *
  106. * 该方法会先从内存中获取,如果未找到任何会话,SDK 从本地数据库获取。
  107. *
  108. * @param isSort 是否对会话排序。
  109. * - YES: YES。SDK 按照最近一条消息的时间戳的倒序返回会话,置顶会话在前,非置顶会话在后。
  110. * - NO: NO
  111. * @result 会话列表,NSArray<EMConversation *> * 类型。
  112. *
  113. * \~english
  114. * Gets all local conversations.
  115. *
  116. * The SDK loads the conversations from the memory first. If there is no conversation is in the memory, the SDK loads from the local database.
  117. *
  118. * @param isSort Whether to sort the conversations.
  119. * - YES: Yes. The SDK returns conversations in the descending order of the timestamp of the latest message in them, with the pinned ones at the top of the list and followed by the unpinned ones.
  120. * - NO: No.
  121. * @result The conversation list of the NSArray<EMConversation *> * type.
  122. */
  123. - (NSArray<EMConversation *> * _Nullable)getAllConversations:(BOOL)isSort;
  124. /**
  125. * \~chinese
  126. * 从服务器获取所有会话。
  127. *
  128. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  129. *
  130. * \~english
  131. * Gets all conversations from the server.
  132. *
  133. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  134. */
  135. - (void)getConversationsFromServer:(void (^_Nullable)(NSArray<EMConversation *> * _Nullable aConversations, EMError * _Nullable aError))aCompletionBlock EM_DEPRECATED_IOS(4_0_0, "Use -IEMChatManager getConversationsFromServerWithCursor:pageSize:completion");
  136. /**
  137. * \~chinese
  138. * 从服务器分页获取会话。
  139. *
  140. * @param pageNumber 当前页码,从 1 开始。
  141. * @param pageSize 每页获取的的会话数。
  142. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  143. *
  144. * \~english
  145. * Gets conversations from the server with pagination.
  146. *
  147. * @param pageNumber The current page number, starting from 1.
  148. * @param pageSize The number of conversations that you expect to get on each page.
  149. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  150. */
  151. - (void)getConversationsFromServerByPage:(NSUInteger)pageNumber
  152. pageSize:(NSUInteger)pageSize
  153. completion:(void (^_Nullable)(NSArray<EMConversation *> * _Nullable aConversations, EMError * _Nullable aError))aCompletionBlock EM_DEPRECATED_IOS(4_0_0, "Use -IEMChatManager getConversationsFromServerWithCursor:pageSize:completion");
  154. /**
  155. * \~chinese
  156. * 分页从服务器获取获取会话列表。
  157. *
  158. * SDK 按照会话活跃时间(会话的最后一条消息的时间戳)倒序返回会话列表。
  159. *
  160. * 若会话中没有消息,则 SDK 按照会话创建时间的倒序返回会话列表。
  161. *
  162. * @param cursor 查询的开始位置。若传入 `nil` 或 `@""`,SDK 从最新活跃的会话开始获取。
  163. * @param pageSize 每页期望返回的会话数量。取值范围为 [1,50]。
  164. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  165. *
  166. * \~english
  167. * Get the list of conversations from the server with pagination.
  168. *
  169. * The SDK retrieves the list of conversations in the reverse chronological order of their active time (the timestamp of the last message).
  170. *
  171. * If there is no message in the conversation, the SDK retrieves the list of conversations in the reverse chronological order of their creation time.
  172. *
  173. * @param cursor The position from which to start getting data. If you pass in `nil` or `@""`, the SDK retrieves conversations from the latest active one.
  174. * @param pageSize The number of conversations that you expect to get on each page. The value range is [1,50].
  175. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  176. */
  177. - (void)getConversationsFromServerWithCursor:(nullable NSString *)cursor pageSize:(UInt8)pageSize completion:(nonnull void (^)(EMCursorResult<EMConversation *> * _Nullable result, EMError * _Nullable error))completionBlock;
  178. /**
  179. * \~chinese
  180. * 分页从服务器获取置顶会话。
  181. *
  182. * SDK 按照会话的置顶时间的倒序返回会话列表。
  183. *
  184. * @param cursor 查询的开始位置。若传 `nil` 或 `@""`,SDK 从最新置顶的会话开始查询。
  185. * @param pageSize 每页期望返回的会话数量。取值范围为 [1,50]。
  186. * @param completionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  187. *
  188. * \~english
  189. * Gets the list of pinned conversations from the server with pagination.
  190. *
  191. * The SDK returns the pinned conversations in the reverse chronological order of their pinning.
  192. *
  193. * @param cursor The position from which to start getting data. If you pass in `nil` or `@""`, the SDK retrieves conversations from the latest pinned one.
  194. * @param pageSize The number of conversations that you expect to get on each page. The value range is [1,50].
  195. * @param completionBlock The completion block, which contains the error message if the method fails.
  196. */
  197. - (void)getPinnedConversationsFromServerWithCursor:(nullable NSString *)cursor pageSize:(UInt8)limit completion:(nonnull void (^)(EMCursorResult<EMConversation *> * _Nullable result, EMError * _Nullable error))completionBlock;
  198. /**
  199. * \~chinese
  200. * 设置是否置顶会话。
  201. *
  202. * @param conversationId 会话 ID。
  203. * @param isPinned 是否置顶会话:
  204. * - YES:置顶;
  205. * - NO:取消置顶。
  206. * @param callback 设置是否置顶会话的结果回调。
  207. *
  208. * \~english
  209. * Sets whether to pin a conversation.
  210. *
  211. * @param conversationId The conversation ID.
  212. * @param isPinned Whether to pin a conversation:
  213. * - `true`:Yes.
  214. * - `false`: No. The conversation is unpinned.
  215. * @param completionBlock The completion block, which contains the error message if the method fails.
  216. */
  217. - (void)pinConversation:(nonnull NSString *)conversationId isPinned:(BOOL)isPinned completionBlock:(nullable void(^)(EMError * _Nullable error))completionBlock;
  218. /**
  219. * \~chinese
  220. * 从本地数据库中获取一个已存在的会话。
  221. *
  222. * @param aConversationId 会话 ID。
  223. *
  224. * @result 会话对象。
  225. *
  226. * \~english
  227. * Gets a conversation from the local database.
  228. *
  229. * @param aConversationId The conversation ID.
  230. *
  231. * @result The conversation object.
  232. */
  233. - (EMConversation *_Nullable)getConversationWithConvId:(NSString * _Nullable)aConversationId;
  234. /**
  235. * \~chinese
  236. * 获取一个会话。
  237. *
  238. * @param aConversationId 会话 ID。
  239. * @param aType 会话类型。
  240. * @param aIfCreate 若该会话不存在是否创建:
  241. * - `YES`:是;
  242. * - `NO`:否。
  243. *
  244. * @result 会话对象。
  245. *
  246. * \~english
  247. * Gets a conversation from the local database.
  248. *
  249. * @param aConversationId The conversation ID.
  250. * @param aType The conversation type.
  251. * @param aIfCreate Whether to create the conversation if it does not exist:
  252. * - `YES`: Yes;
  253. * - `NO`: No.
  254. *
  255. * @result The conversation object.
  256. */
  257. - (EMConversation *_Nullable)getConversation:(NSString *_Nonnull)aConversationId
  258. type:(EMConversationType)aType
  259. createIfNotExist:(BOOL)aIfCreate;
  260. /**
  261. * \~chinese
  262. * 获取一个会话。
  263. *
  264. * @param aConversationId 会话 ID。
  265. * @param aType 会话类型。
  266. * @param aIfCreate 若该会话不存在是否创建。
  267. * - `YES`:是;
  268. * - `NO`:否。
  269. * @param isThread 是否是子区会话,即是否为 `threadChat` 类型的会话。
  270. * - `YES`: 是;
  271. * - `NO`: 否。
  272. * @result 会话对象。
  273. *
  274. * \~english
  275. * Gets a conversation from the local database.
  276. *
  277. * @param aConversationId The conversation ID.
  278. * @param aType The conversation type.
  279. * @param aIfCreate Whether to create the conversation if it does not exist.
  280. * - `YES`: Yes;
  281. * - `NO`: No.
  282. * @param isThread Whether it is thread conversation. That is, whether the conversation is of the `threadChat` type.
  283. * - `YES`: Yes;
  284. * - `NO`: No.
  285. * @result The conversation object.
  286. */
  287. - (EMConversation *_Nullable)getConversation:(NSString *_Nonnull)aConversationId
  288. type:(EMConversationType)aType
  289. createIfNotExist:(BOOL)aIfCreate isThread:(BOOL)isThread;
  290. /**
  291. * \~chinese
  292. * 从本地数据库中删除一个会话。
  293. *
  294. * @param aConversationId 会话 ID。
  295. * @param aIsDeleteMessages 是否删除会话中的消息。
  296. * - `YES`: 是;
  297. * - `NO`: 否。
  298. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  299. *
  300. * \~english
  301. * Deletes a conversation from the local database.
  302. *
  303. * @param aConversationId The conversation ID.
  304. * @param aIsDeleteMessages Whether to delete the messages in the conversation.
  305. * - `YES`: Yes;
  306. * - `NO`: No.
  307. * @param aCompletionBlock The completion block, which contains the error message if the method call fails.
  308. *
  309. */
  310. - (void)deleteConversation:(NSString * _Nonnull)aConversationId
  311. isDeleteMessages:(BOOL)aIsDeleteMessages
  312. completion:(void (^_Nullable)(NSString * _Nullable aConversationId, EMError *_Nullable aError))aCompletionBlock;
  313. /*!
  314. * \~chinese
  315. * 删除服务器会话。
  316. *
  317. * @param aConversationId 会话 ID。
  318. * @param aConversationType 会话类型。
  319. * @param aIsDeleteMessages 是否同时删除会话中的消息。
  320. * - `YES`: 是;
  321. * - `NO`: 否。
  322. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  323. *
  324. * \~english
  325. * Deletes a conversation from the server.
  326. *
  327. * @param aConversationId The conversation ID.
  328. * @param aConversationType The conversation type.
  329. * @param aIsDeleteMessages Whether to delete the related messages with the conversation.
  330. * - `YES`: Yes;
  331. * - `NO`: No.
  332. * @param aCompletionBlock The completion block, which contains the error message if the method call fails.
  333. *
  334. */
  335. - (void)deleteServerConversation:(NSString * _Nonnull)aConversationId
  336. conversationType:(EMConversationType)aConversationType
  337. isDeleteServerMessages:(BOOL)aIsDeleteServerMessages
  338. completion:(void (^_Nullable)(NSString * _Nullable aConversationId, EMError * _Nullable aError))aCompletionBlock;
  339. /*!
  340. * \~chinese
  341. * 删除一组会话。
  342. *
  343. * @param aConversations 会话列表。
  344. * @param aIsDeleteMessages 是否删除会话中的消息。
  345. * - `YES`: 是;
  346. * - `NO`: 否。
  347. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  348. *
  349. * \~english
  350. * Deletes multiple conversations.
  351. *
  352. * @param aConversations The conversation list.
  353. * @param aIsDeleteMessages Whether to delete the messages with the conversations.
  354. * - `YES`: Yes;
  355. * - `NO`: No.
  356. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  357. *
  358. */
  359. - (void)deleteConversations:(NSArray<EMConversation *> * _Nullable)aConversations
  360. isDeleteMessages:(BOOL)aIsDeleteMessages
  361. completion:(void (^_Nullable)(EMError * _Nullable aError))aCompletionBlock;
  362. /**
  363. * \~chinese
  364. * 导入一组会话到本地数据库。
  365. *
  366. * @param aConversations 会话列表。
  367. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  368. *
  369. *
  370. * \~english
  371. * Imports multiple conversations to the local database.
  372. *
  373. * @param aConversations The conversation list.
  374. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  375. *
  376. */
  377. - (void)importConversations:(NSArray<EMConversation *> * _Nullable)aConversations
  378. completion:(void (^ _Nullable)(EMError * _Nullable aError))aCompletionBlock;
  379. #pragma mark - Message
  380. /**
  381. * \~chinese
  382. * 获取指定的消息。
  383. *
  384. * @param aMessageId 消息 ID。
  385. *
  386. * @result 获取到的消息。
  387. *
  388. * \~english
  389. * Gets the specified message.
  390. *
  391. * @param aMessageId The message ID.
  392. * @result EMChatMessage The message content.
  393. */
  394. - (EMChatMessage * _Nullable)getMessageWithMessageId:(NSString * _Nonnull)aMessageId;
  395. /**
  396. * \~chinese
  397. * 获取一个会话中消息附件的本地路径。
  398. *
  399. * 删除会话时,会话中的消息附件也会被删除。
  400. *
  401. * @param aConversationId 会话 ID。
  402. *
  403. * @result 附件路径。
  404. *
  405. * \~english
  406. * Gets the local path of message attachments in a conversation.
  407. *
  408. * When a conversation is deleted, the message attachments in the conversation will also be deleted.
  409. *
  410. * @param aConversationId The conversation ID.
  411. *
  412. * @result The attachment path.
  413. */
  414. - (NSString * _Nullable)getMessageAttachmentPath:(NSString * _Nonnull)aConversationId;
  415. /**
  416. * \~chinese
  417. * 导入一组消息到本地数据库。
  418. *
  419. * @param aMessages 消息列表。
  420. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  421. *
  422. * \~english
  423. * Imports multiple messages to the local database.
  424. *
  425. * @param aMessages The message list.
  426. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  427. *
  428. */
  429. - (void)importMessages:(NSArray<EMChatMessage *> * _Nonnull)aMessages
  430. completion:(void (^_Nullable)(EMError *_Nullable aError))aCompletionBlock;
  431. /**
  432. * \~chinese
  433. * 更新消息到本地数据库。
  434. *
  435. * 该方法会同时更新本地内存和数据库中的消息,消息 ID 不会更新。
  436. *
  437. * @param aMessage 消息。
  438. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  439. *
  440. * \~english
  441. * Updates a message in the local database.
  442. *
  443. * This method updates the message in both the memory and the local database at the same time.
  444. *
  445. * The message ID cannot be updated.
  446. *
  447. * @param aMessage The message instance.
  448. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  449. *
  450. */
  451. - (void)updateMessage:(EMChatMessage *_Nonnull)aMessage
  452. completion:(void (^_Nullable)(EMChatMessage * _Nullable aMessage, EMError * _Nullable aError))aCompletionBlock;
  453. /**
  454. * \~chinese
  455. * 发送消息已读回执。
  456. *
  457. * 异步方法。
  458. *
  459. * @param aMessage 消息 ID。
  460. * @param aUsername 已读回执的接收方。
  461. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  462. *
  463. * \~english
  464. * Sends the read receipt for a message.
  465. *
  466. * This is an asynchronous method.
  467. *
  468. * @param aMessageId The message ID.
  469. * @param aUsername The user ID of the recipient of the read receipt.
  470. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  471. *
  472. */
  473. - (void)sendMessageReadAck:(NSString * _Nonnull)aMessageId
  474. toUser:(NSString * _Nonnull)aUsername
  475. completion:(void (^_Nullable)(EMError *_Nullable aError))aCompletionBlock;
  476. /**
  477. * \~chinese
  478. * 发送群消息已读回执。
  479. *
  480. * 异步方法。
  481. *
  482. * @param aMessageId 消息 ID。
  483. * @param aGroupId 群组 ID。
  484. * @param aContent 消息内容。
  485. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  486. *
  487. * \~english
  488. * Sends the read receipt for a group message.
  489. *
  490. * This is an asynchronous method.
  491. *
  492. * @param aMessageId The message ID.
  493. * @param aGroupId The group ID.
  494. * @param aContent The message content.
  495. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  496. *
  497. */
  498. - (void)sendGroupMessageReadAck:(NSString * _Nonnull)aMessageId
  499. toGroup:(NSString * _Nonnull)aGroupId
  500. content:(NSString * _Nullable)aContent
  501. completion:(void (^_Nullable)(EMError *_Nullable aError))aCompletionBlock;
  502. /**
  503. * \~chinese
  504. * 发送会话已读回执。
  505. *
  506. * 该方法仅适用于单聊会话。
  507. *
  508. * 发送会话已读回执会通知服务器将指定的会话未读消息数置为 0。调用该方法后对方会收到 onConversationRead 回调。
  509. *
  510. * 对话方(包含多端多设备)将会在回调方法 EMChatManagerDelegate onConversationRead(String, String) 中接收到回调。
  511. *
  512. * 为了减少调用次数,我们建议在进入聊天页面有大量未读消息时调用该方法,在聊天过程中调用 `sendMessageReadAck` 方法发送消息已读回执。
  513. *
  514. *
  515. * 异步方法。
  516. *
  517. * @param conversationId 会话 ID。
  518. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  519. *
  520. * \~english
  521. * Sends the conversation read receipt to the server.
  522. *
  523. * This method applies to one-to-one chats only.
  524. *
  525. * This method call notifies the server to set the number of unread messages of the specified conversation as 0, and triggers the onConversationRead callback on the recipient's client.
  526. *
  527. * To reduce the number of method calls, we recommend that you call this method when the user enters a conversation with many unread messages, and call `sendMessageReadAck` during a conversation to send the message read receipts.
  528. *
  529. * This is an asynchronous method.
  530. *
  531. * @param conversationId The conversation ID.
  532. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  533. *
  534. */
  535. - (void)ackConversationRead:(NSString * _Nonnull)conversationId
  536. completion:(void (^_Nullable)(EMError *_Nullable aError))aCompletionBlock;
  537. /**
  538. * \~chinese
  539. * 撤回一条消息。
  540. *
  541. * 异步方法。
  542. *
  543. * @param aMessageId 消息 ID。
  544. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  545. *
  546. * \~english
  547. * Recalls a message.
  548. *
  549. * This is an asynchronous method.
  550. *
  551. * @param aMessageId The message ID
  552. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  553. *
  554. */
  555. - (void)recallMessageWithMessageId:(NSString *_Nonnull)aMessageId
  556. completion:(void (^_Nullable)(EMError *_Nullable aError))aCompletionBlock;
  557. /**
  558. * \~chinese
  559. * 发送消息。
  560. *
  561. * 异步方法。
  562. *
  563. * @param aMessage 消息。
  564. * @param aProgressBlock 附件上传进度回调 block。进度值范围为 [0,100]。
  565. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  566. *
  567. * \~english
  568. * Sends a message.
  569. *
  570. * This is an asynchronous method.
  571. *
  572. * @param aMessage The message instance.
  573. * @param aProgressBlock The callback block of attachment upload progress. The progress value range is [0,100].
  574. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  575. */
  576. - (void)sendMessage:(EMChatMessage *_Nonnull)aMessage
  577. progress:(void (^_Nullable)(int progress))aProgressBlock
  578. completion:(void (^_Nullable)(EMChatMessage *_Nullable message, EMError *_Nullable error))aCompletionBlock;
  579. /**
  580. * \~chinese
  581. * 重新发送消息。
  582. *
  583. * @param aMessage 消息对象。
  584. * @param aProgressBlock 附件上传进度回调 block。进度值范围为 [0,100]。
  585. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  586. *
  587. * \~english
  588. * Resends a message.
  589. *
  590. * @param aMessage The message object.
  591. * @param aProgressBlock The callback block of attachment upload progress. The progress value range is [0,100].
  592. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  593. */
  594. - (void)resendMessage:(EMChatMessage *_Nonnull)aMessage
  595. progress:(void (^_Nullable)(int progress))aProgressBlock
  596. completion:(void (^_Nullable)(EMChatMessage *_Nullable message, EMError *_Nullable error))aCompletionBlock;
  597. /**
  598. * \~chinese
  599. * 下载缩略图(图片缩略图或视频的第一帧图片)。
  600. *
  601. * SDK 会自动下载缩略图。如果自动下载失败,你可以调用该方法下载缩略图。
  602. *
  603. * @param aMessage 消息对象。
  604. * @param aProgressBlock 附件下载进度回调 block。进度值的范围为 [0,100]。
  605. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  606. *
  607. * \~english
  608. * Downloads the message thumbnail (the thumbnail of an image or the first frame of a video).
  609. *
  610. * The SDK automatically downloads the thumbnail. If the auto-download fails, you can call this method to manually download the thumbnail.
  611. *
  612. * @param aMessage The message object.
  613. * @param aProgressBlock The callback block of attachment download progress. The progress value range is [0,100].
  614. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  615. */
  616. - (void)downloadMessageThumbnail:(EMChatMessage *_Nonnull)aMessage
  617. progress:(void (^_Nullable)(int progress))aProgressBlock
  618. completion:(void (^_Nullable)(EMChatMessage *_Nullable message, EMError *_Nullable error))aCompletionBlock;
  619. /**
  620. * \~chinese
  621. * 下载消息附件(语音、视频、图片原图、文件)。
  622. *
  623. * SDK 会自动下载语音消息。如果自动下载失败,你可以调用该方法。
  624. *
  625. * 异步方法。
  626. *
  627. * @param aMessage 消息。
  628. * @param aProgressBlock 附件下载进度回调 block。进度值的范围为 [0,100]。
  629. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  630. *
  631. * \~english
  632. * Downloads message attachment (voice, video, image or file).
  633. *
  634. * The SDK automatically downloads voice messages. If the automatic download fails, you can call this method to download voice messages manually.
  635. *
  636. * This is an asynchronous method.
  637. *
  638. * @param aMessage The message object.
  639. * @param aProgressBlock The callback block of attachment download progress. The progress value range is [0,100].
  640. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  641. */
  642. - (void)downloadMessageAttachment:(EMChatMessage *_Nonnull)aMessage
  643. progress:(void (^_Nullable)(int progress))aProgressBlock
  644. completion:(void (^_Nullable)(EMChatMessage *_Nullable message, EMError *_Nullable error))aCompletionBlock;
  645. /**
  646. * \~chinese
  647. * 从服务器获取指定会话的消息。
  648. *
  649. * @param aConversationId 会话 ID。
  650. * @param aConversationType 会话类型。
  651. * @param aStartMessageId 查询的起始消息 ID。若该参数为空,SDK 从最新一条消息开始获取。
  652. * @param direction 消息搜索方向。详见 {@link EMMessageFetchHistoryDirection}。
  653. * @param aPageSize 每页期望获取的消息条数。
  654. * @param pError 错误信息。
  655. *
  656. * @result 获取的消息内容列表。
  657. *
  658. *
  659. * \~english
  660. * Gets messages in a conversation from the server.
  661. * @param aConversationId The conversation ID.
  662. * @param aConversationType The conversation type.
  663. * @param aStartMessageId The starting message ID for query. If you set this parameter as `nil` or "", the SDK gets messages from the latest one.
  664. * @param direction The message search direction. See {@link EMMessageFetchHistoryDirection}.
  665. * @param aPageSize The number of messages that you expect to get on each page.
  666. * @param pError The error information if the method fails: Error.
  667. *
  668. * @result The list of retrieved messages.
  669. */
  670. - (EMCursorResult<EMChatMessage*> *_Nullable)fetchHistoryMessagesFromServer:(NSString *_Nonnull)aConversationId
  671. conversationType:(EMConversationType)aConversationType
  672. startMessageId:(NSString *_Nullable)aStartMessageId
  673. fetchDirection:(EMMessageFetchHistoryDirection)direction
  674. pageSize:(int)aPageSize
  675. error:(EMError **_Nullable)pError;
  676. /**
  677. * \~chinese
  678. * 从服务器获取指定会话的消息。
  679. *
  680. * @param aConversationId 会话 ID。
  681. * @param aConversationType 会话类型。
  682. * @param aStartMessageId 查询的起始消息 ID。若该参数为空,SDK 从最新一条消息开始获取。
  683. * @param aPageSize 每页期望获取的消息条数。
  684. * @param pError 错误信息。
  685. *
  686. * @result 获取的消息内容列表。
  687. *
  688. *
  689. * \~english
  690. * Gets messages in a conversation from the server.
  691. * @param aConversationId The conversation ID.
  692. * @param aConversationType The conversation type.
  693. * @param aStartMessageId The starting message ID for query. If you set this parameter as `nil` or "", the SDK gets messages from the latest one.
  694. * @param aPageSize The number of messages that you expect to get on each page.
  695. * @param pError The error information if the method fails: Error.
  696. *
  697. * @result The list of retrieved messages.
  698. */
  699. - (EMCursorResult<EMChatMessage*> *_Nullable)fetchHistoryMessagesFromServer:(NSString *_Nonnull)aConversationId
  700. conversationType:(EMConversationType)aConversationType
  701. startMessageId:(NSString *_Nullable)aStartMessageId
  702. pageSize:(int)aPageSize
  703. error:(EMError **_Nullable)pError;
  704. /**
  705. * \~chinese
  706. * 从服务器获取指定会话的消息。
  707. *
  708. * 异步方法。
  709. *
  710. * @param aConversationId 会话 ID。
  711. * @param aConversationType 会话类型。
  712. * @param aStartMessageId 查询的起始消息 ID。
  713. * @param aPageSize 每页期望获取的消息条数。
  714. * @param aCompletionBlock 该方法完成调用的回调。
  715. *
  716. *
  717. * \~english
  718. * Gets messages in a conversation from the server.
  719. *
  720. * This is an asynchronous method.
  721. *
  722. * @param aConversationId The conversation ID.
  723. * @param aConversationType The conversation type.
  724. * @param aStartMessageId The starting message ID for query. If you set this parameter as `nil` or "", the SDK gets messages from the latest one.
  725. * @param aPageSize The number of messages that you expect to get on each page.
  726. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  727. */
  728. - (void)asyncFetchHistoryMessagesFromServer:(NSString *_Nonnull)aConversationId
  729. conversationType:(EMConversationType)aConversationType
  730. startMessageId:(NSString *_Nullable)aStartMessageId
  731. pageSize:(int)aPageSize
  732. completion:(void (^_Nullable)(EMCursorResult<EMChatMessage*> *_Nullable aResult, EMError *_Nullable aError))aCompletionBlock;
  733. /**
  734. * \~chinese
  735. * 从服务器获取指定会话的消息。
  736. *
  737. * 异步方法。
  738. *
  739. * @param aConversationId 会话 ID。
  740. * @param aConversationType 会话类型。
  741. * @param aStartMessageId 查询的起始消息 ID。若该参数为空,SDK 从最新一条消息开始获取。
  742. * @param direction 消息搜索方向。详见 {@link EMMessageFetchHistoryDirection}。
  743. * @param aPageSize 每页期望获取的消息条数。取值范围为 [1,50]。
  744. * @param aCompletionBlock 该方法完成调用的回调。
  745. *
  746. *
  747. * \~english
  748. * Fetches conversation messages from server.
  749. *
  750. * This is an asynchronous method.
  751. *
  752. * @param aConversationId The conversation ID.
  753. * @param aConversationType The conversation type.
  754. * @param aStartMessageId The starting message ID for query. If you set this parameter as `nil` or "", the SDK gets messages from the latest one.
  755. * @param direction The message search direction. See {@link EMMessageFetchHistoryDirection}.
  756. * @param aPageSize The number of messages that you expect to get on each page. The value range is [1,50].
  757. * @param aCompletionBlock The callback block, which contains the error message if the method fails.
  758. */
  759. - (void)asyncFetchHistoryMessagesFromServer:(NSString *_Nonnull)aConversationId
  760. conversationType:(EMConversationType)aConversationType
  761. startMessageId:(NSString *_Nullable)aStartMessageId
  762. fetchDirection:(EMMessageFetchHistoryDirection)direction
  763. pageSize:(int)aPageSize
  764. completion:(void (^_Nullable)(EMCursorResult<EMChatMessage*> *_Nullable aResult, EMError *_Nullable aError))aCompletionBlock;
  765. /**
  766. * \~chinese
  767. * 从服务器获取指定群消息的已读回执。
  768. *
  769. * 可调用该方法了解有多少群成员阅读了指定的群消息。
  770. *
  771. * 异步方法。
  772. *
  773. * @param aMessageId 要获取已读回执的消息 ID。
  774. * @param aGroupId 群组 ID。
  775. * @param aGroupAckId 群消息已读回执 ID。
  776. * @param aPageSize 每页期望获取的回执条数。
  777. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  778. *
  779. *
  780. * \~english
  781. * Gets the read receipts of a specified group message from the server.
  782. *
  783. * By getting the read receipts of a group message, you can see how many group members have read this message.
  784. *
  785. * This is an asynchronous method.
  786. *
  787. * @param aMessageId The message ID.
  788. * @param aGroupId The group ID.
  789. * @param aGroupAckId The ID of the read receipt to get from the server.
  790. * @param aPageSize The number of read receipts that you expect to get on each page.
  791. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  792. */
  793. - (void)asyncFetchGroupMessageAcksFromServer:(NSString *_Nonnull)aMessageId
  794. groupId:(NSString *_Nonnull)aGroupId
  795. startGroupAckId:(NSString *_Nonnull)aGroupAckId
  796. pageSize:(int)aPageSize
  797. completion:(void (^_Nullable)(EMCursorResult<EMGroupMessageAck *> *_Nullable aResult, EMError *_Nullable error, int totalCount))aCompletionBlock;
  798. /**
  799. * \~chinese
  800. * 举报违规消息。
  801. *
  802. * 异步方法。
  803. *
  804. * @param aMessageId 非法消息的 ID。
  805. * @param aTag 非法消息标签,如涉政或涉恐。
  806. * @param aReason 举报原因。
  807. * @param aCompletion 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  808. *
  809. *
  810. * \~english
  811. * Reports an inappropriate message.
  812. *
  813. * This is an asynchronous method.
  814. * @param aMessageId The ID of the inappropriate message.
  815. * @param aTag The message content tag. For example, the message is related to pornography or terrorism.
  816. * @param aReason The reason for reporting the message.
  817. * @param aCompletion The completion block, which contains the error message if the method fails.
  818. */
  819. - (void)reportMessageWithId:(NSString *_Nonnull )aMessageId
  820. tag:(NSString *_Nonnull)aTag
  821. reason:(NSString *_Nonnull)aReason
  822. completion:(void(^_Nullable)(EMError* _Nullable error))aCompletion;
  823. /*!
  824. * \~chinese
  825. * 删除指定时间戳之前的本地历史消息。
  826. *
  827. * 异步方法。
  828. *
  829. * @param aTimestamp 指定的消息时间戳,单位为毫秒。时间戳之前的本地消息会被删除。
  830. * @param aCompletion 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  831. *
  832. * \~english
  833. * Deletes local historical messages with a Unix timestamp before a specified one.
  834. *
  835. * @param aTimestamp The specified Unix timestamp in miliseconds. Messages with a Unix timestamp before the specified one will be deleted.
  836. * @param aCompletion The completion block, which contains the error message if the method fails.
  837. *
  838. */
  839. - (void)deleteMessagesBefore:(NSUInteger)aTimestamp
  840. completion:(void(^)(EMError*error))aCompletion;
  841. /**
  842. * \~chinese
  843. * 从会话中删除消息(包括本地存储和服务器存储)。
  844. *
  845. * @param conversation 会话对象 EMConversation
  846. * @param messageIds 要删除消息 ID 字符串数组。
  847. * @param completion 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  848. *
  849. * \~english
  850. * Removes messages in a conversation (from both local storage and the server).
  851. *
  852. * @param conversation The EMConversation object.
  853. * @param messageIds A string array of message IDs to delete.
  854. * @param completion The completion block, which contains the error message if the method fails.
  855. *
  856. */
  857. - (void)removeMessagesFromServerWithConversation:(EMConversation *_Nonnull)conversation messageIds:(NSArray <__kindof NSString*>*_Nonnull)messageIds completion:(void (^ _Nullable)(EMError * _Nullable aError))aCompletionBlock;
  858. /**
  859. * \~chinese
  860. * 从会话中删除消息(包括本地存储和服务器)。
  861. *
  862. * @param conversation 会话对象 EMConversation。
  863. * @param beforeTimeStamp 指定的时间戳,单位为毫秒。该时间戳之前的消息会被删除。
  864. * @param completion 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  865. *
  866. * \~english
  867. * Removes messages in a conversation (from both local storage and the server).
  868. *
  869. * @param conversation The EMConversation object.
  870. * @param messageIds The specified Unix timestamp in miliseconds. Messages with a timestamp before the specified one will be removed from the conversation.
  871. * @param completion The completion block, which contains the error message if the method fails.
  872. *
  873. */
  874. - (void)removeMessagesFromServerWithConversation:(EMConversation *_Nonnull)conversation timeStamp:(NSTimeInterval)beforeTimeStamp completion:(void (^ _Nullable)(EMError * _Nullable aError))aCompletionBlock;
  875. /*!
  876. * \~chinese
  877. * 翻译消息。
  878. *
  879. * @param aMessage 消息对象。
  880. * @param aLanguages 目标语言代码列表。
  881. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  882. *
  883. * \~english
  884. * Translates a message.
  885. *
  886. * @param aMessage The message object.
  887. * @param aLanguages The list of target language codes.
  888. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  889. */
  890. - (void)translateMessage:(EMChatMessage * _Nonnull)aMessage
  891. targetLanguages:(NSArray<NSString*>* _Nonnull)aLanguages
  892. completion:(void (^_Nullable)(EMChatMessage * _Nullable message, EMError * _Nullable error))aCompletionBlock;
  893. /*!
  894. * \~chinese
  895. * 获取翻译服务支持的语言。
  896. *
  897. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  898. *
  899. * \~english
  900. *
  901. * Gets all languages supported by the translation service.
  902. *
  903. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  904. */
  905. - (void)fetchSupportedLanguages:(void(^_Nullable)(NSArray<EMTranslateLanguage*>* _Nullable languages,EMError* _Nullable error))aCompletionBlock;
  906. /**
  907. * \~chinese
  908. * 通过关键词从数据库获取消息。
  909. *
  910. * 该方法返回的消息按时间顺序排列。
  911. *
  912. * 同步方法,会阻塞当前线程。
  913. *
  914. * @param aType 消息类型。
  915. * @param aTimestamp 参考时间戳。如果该参数设置的时间戳为负数,则从最新消息向前获取。
  916. * @param aCount 获取的消息条数。如果设为小于等于 0,SDK 会获取一条消息。
  917. * @param aUsername 消息发送方。设为 `nil` 表示忽略该参数。
  918. * @param aDirection 消息搜索方向。详见 {@link EMMessageSearchDirection}。
  919. * - `UP`:按消息时间戳的逆序获取。
  920. * - `DOWN`:按消息时间戳的顺序获取。
  921. *
  922. * @result 消息列表。返回的消息列表为数组类型,数组中元素详见 {@link EMChatMessage}。
  923. *
  924. * \~english
  925. * Loads messages with the specified keyword from the local database.
  926. *
  927. * This method returns messages in chronological order.
  928. *
  929. * This is a synchronous method and blocks the current thread.
  930. *
  931. * @param aType The message type to load.
  932. * @param aTimestamp The message timestamp threshold for loading. If you set this parameter as a negative value, the SDK loads messages from the latest one.
  933. * @param aCount The number of messages to load. If you set this parameter to a value less than 1, the SDK gets one message from the local database.
  934. * @param aUsername The message sender. It is optional. If you set this parameter as `nil`, the SDK gets messages while ignoring this parameter.
  935. * @param aDirection The message search direction. See {@link EMMessageSearchDirection}.
  936. * - `UP`: The SDK retrieves messages in the descending order of the timestamp included in them.
  937. * - `DOWN`:The SDK retrieves messages in the ascending order of the timestamp included in them.
  938. *
  939. * @result The list of retrieved messages. The message list is of the array type. For elements in the array, see {@link EMChatMessage}.
  940. *
  941. */
  942. - (NSArray<EMChatMessage *> * _Nullable)loadMessagesWithType:(EMMessageBodyType)aType
  943. timestamp:(long long)aTimestamp
  944. count:(int)aCount
  945. fromUser:(NSString* _Nullable)aUsername
  946. searchDirection:(EMMessageSearchDirection)aDirection;
  947. /**
  948. * \~chinese
  949. * 通过关键词从数据库获取消息。
  950. *
  951. * 该方法返回的消息按时间顺序排列。
  952. *
  953. * @param aType 消息类型。
  954. * @param aTimestamp 参考时间戳。如果该参数设置的时间戳为负数,则 SDK 从最新消息开始获取。
  955. * @param aCount 获取的消息条数。如果设为小于等于 0,SDK 会获取一条消息。
  956. * @param aUsername 消息发送方。设为 `nil` 表示忽略该参数。
  957. * @param aDirection 消息搜索方向,详见 {@link MessageSearchDirection}。
  958. * - `UP`:按消息时间戳的逆序获取。
  959. * - `DOWN`:按消息时间戳的顺序获取。
  960. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  961. *
  962. * \~english
  963. * Loads messages with the specified keyword from the local database.
  964. *
  965. * This method returns messages in chronological order.
  966. *
  967. * @param aType The message type to load.
  968. * @param aTimestamp The message timestamp threshold for loading. If you set this parameter as a negative value, the SDK loads messages from the latest one.
  969. * @param aCount The number of messages to load. If you set this parameter to a value less than 1, the SDK gets one message from the local database.
  970. * @param aUsername The message sender. It is optional. If you set this parameter as `nil`, the SDK ignores this parameter when retrieving messages.
  971. * @param aDirection The message search direction. See {@link EMMessageSearchDirection}.
  972. * - `UP`: The SDK retrieves messages in the descending order of the timestamp included in them.
  973. * - `DOWN`:The SDK retrieves messages in the ascending order of the timestamp included in them.
  974. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  975. *
  976. */
  977. - (void)loadMessagesWithType:(EMMessageBodyType)aType
  978. timestamp:(long long)aTimestamp
  979. count:(int)aCount
  980. fromUser:(NSString*)aUsername
  981. searchDirection:(EMMessageSearchDirection)aDirection
  982. completion:(void (^)(NSArray<EMChatMessage *> *aMessages, EMError *aError))aCompletionBlock;
  983. /**
  984. * \~chinese
  985. * 通过关键词从数据库获取消息。
  986. *
  987. * 该方法返回的消息按时间顺序排列。
  988. *
  989. * 同步方法,会阻塞当前线程。
  990. *
  991. * @param aKeywords 搜索关键词。设为 `nil` 表示忽略该参数。
  992. * @param aTimestamp 参考时间戳。如果该参数设置的时间戳为负数,则从最新消息向前获取。
  993. * @param aCount 获取的消息条数。如果设为小于等于 0,SDK 会获取一条消息。
  994. * @param aSender 消息发送方。设为 `nil` 表示忽略该参数。
  995. * @param aDirection 消息搜索方向,详见 {@link MessageSearchDirection}。
  996. * - `UP`:按消息时间戳的逆序获取。
  997. * - `DOWN`:按消息时间戳的顺序获取。
  998. *
  999. * @result 消息列表。返回的消息列表为数组类型,数组中元素详见 {@link EMChatMessage}。
  1000. *
  1001. * \~english
  1002. * Loads messages with the specified keyword from the local database.
  1003. *
  1004. * This method returns messages in chronological order.
  1005. *
  1006. * This is a synchronous method and blocks the current thread.
  1007. *
  1008. * @param aKeyword The keyword for message search. If you set this parameter as `nil`, the SDK ignores this parameter when retrieving messages.
  1009. * @param aTimestamp The message timestamp threshold for loading. If you set this parameter as a negative value, the SDK loads messages from the latest.
  1010. * @param aCount The number of messages to load. If you set this parameter less than 1, the SDK gets one message from the local database.
  1011. * @param aSender The message sender. If you set this parameter as `nil`, the SDK ignores this parameter when retrieving messages.
  1012. * @param aDirection The message search direction. See {@link EMMessageSearchDirection}.
  1013. * - `UP`: The SDK retrieves messages in the descending order of the timestamp included in them.
  1014. * - `DOWN`:The SDK retrieves messages in the ascending order of the timestamp included in them.
  1015. *
  1016. * @result The list of retrieved messages. The message list is of the array type. For elements in the array, see {@link EMChatMessage}.
  1017. *
  1018. */
  1019. - (NSArray<EMChatMessage *> *)loadMessagesWithKeyword:(NSString*)aKeywords
  1020. timestamp:(long long)aTimestamp
  1021. count:(int)aCount
  1022. fromUser:(NSString*)aSender
  1023. searchDirection:(EMMessageSearchDirection)aDirection;
  1024. /**
  1025. * \~chinese
  1026. * 通过关键词从数据库获取消息。
  1027. *
  1028. * 该方法返回的消息按时间顺序排列。
  1029. *
  1030. * @param aKeywords 搜索关键词,设为 `nil` 表示忽略该参数。
  1031. * @param aTimestamp 参考时间戳。如果该参数设置的时间戳为负数,则从最新消息向前获取。
  1032. * @param aCount 获取的消息条数。如果设为小于等于 0,SDK 会获取一条消息。
  1033. * @param aSender 消息发送方。设为 `nil` 表示忽略该参数。
  1034. * @param aDirection 消息搜索方向,详见 {@link EMMessageSearchDirection}。
  1035. * - `UP`:按消息时间戳的逆序获取。
  1036. * - `DOWN`:按消息时间戳的顺序获取。
  1037. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  1038. *
  1039. * \~english
  1040. * Loads messages with the specified keyword from the local database.
  1041. *
  1042. * This method returns messages in chronological order.
  1043. *
  1044. * @param aKeyword The keyword for message search. If you set this parameter as `nil`, the SDK ignores this parameter when retrieving messages.
  1045. * @param aTimestamp The message timestamp threshold for loading. If you set this parameter as a negative value, the SDK loads messages from the latest.
  1046. * @param aCount The number of messages to load. If you set this parameter less than 1, the SDK gets one message from the local database.
  1047. * @param aSender The sender of the message. If you set this parameter as `nil`, the SDK ignores this parameter when retrieving messages.
  1048. * @param aDirection The message search direction. See {@link EMMessageSearchDirection}.
  1049. * - `UP`: The SDK retrieves messages in the descending order of the timestamp included in them.
  1050. * - `DOWN`:The SDK retrieves messages in the ascending order of the timestamp included in them.
  1051. * @param aCompletionBlock The completion block which contains the error code and error information if the method fails.
  1052. */
  1053. - (void)loadMessagesWithKeyword:(NSString*)aKeywords
  1054. timestamp:(long long)aTimestamp
  1055. count:(int)aCount
  1056. fromUser:(NSString*)aSender
  1057. searchDirection:(EMMessageSearchDirection)aDirection
  1058. completion:(void (^)(NSArray<EMChatMessage *> *aMessages, EMError *aError))aCompletionBlock;
  1059. NS_ASSUME_NONNULL_BEGIN
  1060. /*!
  1061. * \~chinese
  1062. * 添加 Reaction。
  1063. *
  1064. * @param reaction Reaction 内容。
  1065. * @param messageId 消息 ID。
  1066. * @param completion 该方法完成的回调。如果有错误会包含错误信息。
  1067. *
  1068. * \~english
  1069. * Adds a Reaction.
  1070. *
  1071. * @param reaction The Reaction content.
  1072. * @param messageId The message ID.
  1073. * @param completion The completion block which contains the error code and error information if the method fails.
  1074. */
  1075. - (void)addReaction:(NSString *)reaction toMessage:(NSString *)messageId completion:(nullable void(^)(EMError * _Nullable))completion;
  1076. /*!
  1077. * \~chinese
  1078. * 删除 Reaction。
  1079. *
  1080. * @param reaction Reaction 内容。
  1081. * @param messageId 消息 ID。
  1082. * @param completion 该方法完成的回调。如果有错误会包含错误信息。
  1083. *
  1084. * \~english
  1085. * Removes a Reaction.
  1086. *
  1087. * @param reaction The Reaction content.
  1088. * @param messageId The message ID.
  1089. * @param completion The completion block which contains the error code and error information if the method fails.
  1090. */
  1091. - (void)removeReaction:(NSString *)reaction fromMessage:(NSString *)messageId completion:(nullable void(^)(EMError * _Nullable))completion;
  1092. /*!
  1093. * \~chinese
  1094. * 获取消息的 Reaction 列表。
  1095. *
  1096. * @param messageId 消息 ID。
  1097. * @param groupId 群组 ID,该参数只在群聊生效。
  1098. * @param chatType 会话类型,仅支持单聊({@link EMChatTypeChat})和群聊({@link EMChatTypeGroupChat})。
  1099. * @param completion 该方法完成的回调。如果有错误会包含错误信息。
  1100. *
  1101. * \~english
  1102. * Gets the Reaction list.
  1103. *
  1104. * @param messageId The message ID.
  1105. * @param groupId The group ID. This parameter is invalid only for group chat.
  1106. * @param chatType The chat type. Only one-to-one chat ({@link EMChatTypeChat} and group chat ({@link EMChatTypeGroupChat}) are allowed.
  1107. * @param completion The completion block which contains the error code and error information if the method fails.
  1108. */
  1109. - (void)getReactionList:(NSArray <NSString *>*)messageIds
  1110. groupId:(nullable NSString *)groupId
  1111. chatType:(EMChatType)chatType
  1112. completion:(void (^)(NSDictionary <NSString *, NSArray<EMMessageReaction *> *> *, EMError * _Nullable))completion;
  1113. /*!
  1114. * \~chinese
  1115. * 分页获取群聊消息的 Reaction 详细列表。
  1116. *
  1117. * @param messageId 消息 ID。
  1118. * @param reaction Reaction 内容。
  1119. * @param cursor 查询的开始位置。首次调用该方法可传 `nil` 或 `@""` 以 Reaction 创建时间的正序获取。
  1120. * @param pageSize 每页期望返回的 Reaction 数量。取值范围为 [1,100]。
  1121. * @param completion 该方法完成的回调,返回 Reaction 列表和用于继续获取数据的 cursor。当 cursor 为 `nil` 时表示已获取全部数据。
  1122. *
  1123. * \~english
  1124. * Uses the pagination to get the Reaction detail list of a chat group message.
  1125. *
  1126. * @param messageId The message ID.
  1127. * @param reaction The Reaction content.
  1128. * @param cursor The position from which to start getting data. If it is set to `nil` or `@""` at the first call, the SDK retrieves Reactions in the chronological order of their creation time.
  1129. * @param pageSize The number of Reactions that you expect to get on each page. The value range is [1,100].
  1130. * @param completion The completion block, which contains the Reaction list and the cursor for the next query. When the cursor is `nil`, all data is already fetched.
  1131. */
  1132. - (void)getReactionDetail:(NSString *)messageId
  1133. reaction:(NSString *)reaction
  1134. cursor:(nullable NSString *)cursor
  1135. pageSize:(uint64_t)pageSize
  1136. completion:(void (^)(EMMessageReaction *, NSString * _Nullable cursor, EMError * _Nullable))completion;
  1137. /**
  1138. * \~chinese
  1139. * 根据消息拉取参数配置接口(`EMFetchServerMessagesOption`)从服务器分页获取指定会话的历史消息。
  1140. *
  1141. * @param conversationId 会话 ID。
  1142. * @param type 会话类型,只支持单聊(`EMConversationTypeChat`)和群组(`EMConversationTypeGroupChat`)。
  1143. * @param cursor 查询的起始游标位置。
  1144. * @param pageSize 每页期望获取的消息条数。取值范围为 [1,50]。
  1145. * @param option 查询历史消息的参数配置接口,详见 {@link EMFetchServerMessagesOption}。
  1146. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  1147. *
  1148. * \~english
  1149. *
  1150. * @param conversationId The conversation ID, which is the user ID of the peer user for one-to-one chat, but the group ID for group chat.
  1151. * @param type The conversation type. You can set this parameter only to `EMConversationTypeChat` (one-to-one chat) or `EMConversationTypeGroupChat` (group chat).
  1152. * @param cursor The cursor position from which to start querying data.
  1153. * @param pageSize The number of messages that you expect to get on each page. The value range is [1,50].
  1154. * @param option The parameter configuration class for pulling historical messages from the server. See {@link EMFetchServerMessagesOption}.
  1155. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  1156. *
  1157. */
  1158. - (void)fetchMessagesFromServerBy:(NSString* )conversationId
  1159. conversationType:(EMConversationType)type
  1160. cursor:(NSString* _Nullable)cursor
  1161. pageSize:(NSUInteger)pageSize
  1162. option:(EMFetchServerMessagesOption* _Nullable)option
  1163. completion:(void (^_Nullable)(EMCursorResult<EMChatMessage*>* _Nullable result, EMError* _Nullable aError))aCompletionBlock;
  1164. NS_ASSUME_NONNULL_END
  1165. @end