@amityco/ts-sdk-react-native
Version:
Amity Social Cloud Typescript SDK
38 lines (35 loc) • 1.11 kB
text/typescript
import { getActiveClient } from '~/client/api';
import { createEventSubscriber } from '~/core/events';
/**
* ```js
* import { onLiveReactionCreated } from '@amityco/ts-sdk'
* const dispose = onLiveReactionCreated(reactions => {
* // ...
* })
* ```
*
* Fired when a batch of {@link Amity.LiveReaction} has been created
*
* @param callback The function to call when the event was fired
* @returns an {@link Amity.Unsubscriber} function to stop listening
*
* @category Live Reaction Events
*/
export const onLiveReactionCreated = (
callback: Amity.Listener<Amity.LiveReaction[]>,
): Amity.Unsubscriber => {
const client = getActiveClient();
const filter = (rawPayload: Amity.LiveReactionPayload) => {
if (rawPayload.reactions.length > 0) {
// TODO: check with BE if user id is internal or pulbic id
const filteredPayload = rawPayload.reactions.filter(({ userId }) => userId !== client.userId);
callback(filteredPayload);
}
};
return createEventSubscriber(
client,
'live_reaction/onLiveReactionCreated',
'liveReaction.created',
filter,
);
};