2024-07-07 22:11:18 +02:00
|
|
|
import * as React from "bloatless-react";
|
|
|
|
|
|
2024-07-09 14:11:20 +02:00
|
|
|
import { Chat, ChatMessage } from "../Model/chatModel";
|
2024-07-08 12:34:37 +02:00
|
|
|
|
|
|
|
|
import { translation } from "../translations";
|
2024-07-07 22:11:18 +02:00
|
|
|
|
2024-07-09 14:28:13 +02:00
|
|
|
export function ThreadView(chat: Chat) {
|
|
|
|
|
const messageConverter: React.ListItemConverter<ChatMessage> = (message) => {
|
|
|
|
|
function copyMessage() {
|
|
|
|
|
navigator.clipboard.writeText(message.body);
|
|
|
|
|
}
|
2024-07-08 12:50:54 +02:00
|
|
|
|
2024-07-09 14:28:13 +02:00
|
|
|
function decrypt() {
|
|
|
|
|
chat.decryptReceivedMessage(message);
|
|
|
|
|
}
|
2024-07-08 12:34:37 +02:00
|
|
|
|
2024-07-09 14:28:13 +02:00
|
|
|
function remove() {
|
|
|
|
|
chat.deleteMessage(message);
|
|
|
|
|
}
|
2024-07-08 12:50:54 +02:00
|
|
|
|
2024-07-09 17:38:50 +02:00
|
|
|
const messageBody = React.createProxyState(
|
|
|
|
|
[chat.messages],
|
|
|
|
|
() => message.body
|
|
|
|
|
);
|
|
|
|
|
|
2024-07-09 14:28:13 +02:00
|
|
|
return (
|
|
|
|
|
<div class="tile width-100 flex-no padding-0">
|
|
|
|
|
<div class="flex-column">
|
|
|
|
|
<div class="flex-row justify-apart align-center secondary">
|
|
|
|
|
<span class="padding-h ellipsis">
|
|
|
|
|
<b class="info">{message.sender}</b> - {message.channel}
|
|
|
|
|
</span>
|
|
|
|
|
<span class="flex-row">
|
|
|
|
|
<button
|
|
|
|
|
aria-label={translation.copyMessage}
|
|
|
|
|
on:click={copyMessage}
|
|
|
|
|
>
|
|
|
|
|
<span class="icon">content_copy</span>
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
|
|
|
|
aria-label={translation.decryptMessage}
|
|
|
|
|
on:click={decrypt}
|
|
|
|
|
>
|
|
|
|
|
<span class="icon">key</span>
|
|
|
|
|
</button>
|
|
|
|
|
<button aria-label={translation.deleteMessage} on:click={remove}>
|
|
|
|
|
<span class="icon">delete</span>
|
|
|
|
|
</button>
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="flex-column padding-h padding-bottom">
|
2024-07-09 17:38:50 +02:00
|
|
|
<b class="break-word" subscribe:innerText={messageBody}></b>
|
2024-07-09 14:28:13 +02:00
|
|
|
<span class="secondary">
|
|
|
|
|
{new Date(message.isoDate).toLocaleString()}
|
|
|
|
|
</span>
|
2024-07-09 14:11:20 +02:00
|
|
|
</div>
|
2024-07-08 12:34:37 +02:00
|
|
|
</div>
|
2024-07-09 14:28:13 +02:00
|
|
|
</div>
|
2024-07-09 14:11:20 +02:00
|
|
|
);
|
2024-07-09 14:28:13 +02:00
|
|
|
};
|
|
|
|
|
|
2024-07-09 18:21:28 +02:00
|
|
|
const listElement = (
|
2024-07-09 14:28:13 +02:00
|
|
|
<div
|
|
|
|
|
class="flex-column gap"
|
|
|
|
|
children:append={[chat.messages, messageConverter]}
|
|
|
|
|
></div>
|
|
|
|
|
);
|
2024-07-09 18:35:48 +02:00
|
|
|
chat.messages.handleAddition(() => {
|
|
|
|
|
const scrollFromBottom =
|
|
|
|
|
listElement.scrollHeight -
|
|
|
|
|
(listElement.scrollTop + listElement.offsetHeight);
|
|
|
|
|
if (scrollFromBottom > 400) return;
|
2024-07-09 18:58:05 +02:00
|
|
|
|
2024-07-09 18:35:48 +02:00
|
|
|
listElement.scrollTop = listElement.scrollHeight;
|
|
|
|
|
});
|
2024-07-09 18:58:05 +02:00
|
|
|
setTimeout(() => (listElement.scrollTop = listElement.scrollHeight), 50);
|
2024-07-09 18:21:28 +02:00
|
|
|
return listElement;
|
2024-07-07 22:11:18 +02:00
|
|
|
}
|