Skip to content

Commit

Permalink
add 'Copy message text (#2023)
Browse files Browse the repository at this point in the history
  • Loading branch information
SebinSong authored Jun 4, 2024
1 parent a332d12 commit 1bf181e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
38 changes: 35 additions & 3 deletions frontend/views/containers/chatroom/MessageActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -120,6 +128,8 @@ export default ({
return Object.values(MESSAGE_VARIANTS).indexOf(value) !== -1
}
},
messageHash: String,
text: String,
type: String,
isMsgSender: Boolean,
isGroupCreator: Boolean
Expand All @@ -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)
Expand Down
11 changes: 2 additions & 9 deletions frontend/views/containers/chatroom/MessageBase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
v-if='!isEditing'
:variant='variant'
:type='type'
:text='text'
:messageHash='messageHash'
:isMsgSender='isMsgSender'
:isGroupCreator='isGroupCreator'
ref='messageAction'
Expand All @@ -89,7 +91,6 @@
@deleteMessage='$emit("delete-message")'
@reply='reply'
@retry='$emit("retry")'
@copyMessageLink='copyMessageLink'
)
</template>

Expand Down Expand Up @@ -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)
},
Expand Down

0 comments on commit 1bf181e

Please sign in to comment.