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

feat(Message) - copy formatted message (with markdown and mentions) to clipboard #10322

Merged
merged 1 commit into from
Aug 24, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,25 @@

<NcActionSeparator />
<NcActionButton v-if="isPrivateReplyable"
icon="icon-user"
close-after-click
@click.stop="handlePrivateReply">
<template #icon>
<AccountIcon :size="20" />
</template>
{{ t('spreed', 'Reply privately') }}
</NcActionButton>
<NcActionButton icon="icon-external"
close-after-click
<NcActionButton close-after-click
@click.stop="handleCopyMessageText">
<template #icon>
<ContentCopy :size="20" />
</template>
{{ t('spreed', 'Copy formatted message') }}
</NcActionButton>
<NcActionButton close-after-click
@click.stop="handleCopyMessageLink">
<template #icon>
<OpenInNewIcon :size="20" />
</template>
{{ t('spreed', 'Copy message link') }}
</NcActionButton>
<NcActionButton close-after-click
Expand Down Expand Up @@ -127,9 +138,11 @@
</NcActionButton>
<template v-if="isDeleteable">
<NcActionSeparator />
<NcActionButton icon="icon-delete"
close-after-click
<NcActionButton close-after-click
@click.stop="handleDelete">
<template #icon>
<DeleteIcon :size="16" />
</template>
{{ t('spreed', 'Delete') }}
</NcActionButton>
</template>
Expand Down Expand Up @@ -230,16 +243,20 @@
import { frequently, EmojiIndex as EmojiIndexFactory } from 'emoji-mart-vue-fast'
import data from 'emoji-mart-vue-fast/data/all.json'

import AccountIcon from 'vue-material-design-icons/Account.vue'
import AlarmIcon from 'vue-material-design-icons/Alarm.vue'
import ArrowLeft from 'vue-material-design-icons/ArrowLeft.vue'
import CalendarClock from 'vue-material-design-icons/CalendarClock.vue'
import Check from 'vue-material-design-icons/Check.vue'
import CheckAll from 'vue-material-design-icons/CheckAll.vue'
import ClockOutline from 'vue-material-design-icons/ClockOutline.vue'
import CloseCircleOutline from 'vue-material-design-icons/CloseCircleOutline.vue'
import ContentCopy from 'vue-material-design-icons/ContentCopy.vue'
import DeleteIcon from 'vue-material-design-icons/Delete.vue'
import EmoticonOutline from 'vue-material-design-icons/EmoticonOutline.vue'
import EyeOffOutline from 'vue-material-design-icons/EyeOffOutline.vue'
import File from 'vue-material-design-icons/File.vue'
import OpenInNewIcon from 'vue-material-design-icons/OpenInNew.vue'
import Plus from 'vue-material-design-icons/Plus.vue'
import Reply from 'vue-material-design-icons/Reply.vue'
import Share from 'vue-material-design-icons/Share.vue'
Expand Down Expand Up @@ -281,16 +298,20 @@ export default {
NcButton,
NcEmojiPicker,
// Icons
AccountIcon,
AlarmIcon,
ArrowLeft,
CalendarClock,
CloseCircleOutline,
Check,
CheckAll,
ClockOutline,
ContentCopy,
DeleteIcon,
EmoticonOutline,
EyeOffOutline,
File,
OpenInNewIcon,
Plus,
Reply,
Share,
Expand Down Expand Up @@ -599,6 +620,25 @@ export default {
this.$router.push({ name: 'conversation', params: { token: conversation.token } }).catch(err => console.debug(`Error while pushing the new conversation's route: ${err}`))
},

async handleCopyMessageText() {
let parsedText = this.messageObject.message

for (const [key, value] of Object.entries(this.messageObject.messageParameters)) {
if (value?.type === 'call') {
parsedText = parsedText.replace(new RegExp(`{${key}}`, 'g'), '@all')
} else if (value?.type === 'user') {
parsedText = parsedText.replace(new RegExp(`{${key}}`, 'g'), `@${value.id}`)
}
}

try {
await navigator.clipboard.writeText(parsedText)
showSuccess(t('spreed', 'Message text copied to clipboard'))
} catch (error) {
showError(t('spreed', 'Message text could not be copied'))
}
},

handleCopyMessageLink() {
copyConversationLinkToClipboard(this.token, this.id)
},
Expand Down