Browse SDKs · uni-app / uni-app x
Platform
SDKsuni-app / uni-app x

Insert a local single-chat message

Insert a message record directly into the local database for a single-chat conversation.

Copy

Invoke insertSingleMessageToLocalStorage() to write a message item directly into the local device database for a single chat, suitable for device-local system prompts, security reminders, or legacy data migration.

Parameters

ParameterTypeRequiredDescription
messageOpenIMMessageItemYesFully constructed message object created via a message creation method.
recvIDstringYesRecipient user ID for the single chat.
sendIDstringYesSender user ID for the single chat.

Code example

import {
  createTextMessage,
  insertSingleMessageToLocalStorage,
} from '@/uni_modules/unix-openim-sdk'

const message = await createTextMessage('Local notice')
if (message == null) return

await insertSingleMessageToLocalStorage({
  message,
  recvID: targetUserID,
  sendID: currentUserID,
})

The sendID and recvID parameters must match the participants of the target single-chat session.

Return value

The Promise resolves with void upon successful insertion into the local database.

State changes after the call

Promise resolution indicates that the message record was written to the local database. Update your local list state using conversationID:clientMsgID. This call does not send network packets, trigger push notifications, or emit new message events. To transmit messages to remote peers, use Send a message.