Skip to content

Commit

Permalink
fixup! feat(TranslationModal): add translation for html messages
Browse files Browse the repository at this point in the history
Signed-off-by: Grigory Vodyanov <[email protected]>
  • Loading branch information
GVodyanov committed Dec 15, 2024
1 parent 98e23d6 commit b106db5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/components/ThreadEnvelope.vue
Original file line number Diff line number Diff line change
Expand Up @@ -880,9 +880,8 @@ export default {
})
},
async handleHtmlBodyMessages() {
console.log('message', this.message)
if (this.message.isHtml) {
const message = await getPlainText(this.message.id)
if (this.message.hasHtmlBody) {
const message = await getPlainText(this.message.databaseId)
this.plainTextBody = message.body
} else {
this.plainTextBody = this.message.body
Expand Down
7 changes: 5 additions & 2 deletions src/components/TranslationModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,6 @@ export default {
},

async mounted() {
await this.handleHtmlBodyMessages()

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

if (this.selectedTo) {
Expand All @@ -204,6 +202,11 @@ export default {
methods: {
t,
handleTranslate() {
if (!this.selectedFrom || !this.selectedTo) {
showError(t('mail', 'Please select languages to translate to and from'))
return
}

this.translateMessage(this.selectedFrom?.id)
},

Expand Down
7 changes: 4 additions & 3 deletions src/service/plainTextService.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import { generateUrl } from '@nextcloud/router'
import { convertAxiosError } from '../errors/convert.js'

export async function getPlainText(id) {
const url = generateUrl('/apps/mail/api/messages', {
const url = generateUrl('/apps/mail/api/messages/{id}/body?plain=true', {
id,
plain: true,
})

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

return response.data
}

0 comments on commit b106db5

Please sign in to comment.