NIMSDK-iOS
载入中...
搜索中...
未找到
NIMIndexManagerProtocol.h
浏览该文件的文档.
1//
2// NIMIndexManagerProtocol.h
3// NIMLib
4//
5// Created by Netease.
6// Copyright (c) 2021 Netease. All rights reserved.
7//
8
9#import <Foundation/Foundation.h>
10
11@class NIMMessage;
12@class NIMSession;
13
14NS_ASSUME_NONNULL_BEGIN
15
16/**
17 * 索引类型
18 */
19typedef NS_ENUM(NSInteger, NIMIndexType) {
20 /**
21 * 消息文本
22 */
24
25 /**
26 * 自定义索引类型起始
27 */
29};
30
31/**
32 * 索引文本
33 */
34@interface NIMIndexText : NSObject
35
36/**
37 * 索引文本
38 */
39@property (nonatomic, copy) NSString *text;
40
41/**
42 * 索引类型
43 */
44@property (nonatomic, assign) NSInteger type;
45
46@end
47
48/**
49 * 消息索引记录结构
50 */
51@interface NIMMsgIndexRecord : NSObject<NSCopying>
52
53/**
54 * 消息ID
55 */
56@property (nullable, nonatomic, copy) NSString * messageId;
57
58/**
59 * 索引文本
60 */
61@property (nullable, nonatomic, copy) NSString * indexText;
62
63/**
64 * 索引类型
65 */
66@property (nonatomic, assign) NSInteger indexType;
67
68/**
69 * 会话
70 */
71@property (nonatomic, copy) NIMSession * session;
72
73/**
74 * 时间
75 */
76@property (nonatomic, assign) NSTimeInterval timestamp;
77
78/**
79 * 消息
80 */
81@property (nullable, nonatomic) NIMMessage * message;
82
83@end
84
85typedef NS_ENUM(NSInteger, NIMMsgIndexTimeOrder) {
86 /**
87 * 消息时间从新往旧
88 */
90
91 /**
92 * 消息时间从旧往新
93 */
95};
96
97@interface NIMMsgIndexQueryOption : NSObject
98
99/**
100 * 起始时间,默认为0
101 */
102@property (nonatomic, assign) NSTimeInterval startTime;
103
104/**
105 * 结束时间,默认为0
106 * @discussion 搜索的结束时间,0 表示最大时间戳
107 */
108@property (nonatomic, assign) NSTimeInterval endTime;
109
110/**
111 * 检索顺序
112 */
113@property (nonatomic, assign) NIMMsgIndexTimeOrder timeOrder;
114
115/**
116 * 检索条数
117 */
118@property (nonatomic, assign) NSUInteger limit;
119
120@end
121
122/**
123 * 在消息索引结果基础上查询消息 Block
124 *
125 * @param error 错误信息,如果成功,error 为 nil
126 */
127typedef void(^NIMMsgIndexQueryMsgBlock)(NSError * __nullable error);
128
129@interface NIMMsgIndexQueryResult : NSObject
130
131/**
132 * 不包含任何结果
133 */
134@property (nonatomic, readonly) BOOL empty;
135
136/**
137 * 排序的会话列表
138 */
139@property (nonatomic, nullable, readonly) NSArray<NIMSession *> * sessions;
140
141/**
142 * 分会话索引记录
143 */
144@property (nonatomic, nullable, readonly) NSDictionary<NIMSession *, NSArray<NIMMsgIndexRecord *> *> * records;
145
146/**
147 * 是否包含消息
148 */
149@property (nonatomic, readonly) BOOL withMesssage;
150
151/**
152 * 分会话索引记录
153 *
154 * @param session 指定会话
155 * @discussion
156 */
157- (NSArray<NIMMessage *> *)messages:(nonnull NIMSession *)session;
158
159/**
160 * 查询结果中的消息数量
161 *
162 * @param session 指定会话,不传表示所有
163 * @discussion
164 */
165- (NSUInteger)messageCount:(nullable NIMSession *)session;
166
167/**
168 * 查询消息
169 *
170 * @param session 指定会话,不传表示所有
171 * @param completion 完成回调
172 * @discussion 消息结果记录在查询结果中
173 */
174- (void)queryMessage:(nullable NIMSession *)session
175 completion:(nullable NIMMsgIndexQueryMsgBlock)completion;
176
177@end
178
179/**
180 * 消息索引生成委托
181 */
182@protocol NIMMsgIndexProduceDelegate <NSObject>
183
184@optional
185
186- (nullable NSString *)produceText:(NIMMessage *)message;
187
188- (nullable NSArray<NIMIndexText *> *)produceTexts:(NIMMessage *)message;
189
190@end
191
192/**
193 * 同步消息索引 Block
194 *
195 * @param error 错误信息,如果成功,error 为 nil
196 */
197typedef void(^NIMSyncMsgIndexBlock)(NSError * __nullable error);
198
199/**
200 * 查询消息索引 Block
201 *
202 * @param error 错误信息,如果成功,error 为 nil
203 */
204typedef void(^NIMQueryMsgIndexBlock)(NSError * __nullable error, NIMMsgIndexQueryResult * __nullable result);
205
206/**
207 * 重置消息索引 Block
208 *
209 * @param error 错误信息,如果成功,error 为 nil
210 */
211typedef void(^NIMResetMsgIndexBlock)(NSError * __nullable error);
212
213/**
214 * 索引委托
215 */
216@protocol NIMIndexManagerDelegate <NSObject>
217
218@optional
219
220@end
221
222/**
223 * 索引协议
224 */
225@protocol NIMIndexManager <NSObject>
226
227/**
228 * 同步消息索引
229 *
230 * @param old 同步方向,YES往老方向,NO往新方向
231 * @param session 指定会话,不传表示所有
232 * @param completion 完成回调
233 * @discussion 老方向和新方向不代表消息产生时间,而是指存入本地的时间
234 */
235- (void)syncMsgIndex:(BOOL)old
236 session:(nullable NIMSession *)session
237 completion:(nullable NIMSyncMsgIndexBlock)completion;
238
239/**
240 * 查询消息索引
241 *
242 * @param text 查询文本
243 * @param session 指定会话,不传表示所有
244 * @param option 查询选项
245 * @param withMesssage 是否查询消息
246 * @param completion 完成回调
247 * @discussion 老方向和新方向不代表消息产生时间,而是指存入本地的时间
248 */
249- (void)queryMsgIndex:(nonnull NSString *)text
250 session:(nullable NIMSession *)session
251 option:(nullable NIMMsgIndexQueryOption *)option
252 withMessage:(BOOL)withMessage
253 completion:(nullable NIMQueryMsgIndexBlock)completion;
254
255/**
256 * 重置消息索引
257 *
258 * @param completion 完成回调
259 */
260- (void)resetMsgIndex:(nullable NIMResetMsgIndexBlock)completion;
261
262/**
263 * 添加索引委托
264 *
265 * @param delegate 检索委托
266 */
267- (void)addDelegate:(id<NIMIndexManagerDelegate>)delegate;
268
269/**
270 * 移除索引委托
271 *
272 * @param delegate 检索委托
273 */
274- (void)removeDelegate:(id<NIMIndexManagerDelegate>)delegate;
275
276@end
277
278NS_ASSUME_NONNULL_END
void(^ NIMResetMsgIndexBlock)(NSError *__nullable error)
Definition: NIMIndexManagerProtocol.h:211
NIMMsgIndexTimeOrder
Definition: NIMIndexManagerProtocol.h:85
@ NIMMsgIndexTimeOrderAsc
Definition: NIMIndexManagerProtocol.h:94
@ NIMMsgIndexTimeOrderDesc
Definition: NIMIndexManagerProtocol.h:89
void(^ NIMMsgIndexQueryMsgBlock)(NSError *__nullable error)
Definition: NIMIndexManagerProtocol.h:127
void(^ NIMQueryMsgIndexBlock)(NSError *__nullable error, NIMMsgIndexQueryResult *__nullable result)
Definition: NIMIndexManagerProtocol.h:204
NIMIndexType
Definition: NIMIndexManagerProtocol.h:19
@ NIMIndexTypeCustomBase
Definition: NIMIndexManagerProtocol.h:28
@ NIMIndexTypeMsgText
Definition: NIMIndexManagerProtocol.h:23
void(^ NIMSyncMsgIndexBlock)(NSError *__nullable error)
Definition: NIMIndexManagerProtocol.h:197
Definition: NIMIndexManagerProtocol.h:35
NSString * text
Definition: NIMIndexManagerProtocol.h:39
NSInteger type
Definition: NIMIndexManagerProtocol.h:44
Definition: NIMMessage.h:90
Definition: NIMIndexManagerProtocol.h:98
Definition: NIMIndexManagerProtocol.h:130
Definition: NIMIndexManagerProtocol.h:51
Definition: NIMSession.h:49