diff --git a/prodServer.ts b/prodServer.ts index 1e75030..edcfa71 100644 --- a/prodServer.ts +++ b/prodServer.ts @@ -25,6 +25,7 @@ io.on('connection', async (socket) => { const sender = authdb.getUser(msg.id); io!.emit('message', { user: sender.username, + uid: msg.id, message: msg.content, imageSrc: sender.image, channel: msg.channel, diff --git a/src/lib/components/message.svelte b/src/lib/components/message.svelte index 1bcf207..0331006 100644 --- a/src/lib/components/message.svelte +++ b/src/lib/components/message.svelte @@ -2,33 +2,58 @@ import { type TypeMessage } from '$lib/types'; import Prose from '$lib/components/prose.svelte'; import renderMarkdown from '$lib/functions/renderMarkdown'; - const { message, imageSrc, user, timestamp }: TypeMessage = $props(); + import * as ContextMenu from '$lib/components/ui/context-menu'; + + const { message, imageSrc, user, timestamp, uid }: TypeMessage = $props(); + let epoch: number = Math.floor(timestamp.getTime() / 1000); + + function copy(itemName: string, content: string | number) { + navigator.clipboard + .writeText(content as string) + .then(() => { + console.info(`Successfully copied ${itemName} to clipboard`); + // dispatchToast('Successfully copied to clipboard.', true); + }) + .catch((e) => { + console.error(`Error copying ${itemName}: ${(e as Error).message}`); + // dispatchToast('Copying failed. (See console)', false); + }); + } -
-
-
- Profile image for {user} + + +
+
+ Profile image for {user} +
-
-
-

- {user} - · - {timestamp.toLocaleDateString('en-US', { - year: 'numeric', - month: 'short', - day: 'numeric', - hour12: true, - hour: 'numeric', - minute: 'numeric', - })} -

- {@html renderMarkdown(message)} -
-
+
+

+ {user} + · + {timestamp.toLocaleDateString('en-US', { + year: 'numeric', + month: 'short', + day: 'numeric', + hour12: true, + hour: 'numeric', + minute: 'numeric', + })} +

+ {@html renderMarkdown(message)} +
+ + + copy('username', user)}>Copy Username + copy('user ID', uid)}>Copy User ID + + copy('message', message)}>Copy message content + copy('timestamp', epoch)}>Copy message epoch + +