refactor: use mail object
Signed-off-by: Sebastian <krupinski01@gmail.com>
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { useUser } from '@KTXC'
|
||||
import type { EntityObject } from '@MailManager/models'
|
||||
import { MessageObject } from '@MailManager/models/message'
|
||||
import type { EntityObject, MessageObject } from '@MailManager/models'
|
||||
import { SecurityLevel } from '@/utile/emailSanitizer'
|
||||
import ReaderEmpty from './reader/ReaderEmpty.vue'
|
||||
import ReaderToolbar from './reader/ReaderToolbar.vue'
|
||||
@@ -10,46 +9,34 @@ import ReaderHeader from './reader/ReaderHeader.vue'
|
||||
import ReaderBody from './reader/ReaderBody.vue'
|
||||
|
||||
// Props
|
||||
interface Props {
|
||||
message?: EntityObject | null
|
||||
}
|
||||
const props = defineProps<{
|
||||
entity: EntityObject | null
|
||||
}>()
|
||||
|
||||
const props = defineProps<Props>()
|
||||
// Emits
|
||||
const emit = defineEmits<{
|
||||
reply: [entity: EntityObject]
|
||||
forward: [entity: EntityObject]
|
||||
move: [entity: EntityObject]
|
||||
delete: [entity: EntityObject]
|
||||
flag: [entity: EntityObject]
|
||||
compose: []
|
||||
}>()
|
||||
|
||||
// User settings
|
||||
const { getSetting } = useUser()
|
||||
|
||||
// Emits
|
||||
const emit = defineEmits<{
|
||||
reply: [message: EntityObject]
|
||||
forward: [message: EntityObject]
|
||||
move: [message: EntityObject]
|
||||
delete: [message: EntityObject]
|
||||
flag: [message: EntityObject]
|
||||
compose: []
|
||||
}>()
|
||||
// Per-message overrides
|
||||
const allowImages = ref(false)
|
||||
const overrideSecurityLevel = ref<SecurityLevel | null>(null)
|
||||
|
||||
// Computed
|
||||
const hasMessage = computed(() => !!props.message)
|
||||
|
||||
const messageInstance = computed(() => {
|
||||
if (!props.message) return null
|
||||
return new MessageObject(props.message.properties)
|
||||
})
|
||||
|
||||
const messageBody = computed(() => {
|
||||
if (!messageInstance.value) return ''
|
||||
|
||||
const htmlContent = messageInstance.value.getHtmlContent()
|
||||
if (htmlContent) return htmlContent
|
||||
|
||||
const textContent = messageInstance.value.getTextContent()
|
||||
return textContent || ''
|
||||
const message = computed<MessageObject | null>(() => {
|
||||
return props.entity?.properties ?? null
|
||||
})
|
||||
|
||||
const isHtml = computed(() => {
|
||||
if (!messageInstance.value) return false
|
||||
return messageInstance.value.hasHtmlContent()
|
||||
return message.value?.hasHtmlContent() ?? false
|
||||
})
|
||||
|
||||
// Security preferences from user settings
|
||||
@@ -61,17 +48,13 @@ const allowImagesDefault = computed(() => {
|
||||
return getSetting('mail.security.allowImagesDefault') as boolean || false
|
||||
})
|
||||
|
||||
// Per-message overrides
|
||||
const allowImages = ref(false)
|
||||
const overrideSecurityLevel = ref<SecurityLevel | null>(null)
|
||||
|
||||
// Computed effective security level (use override if set, otherwise default)
|
||||
const effectiveSecurityLevel = computed(() => {
|
||||
return overrideSecurityLevel.value ?? securityLevel.value
|
||||
})
|
||||
|
||||
// Reset overrides when message changes
|
||||
watch(() => props.message, () => {
|
||||
watch(() => props.entity, () => {
|
||||
allowImages.value = allowImagesDefault.value
|
||||
overrideSecurityLevel.value = null
|
||||
})
|
||||
@@ -88,32 +71,32 @@ const setSecurityLevel = (level: SecurityLevel) => {
|
||||
|
||||
// Handlers
|
||||
const handleReply = () => {
|
||||
if (props.message) {
|
||||
emit('reply', props.message)
|
||||
if (props.entity) {
|
||||
emit('reply', props.entity)
|
||||
}
|
||||
}
|
||||
|
||||
const handleForward = () => {
|
||||
if (props.message) {
|
||||
emit('forward', props.message)
|
||||
if (props.entity) {
|
||||
emit('forward', props.entity)
|
||||
}
|
||||
}
|
||||
|
||||
const handleDelete = () => {
|
||||
if (props.message) {
|
||||
emit('delete', props.message)
|
||||
if (props.entity) {
|
||||
emit('delete', props.entity)
|
||||
}
|
||||
}
|
||||
|
||||
const handleMove = () => {
|
||||
if (props.message) {
|
||||
emit('move', props.message)
|
||||
if (props.entity) {
|
||||
emit('move', props.entity)
|
||||
}
|
||||
}
|
||||
|
||||
const handleFlag = () => {
|
||||
if (props.message) {
|
||||
emit('flag', props.message)
|
||||
if (props.entity) {
|
||||
emit('flag', props.entity)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,14 +109,13 @@ const handleCompose = () => {
|
||||
<div class="message-reader">
|
||||
<!-- Empty state -->
|
||||
<ReaderEmpty
|
||||
v-if="!hasMessage"
|
||||
v-if="!message"
|
||||
@compose="handleCompose"
|
||||
/>
|
||||
|
||||
<!-- Message viewer -->
|
||||
<template v-else>
|
||||
<ReaderToolbar
|
||||
:message="message!"
|
||||
:is-html="isHtml"
|
||||
:allow-images="allowImages"
|
||||
:security-level="effectiveSecurityLevel"
|
||||
@@ -149,13 +131,12 @@ const handleCompose = () => {
|
||||
|
||||
<!-- Message content -->
|
||||
<div class="message-content">
|
||||
<ReaderHeader :message-instance="messageInstance!" />
|
||||
<ReaderHeader :message="message!" />
|
||||
|
||||
<v-divider />
|
||||
|
||||
<ReaderBody
|
||||
:message-body="messageBody"
|
||||
:is-html="isHtml"
|
||||
:message="message!"
|
||||
:security-level="effectiveSecurityLevel"
|
||||
:allow-images="allowImages"
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user