2022-04-24 20:14:04 +03:00
|
|
|
<script>
|
2022-09-01 19:56:19 +03:00
|
|
|
import { CornerUpLeftIcon, MoreVerticalIcon } from "svelte-feather-icons";
|
2022-09-03 17:30:39 +03:00
|
|
|
import { overlayStore, OverlayType, setMessageInputEvent, userInfoStore } from "../stores";
|
2022-04-26 23:15:49 +03:00
|
|
|
|
2022-04-24 20:14:04 +03:00
|
|
|
export let message;
|
2022-09-01 19:56:19 +03:00
|
|
|
|
|
|
|
const reply = () => {
|
|
|
|
let replyString = "";
|
|
|
|
const messageLines = message.content.split("\n");
|
|
|
|
|
|
|
|
messageLines.forEach(line => {
|
|
|
|
replyString += `> ${line}\n`;
|
|
|
|
});
|
|
|
|
|
2022-09-01 21:07:53 +03:00
|
|
|
replyString += `@${message.author_username}: `;
|
2022-09-01 19:56:19 +03:00
|
|
|
|
|
|
|
setMessageInputEvent.update(replyString);
|
|
|
|
};
|
2022-04-24 20:14:04 +03:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.message {
|
2022-04-26 23:44:06 +03:00
|
|
|
display: flex;
|
2022-08-02 22:35:53 +03:00
|
|
|
align-items: flex-start;
|
2022-08-31 16:12:54 +03:00
|
|
|
overflow-x: hidden;
|
2022-04-24 20:14:04 +03:00
|
|
|
word-break: break-all;
|
2022-09-01 20:49:55 +03:00
|
|
|
padding: var(--space-xxs) var(--space-xxs) var(--space-xxs) var(--space-normplus);
|
2022-04-24 20:14:04 +03:00
|
|
|
}
|
|
|
|
|
2022-09-01 20:10:27 +03:00
|
|
|
.message.pinged {
|
2022-09-01 22:40:31 +03:00
|
|
|
background-color: var(--background-color-2);
|
2022-09-01 20:10:27 +03:00
|
|
|
}
|
|
|
|
|
2022-04-26 23:15:49 +03:00
|
|
|
.message .edit-message {
|
|
|
|
visibility: hidden;
|
|
|
|
}
|
|
|
|
|
|
|
|
.message:hover {
|
2022-09-01 22:40:31 +03:00
|
|
|
background-color: var(--background-color-3);
|
2022-04-26 23:15:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
.message:hover .edit-message {
|
|
|
|
visibility: visible;
|
|
|
|
}
|
|
|
|
|
2022-04-24 20:14:04 +03:00
|
|
|
.message-content {
|
|
|
|
color: var(--foreground-color-2);
|
2022-05-07 16:50:04 +03:00
|
|
|
white-space: pre-wrap;
|
2022-04-24 20:14:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
.pending {
|
|
|
|
color: var(--foreground-color-3);
|
|
|
|
}
|
|
|
|
|
|
|
|
.author {
|
2022-04-26 23:44:06 +03:00
|
|
|
flex-shrink: 0;
|
2022-04-24 20:14:04 +03:00
|
|
|
font-weight: bold;
|
2022-04-26 23:44:06 +03:00
|
|
|
margin-right: var(--space-xs);
|
2022-04-24 20:14:04 +03:00
|
|
|
}
|
2022-04-26 23:15:49 +03:00
|
|
|
|
|
|
|
.edit-message {
|
2022-04-26 23:44:06 +03:00
|
|
|
flex-shrink: 0;
|
2022-04-26 23:15:49 +03:00
|
|
|
float: right;
|
|
|
|
}
|
2022-04-24 20:14:04 +03:00
|
|
|
</style>
|
|
|
|
|
2022-09-01 20:10:27 +03:00
|
|
|
<div class="message" class:pinged={ userInfoStore.value && message.content.includes(`@${userInfoStore.value.username}`) }>
|
2022-04-24 20:14:04 +03:00
|
|
|
<span class="author">{ message.author_username }</span>
|
|
|
|
<span class="message-content" class:pending={ message._isPending }>{ message.content }</span>
|
2022-09-01 19:56:19 +03:00
|
|
|
<button class="icon-button icon-button-auto edit-message" on:click="{ reply }" aria-label="Reply to Message">
|
|
|
|
<CornerUpLeftIcon />
|
|
|
|
</button>
|
2022-08-03 02:34:15 +03:00
|
|
|
{#if userInfoStore.value && (message.author_id === userInfoStore.value.id || userInfoStore.value.is_superuser)}
|
2022-09-03 17:30:39 +03:00
|
|
|
<button class="icon-button edit-message" on:click="{ () => overlayStore.push(OverlayType.EditMessage, { message }) }" aria-label="Edit Message">
|
2022-04-27 20:24:50 +03:00
|
|
|
<MoreVerticalIcon />
|
|
|
|
</button>
|
|
|
|
{/if}
|
2022-04-24 20:14:04 +03:00
|
|
|
</div>
|