fix blocked iframe when change room

This commit is contained in:
grimhilt 2023-04-05 15:46:17 +02:00
parent 41aabb868f
commit 8b4210914b

View File

@ -1,22 +1,17 @@
<script setup>
import { defineProps, onMounted, ref } from "vue";
import { defineProps, onMounted, ref, watch } from "vue";
import { decodeEmojis } from "../../utils/string";
import { removeDuplicates } from "../../utils/array";
import DOMPurify from "dompurify";
import store from "@/store/store";
const props = defineProps({ data: Object });
const date = new Date(props.data.date);
const iframe = ref(null);
onMounted(() => {
const doc = iframe.value.contentDocument || iframe.value.contentWindow.document;
const html = DOMPurify.sanitize(props.data.content);
doc.open();
// todo dompurify
// background vs color
doc.write(`
// todo dompurify
// background vs color
const htmlDefault = (html) => {
return `
<!DOCTYPE html>
<html lang="en">
<head>
@ -29,8 +24,26 @@ onMounted(() => {
${html}
</body>
</html>
`);
`;
};
function setIframeContent(content) {
const doc = iframe.value.contentDocument || iframe.value.contentWindow.document;
const html = DOMPurify.sanitize(content);
doc.open();
doc.write(htmlDefault(html));
doc.close();
}
watch(
() => props.data,
(newData) => {
setIframeContent(newData.content);
},
);
onMounted(() => {
setIframeContent(props.data.content);
});
const displayAddresses = (addressesId) => {
@ -58,7 +71,7 @@ const displayAddresses = (addressesId) => {
<div class="middle">{{ decodeEmojis(props.data.subject) }}</div>
<div class="right" id="date">
{{
date.toLocaleString("en-GB", {
new Date(props.data.date).toLocaleString("en-GB", {
weekday: "short",
year: "numeric",
month: "2-digit",