NIMSDK-iOS
载入中...
搜索中...
未找到
NIMQChatMessageManagerProtocol.h
浏览该文件的文档.
1//
2// NIMQChatMessageManagerProtocol.h
3// NIMLib
4//
5// Created by Netease.
6// Copyright © 2022 Netease. All rights reserved.
7//
8
9#import <Foundation/Foundation.h>
10
11#import "NIMQChatDefs.h"
12
13NS_ASSUME_NONNULL_BEGIN
14
15@class NIMQChatMessage;
16@class NIMSession;
17
25
37
52
53/**
54 * 发送自定义通知消息的回调
55 *
56 * @param error 错误信息
57 * @param result 回调结果
58 */
59typedef void(^NIMQChatSendSystemNotificationHandler)(NSError *__nullable error, NIMQChatSendSystemNotificationResult *__nullable result);
60
61/**
62 * 拉取聊天消息的回调
63 *
64 * @param error 错误信息
65 * @param result 回调结果
66 */
67typedef void(^NIMQChatGetMessageHistoryHandler)(NSError *__nullable error, NIMQChatGetMessageHistoryResult *__nullable result);
68
69/**
70 * 更新圈组消息的回调
71 *
72 * @param error 错误信息
73 * @param result 回调结果
74 */
75typedef void(^NIMQChatUpdateMessageHandler)(NSError *__nullable error, NIMQChatUpdateMessageResult *__nullable result);
76
77/**
78 * 更新系统通知的回调
79 *
80 * @param error 错误信息
81 * @param result 回调结果
82 */
83typedef void(^NIMQChatUpdateSystemNotificationHandler)(NSError *__nullable error, NIMQChatUpdateSystemNotificationResult *__nullable result);
84
85/**
86 * 拉取缓存消息的回调
87 *
88 * @param error 错误信息
89 * @param result 回调结果
90 */
91typedef void(^NIMQChatGetMessageCacheHandler)(NSError *__nullable error, NIMQChatGetMessageCacheResult *__nullable result);
92
93/**
94 * 发送消息正在输入事件的回调
95 *
96 * @param error 错误信息
97 * @param result 回调结果
98 */
99typedef void(^NIMQChatSendMessageTypingEventHandler)(NSError *__nullable error, NIMQChatMessageTypingEvent *__nullable result);
100
101/**
102 * 批量查询频道最后一条消息的回调
103 *
104 * @param error 错误信息
105 * @param result 回调结果
106 */
107typedef void(^NIMQChatGetLastMessageOfChannelsHandler)(NSError *__nullable error, NIMQChatGetLastMessageOfChannelsResult *__nullable result);
108
109/**
110 * 分页搜索圈组消息的回调
111 * @param error 错误信息
112 * @param result 回调结果
113 */
114typedef void(^NIMQChatSearchMsgByPageHandler)(NSError *__nullable error, NIMQChatSearchMsgByPageResult *__nullable result);
115
116/**
117 * 分页搜索圈组 @ 我的消息的回调
118 * @param error 错误信息
119 * @param result 回调结果
120 */
121typedef void(^NIMQChatGetMentionedMeMessagesHandler)(NSError *__nullable error, NIMQChatGetMentionedMeMessagesResult *__nullable result);
122
123/**
124 * 批量查询消息是否 @ 当前用户的回调
125 * @param error 错误信息
126 * @param result 回调结果
127 */
128typedef void(^NIMQChatAreMentionedMeMessagesHandler)(NSError *__nullable error, NIMQChatAreMentionedMeMessagesResult *__nullable result);
129
130
131
132/**
133 * 圈组消息管理器回调
134 */
135@protocol NIMQChatMessageManagerDelegate <NSObject>
136
137@optional
138
139/**
140 * 即将发送消息回调
141 * @discussion 因为发消息之前可能会有个准备过程,所以需要在收到这个回调时才将消息加入到 Datasource 中
142 * @param message 当前发送的消息
143 */
144- (void)willSendMessage:(NIMQChatMessage *)message;
145
146
147/**
148 * 上传资源文件成功的回调
149 * @discussion 对于需要上传资源的消息(图片,视频,音频等),SDK 将在上传资源成功后通过这个接口进行回调,上层可以在收到该回调后进行推送信息的重新配置 (APNS payload)
150 * @param urlString 当前消息资源获得的 url 地址
151 * @param message 当前发送的消息
152 */
153- (void)uploadAttachmentSuccess:(NSString *)urlString
154 forMessage:(NIMQChatMessage *)message;
155
156/**
157 * 发送消息进度回调
158 *
159 * @param message 当前发送的消息
160 * @param progress 进度
161 */
162- (void)sendMessage:(NIMQChatMessage *)message
163 progress:(float)progress;
164
165
166/**
167 * 发送消息完成回调
168 *
169 * @param message 当前发送的消息
170 * @param error 失败原因,如果发送成功则error为nil
171 */
172- (void)sendMessage:(NIMQChatMessage *)message
173 didCompleteWithError:(nullable NSError *)error;
174
175/**
176 * 收取消息附件回调
177 * @param message 当前收取的消息
178 * @param progress 进度
179 * @discussion 附件包括:图片,视频的缩略图,语音文件
180 */
181- (void)fetchMessageAttachment:(NIMQChatMessage *)message
182 progress:(float)progress;
183
184
185/**
186 * 收取消息附件完成回调
187 *
188 * @param message 当前收取的消息
189 * @param error 错误返回,如果收取成功,error为nil
190 */
191- (void)fetchMessageAttachment:(NIMQChatMessage *)message
192 didCompleteWithError:(nullable NSError *)error;
193
194/**
195 * 收到消息回调
196 *
197 * @param messages 消息列表,内部为NIMQChatMessage
198 */
199- (void)onRecvMessages:(NSArray<NIMQChatMessage *> *)messages;
200
201/**
202 * 圈组消息更新事件回调
203 *
204 * @param event 事件详情
205 */
206- (void)onMessageUpdate:(NIMQChatUpdateMessageEvent *)event;
207
208/**
209 * 圈组未读信息变更事件回调(频道)
210 *
211 * @param event 事件详情
212 */
213- (void)unreadInfoChanged:(NIMQChatUnreadInfoChangedEvent *)event;
214
215/**
216 * 圈组服务器未读信息变更事件回调
217 *
218 * @param serverUnreadInfoDic 事件详情, key为@(serverId)(服务器ID的NSNumber),value 为NIMQChatServerUnreadInfo
219 */
220- (void)serverUnreadInfoChanged:(NSDictionary <NSNumber *, NIMQChatServerUnreadInfo *> *)serverUnreadInfoDic;
221
222/**
223 * 圈组系统通知接收事件回调
224 *
225 * @param result 结果详情
226 */
227- (void)onRecvSystemNotification:(NIMQChatReceiveSystemNotificationResult *)result;
228
229/**
230 * 圈组类消息typing事件回调
231 *
232 * @param result 结果详情
233 */
234- (void)onRecvTypingEvent:(NIMQChatMessageTypingEvent *)event;
235
236/**
237 * 圈组系统通知更新事件回调
238 *
239 * @param result 结果详情
240 */
241- (void)onSystemNotificationUpdate:(NIMQChatSystemNotificationUpdateResult *)result;
242
243
244
245@end
246
247/**
248 * 圈组消息管理器
249 */
250@protocol NIMQChatMessageManager <NSObject>
251
252/**
253 * 发送消息
254 *
255 * @param message 消息
256 * @param session 接受方
257 * @param error 错误 如果在准备发送消息阶段发生错误,这个error会被填充相应的信息
258 *
259 * @return 是否调用成功,这里返回的 result 只是表示当前这个函数调用是否成功,需要后续的回调才能够判断消息是否已经发送至服务器
260 */
261- (BOOL)sendMessage:(NIMQChatMessage *)message
262 toSession:(NIMSession *)session
263 error:(NSError * __nullable *)error;
264
265/**
266 * 异步发送消息
267 *
268 * @param message 消息
269 * @param session 接收方
270 * @param completion 发送完成后的回调,这里的回调完成只表示当前这个函数调用完成,需要后续的回调才能判断消息是否已经发送至服务器
271 */
272- (void)sendMessage:(NIMQChatMessage *)message
273 toSession:(NIMSession *)session
274 completion:(nullable NIMQChatHandler)completion;
275
276/**
277 * 取消正在发送的消息
278 *
279 * @param message 目标消息
280 * @return 是否调用成功
281 */
282- (BOOL)cancelSendingMessage:(NIMQChatMessage *)message;
283
284/**
285 * 重发消息
286 *
287 * @param message 重发消息
288 * @param error 错误 如果在准备发送消息阶段发生错误,这个error会被填充相应的信息
289 *
290 * @return 是否调用成功,这里返回的 result 只是表示当前这个函数调用是否成功,需要后续的回调才能够判断消息是否已经发送至服务器
291 */
292- (BOOL)resendMessage:(NIMQChatMessage *)message
293 error:(NSError * __nullable *)error;
294
295/**
296 * 生成转发消息
297 * 得到转发消息后,开发者需自己再调用sendForwardMessage:toSession:error: 进行发送, 和 直接调用forwardMessage:toSession:error:效果一样,但是这样可以得到转发消息的进度方法回调和是否转发成功方法回调
298 *
299 * @param message 要转发的消息
300 * @param error 错误 如果在准备发送消息阶段发生错误,这个error会被填充相应的信息
301 *
302 * @return 生成的需要转发的消息
303 */
304- (nullable NIMQChatMessage *)makeForwardMessage:(NIMQChatMessage *)message
305 error:(NSError * __nullable *)error;
306
307/**
308 * 发送生成的转发消息
309 *
310 * @param message 转发的消息
311 * @param session 接受方
312 * @param error 错误 如果在准备发送消息阶段发生错误,这个error会被填充相应的信息
313 *
314 * @return 是否调用成功,这里返回的 result 只是表示当前这个函数调用是否成功,需要后续的回调才能够判断消息是否已经发送至服务器
315 */
316- (BOOL)sendForwardMessage:(NIMQChatMessage *)message
317 toSession:(NIMSession *)session
318 error:(NSError * __nullable *)error;
319
320/**
321 * 转发消息
322 *
323 * @param message 消息
324 * @param session 接收方
325 * @param error 错误 如果在准备发送消息阶段发生错误,这个error会被填充相应的信息
326 *
327 * @return 是否调用成功,这里返回的 result 只是表示当前这个函数调用是否成功,需要后续的回调才能够判断消息是否已经发送至服务器
328 */
329- (BOOL)forwardMessage:(NIMQChatMessage *)message
330 toSession:(NIMSession *)session
331 error:(NSError * __nullable *)error;
332
333/**
334 * 消息是否正在传输 (发送/接受附件)
335 *
336 * @param message 消息
337 *
338 * @return 是否正在传输
339 */
340- (BOOL)messageInTransport:(NIMQChatMessage *)message;
341
342/**
343 * 传输消息的进度 (发送/接受附件)
344 *
345 * @param message 消息
346 *
347 * @return 正在传输的消息进度,如果消息不在传输,则返回0
348 */
349- (float)messageTransportProgress:(NIMQChatMessage *)message;
350
351/**
352 * 收取消息附件
353 *
354 * @param message 需要收取附件的消息
355 * @param error 错误
356 *
357 * @return 是否调用成功
358 * @discussion 附件包括:图片消息的图片缩略图,视频消息的视频缩略图,音频消息的音频文件,文件消息的文件以及自定义消息中的自定义文件
359 */
360- (BOOL)fetchMessageAttachment:(NIMQChatMessage *)message
361 error:(NSError * __nullable *)error;
362
363/**
364 * 取消收取消息附件
365 *
366 * @param message 需要取消收取附件的消息
367 *
368 * @discussion 附件包括:图片消息的图片缩略图,视频消息的视频缩略图,音频消息的音频文件,文件消息的文件以及自定义消息中的自定义文件
369 */
370- (void)cancelFetchingMessageAttachment:(NIMQChatMessage *)message;
371
372/**
373 * 更新圈组消息
374 * @discussion 支持文本,服务器扩展,自定义消息状态
375 *
376 * @param param 传入参数
377 * @param completion 结果回调
378 */
379- (void)updateMessage:(NIMQChatUpdateMessageParam *)param
380 completion:(nullable NIMQChatUpdateMessageHandler)completion;
381
382/**
383 * 撤回圈组消息
384 * @discussion
385 *
386 * @param param 传入参数
387 * @param completion 结果回调
388 */
389- (void)revokeMessage:(NIMQChatRevokeMessageParam *)param
390 completion:(nullable NIMQChatUpdateMessageHandler)completion;
391
392/**
393 * 删除圈组消息
394 * @discussion
395 *
396 * @param param 传入参数
397 * @param completion 结果回调
398 */
399- (void)deleteMessage:(NIMQChatDeleteMessageParam *)param
400 completion:(nullable NIMQChatUpdateMessageHandler)completion;
401
402/**
403 * 标记消息已读
404 *
405 * @param param 传入参数
406 * @param completion 结果回调
407 */
408- (void)markMessageRead:(NIMQChatMarkMessageReadParam *)param
409 completion:(nullable NIMQChatHandler)completion;
410
411/**
412 * 从服务端查询历史消息
413 *
414 * @param param 传入参数
415 * @param completion 结果回调
416 */
417- (void)getMessageHistory:(NIMQChatGetMessageHistoryParam *)param
418 completion:(nullable NIMQChatGetMessageHistoryHandler)completion;
419
420/**
421 * 从服务端按ID查询历史消息
422 *
423 * @param param 传入参数
424 * @param completion 结果回调
425 */
426- (void)getMessageHistoryByIds:(NIMQChatGetMessageHistoryByIdsParam *)param
427 completion:(nullable NIMQChatGetMessageHistoryHandler)completion;
428
429/**
430 * 发送自定义系统通知
431 *
432 * @param param 传入参数
433 * @param completion 结果回调
434 */
435- (void)sendSystemNotification:(NIMQChatSendSystemNotificationParam *)param
436 completion:(nullable NIMQChatSendSystemNotificationHandler)completion;
437
438/**
439 * 重发自定义系统通知
440 *
441 * @param param 传入参数
442 * @param completion 结果回调
443 */
444- (void)resendSystemNotification:(NIMQChatResendSystemNotificationParam *)param
445 completion:(nullable NIMQChatSendSystemNotificationHandler)completion;
446
447/**
448 * 更新系统通知(可以更新状态、也可以更新内容)
449 */
450- (void)updateSystemNotification:(NIMQChatUpdateSystemNotificationParam *)param
451 completion:(nullable NIMQChatUpdateSystemNotificationHandler)completion;
452
453/**
454 * 标记系统通知已读
455 *
456 * @param param 传入参数
457 * @param completion 结果回调
458 */
459- (void)markSystemNotificationsRead:(NIMQChatMarkSystemNotificationsReadParam *)param
460 completion:(nullable NIMQChatHandler)completion;
461
462/**
463 * 发送正在输入等自定义事件
464 *
465 * @param param 传入参数
466 * @param completion 结果回调
467 */
468- (void)sendMessageTypingEvent:(NIMQChatMessageTypingEvent *)param
469 completion:(nullable NIMQChatSendMessageTypingEventHandler)completion;
470
471/**
472 * 从本地缓存查询消息
473 *
474 * @param param 传入参数
475 * @param completion 结果回调
476 */
477- (void)getMessageCache:(NIMQChatGetMessageCacheParam *)param
478 completion:(nullable NIMQChatGetMessageCacheHandler)completion;
479
480/**
481 * 批量查询频道最后一条消息
482 *
483 * @param param 传入参数
484 * @param completion 结果回调
485 */
486- (void)getLastMessageOfChannels:(NIMQChatGetLastMessageOfChannelsParam *)param
487 completion:(nullable NIMQChatGetLastMessageOfChannelsHandler)completion;
488
489/**
490 * 搜索圈组消息
491 *
492 * @param param 传入参数
493 * @param completion 结果回调
494 */
495- (void)searchMsgByPage:(NIMQChatSearchMsgByPageParam *)param
496 completion:(nullable NIMQChatSearchMsgByPageHandler)completion;
497
498/**
499 * 搜索圈组 @ 我的消息
500 *
501 * @param param 传入参数
502 * @param completion 结果回调
503 */
504- (void)getMentionedMeMessages:(NIMQChatGetMentionedMeMessagesParam *)param
505 completion:(nullable NIMQChatGetMentionedMeMessagesHandler)completion;
506
507
508/**
509 * 批量查询消息是否 @ 当前用户
510 *
511 * @param param 传入参数
512 * @param completion 结果回调
513 */
514- (void)areMentionedMeMessages:(NIMQChatAreMentionedMeMessagesParam *)param
515 completion:(nullable NIMQChatAreMentionedMeMessagesHandler)completion;
516
517/**
518 * 清理消息本地缓存
519 */
520- (void)clearMessageCache;
521
522/**
523 * 增加一条缓存数据,如果该频道下已经存在数据,则被新数据覆盖。
524 *
525 * @param serverId 服务器ID,大于0
526 * @param channelId 频道ID,大于0
527 * @param text 要增加的内容,不能是空指针
528 * @return YES:成功添加或者替换;NO:其它
529 */
530- (BOOL)insertOrReplaceTextCache:(unsigned long long)serverId
531 channelId:(unsigned long long)channelId
532 value:(NSString *)value;
533
534/**
535 * 删除缓存数据。
536 * serverId > 0 && channelId > 0:删除指定频道的数据
537 * serverId > 0 && channelId == 0:删除指定服务器下所有频道的数据
538 * serverId == 0 && channelId > 0:删除指定频道ID的数据
539 * serverId == 0 && channelId == 0:清空数据
540 *
541 * @param serverId 服务器ID,大于等于0
542 * @param channelId 频道ID,大于等于0
543 * @return YES:完成删除操作,包括数据存在的删除和数据不存在的删除;NO:其它
544 */
545- (BOOL)deleteTextCache:(unsigned long long)serverId
546 channelId:(unsigned long long)channelId;
547
548/**
549 * 查询指定频道的缓存数据。
550 *
551 * @param serverId
552 * @param channelId
553 * @return
554 */
555- (nullable NSString *)getTextCache:(unsigned long long)serverId
556 channelId:(unsigned long long)channelId;
557
558/**
559 * 添加通知对象
560 *
561 * @param delegate 通知对象
562 */
563- (void)addDelegate:(id<NIMQChatMessageManagerDelegate>)delegate;
564
565/**
566 * 移除通知对象
567 *
568 * @param delegate 通知对象
569 */
570- (void)removeDelegate:(id<NIMQChatMessageManagerDelegate>)delegate;
571
572@end
573
574NS_ASSUME_NONNULL_END
void(^ NIMQChatHandler)(NSError *__nullable error)
Definition: NIMQChatDefs.h:276
void(^ NIMQChatSearchMsgByPageHandler)(NSError *__nullable error, NIMQChatSearchMsgByPageResult *__nullable result)
Definition: NIMQChatMessageManagerProtocol.h:114
void(^ NIMQChatSendSystemNotificationHandler)(NSError *__nullable error, NIMQChatSendSystemNotificationResult *__nullable result)
Definition: NIMQChatMessageManagerProtocol.h:59
void(^ NIMQChatGetMessageCacheHandler)(NSError *__nullable error, NIMQChatGetMessageCacheResult *__nullable result)
Definition: NIMQChatMessageManagerProtocol.h:91
void(^ NIMQChatUpdateSystemNotificationHandler)(NSError *__nullable error, NIMQChatUpdateSystemNotificationResult *__nullable result)
Definition: NIMQChatMessageManagerProtocol.h:83
void(^ NIMQChatGetLastMessageOfChannelsHandler)(NSError *__nullable error, NIMQChatGetLastMessageOfChannelsResult *__nullable result)
Definition: NIMQChatMessageManagerProtocol.h:107
void(^ NIMQChatSendMessageTypingEventHandler)(NSError *__nullable error, NIMQChatMessageTypingEvent *__nullable result)
Definition: NIMQChatMessageManagerProtocol.h:99
void(^ NIMQChatAreMentionedMeMessagesHandler)(NSError *__nullable error, NIMQChatAreMentionedMeMessagesResult *__nullable result)
Definition: NIMQChatMessageManagerProtocol.h:128
void(^ NIMQChatGetMentionedMeMessagesHandler)(NSError *__nullable error, NIMQChatGetMentionedMeMessagesResult *__nullable result)
Definition: NIMQChatMessageManagerProtocol.h:121
void(^ NIMQChatUpdateMessageHandler)(NSError *__nullable error, NIMQChatUpdateMessageResult *__nullable result)
Definition: NIMQChatMessageManagerProtocol.h:75
void(^ NIMQChatGetMessageHistoryHandler)(NSError *__nullable error, NIMQChatGetMessageHistoryResult *__nullable result)
Definition: NIMQChatMessageManagerProtocol.h:67
Definition: NIMQChatAreMentionedMeMessagesParam.h:22
Definition: NIMQChatAreMentionedMeMessagesResult.h:19
Definition: NIMQChatDeleteMessageParam.h:20
Definition: NIMQChatGetLastMessageOfChannelsParam.h:15
Definition: NIMQChatGetLastMessageOfChannelsResult.h:16
Definition: NIMQChatGetMentionedMeMessagesParam.h:20
Definition: NIMQChatGetMentionedMeMessagesResult.h:19
Definition: NIMQChatGetMessageCacheParam.h:17
Definition: NIMQChatGetMessageCacheResult.h:19
Definition: NIMQChatGetMessageHistoryByIdsParam.h:19
Definition: NIMQChatGetMessageHistoryParam.h:17
Definition: NIMQChatGetMessageHistoryResult.h:18
Definition: NIMQChatMarkMessageReadParam.h:17
Definition: NIMQChatMarkServerReadResult.h:19
Definition: NIMQChatMarkSystemNotificationsReadParam.h:27
Definition: NIMQChatMessage.h:76
Definition: NIMQChatMessageServerIdInfo.h:14
Definition: NIMQChatMessageTypingEvent.h:13
Definition: NIMQChatReceiveSystemNotificationResult.h:17
Definition: NIMQChatResendSystemNotificationParam.h:19
Definition: NIMQChatRevokeMessageParam.h:20
Definition: NIMQChatSearchMsgByPageParam.h:20
Definition: NIMQChatSearchMsgByPageResult.h:19
Definition: NIMQChatSendSystemNotificationParam.h:19
Definition: NIMQChatSendSystemNotificationResult.h:19
Definition: NIMQChatServerUnreadInfo.h:13
Definition: NIMQChatSystemNotificationUpdateResult.h:18
Definition: NIMQChatUnreadInfoChangedEvent.h:19
Definition: NIMQChatUpdateMessageEvent.h:19
Definition: NIMQChatUpdateMessageParam.h:21
Definition: NIMQChatUpdateMessageResult.h:19
Definition: NIMQChatUpdateSystemNotificationParam.h:20
Definition: NIMQChatUpdateSystemNotificationResult.h:19
Definition: NIMSession.h:49