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

[stable3.4] fix(composer): forward messages as attachments #8874

Merged
merged 1 commit into from
Sep 19, 2023
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
19 changes: 6 additions & 13 deletions src/components/Composer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,6 @@
<script>
import debounce from 'lodash/fp/debounce'
import uniqBy from 'lodash/fp/uniqBy'
import isArray from 'lodash/fp/isArray'
import trimStart from 'lodash/fp/trimCharsStart'
import Autosize from 'vue-autosize'
import debouncePromise from 'debounce-promise'
Expand Down Expand Up @@ -910,29 +909,23 @@ export default {
})
})
}

// Add messages forwarded as attachments
let forwards = []
if (this.forwardedMessages && !isArray(this.forwardedMessages)) {
forwards = [this.forwardedMessages]
} else if (this.forwardedMessages && isArray(this.forwardedMessages)) {
forwards = this.forwardedMessages
}
forwards.forEach(id => {
for (const id of this.forwardedMessages) {
const env = this.$store.getters.getEnvelope(id)
if (!env) {
// TODO: also happens when the composer page is reloaded
showError(t('mail', 'Message {id} could not be found', {
id,
}))
return
continue
}

this.attachments.push({
displayName: env.subject + '.eml',
this.bus.$emit('on-add-message-as-attachment', {
id,
type: 'message',
fileName: env.subject + '.eml',
})
})
}

// Set custom date and time picker value if initialized with custom send at value
if (this.sendAt && this.isSendAtCustom) {
Expand Down
9 changes: 8 additions & 1 deletion src/components/ComposerAttachment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<span v-if="attachment.type === 'cloud'" class="cloud-attachment-icon">
<Cloud :size="16" />
</span>
<span v-else-if="attachment.type === 'message'">
<EmailArrowRightOutlineIcon />
</span>
</div>
<div class="attachment-inner">
<span class="new-message-attachment-name">
Expand All @@ -15,7 +18,9 @@
<span v-if="!attachment.finished" class="attachments-upload-progress">
<span class="attachments-upload-progress--bar" :style="&quot;width:&quot; + attachment.percent + &quot;%&quot;" />
</span>
<span v-else class="new-message-attachment-size">{{ attachment.sizeString }}</span>
<span v-else-if="attachment.sizeString" class="new-message-attachment-size">
{{ attachment.sizeString }}
</span>
</div>
<button @click="onDelete(attachment)">
<Close :size="24" />
Expand All @@ -27,12 +32,14 @@
import { generateUrl } from '@nextcloud/router'
import Close from 'vue-material-design-icons/Close'
import Cloud from 'vue-material-design-icons/Cloud'
import EmailArrowRightOutlineIcon from 'vue-material-design-icons/EmailArrowRightOutline.vue'

export default {
name: 'ComposerAttachment',
components: {
Close,
Cloud,
EmailArrowRightOutlineIcon,
},
props: {
bus: {
Expand Down
21 changes: 21 additions & 0 deletions src/components/ComposerAttachments.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- @copyright 2020 Gary Kim <[email protected]>
-
- @author 2018 Christoph Wurst <[email protected]>
- @author Richard Steinmetz <[email protected]>
-
- @license AGPL-3.0-or-later
-
Expand Down Expand Up @@ -166,6 +167,7 @@ export default {
this.bus.$on('on-add-local-attachment', this.onAddLocalAttachment)
this.bus.$on('on-add-cloud-attachment', this.onAddCloudAttachment)
this.bus.$on('on-add-cloud-attachment-link', this.onAddCloudAttachmentLink)
this.bus.$on('on-add-message-as-attachment', this.onAddMessageAsAttachment)
this.value.map(attachment => {
this.attachments.push({
id: attachment.id,
Expand Down Expand Up @@ -341,6 +343,25 @@ export default {
logger.error('could not choose a file as attachment link', { error })
}
},
/**
* Add a forwarded message as an attachment
*
* @param {object} data Payload
* @param {number} data.id Database id of the message to forward as an attachment
* @param {string} data.fileName File name of the attachment
*/
onAddMessageAsAttachment({ id, fileName }) {
const attachment = {
type: 'message',
id,
fileName,
}
this.attachments.push({
...attachment,
finished: true,
})
this.emitNewAttachments([attachment])
},
showAttachmentFileSizeWarning(num) {
showWarning(n(
'mail',
Expand Down
4 changes: 2 additions & 2 deletions src/components/EnvelopeList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,8 @@ export default {
this.showTagModal = false
},
async forwardSelectedAsAttachment() {
await this.$store.dispatch('showMessageComposer', {
forwardedMessages: this.selection,
await this.$store.dispatch('startComposerSession', {
forwardedMessages: [...this.selection],
})
this.unselectAll()
},
Expand Down
5 changes: 2 additions & 3 deletions src/components/MenuEnvelope.vue
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,8 @@ export default {
this.$emit('update:selected')
},
async forwardSelectedAsAttachment() {
this.forwardedMessages = [this.envelope.databaseId]
await this.$store.dispatch('showMessageComposer', {
forwardedMessages: this.forwardedMessages,
await this.$store.dispatch('startComposerSession', {
forwardedMessages: [this.envelope.databaseId],
})
},
async onShowSourceModal() {
Expand Down