NIMConversationManagerProtocol.h
10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
//
// NIMConversationManager.h
// NIMLib
//
// Created by Netease.
// Copyright (c) 2015 Netease. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class NIMMessage;
@class NIMSession;
@class NIMRecentSession;
@class NIMHistoryMessageSearchOption;
@class NIMMessageSearchOption;
@class NIMDeleteMessagesOption;
@class NIMImportedRecentSession;
/**
* 读取服务器消息记录block
*
* @param error 错误,如果成功则error为nil
* @param messages 读取的消息列表
*/
typedef void(^NIMFetchMessageHistoryBlock)(NSError * __nullable error,NSArray<NIMMessage *> * __nullable messages);
/**
* 更新本地消息 Block
*
* @param error 错误,如果成功则error为nil
*/
typedef void(^NIMUpdateMessageBlock)(NSError * __nullable error);
/**
* 导入本地最近会话 Block
*
* @param error 错误,如果成功则error为nil
* @param failedImportedRecentSessions 导入失败的最近会话
*/
typedef void(^NIMImportRecentSessionsBlock)(NSError * __nullable error, NSArray<NIMImportedRecentSession *> * __nullable failedImportedRecentSessions);
/**
* 标记远端会话Block
*
* @param error 错误,如果成功则error为nil
*/
typedef void(^NIMRemoveRemoteSessionBlock)(NSError * __nullable error);
/**
* 搜索本地消息记录Block
*
* @param error 错误,如果成功则error为nil
* @param messages 读取的消息列表
* @discussion 只有在传入参数错误时才会有error产生
*/
typedef void(^NIMSearchMessageBlock)(NSError * __nullable error,NSArray<NIMMessage *> * __nullable messages);
/**
* 全局搜索本地消息记录Block
*
* @param error 错误,如果成功则error为nil
* @param messages 读取的消息列表
*/
typedef void(^NIMGlobalSearchMessageBlock)(NSError * __nullable error,NSDictionary<NIMSession *,NSArray<NIMMessage *> *> * __nullable messages);
/**
* 会话管理器回调
*/
@protocol NIMConversationManagerDelegate <NSObject>
@optional
/**
* 增加最近会话的回调
*
* @param recentSession 最近会话
* @param totalUnreadCount 目前总未读数
* @discussion 当新增一条消息,并且本地不存在该消息所属的会话时,会触发此回调。
*/
- (void)didAddRecentSession:(NIMRecentSession *)recentSession
totalUnreadCount:(NSInteger)totalUnreadCount;
/**
* 最近会话修改的回调
*
* @param recentSession 最近会话
* @param totalUnreadCount 目前总未读数
* @discussion 触发条件包括: 1.当新增一条消息,并且本地存在该消息所属的会话。
* 2.所属会话的未读清零。
* 3.所属会话的最后一条消息的内容发送变化。(例如成功发送后,修正发送时间为服务器时间)
* 4.删除消息,并且删除的消息为当前会话的最后一条消息。
*/
- (void)didUpdateRecentSession:(NIMRecentSession *)recentSession
totalUnreadCount:(NSInteger)totalUnreadCount;
/**
* 删除最近会话的回调
*
* @param recentSession 最近会话
* @param totalUnreadCount 目前总未读数
*/
- (void)didRemoveRecentSession:(NIMRecentSession *)recentSession
totalUnreadCount:(NSInteger)totalUnreadCount;
/**
* 单个会话里所有消息被删除的回调
*
* @param session 消息所属会话
*/
- (void)messagesDeletedInSession:(NIMSession *)session;
/**
* 所有消息被删除的回调
*/
- (void)allMessagesDeleted;
/**
* 所有消息已读的回调
*/
- (void)allMessagesRead;
@end
/**
* 会话管理器
*/
@protocol NIMConversationManager <NSObject>
/**
* 删除某条消息
*
* @param message 待删除的聊天消息
*/
- (void)deleteMessage:(NIMMessage *)message;
/**
* 删除某个会话的所有消息
*
* @param session 待删除会话
* @param option 删除消息选项
*/
- (void)deleteAllmessagesInSession:(NIMSession *)session
option:(nullable NIMDeleteMessagesOption *)option;
/**
* 删除所有会话消息
*
* @param option 删除消息选项
* @discussion 调用这个接口只会触发allMessagesDeleted这个回调,其他针对单个recentSession的回调都不会被调用
*/
- (void)deleteAllMessages:(nullable NIMDeleteMessagesOption *)option;
/**
* 删除某个最近会话
*
* @param recentSession 待删除的最近会话
* @discussion 异步方法,删除最近会话,但保留会话内消息
*/
- (void)deleteRecentSession:(NIMRecentSession *)recentSession;
/**
* 设置所有会话消息为已读
*
* @discussion 异步方法,消息会标记为设置的状态。不会触发单条 recentSession 更新的回调,但会触发回调 - (void)allMessagesRead
*/
- (void)markAllMessagesRead;
/**
* 设置一个会话里所有消息置为已读
*
* @param session 需设置的会话
* @discussion 异步方法,消息会标记为设置的状态
*/
- (void)markAllMessagesReadInSession:(NIMSession *)session;
/**
* 更新本地已存的消息记录
*
* @param message 需要更新的消息
* @param session 需要更新的会话
* @param completion 完成后的回调
* @discussion 为了保证存储消息的完整性,提供给上层调用的消息更新接口只允许更新如下字段:所有消息的本地拓展字段(LocalExt)和自定义消息的消息对象(messageObject)
*/
- (void)updateMessage:(NIMMessage *)message
forSession:(NIMSession *)session
completion:(nullable NIMUpdateMessageBlock)completion;
/**
* 写入消息
*
* @param message 需要更新的消息
* @param session 需要更新的会话
* @param completion 完成后的回调
* @discussion 当保存消息成功之后,会收到 NIMChatManagerDelegate 中的 onRecvMessages: 回调。不允许插入已存在的消息
*/
- (void)saveMessage:(NIMMessage *)message
forSession:(NIMSession *)session
completion:(nullable NIMUpdateMessageBlock)completion;
/**
* 导入最近会话
*
* @param importedRecentSession 待导入的会话集合
* @param completion 完成后的回调
* @discussion 当导入最近会话成功之后,不会收到 NIMChatManagerDelegate 中的 recentSession 变化的回调,请直接在 completion 中做处理。不允许插入已经存在的最近会话。
*/
- (void)importRecentSessions:(NSArray<NIMImportedRecentSession *> *)importedRecentSession
completion:(nullable NIMImportRecentSessionsBlock)completion;
/**
* 从本地db读取一个会话里某条消息之前的若干条的消息
*
* @param session 消息所属的会话
* @param message 当前最早的消息,没有则传入nil
* @param limit 个数限制
*
* @return 消息列表,按时间从小到大排列
*/
- (nullable NSArray<NIMMessage *> *)messagesInSession:(NIMSession *)session
message:(nullable NIMMessage *)message
limit:(NSInteger)limit;
/**
* 根据消息Id获取消息
*
* @param session 消息所属会话结合
*
* @param messageIds 消息Id集合
*
* @return 消息列表,按时间从小到大排列
*/
- (nullable NSArray<NIMMessage *> *)messagesInSession:(NIMSession *)session
messageIds:(NSArray<NSString *> *)messageIds;
/**
* 获取所有未读数
* @discussion 只能在主线程调用,包括忽略提醒的会话
* @return 未读数
*/
- (NSInteger)allUnreadCount;
/**
* 获取所有最近会话
* @discussion 只能在主线程调用
* @return 最近会话列表
* @discussion SDK 以 map 的形式保存 sessions,调用这个方法是将进行排序,数据量较大 (上万) 时会比较耗时。
*/
- (nullable NSArray<NIMRecentSession *> *)allRecentSessions;
/**
* 根据当前 session 返回对应的最近会话信息
*
* @param session 会话
*
* @return 最近会话信息,如果找不到则返回 nil
*/
- (nullable NIMRecentSession *)recentSessionBySession:(NIMSession *)session;
/**
* 从服务器上获取一个会话里某条消息之前的若干条的消息
*
* @param session 消息所属的会话
* @param option 搜索选项
* @param result 读取的消息列表结果
* @discussion 此接口不支持查询聊天室消息,聊天室请参考 NIMChatroomManagerProtocol 中的查询消息接口。
*
*/
- (void)fetchMessageHistory:(NIMSession *)session
option:(NIMHistoryMessageSearchOption *)option
result:(nullable NIMFetchMessageHistoryBlock)result;
/**
* 搜索本地会话内消息
*
* @param session 消息所属的会话
* @param option 搜索选项
* @param result 读取的消息列表结果
*
*/
- (void)searchMessages:(NIMSession *)session
option:(NIMMessageSearchOption *)option
result:(nullable NIMSearchMessageBlock)result;
/**
* 全局搜索本地消息
*
* @param option 搜索选项
* @param result 读取的消息内容
*/
- (void)searchAllMessages:(NIMMessageSearchOption *)option
result:(nullable NIMGlobalSearchMessageBlock)result;
/**
* 删除服务器端最近会话
*
* @param sessions 需要删除的会话列表,内部只能是NIMSession
* @param completion 完成的回调
* @discussion 调用这个接口成功后,当前会话之前的消息都不会漫游到其他端
*/
- (void)deleteRemoteSessions:(NSArray<NIMSession *> *)sessions
completion:(nullable NIMRemoveRemoteSessionBlock)completion;
/**
* 更新最近会话的本地扩展
*
* @param ext 扩展信息
* @param recentSession 要更新的最近会话
* @discussion 此扩展不会漫游到其他端,上层需要保证 NSDictionary 可以转换为 JSON。
*/
- (void)updateRecentLocalExt:(nullable NSDictionary *)ext
recentSession:(NIMRecentSession *)recentSession;
/**
* 添加通知对象
*
* @param delegate 通知对象
*/
- (void)addDelegate:(id<NIMConversationManagerDelegate>)delegate;
/**
* 删除通知对象
*
* @param delegate 通知对象
*/
- (void)removeDelegate:(id<NIMConversationManagerDelegate>)delegate;
@end
NS_ASSUME_NONNULL_END