NIMChatManagerProtocol.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. //
  2. // NIMChatManagerProtocol.h
  3. // NIMLib
  4. //
  5. // Created by Netease.
  6. // Copyright (c) 2015 Netease. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. @class NIMMessage;
  10. @class NIMSession;
  11. @class NIMMessageReceipt;
  12. @class NIMRevokeMessageNotification;
  13. @class NIMTeamMessageReceiptDetail;
  14. NS_ASSUME_NONNULL_BEGIN
  15. /**
  16. * P2P 发送已读回执 Block
  17. *
  18. * @param error 错误信息,如果成功,error 为 nil
  19. */
  20. typedef void(^NIMSendMessageReceiptBlock)(NSError * __nullable error);
  21. /**
  22. * Team 发送已读回执 Block
  23. *
  24. * @param error 错误信息,如果成功,error 为 nil
  25. * @param failedReceipts 失败的回执
  26. */
  27. typedef void(^NIMSendTeamMessageReceiptsBlock)(NSError * __nullable error,NSArray<NIMMessageReceipt *> * __nullable failedReceipts);
  28. /**
  29. * 撤回消息Block
  30. *
  31. * @param error 错误信息,如果成功,error 为 nil
  32. */
  33. typedef void(^NIMRevokeMessageBlock)(NSError * __nullable error);
  34. /**
  35. * 查询群组消息回执详情Block
  36. *
  37. * @param error 错误,如果成功则error为nil
  38. * @param detail 已读回执详情
  39. */
  40. typedef void(^NIMQueryReceiptDetailBlock)(NSError * __nullable error,NIMTeamMessageReceiptDetail * __nullable detail);
  41. /**
  42. * 聊天委托
  43. */
  44. @protocol NIMChatManagerDelegate <NSObject>
  45. @optional
  46. /**
  47. * 即将发送消息回调
  48. * @discussion 因为发消息之前可能会有个准备过程,所以需要在收到这个回调时才将消息加入到 Datasource 中
  49. * @param message 当前发送的消息
  50. */
  51. - (void)willSendMessage:(NIMMessage *)message;
  52. /**
  53. * 上传资源文件成功的回调
  54. * @discussion 对于需要上传资源的消息(图片,视频,音频等),SDK 将在上传资源成功后通过这个接口进行回调,上层可以在收到该回调后进行推送信息的重新配置 (APNS payload)
  55. * @param urlString 当前消息资源获得的 url 地址
  56. * @param message 当前发送的消息
  57. */
  58. - (void)uploadAttachmentSuccess:(NSString *)urlString
  59. forMessage:(NIMMessage *)message;
  60. /**
  61. * 发送消息进度回调
  62. *
  63. * @param message 当前发送的消息
  64. * @param progress 进度
  65. */
  66. - (void)sendMessage:(NIMMessage *)message
  67. progress:(float)progress;
  68. /**
  69. * 发送消息完成回调
  70. *
  71. * @param message 当前发送的消息
  72. * @param error 失败原因,如果发送成功则error为nil
  73. */
  74. - (void)sendMessage:(NIMMessage *)message
  75. didCompleteWithError:(nullable NSError *)error;
  76. /**
  77. * 收到消息回调
  78. *
  79. * @param messages 消息列表,内部为NIMMessage
  80. */
  81. - (void)onRecvMessages:(NSArray<NIMMessage *> *)messages;
  82. /**
  83. * 收到消息回执
  84. *
  85. * @param receipts 消息回执数组
  86. * @discussion 当上层收到此消息时所有的存储和 model 层业务都已经更新,只需要更新 UI 即可。
  87. */
  88. - (void)onRecvMessageReceipts:(NSArray<NIMMessageReceipt *> *)receipts;
  89. /**
  90. * 收到消息被撤回的通知
  91. *
  92. * @param notification 被撤回的消息信息
  93. * @discusssion 云信在收到消息撤回后,会先从本地数据库中找到对应消息并进行删除,之后通知上层消息已删除
  94. */
  95. - (void)onRecvRevokeMessageNotification:(NIMRevokeMessageNotification *)notification;
  96. /**
  97. * 收取消息附件回调
  98. * @param message 当前收取的消息
  99. * @param progress 进度
  100. * @discussion 附件包括:图片,视频的缩略图,语音文件
  101. */
  102. - (void)fetchMessageAttachment:(NIMMessage *)message
  103. progress:(float)progress;
  104. /**
  105. * 收取消息附件完成回调
  106. *
  107. * @param message 当前收取的消息
  108. * @param error 错误返回,如果收取成功,error为nil
  109. */
  110. - (void)fetchMessageAttachment:(NIMMessage *)message
  111. didCompleteWithError:(nullable NSError *)error;
  112. @end
  113. /**
  114. * 聊天协议
  115. */
  116. @protocol NIMChatManager <NSObject>
  117. /**
  118. * 发送消息
  119. *
  120. * @param message 消息
  121. * @param session 接受方
  122. * @param error 错误 如果在准备发送消息阶段发生错误,这个error会被填充相应的信息
  123. *
  124. * @return 是否调用成功,这里返回的 result 只是表示当前这个函数调用是否成功,需要后续的回调才能够判断消息是否已经发送至服务器
  125. */
  126. - (BOOL)sendMessage:(NIMMessage *)message
  127. toSession:(NIMSession *)session
  128. error:(NSError * __nullable *)error;
  129. /**
  130. * 异步发送消息
  131. *
  132. * @param message 消息
  133. * @param session 接收方
  134. * @param completion 发送完成后的回调,这里的回调完成只表示当前这个函数调用完成,需要后续的回调才能判断消息是否已经发送至服务器
  135. */
  136. - (void)sendMessage:(NIMMessage *)message
  137. toSession:(NIMSession *)session
  138. completion:(nullable void(^)(NSError * __nullable error))completion;
  139. /**
  140. * 取消正在发送的消息
  141. *
  142. * @param message 目标消息
  143. * @return 是否调用成功
  144. */
  145. - (BOOL)cancelSendingMessage:(NIMMessage *)message;
  146. /**
  147. * 重发消息
  148. *
  149. * @param message 重发消息
  150. * @param error 错误 如果在准备发送消息阶段发生错误,这个error会被填充相应的信息
  151. *
  152. * @return 是否调用成功,这里返回的 result 只是表示当前这个函数调用是否成功,需要后续的回调才能够判断消息是否已经发送至服务器
  153. */
  154. - (BOOL)resendMessage:(NIMMessage *)message
  155. error:(NSError * __nullable *)error;
  156. /**
  157. * 转发消息
  158. *
  159. * @param message 消息
  160. * @param session 接收方
  161. * @param error 错误 如果在准备发送消息阶段发生错误,这个error会被填充相应的信息
  162. *
  163. * @return 是否调用成功,这里返回的 result 只是表示当前这个函数调用是否成功,需要后续的回调才能够判断消息是否已经发送至服务器
  164. */
  165. - (BOOL)forwardMessage:(NIMMessage *)message
  166. toSession:(NIMSession *)session
  167. error:(NSError * __nullable *)error;
  168. /**
  169. * 发送已读回执 (P2P)
  170. *
  171. * @param receipt 已读回执
  172. * @param completion 完成回调
  173. * @discussion 此接口仅适用于 P2P 消息,群消息已读回执使用 sendTeamMessageReceipts:completion 如果已有比当前已读回执时间戳更大的已读回执已确认,则接口返回成功。
  174. */
  175. - (void)sendMessageReceipt:(NIMMessageReceipt *)receipt
  176. completion:(nullable NIMSendMessageReceiptBlock)completion;
  177. /**
  178. * 发送已读回执 (Team 批量接口)
  179. *
  180. * @param receipts 已读回执
  181. * @param completion 完成回调
  182. * @discussion 此接口仅适用于 Team 消息。
  183. */
  184. - (void)sendTeamMessageReceipts:(NSArray<NIMMessageReceipt *> *)receipts
  185. completion:(nullable NIMSendTeamMessageReceiptsBlock)completion;
  186. /**
  187. * 刷新群组消息已读、未读数量
  188. *
  189. * @param messages 要查询的消息集合
  190. * @discussion 消息已读变化后,会通过 NIMChatManager 的代理 onRecvMessageReceipts: 回调给上层
  191. * 刷新的消息必须为群组消息
  192. */
  193. - (void)refreshTeamMessageReceipts:(NSArray<NIMMessage *> *)messages;
  194. /**
  195. * 查询群组消息回执详情
  196. *
  197. * @param message 要查询的消息
  198. * @param completion 完成后的回调
  199. * @discussion 详情包括已读人数的 id 列表和未读人数的 id 列表
  200. * 查询详情对象不会跟着回执人数变化而变化,如果要获取最新的详情,必须再次调用此接口
  201. *
  202. */
  203. - (void)queryMessageReceiptDetail:(NIMMessage *)message
  204. completion:(NIMQueryReceiptDetailBlock)completion;
  205. /**
  206. * 撤回消息
  207. *
  208. * @param message 需要被撤回的消息
  209. * @param completion 完成回调
  210. */
  211. - (void)revokeMessage:(NIMMessage *)message
  212. completion:(nullable NIMRevokeMessageBlock)completion;
  213. /**
  214. * 收取消息附件
  215. *
  216. * @param message 需要收取附件的消息
  217. * @param error 错误
  218. *
  219. * @return 是否调用成功
  220. * @discussion 附件包括:图片消息的图片缩略图,视频消息的视频缩略图,音频消息的音频文件,文件消息的文件以及自定义消息中的自定义文件
  221. * 个人和群组消息 SDK 会在收到该消息时自动调用本接口,自动下载除 "文件消息的文件" 外的所有附件内容
  222. *
  223. */
  224. - (BOOL)fetchMessageAttachment:(NIMMessage *)message
  225. error:(NSError * __nullable *)error;
  226. /**
  227. * 取消收取消息附件
  228. *
  229. * @param message 需要取消收取附件的消息
  230. *
  231. * @discussion 附件包括:图片消息的图片缩略图,视频消息的视频缩略图,音频消息的音频文件,文件消息的文件以及自定义消息中的自定义文件
  232. * 个人和群组消息。SDK 不会触发任何下载回调
  233. */
  234. - (void)cancelFetchingMessageAttachment:(NIMMessage *)message;
  235. /**
  236. * 消息是否正在传输 (发送/接受附件)
  237. *
  238. * @param message 消息
  239. *
  240. * @return 是否正在传输
  241. */
  242. - (BOOL)messageInTransport:(NIMMessage *)message;
  243. /**
  244. * 传输消息的进度 (发送/接受附件)
  245. *
  246. * @param message 消息
  247. *
  248. * @return 正在传输的消息进度,如果消息不在传输,则返回0
  249. */
  250. - (float)messageTransportProgress:(NIMMessage *)message;
  251. /**
  252. * 添加聊天委托
  253. *
  254. * @param delegate 聊天委托
  255. */
  256. - (void)addDelegate:(id<NIMChatManagerDelegate>)delegate;
  257. /**
  258. * 移除聊天委托
  259. *
  260. * @param delegate 聊天委托
  261. */
  262. - (void)removeDelegate:(id<NIMChatManagerDelegate>)delegate;
  263. @end
  264. NS_ASSUME_NONNULL_END