Commit aba72aa 1 parent 72d3543 commit aba72aa Copy full SHA for aba72aa
File tree 2 files changed +23
-0
lines changed
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -1149,6 +1149,22 @@ impl RoomInfo {
1149
1149
1150
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
1170
/// Generate a [CompletionMap] for Emoji shortcodes.
Original file line number Diff line number Diff line change @@ -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
382
let reaction = Annotation :: new ( event_id, emoji) ;
376
383
let msg = ReactionEventContent :: new ( reaction) ;
377
384
let _ = room. send ( msg) . await . map_err ( IambError :: from) ?;
You can’t perform that action at this time.
0 commit comments