Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2012 - Add "Copy message text" menu to the chat message toast pop-up #2023

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 () {
Copy link
Collaborator Author

@SebinSong SebinSong May 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This existing 'copy' action can rather be handled inside MessageActions.vue directly (it's not necessary to keep/execute the logic in the parent component, which requires emitting a custom-event from the child). So I thought I would DRY this logic while at this task.

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
Loading