Skip to content

Commit ef74c86

Browse files
committed
fix: properly take enforced unique reactions into account
1 parent 33f5bac commit ef74c86

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

package/src/components/MessageMenu/hooks/useFetchReactions.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,31 @@ export const useFetchReactions = ({
7676
}),
7777
);
7878

79-
['reaction.new', 'reaction.updated'].forEach((eventType) => {
80-
listeners.push(
81-
client.on(eventType, (event) => {
82-
const { reaction } = event;
79+
listeners.push(
80+
client.on('reaction.new', (event) => {
81+
const { reaction } = event;
82+
83+
if (reaction && reaction.type === reactionType) {
84+
setReactions((prevReactions) => [reaction, ...prevReactions]);
85+
}
86+
}),
87+
);
8388

84-
if (reaction && reaction.type === reactionType) {
89+
listeners.push(
90+
client.on('reaction.updated', (event) => {
91+
const { reaction } = event;
92+
93+
if (reaction) {
94+
if (reaction.type === reactionType) {
8595
setReactions((prevReactions) => [reaction, ...prevReactions]);
96+
} else {
97+
setReactions((prevReactions) =>
98+
prevReactions.filter((r) => r.user_id !== reaction.user_id),
99+
);
86100
}
87-
}),
88-
);
89-
});
101+
}
102+
}),
103+
);
90104

91105
listeners.push(
92106
client.on('reaction.deleted', (event) => {

0 commit comments

Comments
 (0)