147 lines
3.7 KiB
Vue
147 lines
3.7 KiB
Vue
<script setup lang="ts">
|
|
import { defineProps, onMounted, ref, watch, PropType, Prop } from "vue";
|
|
import { decodeEmojis } from "../../utils/string";
|
|
import { removeDuplicates } from "../../utils/array";
|
|
import DOMPurify from "dompurify";
|
|
import { Address, Message } from "@/store/models/model";
|
|
|
|
const props = defineProps({
|
|
msg: Object as PropType<Message>,
|
|
members: Array as PropType<Address[]>,
|
|
});
|
|
const iframe = ref<HTMLIFrameElement>();
|
|
|
|
// todo dompurify
|
|
// background vs color
|
|
const htmlDefault = (html: string) => {
|
|
return `
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Document</title>
|
|
</head>
|
|
<body style="margin: 0;">
|
|
${html}
|
|
</body>
|
|
</html>
|
|
`;
|
|
};
|
|
|
|
function setIframeContent(content: string | undefined) {
|
|
if (!iframe.value) return;
|
|
if (!content) return;
|
|
const doc = iframe.value.contentDocument || iframe.value.contentWindow?.document;
|
|
if (!doc) return;
|
|
const html = DOMPurify.sanitize(content);
|
|
doc.open();
|
|
doc.write(htmlDefault(html));
|
|
doc.close();
|
|
}
|
|
|
|
watch(
|
|
() => props.msg,
|
|
(newData: Message | undefined) => {
|
|
setIframeContent(newData?.content);
|
|
},
|
|
);
|
|
|
|
onMounted(() => {
|
|
setIframeContent(props.msg?.content);
|
|
});
|
|
|
|
const displayAddresses = (addressIds: string[] | undefined): string => {
|
|
if (!addressIds) return "";
|
|
addressIds = removeDuplicates(addressIds);
|
|
let res = "";
|
|
addressIds.forEach((addressId) => {
|
|
const address = props.members?.find((member) => member.id === parseInt(addressId));
|
|
if (address) res += address.email;
|
|
});
|
|
return res;
|
|
};
|
|
</script>
|
|
<!-- to if to is more than me
|
|
cc -->
|
|
<!-- object (channel only)
|
|
content
|
|
attachments -->
|
|
<template>
|
|
<div class="message">
|
|
<div id="context">
|
|
<div class="left" id="profile">
|
|
{{ displayAddresses(props.msg?.fromA?.split(",")) }} - {{ props.msg?.fromA }}
|
|
</div>
|
|
<div class="middle">{{ decodeEmojis(props.msg?.subject) }}</div>
|
|
<div class="right" id="date">
|
|
{{
|
|
new Date(props.msg?.date ?? "").toLocaleString("en-GB", {
|
|
weekday: "short",
|
|
year: "numeric",
|
|
month: "2-digit",
|
|
day: "2-digit",
|
|
hour: "2-digit",
|
|
minute: "2-digit",
|
|
timeZone: "Europe/Paris",
|
|
})
|
|
}}
|
|
</div>
|
|
</div>
|
|
<div class="content">
|
|
<iframe ref="iframe"></iframe>
|
|
<div class="options">options</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.message {
|
|
width: auto;
|
|
/* border: white 1px solid; */
|
|
margin: 10px 5px 0px 5px;
|
|
}
|
|
|
|
#context {
|
|
display: flex;
|
|
flex-direction: row;
|
|
justify-content: space-between;
|
|
background-color: var(--quaternary-background);
|
|
padding: 3px 10px;
|
|
border-radius: 4px 4px 0 0;
|
|
}
|
|
|
|
.left,
|
|
.right {
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.middle {
|
|
margin: 0 10px;
|
|
text-align: center;
|
|
}
|
|
|
|
.content {
|
|
display: flex;
|
|
padding-top: 6px;
|
|
flex-direction: row;
|
|
/* background-color: #ec7a4342;
|
|
background-color: #353c6261; */
|
|
}
|
|
|
|
iframe {
|
|
overflow-y: auto;
|
|
max-height: 300px;
|
|
flex-basis: 100%;
|
|
border: none;
|
|
max-width: 600px; /* template width being 600px to 640px up to 750px (experiment and test) */
|
|
background-color: rgb(234, 234, 234);
|
|
}
|
|
|
|
.options {
|
|
flex: 1;
|
|
text-align: center;
|
|
}
|
|
</style>
|