Browse SDKs · HarmonyOS
Platform
SDKsHarmonyOSEnterprise

Receive and query typing status

Query active typing platforms for a member and listen for real-time typing status changes.

Copy

When entering a conversation, reconnecting, or when event state might be incomplete, query which platforms a specific member is currently typing on.

Code example

import sdk, {
  EventOnConversationUserInputStatusChangedData,
  GetInputStatesReq,
  GetInputStatesResp,
  OpenIMSDKEvent,
} from '@openimsdk/imsdk';

const request: GetInputStatesReq = {
  conversationID: conversationID,
  userID: memberUserID,
};
const response: GetInputStatesResp = await sdk.getInputStates(request);
setTyping(memberUserID, response.platforms.length > 0);

const handleInputStatusChanged = (data: EventOnConversationUserInputStatusChangedData): void => {
  updateTypingState(data.conversationID, data.userID, data.platforms);
};
const unsubscribeInputStatus = sdk.on(
  OpenIMSDKEvent.EventOnConversationUserInputStatusChanged,
  handleInputStatusChanged,
);

export function removeInputStatusListener(): void {
  unsubscribeInputStatus();
}

Parameters

ParameterTypeRequiredDescription
conversationIDstringYesTarget conversation identifier.
userIDstringYesMember user ID to query.

Return value

Returns a Promise resolving to GetInputStatesResp:

PropertyTypeDescription
platformsnumber[]Array of platform IDs on which the user is actively typing.

State changes after the call

An empty platforms array indicates that no device is currently typing. Merge member typing indicators using conversationID:userID. Event updates do not replace initial query snapshots and are ephemeral. Upon reconnecting, re-query only members currently visible on screen; avoid polling all members in large group chats. Call unsubscribeInputStatus() when disposing of the state layer. To broadcast typing state from the sender side, see Update typing status.