Emoji Reactions
Users can react to messages using emoji.
You can see a summary of all the reactions on a message in MessageSnapshot.reactions.
To see the list of users who reacted with a specific emoji, use ReactionsRef.subscribe or ReactionsRef.getFirstReactions.
References all the reactions on a message using a specific emoji.
Used in all Data API operations affecting reactions with this emoji. This includes mutating *your* reaction with .add and .remove, as well as fetching information about the aggregate state using getFirstReactions and .subscribe. Created via MessageRef​.reactions.
| add | React with this emoji reaction, as the current user. |
| getFirstReactions | Lists the first 10 users who added this reaction to the message. |
| remove | Un-react with this emoji reaction, as the current user. |
| subscribe | Subscribe to the list of users who have added this reaction to the message |
The ID of the conversation the message belongs to.
Immutable: if you want reactions for a message in a different conversation, get a new MessageRef from that conversation and call .reactions on that MessageRef.
Which emoji the reactions use.
Either a single Unicode emoji, or the name of a custom emoji with a colon at the start and end. This is not validated until you send a request to the server. Since custom emoji are configured in the frontend, there are no checks to make sure a custom emoji actually exists.
Immutable: if you want to use a different emoji, get a new ReactionRef instead.
The ID of the message that this is a reaction to.
Immutable: if you want reactions for a different message, get a new ReactionRef instead.
reactionsRef.add(): Promise<void>
React with this emoji reaction, as the current user.
Returns
A promise that resolves when the operation completes. The promise will reject if the request is invalid, the message doesn't exist, there are already 50 different reactions on this message, or if you do not have permission to use emoji reactions on that message. The promise will resolve with no effect if you have already reacted with this emoji.
reactionsRef.getFirstReactions(): Promise<SingleReactionSnapshot[] | null>
Lists the first 10 users who added this reaction to the message.
If more than 10 users added this reaction to the message, only the first 10 users will be returned.
To load more than 10 users, and to get real-time updates when users add or remove reactions, use subscribe instead.
Returns
The first 10 users, or null if the message doesn't exist or is inaccessible to you.
reactionsRef.remove(): Promise<void>
Un-react with this emoji reaction, as the current user.
Returns
A promise that resolves when the operation completes. The promise will reject if the request is invalid, the message doesn't exist, or you do not have permission to use emoji reactions on that message. The promise will resolve with no effect if you have not reacted with this emoji.
reactionsRef.subscribe(onSnapshot): ReactionsSubscription
Subscribe to the list of users who have added this reaction to the message
Parameters
Returns
A snapshot of a user's reaction to a message.
Returned from ReactionsRef​.getFirstReactions and ReactionsRef​.subscribe
The timestamp of when the user added this reaction to the message
Which user added the reaction
A subscription to the users who have reacted with a specific emoji on a specific message.
Get a ReactionsSubscription by calling ReactionsRef​.subscribe
The subscription is 'windowed'. It includes all reactions up to a certain point in time. By default, you subscribe to the 10 oldest reactions.
You can expand this window to load newer reactions by calling loadMore, which extends the window further into the future.
Remember to .unsubscribe the subscription once you are done with it.
| loadMore | Expand the window to include people who added the reaction later |
| unsubscribe | Unsubscribe from this resource and stop receiving updates. |
Resolves when the subscription starts receiving updates from the server.
Wait for this promise if you want to perform some action as soon as the subscription is active.
The promise rejects if the subscription is terminated before it connects.
The current state of the subscription
An object with the following fields:
type is one of "pending", "active", "unsubscribed", or "error".
When type is "active", includes latestSnapshot and loadedAll.
- latestSnapshot: SingleReactionSnapshot[] | null the current state of who used this reaction, or null if the message does not exist, or if you're not a participant in the conversation
- loadedAll: boolean true when latestSnapshot contains all the users who added this reaction to the message
When type is "error", includes the error field. It is a JS Error object explaining what caused the subscription to be terminated.
Resolves when the subscription permanently stops receiving updates from the server.
This is either because you unsubscribed or because the subscription encountered an unrecoverable error.
reactionsSubscription.loadMore(count): Promise<void>
Expand the window to include people who added the reaction later
The count parameter is relative to the current number of loaded users. If you call loadMore(5) and then call loadMore(10) immediately afterwards (without awaiting the promise), then only 10 additional users will be loaded, not 15.
Avoid calling .loadMore in a loop until you have loaded all users. If you do need to call loadMore in a loop, make sure you set an upper bound (e.g. 1000) on the number of users, where the loop will exit.
Parameters
The number of additional users to load. Must be between 1 and 100. Default 30.
Returns
A promise that resolves once the additional users have loaded
reactionsSubscription.unsubscribe()
Unsubscribe from this resource and stop receiving updates.
If the subscription is already in the "unsubscribed" or "error" state, this is a no-op.