Skip to content

Commit

Permalink
feat(TranslationModal): add translation for html messages
Browse files Browse the repository at this point in the history
Signed-off-by: Grigory V <scratchx@gmx.com>
  • Loading branch information
GVodyanov committed Dec 14, 2024
1 parent 2a75349 commit 98e23d6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 11 deletions.
7 changes: 1 addition & 6 deletions src/components/MenuEnvelope.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
</template>
{{ t('mail', 'Unsnooze') }}
</ActionButton>
<ActionButton v-if="!isHtml"
<ActionButton
:close-after-click="true"
@click.prevent="$emit('open-translation-modal')">
<template #icon>
Expand Down Expand Up @@ -310,11 +310,6 @@ export default {
type: Boolean,
default: true,
},
isHtml: {
// Indicates if the envelope is HTML
type: Boolean,
default: false,
},
},
data() {
return {
Expand Down
18 changes: 15 additions & 3 deletions src/components/ThreadEnvelope.vue
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@
:with-select="false"
:with-show-source="true"
:more-actions-open.sync="moreActionsOpen"
:is-html="false"
@reply="onReply"
@delete="$emit('delete',envelope.databaseId)"
@show-source-modal="onShowSourceModal"
Expand Down Expand Up @@ -221,7 +220,7 @@
@close="onCloseTagModal" />
<TranslationModal v-if="showTranslationModal"
:rich-parameters="{}"
:message="message.body"
:message="plainTextBody"
@close="onCloseTranslationModal" />
</template>
</div>
Expand Down Expand Up @@ -315,6 +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'

// Ternary loading state
const LOADING_DONE = 0
Expand Down Expand Up @@ -408,6 +408,7 @@ export default {
showTaskModal: false,
showTagModal: false,
showTranslationModal: false,
plainTextBody: '',
rawMessage: '', // Will hold the raw source of the message when requested
isInternal: true,
enabledSmartReply: loadState('mail', 'llm_freeprompt_available', false),
Expand Down Expand Up @@ -874,7 +875,18 @@ export default {
this.showTagModal = false
},
onOpenTranslationModal() {
this.showTranslationModal = true
this.handleHtmlBodyMessages().then(() => {
this.showTranslationModal = true
})
},
async handleHtmlBodyMessages() {

Check failure on line 882 in src/components/ThreadEnvelope.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected console statement
console.log('message', this.message)
if (this.message.isHtml) {
const message = await getPlainText(this.message.id)
this.plainTextBody = message.body
} else {
this.plainTextBody = this.message.body
}
},
onCloseTranslationModal() {
this.showTranslationModal = false
Expand Down
6 changes: 4 additions & 2 deletions src/components/TranslationModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,13 @@ export default {
this.availableLanguages = response.data.ocs.data.languages
},

mounted() {
async mounted() {
await this.handleHtmlBodyMessages()

this.selectedTo = this.optionsTo.find(language => language.id === this.userLanguage) || null

if (this.selectedTo) {
this.translateMessage()
await this.translateMessage()
}

this.$nextTick(() => {
Expand Down
19 changes: 19 additions & 0 deletions src/service/plainTextService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* 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,
plain: true,
})

return await axios.get(url).catch((error) => {
throw convertAxiosError(error)
})
}

0 comments on commit 98e23d6

Please sign in to comment.