From ac71bb3bb1b21110180c83da289b4419685a4c24 Mon Sep 17 00:00:00 2001 From: SebinSong Date: Mon, 27 May 2024 12:12:06 +1200 Subject: [PATCH] add 'Copy message text --- .../containers/chatroom/MessageActions.vue | 38 +++++++++++++++++-- .../views/containers/chatroom/MessageBase.vue | 11 +----- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/frontend/views/containers/chatroom/MessageActions.vue b/frontend/views/containers/chatroom/MessageActions.vue index aea4fd9b9..182a4bed3 100644 --- a/frontend/views/containers/chatroom/MessageActions.vue +++ b/frontend/views/containers/chatroom/MessageActions.vue @@ -82,12 +82,20 @@ menu-parent(ref='menu') i.icon-undo i18n Add emoticons + menu-item.is-icon-small( + v-if='isText' + tag='button' + @click='action("copyMessageText")' + ) + i.icon-copy + i18n Copy message text + menu-item.is-icon-small( tag='button' @click='action("copyMessageLink")' ) i.icon-link - i18n Copy message Link + i18n Copy message link menu-item.is-icon-small.is-danger( tag='button' @@ -120,6 +128,8 @@ export default ({ return Object.values(MESSAGE_VARIANTS).indexOf(value) !== -1 } }, + messageHash: String, + text: String, type: String, isMsgSender: Boolean, isGroupCreator: Boolean @@ -140,8 +150,30 @@ export default ({ }, methods: { action (type, e) { - // Change to sbp action - this.$emit(type, e) + const copyString = str => { + navigator?.clipboard.writeText(str) + } + switch (type) { + case 'copyMessageLink': { + if (!this.messageHash) { return } + + const url = new URL(location.href) + url.search = `mhash=${this.messageHash}` + + copyString(url.href) + break + } + case 'copyMessageText': { + if (!this.text) { return } + + copyString(this.text) + break + } + default: { + // Change to sbp action + this.$emit(type, e) + } + } } } }: Object) diff --git a/frontend/views/containers/chatroom/MessageBase.vue b/frontend/views/containers/chatroom/MessageBase.vue index a059cb503..464ff3956 100644 --- a/frontend/views/containers/chatroom/MessageBase.vue +++ b/frontend/views/containers/chatroom/MessageBase.vue @@ -100,6 +100,8 @@ v-if='!isEditing' :variant='variant' :type='type' + :text='text' + :messageHash='messageHash' :isMsgSender='isMsgSender' :isGroupCreator='isGroupCreator' ref='messageAction' @@ -108,7 +110,6 @@ @deleteMessage='$emit("delete-message")' @reply='reply' @retry='$emit("retry")' - @copyMessageLink='copyMessageLink' ) @@ -236,14 +237,6 @@ export default ({ reply () { this.$emit('reply') }, - copyMessageLink () { - if (!this.messageHash) { return } - - const url = new URL(location.href) - url.search = `mhash=${this.messageHash}` - - navigator.clipboard.writeText(url.href) - }, selectEmoticon (emoticon) { this.$emit('add-emoticon', emoticon.native || emoticon) },