搜索消息
更新时间:2024-07-15
PDF
根据关键字搜索
根据关键字搜索指定会话中的消息
方法
Future<int> searchMessages(RCIMIWConversationType type, String targetId, String? channelId, String keyword, int startTime, int count, {IRCIMIWSearchMessagesCallback? callback});
已复制
1
参数说明
参数名 | 参数类型 | 描述 |
---|---|---|
type | RCIMIWConversationType | 会话类型 |
targetId | String | 会话 ID |
channelId | String | 频道 ID,仅支持超级群使用,其他会话类型传 null 即可。 |
keyword | String | 搜索的关键字 |
startTime | int | 查询 beginTime 之前的消息, 传 0 时从最新消息开始搜索,从该时间往前搜索。 |
count | int | 查询的数量,0 < count <= 50。 |
callback | IRCIMIWSearchMessagesCallback | 事件回调。SDK 从 5.3.1 版本开始支持 callback 方式回调。从 5.4.0 版本废弃该接口的其他回调方式。如果传入了 callback 参数,仅触发 callback 回调。 |
返回值
返回值 | 描述 |
---|---|
Future<int> | 当次接口操作的状态码。0 代表调用成功 具体结果需要实现接口回调,非 0 代表当前接口调用操作失败,不会触发接口回调,详细错误参考错误码 |
代码示例
IRCIMIWSearchMessagesCallback? callback = IRCIMIWSearchMessagesCallback(onSuccess: (List<RCIMIWMessage>? t) {
//...
}, onError: (int? code) {
//...
});
int? ret = await engine?.searchMessages(type, targetId, channelId, keyword, startTime, count, callback:callback);
已复制
1
2
3
4
5
6
7
回调方法
onMessagesSearched
接口调用结果的监听
Function(int? code, RCIMIWConversationType? type, String? targetId, String? channelId, String? keyword, int? startTime, int? count, List<RCIMIWMessage>? messages)? onMessagesSearched;
已复制
1
参数说明
参数名 | 参数类型 | 描述 |
---|---|---|
code | int | 接口回调的状态码,0 代表成功,非 0 代表出现异常 |
type | RCIMIWConversationType | 会话类型 |
targetId | String | 会话 ID |
channelId | String | 频道 ID,仅支持超级群使用,其他会话类型传 null 即可。 |
keyword | String | 搜索的关键字 |
startTime | int | 查询 beginTime 之前的消息 |
count | int | 查询的数量 |
messages | List<RCIMIWMessage> | 查询到的消息集合 |
代码示例
engine?.onMessagesSearched = (int? code, RCIMIWConversationType? type, String? targetId, String? channelId, String? keyword, int? startTime, int? count, List<RCIMIWMessage>? messages) {
//...
};
已复制
1
2
3
根据关键字搜索指定会话中某个时间段的消息
方法
Future<int> searchMessagesByTimeRange(RCIMIWConversationType type, String targetId, String? channelId, String keyword, int startTime, int endTime, int offset, int count, {IRCIMIWSearchMessagesByTimeRangeCallback? callback});
已复制
1
参数说明
参数名 | 参数类型 | 描述 |
---|---|---|
type | RCIMIWConversationType | 会话类型 |
targetId | String | 会话 ID |
channelId | String | 频道 ID,仅支持超级群使用,其他会话类型传 null 即可。 |
keyword | String | 搜索的关键字 |
startTime | int | 开始时间 |
endTime | int | 结束时间 |
offset | int | 偏移量 |
count | int | 返回的搜索结果数量,0 < count <= 50。 |
callback | IRCIMIWSearchMessagesByTimeRangeCallback | 事件回调。SDK 从 5.3.1 版本开始支持 callback 方式回调。从 5.4.0 版本废弃该接口的其他回调方式。如果传入了 callback 参数,仅触发 callback 回调。 |
返回值
返回值 | 描述 |
---|---|
Future<int> | 当次接口操作的状态码。0 代表调用成功 具体结果需要实现接口回调,非 0 代表当前接口调用操作失败,不会触发接口回调,详细错误参考错误码 |
代码示例
IRCIMIWSearchMessagesByTimeRangeCallback? callback = IRCIMIWSearchMessagesByTimeRangeCallback(onSuccess: (List<RCIMIWMessage>? t) {
//...
}, onError: (int? code) {
//...
});
int? ret = await engine?.searchMessagesByTimeRange(type, targetId, channelId, keyword, startTime, endTime, offset, count, callback:callback);
已复制
1
2
3
4
5
6
7
回调方法
- onMessagesSearchedByTimeRange
Function(int? code, RCIMIWConversationType? type, String? targetId, String? channelId, String? keyword, int? startTime, int? endTime, int? offset, int? count, List<RCIMIWMessage>? messages)? onMessagesSearchedByTimeRange;
已复制
1
参数说明
参数名 | 参数类型 | 描述 |
---|---|---|
code | int | 接口回调的状态码,0 代表成功,非 0 代表出现异常 |
type | RCIMIWConversationType | 会话类型 |
targetId | String | 会话 ID |
channelId | String | 频道 ID,仅支持超级群使用,其他会话类型传 null 即可。 |
keyword | String | 搜索的关键字 |
startTime | int | 开始时间 |
endTime | int | 结束时间 |
offset | int | 偏移量 |
count | int | 查询的数量 |
messages | List<RCIMIWMessage> | 查询到的消息集合 |
代码示例
engine?.onMessagesSearchedByTimeRange = (int? code, RCIMIWConversationType? type, String? targetId, String? channelId, String? keyword, int? startTime, int? endTime, int? offset, int? count, List<RCIMIWMessage>? messages) {
//...
};
已复制
1
2
3
根据用户 id 搜索指定会话中的消息
方法
Future<int> searchMessagesByUserId(String userId, RCIMIWConversationType type, String targetId, String? channelId, int startTime, int count, {IRCIMIWSearchMessagesByUserIdCallback? callback});
已复制
1
参数说明
参数名 | 参数类型 | 描述 |
---|---|---|
userId | String | 用户 id |
type | RCIMIWConversationType | 会话类型 |
targetId | String | 会话 ID |
channelId | String | 频道 ID,仅支持超级群使用,其他会话类型传 null 即可。 |
startTime | int | 查询记录的起始时间, 传 0 时从最新消息开始搜索,从该时间往前搜索。 |
count | int | 返回的搜索结果数量 0 < count <= 50。 |
callback | IRCIMIWSearchMessagesByUserIdCallback | 事件回调。SDK 从 5.3.1 版本开始支持 callback 方式回调。从 5.4.0 版本废弃该接口的其他回调方式。如果传入了 callback 参数,仅触发 callback 回调。 |
返回值
返回值 | 描述 |
---|---|
Future<int> | 当次接口操作的状态码。0 代表调用成功 具体结果需要实现接口回调,非 0 代表当前接口调用操作失败,不会触发接口回调,详细错误参考错误码 |
代码示例
IRCIMIWSearchMessagesByUserIdCallback? callback = IRCIMIWSearchMessagesByUserIdCallback(onSuccess: (List<RCIMIWMessage>? t) {
//...
}, onError: (int? code) {
//...
});
int? ret = await engine?.searchMessagesByUserId(userId, type, targetId, channelId, startTime, count, callback:callback);
已复制
1
2
3
4
5
6
7
回调方法
onMessagesSearchedByUserId
接口调用结果的监听
Function(int? code, String? userId, RCIMIWConversationType? type, String? targetId, String? channelId, int? startTime, int? count, List<RCIMIWMessage>? messages)? onMessagesSearchedByUserId;
已复制
1
参数说明
参数名 | 参数类型 | 描述 |
---|---|---|
code | int | 接口回调的状态码,0 代表成功,非 0 代表出现异常 |
userId | String | 用户 id |
type | RCIMIWConversationType | 会话类型 |
targetId | String | 会话 ID |
channelId | String | 频道 ID,仅支持超级群使用,其他会话类型传 null 即可。 |
startTime | int | 查询记录的起始时间 |
count | int | 查询的数量 |
messages | List<RCIMIWMessage> | 查询到的消息集合 |
代码示例
engine?.onMessagesSearchedByUserId = (int? code, String? userId, RCIMIWConversationType? type, String? targetId, String? channelId, int? startTime, int? count, List<RCIMIWMessage>? messages) {
//...
};
已复制
1
2
3