Commit aba72aa64d

aba72aa64d7a50ec33610dc7a61ed14e3c635a2a

parent: 72d35431de

Unregistered key

Matthias Ahouansou <matthias@ahouansou.cz> · 2024-04-02 15:21 UTC
committer: <noreply@github.com>

Prevent sending duplicate reaction events (#240)

Layout: unified · split

src/base.rs +16
@@ -1149,6 +1149,22 @@ impl RoomInfo {
11491149
11501150 return top;
11511151 }
1152
1153 /// Checks if a given user has reacted with the given emoji on the given event
1154 pub fn user_reactions_contains(
1155 &mut self,
1156 user_id: &UserId,
1157 event_id: &EventId,
1158 emoji: &str,
1159 ) -> bool {
1160 if let Some(reactions) = self.reactions.get(event_id) {
1161 reactions
1162 .values()
1163 .any(|(annotation, user)| annotation == emoji && user == user_id)
1164 } else {
1165 false
1166 }
1167 }
11521168}
11531169
11541170/// Generate a [CompletionMap] for Emoji shortcodes.
src/windows/room/chat.rs +7
@@ -372,6 +372,13 @@ impl ChatState {
372372 },
373373 };
374374
375 if info.user_reactions_contains(&settings.profile.user_id, &event_id, &emoji) {
376 let msg = format!("You’ve already reacted to this message with {}", emoji);
377 let err = UIError::Failure(msg);
378
379 return Err(err);
380 }
381
375382 let reaction = Annotation::new(event_id, emoji);
376383 let msg = ReactionEventContent::new(reaction);
377384 let _ = room.send(msg).await.map_err(IambError::from)?;