From 7ac777d9716d9b93f6390fcde2fb22267bc275cd Mon Sep 17 00:00:00 2001 From: N Pex Date: Wed, 8 Feb 2023 14:02:08 +0000 Subject: [PATCH] When sending reaction, redact if already send --- src/components/Chat.vue | 23 ++++++++++++++++++++-- src/components/messages/QuickReactions.vue | 17 ++++++++++++++-- src/main.js | 12 +++++++++-- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/components/Chat.vue b/src/components/Chat.vue index 4d85aea..e3e48c2 100644 --- a/src/components/Chat.vue +++ b/src/components/Chat.vue @@ -55,7 +55,7 @@ } " v-on:touchend="touchEnd" v-on:touchcancel="touchCancel" v-on:touchmove="touchMove"> @@ -510,7 +510,7 @@ export default { return util.browserCanRecordAudio(); }, debugging() { - return (window.location.host || "").startsWith("localhost"); + return false; //(window.location.host || "").startsWith("localhost"); }, invitationCount() { return this.$matrix.invites.length; @@ -1202,6 +1202,24 @@ export default { }, sendQuickReaction(e) { + let previousReaction = null; + + // Figure out if we have already sent this emoji, in that case redact it again (toggle) + // + const reactions = this.timelineSet.relations.getChildEventsForEvent(e.event.getId(), 'm.annotation', 'm.reaction'); + if (reactions && reactions._eventsCount > 0) { + const relations = reactions.getRelations(); + for (const r of relations) { + const emoji = r.getRelation().key; + const sender = r.getSender(); + if (emoji == e.reaction && sender == this.$matrix.currentUserId) { + previousReaction = r.isRedacted() ? null : r; + } + } + } + if (previousReaction) { + this.redact(previousReaction); + } else { util .sendQuickReaction(this.$matrix.matrixClient, this.roomId, e.reaction, e.event) .then(() => { @@ -1210,6 +1228,7 @@ export default { .catch((err) => { console.log("Failed to send quick reaction:", err); }); + } }, sendSticker(stickerShortCode) { diff --git a/src/components/messages/QuickReactions.vue b/src/components/messages/QuickReactions.vue index baa69ce..63dc6be 100644 --- a/src/components/messages/QuickReactions.vue +++ b/src/components/messages/QuickReactions.vue @@ -1,6 +1,6 @@