@ably/chat - v0.14.1
    Preparing search index...

    Interface MessageReactions

    Send, delete, and subscribe to message reactions.

    interface MessageReactions {
        clientReactions(
            messageSerial: string,
            clientId?: string,
        ): Promise<MessageReactionSummary>;
        delete(
            messageSerial: string,
            params?: DeleteMessageReactionParams,
        ): Promise<void>;
        send(
            messageSerial: string,
            params: SendMessageReactionParams,
        ): Promise<void>;
        subscribe(listener: MessageReactionListener): Subscription;
        subscribeRaw(listener: MessageRawReactionListener): Subscription;
    }
    Index

    Methods

    • Get the reaction count for a message for a particular client.

      Parameters

      • messageSerial: string

        The serial of the message to remove the reaction from.

      • OptionalclientId: string

        The client to fetch the reaction summary for (leave unset for current client).

      Returns Promise<MessageReactionSummary>

      A clipped reaction summary containing only the requested clientId.

      // Subscribe to reaction summaries and check for specific client reactions
      room.messages.reactions.subscribe(async (event) => {
      // For brevity of example, we check unique 👍 (normally iterate for all relevant reactions)
      const uniqueLikes = event.summary.unique['👍'];
      if (uniqueLikes && uniqueLikes.clipped && !uniqueLikes.clientIds.includes(myClientId)) {
      // summary is clipped and doesn't include myClientId, so we need to fetch a clientSummary
      const clientReactions = await room.messages.reactions.clientReactions(
      event.messageSerial,
      myClientId
      );
      if (clientReactions.unique && clientReactions.unique['👍']) {
      // client has reacted with 👍
      event.reactions.unique['👍'].clientIds.push(myClientId);
      }
      }
      // from here, process the summary as usual
      });