Skip to main content

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

tip

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 the name is searchable.
  • For custom messages, the searchable fields are determined by the searchProps parameter in registerMessageType.
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)
})
ParameterTypeDescription
conversationIConversationOptionConversation
keywordstringKeyword
startTimenumberSearch time, messages before this time will be searched
countnumberNumber of messages to retrieve
messageTypesstring[]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 Description

    ParameterTypeDescription
    conversationTypeIConversationTypeConversation type
    targetIdstringConversation ID
    channelIdnumberChannel 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

tip

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)
})
ParameterTypeDescription
conversationObjectConversation, see conversation Parameter Description below.
optionISearchMessageInTimeRangeOptionSearch parameters, see option Parameter Description below.
  • conversation Parameter Description

    ParameterTypeDescription
    conversationTypeIConversationTypeConversation type
    targetIdstringConversation ID
  • option Parameter Description

    ParameterTypeDescription
    keywordstringSearch keyword
    startTimenumberStart time
    endTimenumberEnd time
    offsetnumberOffset for paginated search, default is 0
    limitnumberNumber of messages per page, default is 5

Search Local Messages by User ID

tip

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)
})
ParameterTypeDescription
conversationIConversationOptionConversation
userIdstringUser ID
startTimenumberSearch time, messages before this time will be searched
countnumberNumber of messages to retrieve