IEMContactManager.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. /**
  2. * \~chinese
  3. * @header IEMContactManager.h
  4. * @abstract 联系人相关操作协议类。
  5. * @author Hyphenate
  6. * @version 3.00
  7. *
  8. * \~english
  9. * @header IEMContactManager.h
  10. * @abstract The protocol defines the operations of contact.
  11. * @author Hyphenate
  12. * @version 3.00
  13. */
  14. #import <Foundation/Foundation.h>
  15. #import "EMCommonDefs.h"
  16. #import "EMContactManagerDelegate.h"
  17. @class EMError;
  18. /**
  19. * \~chinese
  20. * 好友相关操作。
  21. *
  22. * \~english
  23. * The contact management.
  24. */
  25. @protocol IEMContactManager <NSObject>
  26. @required
  27. #pragma mark - Delegate
  28. /**
  29. * \~chinese
  30. * 添加回调代理。
  31. *
  32. * @param aDelegate 要添加的代理。
  33. * @param aQueue aQueue 是指定执行代理方法的运行队列,如果传入 nil,则运行在主队列;传入指定的运行队列则在子线程运行。
  34. *
  35. * \~english
  36. * Adds delegate.
  37. *
  38. * @param aDelegate The delegate to be added.
  39. * @param aQueue (optional) The queue of calling delegate methods. You need to set this parameter as nil to run on main thread.
  40. */
  41. - (void)addDelegate:(id<EMContactManagerDelegate> _Nonnull)aDelegate
  42. delegateQueue:(dispatch_queue_t)aQueue;
  43. /**
  44. * \~chinese
  45. * 移除回调代理。
  46. *
  47. * @param aDelegate 要移除的代理。
  48. *
  49. * \~english
  50. * Removes delegate.
  51. *
  52. * @param aDelegate The delegate to be removed.
  53. */
  54. - (void)removeDelegate:(id _Nonnull)aDelegate;
  55. #pragma mark - Contact Operations
  56. /**
  57. * \~chinese
  58. * 获取本地存储的所有好友。
  59. *
  60. * 同步方法。
  61. *
  62. * @result 好友列表。
  63. *
  64. * \~english
  65. * Gets all contacts from the local database.
  66. *
  67. * This is a synchronous method and blocks the current thread.
  68. *
  69. * @result The contact NSArray.
  70. */
  71. - (NSArray<NSString *> *_Nullable )getContacts;
  72. /**
  73. * \~chinese
  74. * 从服务器获取所有的好友。
  75. *
  76. * 异步方法。
  77. *
  78. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  79. *
  80. * \~english
  81. * Gets all contacts from the server.
  82. *
  83. * This is an asynchronous method.
  84. *
  85. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  86. *
  87. */
  88. - (void)getContactsFromServerWithCompletion:(void (^)(NSArray<NSString *> *_Nullable aList, EMError *aError_Nullable ))aCompletionBlock;
  89. /**
  90. * \~chinese
  91. * 从服务器获取所有的好友。
  92. *
  93. * 同步方法,会阻塞当前线程。
  94. *
  95. * @param pError 错误信息。
  96. *
  97. * @result 好友列表。
  98. *
  99. * \~english
  100. * Gets all the contacts from the server.
  101. *
  102. * This is a synchronous method and blocks the current thread.
  103. *
  104. * @param pError The error information if the method fails: Error.
  105. *
  106. * @result The contact NSArray.
  107. */
  108. - (NSArray<NSString *> *_Nullable )getContactsFromServerWithError:(EMError **_Nullable )pError;
  109. /**
  110. * \~chinese
  111. * 添加好友。
  112. *
  113. * 同步方法,会阻塞当前线程。
  114. *
  115. * @param aUsername 要添加的用户。
  116. * @param aMessage 邀请信息。
  117. *
  118. * @result 错误信息。
  119. *
  120. * \~english
  121. * Adds a contact with invitation message.
  122. *
  123. * This is a synchronous method and blocks the current thread.
  124. *
  125. * @param aUsername The user to add contact.
  126. * @param aMessage (optional) The invitation message. Sets the parameter as nil if you want to ignore the information.
  127. *
  128. * @result The error information if the method fails: Error.
  129. */
  130. - (EMError *_Nullable )addContact:(NSString *_Nonnull)aUsername
  131. message:(NSString *_Nullable )aMessage;
  132. /**
  133. * \~chinese
  134. * 添加好友。
  135. *
  136. * 异步方法。
  137. *
  138. * @param aUsername 要添加的用户。
  139. * @param aMessage 邀请信息。
  140. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  141. *
  142. * \~english
  143. * Adds a contact.
  144. *
  145. * This is an asynchronous method.
  146. *
  147. * @param aUsername The user to be added as a contact.
  148. * @param aMessage The invitation message.
  149. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  150. *
  151. */
  152. - (void)addContact:(NSString *_Nonnull)aUsername
  153. message:(NSString *_Nullable )aMessage
  154. completion:(void (^_Nullable )(NSString *_Nullable aUsername, EMError *_Nullable aError))aCompletionBlock;
  155. /**
  156. * \~chinese
  157. * 删除好友。
  158. *
  159. * 同步方法,会阻塞当前线程。
  160. *
  161. * @param aUsername 要删除的好友。
  162. * @param aIsDeleteConversation 是否删除会话。YES:删除好友,会同步删除与好友的会话,NO:仅删除好友,不删除会话。
  163. *
  164. * @result 错误信息。
  165. *
  166. * \~english
  167. * Deletes a contact.
  168. *
  169. * This is a synchronous method and blocks the current thread.
  170. *
  171. * @param aUsername The contact to be deleted.
  172. * @param aIsDeleteConversation Whether to keep the associated conversation and messages. Yes means delete the contact and synchronisely delete the conversations between the contact and the user. No means don't delete the conversations when deleting the contact.
  173. *
  174. * @result The error information if the method fails: Error.
  175. */
  176. - (EMError *_Nullable )deleteContact:(NSString *_Nonnull)aUsername
  177. isDeleteConversation:(BOOL)aIsDeleteConversation;
  178. /**
  179. * \~chinese
  180. * 删除好友。
  181. *
  182. * 异步方法。
  183. *
  184. * @param aUsername 要删除的好友。
  185. * @param aIsDeleteConversation 是否删除会话。YES:删除好友,会同步删除与好友的会话,NO:仅删除好友,不删除会话。
  186. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  187. *
  188. * \~english
  189. * Deletes a contact.
  190. *
  191. * This is an asynchronous method.
  192. *
  193. * @param aUsername The contact to be deleted.
  194. * @param aIsDeleteConversation Whether to delete the related conversation. Yes means delete the contact and synchronisely delete the conversations between the contact and the user. No means don't delete the conversations when deleting the contact.
  195. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  196. *
  197. */
  198. - (void)deleteContact:(NSString *_Nonnull)aUsername
  199. isDeleteConversation:(BOOL)aIsDeleteConversation
  200. completion:(void (^_Nullable )(NSString *_Nullable aUsername, EMError *_Nullable aError))aCompletionBlock;
  201. /**
  202. * \~chinese
  203. * 同意好友申请。
  204. *
  205. * 异步方法。
  206. *
  207. * @param aUsername 申请者。
  208. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  209. *
  210. * \~english
  211. * Approves a friend request.
  212. *
  213. * This is an asynchronous method.
  214. *
  215. * @param aUsername The user who initiated the friend request.
  216. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  217. *
  218. */
  219. - (void)approveFriendRequestFromUser:(NSString *_Nonnull)aUsername
  220. completion:(void (^_Nullable )(NSString *_Nullable aUsername, EMError *_Nullable aError))aCompletionBlock;
  221. /**
  222. * \~chinese
  223. * 拒绝好友申请。
  224. *
  225. * 异步方法。
  226. *
  227. * @param aUsername 申请者。
  228. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  229. *
  230. * \~english
  231. * Declines a friend request.
  232. *
  233. * This is an asynchronous method.
  234. *
  235. * @param aUsername The user who initiated the friend request.
  236. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  237. *
  238. */
  239. - (void)declineFriendRequestFromUser:(NSString *_Nonnull)aUsername
  240. completion:(void (^_Nullable )(NSString *aUsername, EMError *_Nullable aError))aCompletionBlock;
  241. #pragma mark - Blacklist Operations
  242. /**
  243. * \~chinese
  244. * 从本地获取黑名单列表。
  245. *
  246. * 同步方法,会阻塞当前线程。
  247. *
  248. * @result 黑名单列表。
  249. *
  250. * \~english
  251. * Gets the list of blocked users from local database.
  252. * This is a synchronous method and blocks the current thread.
  253. * @result The blocklist usernames NSArray. See <NSString>.
  254. */
  255. - (NSArray<NSString *> *_Nullable )getBlackList;
  256. /**
  257. * \~chinese
  258. * 从服务器获取黑名单列表。
  259. *
  260. * 异步方法。
  261. *
  262. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  263. *
  264. * \~english
  265. * Gets the blocklist from the server.
  266. *
  267. * This is an asynchronous method.
  268. *
  269. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  270. *
  271. */
  272. - (void)getBlackListFromServerWithCompletion:(void (^_Nullable )(NSArray<NSString *> *_Nullable aList, EMError *_Nullable aError))aCompletionBlock;
  273. /**
  274. * \~chinese
  275. * 从服务器获取黑名单列表。
  276. *
  277. * 同步方法,会阻塞当前线程。
  278. *
  279. * @param pError 错误信息。
  280. *
  281. * @result 黑名单列表。
  282. *
  283. * \~english
  284. * Gets the blocklist from the server.
  285. *
  286. * This is a synchronous method and blocks the current thread.
  287. *
  288. * @param pError The error information if the method fails: Error.
  289. *
  290. * @result The blocklist NSArray.
  291. */
  292. - (NSArray<NSString *> *_Nullable )getBlackListFromServerWithError:(EMError **_Nullable )pError;
  293. /**
  294. * \~chinese
  295. * 将用户加入黑名单。
  296. *
  297. * 同步方法,会阻塞当前线程。
  298. *
  299. * @param aUsername 要加入黑名单的用户。
  300. *
  301. * @result 错误信息。
  302. *
  303. * \~english
  304. * Adds a user to the blocklist.
  305. *
  306. * This is a synchronous method and blocks the current thread.
  307. *
  308. * @param aUsername The user to be added into the blocklist.
  309. *
  310. * @result The error information if the method fails: Error.
  311. */
  312. - (EMError *_Nullable )addUserToBlackList:(NSString *_Nonnull)aUsername;
  313. /**
  314. * \~chinese
  315. * 将用户加入黑名单。
  316. *
  317. * 异步方法。
  318. *
  319. * @param aUsername 要加入黑名单的用户。
  320. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  321. *
  322. * \~english
  323. * Adds a user to the blocklist.
  324. *
  325. * This is an asynchronous method.
  326. *
  327. * @param aUsername The user to be added into the blocklist.
  328. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  329. *
  330. */
  331. - (void)addUserToBlackList:(NSString *_Nonnull)aUsername
  332. completion:(void (^_Nullable )(NSString *_Nullable aUsername, EMError *_Nullable aError))aCompletionBlock;
  333. /**
  334. * \~chinese
  335. * 将用户移出黑名单。
  336. *
  337. * 同步方法,会阻塞当前线程。
  338. *
  339. * @param aUsername 要移出黑名单的用户。
  340. *
  341. * @result 错误信息。
  342. *
  343. * \~english
  344. * Removes the user out of the blocklist.
  345. *
  346. * This is a synchronous method and blocks the current thread.
  347. *
  348. * @param aUsername The user to be removed from the blocklist.
  349. *
  350. * @result The error information if the method fails: Error.
  351. */
  352. - (EMError *_Nullable )removeUserFromBlackList:(NSString *_Nonnull)aUsername;
  353. /**
  354. * \~chinese
  355. * 将用户移出黑名单。
  356. *
  357. * 异步方法。
  358. *
  359. * @param aUsername 要移出黑名单的用户。
  360. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  361. *
  362. * \~english
  363. * Removes the user from the blocklist.
  364. *
  365. * This is an asynchronous method.
  366. *
  367. * @param aUsername The user to be removed from the blocklist.
  368. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  369. *
  370. */
  371. - (void)removeUserFromBlackList:(NSString *_Nonnull)aUsername
  372. completion:(void (^_Nullable )(NSString *_Nullable aUsername, EMError *_Nullable aError))aCompletionBlock;
  373. /**
  374. * \~chinese
  375. * 同意加好友的申请。
  376. *
  377. * 同步方法,会阻塞当前线程。
  378. *
  379. * @param aUsername 申请者。
  380. *
  381. * @result 错误信息。
  382. *
  383. * \~english
  384. * Accepts a friend request.
  385. *
  386. * This is a synchronous method and blocks the current thread.
  387. *
  388. * @param aUsername The user who initiated the friend request.
  389. *
  390. * @result The error information if the method fails: Error.
  391. */
  392. - (EMError *_Nullable )acceptInvitationForUsername:(NSString *_Nonnull)aUsername;
  393. /**
  394. * \~chinese
  395. * 拒绝加好友的申请。
  396. *
  397. * 同步方法,会阻塞当前线程。
  398. *
  399. * @param aUsername 申请者。
  400. *
  401. * @result 错误信息。
  402. *
  403. * \~english
  404. * Declines a friend request.
  405. *
  406. * This is a synchronous method and blocks the current thread.
  407. *
  408. * @param aUsername The user who initiates the friend request.
  409. *
  410. * @result The error information if the method fails: Error.
  411. *
  412. * Please use this new method.
  413. *
  414. * - (void)declineFriendRequestFromUser:(NSString *)aUsername
  415. * completion:(void (^)(NSString *aUsername, EMError *aError))aCompletionBlock;
  416. */
  417. - (EMError *_Nullable )declineInvitationForUsername:(NSString *_Nonnull)aUsername;
  418. #pragma mark - Other platform
  419. /**
  420. * \~chinese
  421. * 获取当前账号在其他平台(Windows 或者 Web)登录的 ID 列表。
  422. * ID 使用方法类似于好友 username。
  423. *
  424. * 同步方法,会阻塞当前线程。
  425. *
  426. * @param pError 错误信息。
  427. *
  428. * @result ID 列表。
  429. *
  430. * \~english
  431. * Gets the ID list of the current account on another platform (Windows or Web)
  432. * The ID usage is similar to friend username.
  433. *
  434. * This is a synchronous method and blocks the current thread.
  435. *
  436. * @param pError The error information if the method fails: Error.
  437. *
  438. * @result The ID NSArray. See <NSString>.
  439. *
  440. */
  441. - (NSArray<NSString *> *_Nullable )getSelfIdsOnOtherPlatformWithError:(EMError **_Nullable )pError;
  442. /**
  443. * \~chinese
  444. * 获取当前账号在其他平台(Windows 或者 Web)登录的 ID 列表。
  445. * ID 使用方法类似于好友 username。
  446. *
  447. * 异步方法。
  448. *
  449. * @param aCompletionBlock 该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。
  450. *
  451. * \~english
  452. * Gets the ID list of the current account on another platform (Windows or Web)
  453. * The ID usage is similar to friend username.
  454. *
  455. * This is an asynchronous method.
  456. *
  457. * @param aCompletionBlock The completion block, which contains the error message if the method fails.
  458. *
  459. */
  460. - (void)getSelfIdsOnOtherPlatformWithCompletion:(void (^_Nullable)(NSArray<NSString *> *_Nullable aList, EMError *_Nullable aError))aCompletionBlock;
  461. @end