Commit aba72aa64d
Unregistered key
Layout: unified · split
src/base.rs +16
| @@ -1149,6 +1149,22 @@ impl RoomInfo { | |||
| 1149 | 1149 | ||
| 1150 | return top; | 1150 | return top; |
| 1151 | } | 1151 | } |
| 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 | } | ||
| 1152 | } | 1168 | } |
| 1153 | 1169 | ||
| 1154 | /// Generate a [CompletionMap] for Emoji shortcodes. | 1170 | /// Generate a [CompletionMap] for Emoji shortcodes. |
src/windows/room/chat.rs +7
| @@ -372,6 +372,13 @@ impl ChatState { | |||
| 372 | }, | 372 | }, |
| 373 | }; | 373 | }; |
| 374 | 374 | ||
| 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 | |||
| 375 | let reaction = Annotation::new(event_id, emoji); | 382 | let reaction = Annotation::new(event_id, emoji); |
| 376 | let msg = ReactionEventContent::new(reaction); | 383 | let msg = ReactionEventContent::new(reaction); |
| 377 | let _ = room.send(msg).await.map_err(IambError::from)?; | 384 | let _ = room.send(msg).await.map_err(IambError::from)?; |