Insert a local single-chat message
Insert a message record directly into the local database for a single-chat conversation.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
message | OpenIMMessageItem | Yes | Fully constructed message object created via a message creation method. |
recvID | string | Yes | Recipient user ID for the single chat. |
sendID | string | Yes | Sender 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.
Was this page helpful?