文档导航
Web
SDK 版本:  5.X
公告:融云新文档中心已上线,欢迎到新文档中心阅读 Web IMLibWeb IMKit 的文档。

搜索消息(Electron)

更新时间:2024-04-22 PDF

本文档仅适用于 Electron 解决方案,仅限于配合 Electron 模块 (@rongcloud/electron@rongcloud/electron-renderer)使用。

本文档描述了如何搜索存储在客户端本地的消息。

根据关键字搜索本地消息

提示

从 SDK 5.4.0 开始支持该接口。

调用 electronExtension.searchMessages 根据关键字搜索指定会话中的消息

  • 文本类型消息只支持搜索 content,文件类型消息只支持搜索 name
  • 自定义消息根据 registerMessageType 的 searchProps 参数决定
  • 引用消息不支持搜索
const conversation = {
    conversationType: RongIMLib.ConversationType.PRIVATE,
    targetId: "<目标用户ID>",
    channelId: ""
}
const keyword = '搜索关键字'
const startTime = Date.now()
const count = 10

RongIMLib.electronExtension.searchMessages(conversation, keyword, startTime, count).then(res => {
  if (res.code === 0) {
    console.log(res.code, res.data)
  } else {
    console.log(res.code, res.msg)
  }
}).catch(error => {
  console.log(error)
})
              
已复制
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

参数 类型 说明
conversation IConversationOption 会话
keyword string 关键字
startTime number 搜索时间, 搜索该时间之前的消息
count number 获取的数量
messageTypes string[] 指定消息类型,支持:文本(RC:TxtMsg)、文件(RC:FileMsg)、引用消息(RC:ReferenceMsg)、自定义消息,5.9.8 版本开始支持
  • conversation 字段说明

    参数 类型 说明
    conversationType IConversationType 会话类型
    targetId string 会话 ID
    channelId number 频道 ID, 限定搜索指定频道内的消息, 如果不传,则在所有频道中进行搜索

在指定时间范围内搜索本地消息

提示

从 SDK 5.4.0 开始支持该接口。

调用 electronExtension.searchMessageInTimeRange 在指定会话的所有频道中搜索时间范围内的消息

const conversation = {
    conversationType: RongIMLib.ConversationType.PRIVATE,
    targetId: "<目标用户ID>"
}
const option = {
  keyword: 'hello',
  startTime: 0,
  endTime: 1632728573423,
  offset: 0,
  limit: 5
}
RongIMLib.electronExtension.searchMessageInTimeRange(conversation, option).then(res => {
  if (res.code === 0) {
    console.log(res.code, res.data)
  } else {
    console.log(res.code)
  }
}).catch(error => {
  console.log(error)
})
              
已复制
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

参数 类型 说明
conversation Object 会话,详见下方 conversation 参数说明
option ISearchMessageInTimeRangeOption 搜索参数,详见下方 option 参数说明
  • conversation 参数说明

    参数 类型 说明
    conversationType IConversationType 会话类型
    targetId string 会话 ID
  • option 参数说明

    参数 类型 说明
    keyword string 搜索关键字
    startTime number 开始时间
    endTime number 截止时间
    offset number 分页搜索时的偏移量,默认为0
    limit number 每页的数量,默认为 5

根据用户 ID 搜索本地消息

提示

从 SDK 5.7.10 开始支持该接口。

调用 electronExtension.searchMessagesByUser 在指定会话的所有频道中搜索时间范围内的消息

const conversation = {
    conversationType: RongIMLib.ConversationType.PRIVATE,
    targetId: "<会话 ID>",
    channelId: ""
}
const userId = '用户 ID'
const startTime = Date.now()
const count = 10

RongIMLib.electronExtension.searchMessagesByUser(conversation, userId, startTime, count).then(res => {
  if (res.code === 0) {
    console.log(res.code, res.data)
  } else {
    console.log(res.code, res.msg)
  }
}).catch(error => {
  console.log(error)
})
              
已复制
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

参数 类型 说明
conversation IConversationOption 会话
userId string 用户 id
startTime number 搜索时间, 搜索该时间之前的消息
count number 获取的数量
文档反馈
意见反馈

您的改进建议

意见反馈

问题类型

联系我们

提交工单

技术支持|集成使用|产品方案


商务咨询

7 x 24 小时

为您解答方案与报价问题

131 6185 6839

文档反馈