From 824685ae647d442d46e8e498c61d4b455766540a Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Tue, 15 Oct 2019 00:15:18 +0300 Subject: [PATCH] Redact existing reaction instead of trying to double-react Signed-off-by: Tulir Asokan --- .../views/messages/MessageActionBar.js | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/components/views/messages/MessageActionBar.js b/src/components/views/messages/MessageActionBar.js index 95ab57d324..ca617112a3 100644 --- a/src/components/views/messages/MessageActionBar.js +++ b/src/components/views/messages/MessageActionBar.js @@ -89,19 +89,35 @@ export default class MessageActionBar extends React.PureComponent { const EmojiPicker = sdk.getComponent('emojipicker.EmojiPicker'); const buttonRect = ev.target.getBoundingClientRect(); + const getReactions = () => { + const userId = MatrixClientPeg.get().getUserId(); + const myAnnotations = this.props.reactions.getAnnotationsBySender()[userId]; + return Object.fromEntries([...myAnnotations] + .filter(event => !event.isRedacted()) + .map(event => [event.getRelation().key, event.getId()])) + }; + const menuOptions = { reactions: this.props.reactions, chevronFace: "none", onFinished: () => this.onFocusChange(false), onChoose: reaction => { this.onFocusChange(false); - MatrixClientPeg.get().sendEvent(this.props.mxEvent.getRoomId(), "m.reaction", { - "m.relates_to": { - "rel_type": "m.annotation", - "event_id": this.props.mxEvent.getId(), - "key": reaction, - }, - }); + const myReactions = getReactions(); + if (myReactions.hasOwnProperty(reaction)) { + MatrixClientPeg.get().redactEvent( + this.props.mxEvent.getRoomId(), + myReactions[reaction], + ); + } else { + MatrixClientPeg.get().sendEvent(this.props.mxEvent.getRoomId(), "m.reaction", { + "m.relates_to": { + "rel_type": "m.annotation", + "event_id": this.props.mxEvent.getId(), + "key": reaction, + }, + }); + } }, };