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