diff --git a/src/components/ThreadEnvelope.vue b/src/components/ThreadEnvelope.vue index 4492acbdff..bdc4963cdc 100644 --- a/src/components/ThreadEnvelope.vue +++ b/src/components/ThreadEnvelope.vue @@ -314,7 +314,7 @@ import { mapStores } from 'pinia' import moment from '@nextcloud/moment' import { translateTagDisplayName } from '../util/tag.js' import { FOLLOW_UP_TAG_LABEL } from '../store/constants.js' -import { getPlainText } from '../service/plainTextService.js' +import { Text, toPlain } from '../util/text.js' // Ternary loading state const LOADING_DONE = 0 @@ -881,8 +881,9 @@ export default { }, async handleHtmlBodyMessages() { if (this.message.hasHtmlBody) { - const message = await getPlainText(this.message.databaseId) - this.plainTextBody = message.body + let text = new Text('html', this.message.body) + text = toPlain(text) + this.plainTextBody = text.value } else { this.plainTextBody = this.message.body } diff --git a/src/components/TranslationModal.vue b/src/components/TranslationModal.vue index d23be84f50..8223f1bce8 100644 --- a/src/components/TranslationModal.vue +++ b/src/components/TranslationModal.vue @@ -44,12 +44,14 @@ @@ -213,7 +215,7 @@ export default { async translateMessage(sourceLanguage = null) { try { this.isLoading = true - const response = await translateText(this.message, sourceLanguage, this.selectedTo?.id) + const response = await translateText(this.message.trim(), sourceLanguage, this.selectedTo?.id) this.translatedMessage = response.data.ocs.data.text } catch (error) { console.error(error) diff --git a/src/service/plainTextService.js b/src/service/plainTextService.js deleted file mode 100644 index 87f85d821a..0000000000 --- a/src/service/plainTextService.js +++ /dev/null @@ -1,20 +0,0 @@ -/** - * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -import axios from '@nextcloud/axios' -import { generateUrl } from '@nextcloud/router' -import { convertAxiosError } from '../errors/convert.js' - -export async function getPlainText(id) { - const url = generateUrl('/apps/mail/api/messages/{id}/body?plain=true', { - id, - }) - - const response = await axios.get(url).catch((error) => { - throw convertAxiosError(error) - }) - - return response.data -} diff --git a/src/util/text.js b/src/util/text.js index 5d32878a40..fb4f86cef6 100644 --- a/src/util/text.js +++ b/src/util/text.js @@ -10,7 +10,7 @@ import { convert } from 'html-to-text' /** * @type {Text} */ -class Text { +export class Text { constructor(format, value) { this.format = format