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

Set a conversation draft

Save or clear draft input text for a conversation.

Copy

Save a conversation draft when the user navigates away from a chat view, switches to another conversation, or stops typing. Maintain keystrokes in component state with debouncing during active composition, and persist the draft to the SDK upon page exit to avoid high-frequency database writes on every character entered.

Parameters

ParameterTypeRequiredDescription
conversationIDstringYesIdentifier of the target conversation.
draftTextstringYesDraft text to store; pass an empty string "" to clear the draft.

Code example

import { setConversationDraft } from '@/uni_modules/unix-openim-sdk'

await setConversationDraft({
  conversationID,
  draftText: editorValue,
})

Return value

The Promise resolves with void upon successful local persistence.

State changes after the call

Promise resolution confirms that the draft text was saved to local storage. You can immediately update the local conversation item's draft fields. The SDK then emits onConversationChanged, where you can verify draftText and draftTextTime using conversationID as the primary key. For the centralized conversation listener implementation, see Retrieve conversation list. Clear in-memory input states when logging out or switching accounts to prevent drafts from leaking across sessions.