From 50524c2ea20abc0cb55f4a07f6206eb692b933ee Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Wed, 6 Apr 2022 14:30:04 +0200 Subject: Pipe all composer data through the Vuex store Signed-off-by: Christoph Wurst --- src/store/actions.js | 36 +++++++++++++++++++++++++++++++++++- src/store/getters.js | 5 ++++- src/store/mutations.js | 5 +++-- 3 files changed, 42 insertions(+), 4 deletions(-) (limited to 'src/store') diff --git a/src/store/actions.js b/src/store/actions.js index e18243545..8c5180d1f 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -82,6 +82,11 @@ import { updateAccount as updateSieveAccount } from '../service/SieveService' import { PAGE_SIZE, UNIFIED_INBOX_ID } from './constants' import * as ThreadService from '../service/ThreadService' import { getPrioritySearchQueries } from '../util/priorityInbox' +import { html, plain } from '../util/text' +import Axios from '@nextcloud/axios' +import { generateUrl } from '@nextcloud/router' +import { showWarning } from '@nextcloud/dialogs' +import { translate as t } from '@nextcloud/l10n' const sliceToPage = slice(0, PAGE_SIZE) @@ -253,8 +258,37 @@ export default { updated, }) }, - async showMessageComposer({ commit }, { forwardedMessages = [], templateMessageId = undefined }) { + async showMessageComposer({ commit, dispatch }, { type = 'imap', data = {}, forwardedMessages = [], templateMessageId }) { + if (templateMessageId) { + const message = await dispatch('fetchMessage', templateMessageId) + // Merge the original into any existing data + data = { + ...data, + message, + } + + // Fetch and transform the body into a rich text object + if (message.hasHtmlBody) { + const resp = await Axios.get( + generateUrl('/apps/mail/api/messages/{id}/html?plain=true', { + id: templateMessageId, + }) + ) + + data.body = html(resp.data) + } else { + data.body = plain(message.body) + } + + // TODO: implement attachments + if (message.attachments.length) { + showWarning(t('mail', 'Attachments were not copied. Please add them manually.')) + } + } + commit('showMessageComposer', { + type, + data, forwardedMessages, templateMessageId, }) diff --git a/src/store/getters.js b/src/store/getters.js index 5c87d45c7..255c65fa1 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -57,7 +57,10 @@ export const getters = { showMessageComposer: (state) => { return state.newMessage !== undefined }, - messageComposerOptions: (state) => { + composerMessage: (state) => { + return state.newMessage + }, + composerMessageOptions: (state) => { return state.newMessage?.options }, getEnvelope: (state) => (id) => { diff --git a/src/store/mutations.js b/src/store/mutations.js index ff9c8efc0..9bb71337e 100644 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -174,11 +174,12 @@ export default { } removeRec(account) }, - showMessageComposer(state, { forwardedMessages, templateMessageId }) { + showMessageComposer(state, { type, data, forwardedMessages }) { Vue.set(state, 'newMessage', { + type, + data, options: { forwardedMessages, - templateMessageId, }, }) }, -- cgit v1.2.3