Interface ChatMessageEventListener

The message event listener.

This listener listens for message state changes:

  • If messages are sent successfully, a delivery receipt will be returned to the sender (the delivery receipt function needs to be enabled: ChatOptions.requireDeliveryAck.

  • If the recipient reads the received message, a read receipt will be returned to the sender (the read receipt function needs to be enabled: ChatOptions.requireAck)

During message delivery, the message ID will be changed from a local uuid to a global unique ID that is generated by the server to uniquely identify a message on all devices using the SDK.

Adds a message event listener:

let msgListener = new (class ss implements ChatMessageEventListener {
onMessagesReceived(messages: ChatMessage[]): void {
chatlog.log('ConnectScreen.onMessagesReceived', messages);
}
onCmdMessagesReceived(messages: ChatMessage[]): void {
chatlog.log('ConnectScreen.onCmdMessagesReceived', messages);
}
onMessagesRead(messages: ChatMessage[]): void {
chatlog.log('ConnectScreen.onMessagesRead', messages);
}
onGroupMessageRead(groupMessageAcks: ChatGroupMessageAck[]): void {
chatlog.log('ConnectScreen.onGroupMessageRead', groupMessageAcks);
}
onMessagesDelivered(messages: ChatMessage[]): void {
chatlog.log('ConnectScreen.onMessagesDelivered', messages);
}
onMessagesRecalled(messages: ChatMessage[]): void {
chatlog.log('ConnectScreen.onMessagesRecalled', messages);
}
onConversationsUpdate(): void {
chatlog.log('ConnectScreen.onConversationsUpdate');
}
onConversationRead(from: string, to?: string): void {
chatlog.log('ConnectScreen.onConversationRead', from, to);
}
})();
ChatClient.getInstance().chatManager.addListener(msgListener);

Removes a message event listener:

ChatClient.getInstance().chatManager.delListener(this.msgListener);
interface ChatMessageEventListener {
    onChatMessageThreadCreated?(event: ChatMessageThreadEvent): void;
    onChatMessageThreadDestroyed?(event: ChatMessageThreadEvent): void;
    onChatMessageThreadUpdated?(event: ChatMessageThreadEvent): void;
    onChatMessageThreadUserRemoved?(event: ChatMessageThreadEvent): void;
    onCmdMessagesReceived?(messages: ChatMessage[]): void;
    onConversationRead?(from: string, to?: string): void;
    onConversationsUpdate?(): void;
    onGroupMessageRead?(groupMessageAcks: ChatGroupMessageAck[]): void;
    onMessageContentChanged?(message: ChatMessage, lastModifyOperatorId: string, lastModifyTime: number): void;
    onMessagePinChanged?(params: {
        convId: string;
        messageId: string;
        pinInfo: ChatMessagePinInfo;
        pinOperation: number;
    }): void;
    onMessageReactionDidChange?(list: ChatMessageReactionEvent[]): void;
    onMessagesDelivered?(messages: ChatMessage[]): void;
    onMessagesRead?(messages: ChatMessage[]): void;
    onMessagesRecalled?(messages: ChatMessage[]): void;
    onMessagesReceived?(messages: ChatMessage[]): void;
}

Methods

  • Occurs when a message thread is created.

    Each member of the group where the message thread belongs can call this method.

    Parameters

    Returns void

  • Occurs when a message thread is destroyed.

    Each member of the group where the message thread belongs can call this method.

    Parameters

    Returns void

  • Occurs when a message thread is updated.

    This method is triggered when the message thread name is changed or a message in the message thread is updated.

    Each member of the group where the message thread belongs can call this method.

    Parameters

    Returns void

  • Occurs when the current user is removed from the message thread by the admin.

    Parameters

    Returns void

  • Occurs when a command message is received.

    Unlike onMessagesReceived, this callback only contains a command message body that is usually invisible to users.

    Parameters

    • messages: ChatMessage[]

      The received command message(s).

    Returns void

  • Occurs when a conversation read receipt is received.

    This callback occurs in either of the following cases:

    • The message is read by the recipient and the conversation read receipt is sent. Upon receiving this event, the SDK sets the isAcked property of the message in the conversation to true in the local database.

    • In a multi-device login scenario, when one device sends a conversation receipt, the server will set the number of unread messages to 0, call the callback method on the other devices, and set the isRead property of the message in the conversation to true in the local database.

    Parameters

    • from: string

      The user who sends the conversation read receipt.

    • Optionalto: string

      The user who receives the conversation read receipt.

    Returns void

  • Occurs when the conversation is updated.

    This callback is triggered only when a conversation is added or removed.

    Returns void

  • Occurs when a read receipt is received for a group message.

    Parameters

    Returns void

  • Occurs when the content of a text message is modified.

    Parameters

    • message: ChatMessage

      The modified message.

    • lastModifyOperatorId: string

      The user ID of the operator that modified the message last time.

    • lastModifyTime: number

      The last message modification time. It is a UNIX timestamp in milliseconds.

    Returns void

  • Occurs when the message pinning status changed.

    Parameters

    • params: {
          convId: string;
          messageId: string;
          pinInfo: ChatMessagePinInfo;
          pinOperation: number;
      }

    Returns void

    params -

    • Param [messageId] The ID of the message with the changed pinning status.
    • Param [convId] The ID of the conversation that contains the message.
    • Param [pinOperation] The message pinning or unpinning operation.
    • Param [pinInfo] The information about message pinning or unpinning, including the operation time and the user ID of the operator. See ChatMessagePinInfo.
  • Occurs when a message reaction changes.

    Parameters

    Returns void

  • Occurs when a delivery receipt is received.

    Parameters

    • messages: ChatMessage[]

      The message(s) for which delivery receipt(s) is sent.

    Returns void

  • Occurs when a read receipt is received for a message.

    Parameters

    Returns void

  • Occurs when a received message is recalled.

    If the recipient is offline when the message is delivered and recalled, the recipient only receives this callback instead of the message.

    Parameters

    Returns void

  • Occurs when a message is received.

    This callback is triggered to notify the user of the message that is received, such as texts or an image, video, voice, location, or file.

    Parameters

    Returns void