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 5ac303432..71b150432 100644 --- a/frontend/views/containers/chatroom/MessageBase.vue +++ b/frontend/views/containers/chatroom/MessageBase.vue @@ -81,6 +81,8 @@ v-if='!isEditing' :variant='variant' :type='type' + :text='text' + :messageHash='messageHash' :isMsgSender='isMsgSender' :isGroupCreator='isGroupCreator' ref='messageAction' @@ -89,7 +91,6 @@ @deleteMessage='$emit("delete-message")' @reply='reply' @retry='$emit("retry")' - @copyMessageLink='copyMessageLink' ) @@ -194,14 +195,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) },