Skip to content

Commit b60d54e

Browse files
authored
Merge pull request #955 from GetStream/adjust-reaction-handler
Adjust reaction error catch
2 parents 57ac60f + dc7ba7b commit b60d54e

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Chore
66

77
- Throttle send/remove message reaction functions [#953](https://github.com/GetStream/stream-chat-react/pull/953)
8+
and [#955](https://github.com/GetStream/stream-chat-react/pull/955)
89

910
### Bug
1011

src/components/Message/hooks/useReactionHandler.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ export const useReactionHandler = <
4545
await channel.deleteReaction(id, type);
4646
}
4747
} catch (error) {
48-
throw new Error('toggle reaction failed');
48+
// revert to the original message if the API call fails
49+
if (message) updateMessage(message);
4950
}
5051
}, 1000);
5152

@@ -54,9 +55,8 @@ export const useReactionHandler = <
5455
event.preventDefault();
5556
}
5657

57-
if (!updateMessage || !message || !channel || !client) {
58-
console.warn(reactionHandlerWarning);
59-
return;
58+
if (!message) {
59+
return console.warn(reactionHandlerWarning);
6060
}
6161

6262
let userExistingReaction = (null as unknown) as ReactionResponse<Re, Us>;
@@ -75,18 +75,14 @@ export const useReactionHandler = <
7575
});
7676
}
7777

78-
// Make the API call in the background
79-
// If it fails, revert to the old message...
8078
try {
8179
if (userExistingReaction) {
8280
await toggleReaction(message.id, userExistingReaction.type, false);
8381
} else {
84-
// this.props.channel.state.addReaction(tmpReaction, this.props.message);
8582
await toggleReaction(message.id, reactionType, true);
8683
}
8784
} catch (error) {
88-
// revert to the original message if the API call fails
89-
updateMessage(message);
85+
console.log({ error });
9086
}
9187
};
9288
};

0 commit comments

Comments
 (0)