Search Messages (Electron)
This document is applicable only to the Electron solution and is intended for use in conjunction with the Electron modules (@rongcloud/electron and @rongcloud/electron-renderer).
This document describes how to search for messages stored locally on the client.
Search Local Messages by Keyword
This interface is supported starting from SDK version 5.4.0.
Call electronExtension.searchMessages to search for messages in a specified conversation based on a keyword.
- For text messages, only the
content
is searchable; for file messages, only thename
is searchable. - For custom messages, the searchable fields are determined by the
searchProps
parameter inregisterMessageType
.
const conversation = {
conversationType: RongIMLib.ConversationType.PRIVATE,
targetId: "<Target User ID>",
channelId: ""
}
const keyword = 'Search 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)
})
Parameter | Type | Description |
---|---|---|
conversation | IConversationOption | Conversation |
keyword | string | Keyword |
startTime | number | Search time, messages before this time will be searched |
count | number | Number of messages to retrieve |
messageTypes | string[] | Specify message types, supported types: text (RC:TxtMsg), file (RC:FileMsg), reference message (RC:ReferenceMsg), custom message. Supported starting from version 5.9.8 |
-
conversation
Field DescriptionParameter Type Description conversationType IConversationType Conversation type targetId string Conversation ID channelId number Channel ID, limits the search to messages within the specified channel. If not provided, searches across all channels.
Search Local Messages Within a Specified Time Range
This interface is supported starting from SDK version 5.4.0.
Call electronExtension.searchMessageInTimeRange to search for messages within a specified time range across all channels in a given conversation.
const conversation = {
conversationType: RongIMLib.ConversationType.PRIVATE,
targetId: "<Target User 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)
})
Parameter | Type | Description |
---|---|---|
conversation | Object | Conversation, see conversation Parameter Description below. |
option | ISearchMessageInTimeRangeOption | Search parameters, see option Parameter Description below. |
-
conversation
Parameter DescriptionParameter Type Description conversationType IConversationType Conversation type targetId string Conversation ID -
option
Parameter DescriptionParameter Type Description keyword string Search keyword startTime number Start time endTime number End time offset number Offset for paginated search, default is 0 limit number Number of messages per page, default is 5
Search Local Messages by User ID
This interface is supported starting from SDK version 5.7.10.
Call electronExtension.searchMessagesByUser to search for messages within a specified time range across all channels in a given conversation.
const conversation = {
conversationType: RongIMLib.ConversationType.PRIVATE,
targetId: "<Conversation ID>",
channelId: ""
}
const userId = 'User 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)
})
Parameter | Type | Description |
---|---|---|
conversation | IConversationOption | Conversation |
userId | string | User ID |
startTime | number | Search time, messages before this time will be searched |
count | number | Number of messages to retrieve |