NIMChatManagerProtocol.h 11 KB

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