NIMSDK-iOS
载入中...
搜索中...
未找到
NIMConversationManagerProtocol.h
浏览该文件的文档.
1//
2// NIMConversationManager.h
3// NIMLib
4//
5// Created by Netease.
6// Copyright (c) 2015 Netease. All rights reserved.
7//
8
9#import <Foundation/Foundation.h>
10#import "NIMSession.h"
11
12NS_ASSUME_NONNULL_BEGIN
13
14@class NIMMessage;
15//@class NIMSession;
16@class NIMRecentSession;
37/**
38 * 读取服务器消息记录block
39 *
40 * @param error 错误,如果成功则error为nil
41 * @param messages 读取的消息列表
42 */
43typedef void(^NIMFetchMessageHistoryBlock)(NSError * __nullable error,NSArray<NIMMessage *> * __nullable messages);
44
45/**
46 * 服务器消息检索记录block
47 *
48 * @param error 错误,如果成功则error为nil
49 * @param messages 读取的消息列表
50 */
51typedef void(^NIMRetrieveServerMessagesBlock)(NSError * __nullable error,NSArray<NIMMessage *> * __nullable messages);
52
53/**
54 * 删除本地消息记录block
55 *
56 * @param error 错误,如果成功则error为nil
57 */
58typedef void (^NIMBatchDeleteMessagesBlock)(NSError * __nullable error);
59
60/**
61 * 更新本地消息 Block
62 *
63 * @param error 错误,如果成功则error为nil
64 */
65typedef void(^NIMUpdateMessageBlock)(NSError * __nullable error);
66
67/**
68 * 导入本地最近会话 Block
69 *
70 * @param error 错误,如果成功则error为nil
71 * @param failedImportedRecentSessions 导入失败的最近会话
72 */
73typedef void(^NIMImportRecentSessionsBlock)(NSError * __nullable error, NSArray<NIMImportedRecentSession *> * __nullable failedImportedRecentSessions);
74
75
76/**
77 * 标记远端会话Block
78 *
79 * @param error 错误,如果成功则error为nil
80 */
81typedef void(^NIMRemoveRemoteMessageBlock)(NSError * __nullable error);
82
83/**
84 * 标记远端会话Block
85 *
86 * @param error 错误,如果成功则error为nil
87 */
88typedef void(^NIMRemoveRemoteSessionBlock)(NSError * __nullable error);
89
90
91/**
92 * 清空历史消息block
93 * @param error 错误,如果成功则error为nil
94 */
95typedef void(^NIMSessionDeleteAllRemoteMessagesCompletionBlock)(NSError * _Nullable error);
96
97/**
98 * 批量单向删除消息的回调block
99 */
100typedef void(^NIMDeleteRemoteMessagesCompletionBlock)(NSError * _Nullable error);
101
102/**
103 * 搜索本地消息记录Block
104 *
105 * @param error 错误,如果成功则error为nil
106 * @param messages 读取的消息列表
107 * @discussion 只有在传入参数错误时才会有error产生
108 */
109typedef void(^NIMSearchMessageBlock)(NSError * __nullable error,NSArray<NIMMessage *> * __nullable messages);
110
111/**
112 * 全局搜索本地消息记录Block
113 *
114 * @param error 错误,如果成功则error为nil
115 * @param messages 读取的消息列表
116 */
117typedef void(^NIMGlobalSearchMessageBlock)(NSError * __nullable error,NSDictionary<NIMSession *,NSArray<NIMMessage *> *> * __nullable messages);
118
119/**
120 导出历史消息进度回调
121
122 @param progress 进度 0-100
123 */
124typedef void(^NIMExportMessageProgress)(float progress);
125
126/**
127 导出历史消息完成回调
128
129 @param error 错误,如果成功则为 nil
130 @param resultFilePath 如果成功,则为结果文件路径
131 */
132typedef void(^NIMExportMessageComletion)(NSError * __nullable error, NSString * __nullable resultFilePath);
133
134/**
135 导入历史消息进度回调
136
137 @param progress 进度 0-100
138 */
139typedef void(^NIMImportMessageProgress)(float progress);
140
141/**
142 导入历史消息完成回调
143
144 @param error 错误,如果成功则为 nil
145 */
146typedef void(^NIMImportMessageCompletion)(NSError * __nullable error);
147
148/**
149 更新服务器历史备份文件结果回调
150
151 @param error 错误,如果成功则为 nil
152 */
153typedef void(^NIMUpdateMigrateMessageCompletion)(NSError * __nullable error);
154
155/**
156 获取历史备份文件结果回调
157
158 @param error 错误,如果成功则为 nil
159 @param remoteFilePath 备份文件远端路径
160 @param secureKey 备份文件解密的 key
161 */
162typedef void(^NIMFetchMigrateMessageCompletion)(NSError * __nullable error, NSString * __nullable remoteFilePath, NSString * __nullable secureKey);
163
164
165/**
166 * 读取服务器会话列表block
167 *
168 * @param error 错误,如果成功则error为nil
169 * @param recentSessions 读取的消息列表
170 * @param hasMore 最小时间戳只有请求第一页时会返回这个参数,表示下一次增量同步时带在请求参数里
171 */
172typedef void(^NIMFetchRecentSessionsHistoryBlock)(NSError * __nullable error,
173 NSArray<NIMRecentSession *> * __nullable recentSessions,
174 BOOL hasMore);
175
176/**
177 * 读取服务器会话block
178 *
179 * @param error 错误,如果成功则error为nil
180 * @param recentSession 结果会话
181 */
182typedef void(^NIMFetchRecentSessionHistoryBlock)(NSError * __nullable error,
183 NIMRecentSession * _Nullable recentSession);
184
185/**
186* 更新服务端端会话扩展
187*
188* @param error 错误,如果成功则error为nil
189*/
190typedef void(^NIMRemoteRecentSessionBlock)(NSError * __nullable error);
191
192
193
194/**
195 * 批量更新未完整会话列表
196 *
197 * @param error 错误,如果成功则error为nil
198 * @param faileds 更新失败的会话
199 */
200typedef void(^NIMUpdateIncompleteSessionsBlock)(NSError * __nullable error, NSArray<NIMImportedRecentSession *> * __nullable faileds);
201
202/**
203 * 未完整会话信息
204 *
205 * @param error 错误,如果成功则error为nil
206 * @param result 更新失败的会话
207 */
208typedef void(^NIMIncompleteSessionsBlock)(NSError * __nullable error, NSArray<NIMIncompleteSessionInfo *> * __nullable result);
209
210/**
211 * 批量发送会话已读回调
212 *
213 * @param error 错误,如果成功则error为nil
214 * @param result 发送失败的会话
215 */
216typedef void(^NIMBatchSendACKSessionsBlock)(NSError * __nullable error, NSArray <NIMSession * > * _Nullable sessions);
217
218/**
219 * 发送会话已读回调
220 *
221 * @param error 错误,如果成功则error为nil
222 */
223typedef void(^NIMSendACKSessionsBlock)(NSError * __nullable error);
224
225/**
226 * 动态获取消息的回调
227 *
228 * @param error 错误,如果成功则error为nil
229 * @param isReliable 是否可靠(是否一定符合输入条件的)
230 * @param messages 消息
231 */
232typedef void(^NIMGetMessagesDynamicallyBlock)(NSError * __nullable error, BOOL isReliable, NSArray<NIMMessage *> * __nullable messages);
233/**
234 清空会话消息完成时状态回调
235 */
236typedef NS_ENUM(NSUInteger, NIMClearMessagesStatus)
237{
241};
242
243/**
244 * 会话管理器回调
245 */
246@protocol NIMConversationManagerDelegate <NSObject>
247
248@optional
249
250/**
251* 最近会话数据库读取完成
252*
253* @discussion 所有最近会话读取完成。设置NIMSDKConfig中的asyncLoadRecentSessionEnabled属性为YES时,且本地数目大于1000条时,此回调会执行。
254* 该回调执行表示最近会话全部加载完毕可以通过allRecentSessions来取全部对话。
255*/
256- (void)didLoadAllRecentSessionCompletion;
257
258
259/**
260 * 增加最近会话的回调
261 *
262 * @param recentSession 最近会话
263 * @param totalUnreadCount 目前总未读数
264 * @discussion 当新增一条消息,并且本地不存在该消息所属的会话时,会触发此回调。
265 */
266- (void)didAddRecentSession:(NIMRecentSession *)recentSession
267 totalUnreadCount:(NSInteger)totalUnreadCount;
268
269///**
270// * 增加最近会话的回调
271// *
272// * @param recentSession 最近会话
273// * @param totalUnreadCount 目前总未读数
274// * @discussion 当新增一条消息,并且本地不存在该消息所属的会话时,会触发此回调。
275// */
276//- (void)didAddRecentSession:(NSDictionary <NSNumber *, NIMRecentSession *> *)recentSessions
277// totalUnreadCount:(NSDictionary <NSNumber *, NSNumber *> *)unreadCounts;
278
279/**
280 * 最近会话修改的回调
281 *
282 * @param recentSession 最近会话
283 * @param totalUnreadCount 目前总未读数
284 * @discussion 触发条件包括: 1.当新增一条消息,并且本地存在该消息所属的会话。
285 * 2.所属会话的未读清零。
286 * 3.所属会话的最后一条消息的内容发送变化。(例如成功发送后,修正发送时间为服务器时间)
287 * 4.删除消息,并且删除的消息为当前会话的最后一条消息。
288 */
289- (void)didUpdateRecentSession:(NIMRecentSession *)recentSession
290 totalUnreadCount:(NSInteger)totalUnreadCount;
291///**
292// * 最近会话修改的回调
293// *
294// * @param recentSession 最近会话
295// * @param totalUnreadCount 目前根据sessionType 划分的未读数
296// * @discussion 触发条件包括: 1.当新增一条消息,并且本地存在该消息所属的会话。
297// * 2.所属会话的未读清零。
298// * 3.所属会话的最后一条消息的内容发送变化。(例如成功发送后,修正发送时间为服务器时间)
299// * 4.删除消息,并且删除的消息为当前会话的最后一条消息。
300// */
301//- (void)didUpdateRecentSession:(NSDictionary <NSNumber *, NIMRecentSession *> *)recentSessions
302// unreadCount:(NSDictionary <NSNumber *, NSNumber *> *)unreadCounts;
303
304/**
305 * 删除最近会话的回调
306 *
307 * @param recentSession 最近会话
308 * @param totalUnreadCount 目前总未读数
309 */
310- (void)didRemoveRecentSession:(NIMRecentSession *)recentSession
311 totalUnreadCount:(NSInteger)totalUnreadCount;
312
313/**
314 * 未读数更新的回调 (markRead不会走此回调)
315 *
316 * @param unreadCountDic 各类型未读数的字典: [@(NIMSessionType): @(条数)]
317 */
318- (void)didUpdateUnreadCountDic:(NSDictionary *)unreadCountDic;
319
320/**
321 * 单个会话里所有消息被删除的回调
322 *
323 * @param session 消息所属会话
324 */
325- (void)messagesDeletedInSession:(NIMSession *)session;
326
327/**
328 * 所有消息被删除的回调
329 */
330- (void)allMessagesDeleted;
331
332/**
333 * 单个会话所有消息在本地和服务端都被清空
334 * @param session 消息所属会话
335 */
336- (void)allMessagesClearedInSession:(NIMSession *)session step:(NIMClearMessagesStatus)step;
337
338/**
339 * 所有消息已读的回调
340 */
341- (void)allMessagesRead;
342
343/**
344 * 消息已读的回调
345 *
346 * @param type 消息所属会话类型
347 */
348- (void)messagesReadOfType:(NIMSessionType)type;
349
350/**
351 * 会话服务,会话更新
352 *
353 * @param recentSession 最近会话
354 */
355- (void)didServerSessionUpdated:(nullable NIMRecentSession *)recentSession;
356
357/**
358 * 消息单向删除通知
359 * @deprecated 请使用 - onRecvMessagesDeleted: exts:
360 *
361 * @param message 被删除消息
362 * @param ext 扩展消息
363 */
364- (void)onRecvMessageDeleted:(NIMMessage *)message ext:(nullable NSString *)ext __attribute__((deprecated("请使用 - onRecvMessagesDeleted: exts:")));
365
366/**
367 * 消息单向删除通知
368 *
369 * @param message 被删除消息
370 * @param exts 删除时的扩展字段字典,key: messageId,value: ext
371 */
372- (void)onRecvMessagesDeleted:(NSArray<NIMMessage *> *)messages exts:(nullable NSDictionary<NSString *, NSString *> *)exts;
373
374/**
375 * 未漫游完整会话列表回调
376 * @param infos 未漫游完整的会话信息
377 */
378- (void)onRecvIncompleteSessionInfos:(nullable NSArray<NIMIncompleteSessionInfo *> *)infos;
379
380/**
381 * 标记已读回调
382 * @param session session
383 * @param error 失败原因
384 */
385- (void)onMarkMessageReadCompleteInSession:(NIMSession *)session error:(nullable NSError *)error;
386
387/**
388 * 批量标记已读的回调
389 * @param session session
390*/
391- (void)onBatchMarkMessagesReadInSessions:(NSArray<NIMSession *> *)sessions;
392
393/**
394 * 远端消息清空的通知
395 * @param info 清空会话的信息
396 */
397- (void)onRecvAllRemoteMessagesInSessionDeleted:(NIMSessionDeleteAllRemoteMessagesInfo *)info;
398
399@end
400
401/**
402 导出历史消息过程 delegate,可用于处理自定义消息
403 */
404@protocol NIMExportMessageDelegate <NSObject>
405
406@optional
407
408/**
409 是否导出消息,YES - 导出,NO -不导出
410
411 @param message 消息体
412 @return YES / NO
413 */
414- (BOOL)shouldExportMessage:(NIMMessage *)message;
415
416/**
417 消息导出前的通知回调
418
419 @param message 将导出的消息
420 */
421- (void)onMessageWillExport:(NIMMessage *)message;
422
423@end
424
425/**
426 导入历史消息过程 delegate,可用于处理自定义消息
427 */
428@protocol NIMImportMessageDelegate <NSObject>
429
430@optional
431
432/**
433 是否导入消息,YES - 导入,NO -不导入
434
435 @param message 消息体
436 @return YES / NO
437 */
438- (BOOL)shouldImportMessage:(NIMMessage *)message;
439
440/**
441 消息导入前的通知回调
442
443 @param message 消息体
444 */
445- (void)onMessageWillImport:(NIMMessage *)message;
446
447@end
448
449/**
450 * 会话管理器
451 */
452@protocol NIMConversationManager <NSObject>
453
454/**
455 * 删除某条消息
456 *
457 * @param message 待删除的聊天消息
458 */
459- (void)deleteMessage:(NIMMessage *)message;
460
461/**
462* 删除某条消息
463*
464* @param message 待删除的聊天消息
465* @param option 删除消息选项
466*/
467- (void)deleteMessage:(NIMMessage *)message
468 option:(nullable NIMDeleteMessageOption *)option;
469
470/**
471 * 删除本地某条消息,同时删除服务端历史、漫游
472 *
473 * @param message 待删除的聊天消息
474 * @param ext 扩展字段
475 * @param block 完成回调
476 */
477- (void)deleteMessageFromServer:(NIMMessage *)message
478 ext:(nullable NSString *)ext
479 completion:(nullable NIMRemoveRemoteMessageBlock)block;
480
481/**
482 * 删除某个会话的所有消息
483 *
484 * @param session 待删除会话
485 * @param option 删除消息选项
486 */
487- (void)deleteAllmessagesInSession:(NIMSession *)session
488 option:(nullable NIMDeleteMessagesOption *)option;
489
490/**
491 * 删除所有会话消息
492 *
493 * @param option 删除消息选项
494 * @discussion 调用这个接口只会触发allMessagesDeleted这个回调,其他针对单个recentSession的回调都不会被调用
495 */
496- (void)deleteAllMessages:(nullable NIMDeleteMessagesOption *)option;
497
498
499/**
500 * 删除指定范围内的消息,如指定时间范围
501 *
502 * @param session 目标会话
503 * @param option 删除消息选项
504 * @param block 完成回调
505 */
506- (void)deleteMessagesInSession:(NIMSession *)session
507 option:(nullable NIMBatchDeleteMessagesOption *)option
508 completion:(nullable NIMBatchDeleteMessagesBlock)block;
509
510/**
511 * 删除某个会话的所有本地和云端的历史消息。删除后,查询云端消息历史的接口将不能返回这些消息。
512 *
513 * @param session 目标会话
514 * @param options 清空消息历史的可选项
515 * @param block 清空完成后的回调
516 */
517- (void)deleteAllRemoteMessagesInSession:(NIMSession *)session
520
521/**
522 * 批量删除消息,同时删除服务端和本地。所有传入的消息必需属于同一个会话。
523 *
524 * @param messages 消息数组
525 * @param exts key为消息id,value为删除该消息所对应的扩展信息
526 * @param completion 删除完成的回调
527 */
528- (void)deleteRemoteMessages:(NSArray<NIMMessage *> *)messages
529 exts:(nullable NSDictionary<NSString *,NSString *> *)exts
530 completion:(nullable NIMDeleteRemoteMessagesCompletionBlock)completion;
531
532/**
533 * 增加某个最近会话
534 *
535 * @param session 待增加的最近会话
536 * @discussion 异步方法
537 */
538- (void)addEmptyRecentSessionBySession:(NIMSession *)session;
539
540/**
541 * 增加某个最近会话
542 *
543 * @param session 待增加的最近会话
544 * @param option 配置项
545 * @discussion 异步方法
546 */
547- (void)addEmptyRecentSessionBySession:(NIMSession *)session
549
550/**
551 * 删除某个最近会话
552 *
553 * @param recentSession 待删除的最近会话
554 * @discussion 异步方法,删除最近会话,但保留会话内消息
555 */
556- (void)deleteRecentSession:(NIMRecentSession *)recentSession;
557
558/**
559* 删除某个最近会话
560*
561* @param recentSession 待删除的最近会话
562* @param option 是否删除漫游选项,isDeleteRoamMessage默认为NO
563* @param completion 结果回调
564* @discussion 异步方法,删除最近会话,但保留会话内消息
565*/
566- (void)deleteRecentSession:(NIMRecentSession *)recentSession option:(NIMDeleteRecentSessionOption *)option completion:(NIMRemoveRemoteSessionBlock)completion;
567
568/**
569 * 设置所有会话消息为已读
570 *
571 * @discussion 异步方法,消息会标记为设置的状态。不会触发单条 recentSession 更新的回调,但会触发回调 - (void)allMessagesRead
572 */
573- (void)markAllMessagesRead;
574
575/**
576 * 设置会话消息为已读
577 *
578 * @param type 会话类型
579 * @discussion 异步方法,消息会标记为设置的状态。不会触发单条 recentSession 更新的回调,但会触发回调 - (void)messagesReadOfType:
580 */
581- (void)markMessagesReadOfType:(NIMSessionType)type;
582
583/**
584 * 批量设置多个会话消息已读
585 *
586 * @discussion 异步方法。不会触发单条 recentSession 更新的回调,但会触发回调 - onBatchMarkMessagesReadInSessions:
587*/
588- (void)batchMarkMessagesReadInSessions:(NSArray<NIMSession *> *)sessions;
589
590/**
591 * 批量设置多个会话消息已读
592 *
593 * @param completion 结果回调。部分成功时,可以从NIMBatchSendACKSessionsBlock的sessions参数得到失败的会话
594 * @discussion 异步方法。不会触发单条 recentSession 更新的回调,但会触发回调 - onBatchMarkMessagesReadInSessions:
595*/
596- (void)batchMarkMessagesReadInSessions:(NSArray<NIMSession *> *)sessions completion:(NIMBatchSendACKSessionsBlock)completion;
597
598/**
599 * 设置一个会话里所有消息置为已读
600 *
601 * @param session 需设置的会话
602 * @discussion 异步方法,消息会标记为设置的状态
603 */
604- (void)markAllMessagesReadInSession:(NIMSession *)session;
605
606/**
607 * 设置一个会话里所有消息置为已读
608 *
609 * @param session 需设置的会话
610 * @param session 结果回调
611 * @discussion 异步方法,消息会标记为设置的状态
612 */
613- (void)markAllMessagesReadInSession:(NIMSession *)session completion:(NIMSendACKSessionsBlock)completion;
614
615
616
617/**
618 * 更新本地已存的消息记录
619 *
620 * @param message 需要更新的消息
621 * @param session 需要更新的会话
622 * @param completion 完成后的回调
623 * @discussion 为了保证存储消息的完整性,提供给上层调用的消息更新接口只允许更新如下字段:所有消息的本地拓展字段(LocalExt)和自定义消息的消息对象(messageObject)
624 */
625- (void)updateMessage:(NIMMessage *)message
626 forSession:(NIMSession *)session
627 completion:(nullable NIMUpdateMessageBlock)completion;
628
629
630/**
631 * 写入消息
632 *
633 * @param message 需要更新的消息
634 * @param session 需要更新的会话
635 * @param completion 完成后的回调
636 * @discussion 当保存消息成功之后,会收到 NIMChatManagerDelegate 中的 onRecvMessages: 回调。不允许插入已存在的消息
637 */
638- (void)saveMessage:(NIMMessage *)message
639 forSession:(NIMSession *)session
640 completion:(nullable NIMUpdateMessageBlock)completion;
641
642
643
644/**
645 * 导入最近会话
646 *
647 * @param importedRecentSession 待导入的会话集合
648 * @param completion 完成后的回调
649 * @discussion 当导入最近会话成功之后,不会收到 NIMChatManagerDelegate 中的 recentSession 变化的回调,请直接在 completion 中做处理。不允许插入已经存在的最近会话。
650 */
651- (void)importRecentSessions:(NSArray<NIMImportedRecentSession *> *)importedRecentSession
652 completion:(nullable NIMImportRecentSessionsBlock)completion;
653
654
655/**
656 * 从本地db读取一个会话里某条消息之前的若干条的消息
657 *
658 * @param session 消息所属的会话
659 * @param message 当前最早的消息,没有则传入nil
660 * @param limit 个数限制
661 *
662 * @return 消息列表,按时间从小到大排列
663 */
664- (nullable NSArray<NIMMessage *> *)messagesInSession:(NIMSession *)session
665 message:(nullable NIMMessage *)message
666 limit:(NSInteger)limit;
667
668/**
669 * 从本地db读取一个会话里某条消息之前的若干条的消息
670 *
671 * @param session 消息所属的会话
672 * @param message 当前最早的消息,没有则传入nil
673 * @param limit 个数限制
674 * @param completion 完成后的回调
675 */
676- (void)messagesInSession:(NIMSession *)session
677 message:(nullable NIMMessage *)message
678 limit:(NSInteger)limit
679 completion:(NIMFetchMessageHistoryBlock)completion;
680
681/**
682 * 动态途径获取消息,默认回调错误码403,动态能力需要开通功能,并在同步完成后生效
683 *
684 * @param param
685 * @param completion 完成后的回调
686 */
687- (void)getMessagesDynamically:(nonnull NIMGetMessagesDynamicallyParam *)param
688 completion:(NIMGetMessagesDynamicallyBlock)completion;
689
690/**
691 * 根据消息Id获取消息
692 *
693 * @param session 消息所属会话结合
694 *
695 * @param messageIds 消息Id集合
696 *
697 * @return 消息列表,按时间从小到大排列
698 */
699- (nullable NSArray<NIMMessage *> *)messagesInSession:(NIMSession *)session
700 messageIds:(NSArray<NSString *> *)messageIds;
701
702/**
703 * 获取所有未读数
704 * @discussion 只能在主线程调用,包括忽略提醒的会话
705 * @return 未读数
706 */
707- (NSInteger)allUnreadCount;
708
709/**
710 * 按 SessionType 获取未读数
711 * @discussion 只能在主线程调用,包括忽略提醒的会话
712 * @param type 会话类型
713 * @return 未读数
714 */
715- (NSInteger)unreadCountOfType:(NIMSessionType)type;
716
717/**
718 * 获取所有需要通知/不需要通知的最近会话未读数
719 * @param notify 是否需要通知
720 * @return 未读数
721 * @discussion 群只有 notify state != NIMTeamNotifyStateNone 才算是不允许通知
722 */
723- (NSInteger)allUnreadCount:(BOOL)notify;
724
725
726- (NSArray *)allUnreadMessagesInSession: (NIMSession *)session;
727
728- (void)allUnreadMessagesInSession: (NIMSession *)session completion:(NIMFetchMessageHistoryBlock)completion;
729
730/**
731 * 获取所有最近会话。
732 * @return 最近会话列表
733 * @discussion SDK 以 map 的形式保存 sessions,调用这个方法时将进行排序,数据量较大 (上万) 时会比较耗时。
734 * 该方法默认是同步查询所有sessions,当数据量较大(上万)会比较耗时,可能会卡主线程,这种情况下
735 * 用户可以配置NIMSDKConfig中的asyncLoadRecentSessionEnabled属性为YES,此时该接口可以先返回
736 * 100条最近会话,等全部加载完会回调didLoadAllRecentSessionCompletion,此后再调用该接口可以全量返回
737 * 所有会话,用户需要在didLoadAllRecentSessionCompletion回调中及时更新UI展示。
738 */
739- (nullable NSArray<NIMRecentSession *> *)allRecentSessions;
740
741/**
742 * 获取所有最近会话
743 * @return 最近会话列表
744 * @discussion SDK 以 map 的形式保存 sessions,调用这个方法时将进行排序,数据量较大 (上万) 时会比较耗时。
745 * 通过该接口获取的最近会话列表与allRecentSessions接口不同,是基于allRecentSessions接口筛选类型之后重新生成的新对象
746 * 需要用户自行在外部管理,所有回调不回回调该接口查询的任何会话
747 */
748- (nullable NSArray<NIMRecentSession *> *)allRecentSessionsWithOption:(NIMRecentSessionOption *)option;
749
750/**
751 * 根据当前 session 返回对应的最近会话信息
752 *
753 * @param session 会话
754 *
755 * @return 最近会话信息,如果找不到则返回 nil
756 */
757- (nullable NIMRecentSession *)recentSessionBySession:(NIMSession *)session;
758
759
760/**
761* 从服务端分页获取历史会话列表
762*
763* @param option 分页查询选项,可为空,空时默认全量获取
764*
765* @param completion 完成回调
766*/
767- (void)fetchServerSessions:(nullable NIMFetchServerSessionOption *)option
768 completion:(nullable NIMFetchRecentSessionsHistoryBlock)completion;
769
770
771/**
772 * 从服务端获取会话信息
773 *
774 * @param session 目标会话
775 *
776 * @param completion 完成回调
777 */
778- (void)fetchServerSessionBySession:(NIMSession *)session
779 completion:(nullable NIMFetchRecentSessionHistoryBlock)completion;
780
781
782/**
783* 更新服务端获取会话扩展信息
784*
785* @param ext 扩展信息
786*
787* @param session 目标最近会话
788*
789* @param completion 完成回调
790*/
791- (void)updateServerSessionExt:(NSString *)ext
792 session:(NIMSession *)session
793 completion:(nullable NIMRemoteRecentSessionBlock)completion;
794
795/**
796* 删除服务端
797*
798* @param sessions 目标会话
799*
800* @param completion 完成回调
801*/
802- (void)deleteServerSessions:(NSArray<NIMSession *> *)sessions
803 completion:(nullable NIMRemoteRecentSessionBlock)completion;
804
805
806/**
807 * 从服务器上获取一个会话里某条消息之前的若干条的消息
808 *
809 * @param session 消息所属的会话
810 * @param option 搜索选项
811 * @param result 读取的消息列表结果
812 * @discussion 此接口不支持查询聊天室消息,聊天室请参考 NIMChatroomManagerProtocol 中的查询消息接口。
813 *
814 */
815- (void)fetchMessageHistory:(NIMSession *)session
816 option:(NIMHistoryMessageSearchOption *)option
817 result:(nullable NIMFetchMessageHistoryBlock)result;
818
819
820
821
822/**
823 * 根据关键字从服务器上检索消息
824 *
825 * @param session 消息所属的会话
826 * @param option 检索选项
827 * @param result 读取的消息列表结果
828 * @discussion 检索消息内容,大小写不敏感;此接口不支持查询聊天室消息,聊天室请参考 NIMChatroomManagerProtocol 中的消息接口。
829 *
830 */
831- (void)retrieveServerMessages:(NIMSession *)session
832 option:(NIMMessageServerRetrieveOption *)option
833 result:(nullable NIMRetrieveServerMessagesBlock)result;
834
835
836
837
838/**
839 * 根据关键字从服务器上全量检索消息
840 *
841 * @param option 检索选项
842 * @param result 读取的消息列表结果
843 * @discussion 检索消息内容,此接口仅支持查询P2P和群聊消息,不支持聊天室和超大群
844 *
845 */
846- (void)retrieveServerMessages:(NIMMessageFullKeywordSearchOption *)option
847 result:(nullable NIMRetrieveServerMessagesBlock)result;
848
849/**
850 * 云端历史消息全文检索(按时间排序,不按会话分组)
851 *
852 * @param option 检索选项,其中sessionLimit为无效变量
853 * @param result 读取的消息列表结果
854 * @discussion 检索消息内容
855 */
856- (void)retrieveServerMessagesOrderByTime:(NIMMessageFullKeywordSearchOrderByTimeOption *)option
857 result:(nullable NIMRetrieveServerMessagesBlock)result;
858
859/**
860 * 搜索本地会话内消息
861 *
862 * @param session 消息所属的会话
863 * @param option 搜索选项
864 * @param result 读取的消息列表结果
865 *
866 */
867- (void)searchMessages:(NIMSession *)session
868 option:(NIMMessageSearchOption *)option
869 result:(nullable NIMSearchMessageBlock)result;
870
871/**
872 * 全局搜索本地消息
873 *
874 * @param option 搜索选项
875 * @param result 读取的消息内容
876 */
877- (void)searchAllMessages:(NIMMessageSearchOption *)option
878 result:(nullable NIMGlobalSearchMessageBlock)result;
879
880
881
882/**
883 * 删除服务器端最近会话
884 *
885 * @param sessions 需要删除的会话列表,内部只能是NIMSession
886 * @param completion 完成的回调
887 * @discussion 调用这个接口成功后,当前会话之前的消息都不会漫游到其他端
888 */
889- (void)deleteRemoteSessions:(NSArray<NIMSession *> *)sessions
890 completion:(nullable NIMRemoveRemoteSessionBlock)completion;
891
892/**
893 * 清空点对点会话对应服务端的消息
894 *
895 * @param session 目标会话列表
896 * @param option 清空消息选项
897 * @param completion 完成回调
898 * @discussion 只支持点对点,清空本用户的服务端消息,不影响对方;如果不设置清空选项,服务端默认会同时清空漫游消息;
899 */
900- (void)deleteSelfRemoteSession:(NIMSession *)session
901 option:(nullable NIMClearMessagesOption *)option
902 completion:(nullable NIMRemoveRemoteSessionBlock)completion;
903
904/**
905 * 更新最近会话的本地扩展
906 *
907 * @param ext 扩展信息
908 * @param recentSession 要更新的最近会话
909 * @discussion 此扩展不会漫游到其他端,上层需要保证 NSDictionary 可以转换为 JSON。
910 */
911- (void)updateRecentLocalExt:(nullable NSDictionary *)ext
912 recentSession:(NIMRecentSession *)recentSession;
913
914
915/**
916 导出历史消息到本地文件
917
918 @param delegate 自定义消息的处理 delegate
919 @param progress 导出进度更新回调
920 @param completion 导出完成回调
921 */
922- (void)exportMeessageInfosWithDelegate:(id<NIMExportMessageDelegate>)delegate
923 progress:(NIMExportMessageProgress)progress
924 completion:(NIMExportMessageComletion)completion;
925
926
927/**
928 导入历史消息
929
930 @param infoFilePath 已解码并序列化了的本地历史消息文件路径
931 @param delegate 自定义消息的处理 delegate
932 @param progress 导入进度更新回调
933 @param completion 导入完成回调
934 */
935- (void)importMessageInfosAtPath:(NSString *)infoFilePath
936 delegate:(id<NIMImportMessageDelegate>)delegate
937 progress:(NIMImportMessageProgress)progress
938 completion:(NIMImportMessageCompletion)completion;
939
940
941/**
942 取消 导出/导入 历史消息操作
943 */
944- (void)cancelMigrateMessages;
945
946
947/**
948 更新历史消息备份信息
949
950 @param URL 历史消息备份的 URL
951 @param key 历史消息备份的加密 key
952 @param completion 更新信息的完成回调
953 */
954- (void)updateMigrateMessageInfoWithURL:(NSString *)URL key:(NSString *)key completion:(NIMUpdateMigrateMessageCompletion)completion;
955
956
957/**
958 获取历史消息备份信息
959
960 @param completion 获取历史消息备份的完成回调
961 */
962- (void)fetchMigrateMessageInfo:(NIMFetchMigrateMessageCompletion)completion;
963
964/**
965 反序列化消息数据
966
967 @param encodeData 序列化的数据
968 @return 消息对象
969 @discussion 此接口用于反序列化消息的数据,请与encodeMessageToData配套使用,用于实现消息本地序列化
970*/
971- (NIMMessage *)decodeMessageFromData:(NSData *)encodeData;
972
973/**
974 序列化消息
975
976 @param message 消息对象
977 @return 序列化数据
978 @discussion 此接口用于序列化消息,请与decodeMessageFromData配套使用,用于实现消息本地序列化
979*/
980- (NSData *)encodeMessageToData:(NIMMessage *)message;
981
982
983#pragma mark - 漫游消息未完整会话接口
984
985/**
986 查询漫游消息未完整会话信息
987
988 @param session 目标会话
989 @param completion 结果完成回调
990*/
991- (void)incompleteSessionInfoBySession:(NIMSession *)session
992 completion:(nullable NIMIncompleteSessionsBlock)completion;
993/**
994 查询所有漫游消息未漫游完整会话信息
995
996 @param completion 结果完成回调
997*/
998- (void)allIncompleteSessionInfos:(NIMIncompleteSessionsBlock)completion;
999
1000/**
1001 更新未漫游完整会话列表
1002
1003 @param messages 消息对象,使用NIMMessage的会话、severId、timestamp、from等去更新b
1004 @param completion 结果完成回调
1005*/
1006- (void)updateIncompleteSessions:(NSArray<NIMMessage *> *)messages
1007 completion:(nullable NIMUpdateIncompleteSessionsBlock)completion;
1008
1009/**
1010 根据会话移除未漫游完整会话信息
1011
1012 @param session 目标会话
1013 */
1014- (void)removeIncompleteSessionInfoBySession:(NIMSession *)session;
1015
1016/**
1017 移除所有未完整会话信息
1018 */
1019- (void)removeAllIncompleteSessionInfos;
1020
1021
1022/**
1023 * 添加通知对象
1024 *
1025 * @param delegate 通知对象
1026 */
1027- (void)addDelegate:(id<NIMConversationManagerDelegate>)delegate;
1028
1029/**
1030 * 删除通知对象
1031 *
1032 * @param delegate 通知对象
1033 */
1034- (void)removeDelegate:(id<NIMConversationManagerDelegate>)delegate;
1035
1036@end
1037
1038NS_ASSUME_NONNULL_END
1039
1040
1041
void(^ NIMRemoteRecentSessionBlock)(NSError *__nullable error)
Definition: NIMConversationManagerProtocol.h:190
NIMClearMessagesStatus
Definition: NIMConversationManagerProtocol.h:237
@ NIMClearMessagesStatusServerFailed
Definition: NIMConversationManagerProtocol.h:240
@ NIMClearMessagesStatusServerCleared
Definition: NIMConversationManagerProtocol.h:239
@ NIMClearMessagesStatusLocalCleared
Definition: NIMConversationManagerProtocol.h:238
void(^ NIMUpdateMigrateMessageCompletion)(NSError *__nullable error)
Definition: NIMConversationManagerProtocol.h:153
void(^ NIMRetrieveServerMessagesBlock)(NSError *__nullable error, NSArray< NIMMessage * > *__nullable messages)
Definition: NIMConversationManagerProtocol.h:51
void(^ NIMSendACKSessionsBlock)(NSError *__nullable error)
Definition: NIMConversationManagerProtocol.h:223
void(^ NIMImportRecentSessionsBlock)(NSError *__nullable error, NSArray< NIMImportedRecentSession * > *__nullable failedImportedRecentSessions)
Definition: NIMConversationManagerProtocol.h:73
void(^ NIMSessionDeleteAllRemoteMessagesCompletionBlock)(NSError *_Nullable error)
Definition: NIMConversationManagerProtocol.h:95
void(^ NIMIncompleteSessionsBlock)(NSError *__nullable error, NSArray< NIMIncompleteSessionInfo * > *__nullable result)
Definition: NIMConversationManagerProtocol.h:208
void(^ NIMImportMessageCompletion)(NSError *__nullable error)
Definition: NIMConversationManagerProtocol.h:146
void(^ NIMGetMessagesDynamicallyBlock)(NSError *__nullable error, BOOL isReliable, NSArray< NIMMessage * > *__nullable messages)
Definition: NIMConversationManagerProtocol.h:232
void(^ NIMDeleteRemoteMessagesCompletionBlock)(NSError *_Nullable error)
Definition: NIMConversationManagerProtocol.h:100
void(^ NIMUpdateMessageBlock)(NSError *__nullable error)
Definition: NIMConversationManagerProtocol.h:65
void(^ NIMRemoveRemoteMessageBlock)(NSError *__nullable error)
Definition: NIMConversationManagerProtocol.h:81
void(^ NIMBatchSendACKSessionsBlock)(NSError *__nullable error, NSArray< NIMSession * > *_Nullable sessions)
Definition: NIMConversationManagerProtocol.h:216
void(^ NIMUpdateIncompleteSessionsBlock)(NSError *__nullable error, NSArray< NIMImportedRecentSession * > *__nullable faileds)
Definition: NIMConversationManagerProtocol.h:200
void(^ NIMRemoveRemoteSessionBlock)(NSError *__nullable error)
Definition: NIMConversationManagerProtocol.h:88
void(^ NIMFetchMigrateMessageCompletion)(NSError *__nullable error, NSString *__nullable remoteFilePath, NSString *__nullable secureKey)
Definition: NIMConversationManagerProtocol.h:162
void(^ NIMFetchRecentSessionHistoryBlock)(NSError *__nullable error, NIMRecentSession *_Nullable recentSession)
Definition: NIMConversationManagerProtocol.h:182
void(^ NIMImportMessageProgress)(float progress)
Definition: NIMConversationManagerProtocol.h:139
void(^ NIMExportMessageComletion)(NSError *__nullable error, NSString *__nullable resultFilePath)
Definition: NIMConversationManagerProtocol.h:132
void(^ NIMBatchDeleteMessagesBlock)(NSError *__nullable error)
Definition: NIMConversationManagerProtocol.h:58
void(^ NIMGlobalSearchMessageBlock)(NSError *__nullable error, NSDictionary< NIMSession *, NSArray< NIMMessage * > * > *__nullable messages)
Definition: NIMConversationManagerProtocol.h:117
void(^ NIMExportMessageProgress)(float progress)
Definition: NIMConversationManagerProtocol.h:124
void(^ NIMSearchMessageBlock)(NSError *__nullable error, NSArray< NIMMessage * > *__nullable messages)
Definition: NIMConversationManagerProtocol.h:109
void(^ NIMFetchMessageHistoryBlock)(NSError *__nullable error, NSArray< NIMMessage * > *__nullable messages)
Definition: NIMConversationManagerProtocol.h:43
void(^ NIMFetchRecentSessionsHistoryBlock)(NSError *__nullable error, NSArray< NIMRecentSession * > *__nullable recentSessions, BOOL hasMore)
Definition: NIMConversationManagerProtocol.h:172
NIMSessionType
Definition: NIMSession.h:17
Definition: NIMAddEmptyRecentSessionBySessionOption.h:11
Definition: NIMBatchDeleteMessagesOption.h:17
Definition: NIMClearMessagesOption.h:17
Definition: NIMDeleteMessageOption.h:14
Definition: NIMDeleteMessagesOption.h:17
Definition: NIMDeleteRecentSessionOption.h:14
Definition: NIMRecentSession.h:102
Definition: NIMMessageSearchOption.h:367
Definition: NIMMessageSearchOption.h:111
Definition: NIMImportedRecentSession.h:19
Definition: NIMIncompleteSessionInfo.h:17
Definition: NIMMessageSearchOption.h:230
Definition: NIMMessageSearchOption.h:304
Definition: NIMMessage.h:90
Definition: NIMMessageReceipt.h:21
Definition: NIMMessageSearchOption.h:46
Definition: NIMMessageSearchOption.h:193
Definition: NIMRecentSession.h:37
Definition: NIMRecentSession.h:88
Definition: NIMSessionDeleteAllRemoteMessagesInfo.h:16
Definition: NIMSessionDeleteAllRemoteMessagesOptions.h:14
Definition: NIMSession.h:49
Definition: NIMTeamMessageReceiptDetail.h:19