flotilla/src/app/components/ChatItem.svelte

75 lines
2.6 KiB
Svelte
Raw Normal View History

<script lang="ts">
import {onMount} from "svelte"
import {page} from "$app/stores"
2026-01-06 18:51:37 +00:00
import {remove, uniq, formatTimestamp} from "@welshman/lib"
import type {TrustedEvent} from "@welshman/util"
2025-11-20 23:12:16 +00:00
import {pubkey, loadMessagingRelayList} from "@welshman/app"
2024-11-14 18:53:13 +00:00
import {fade} from "@lib/transition"
import Link from "@lib/components/Link.svelte"
2024-10-11 23:18:05 +00:00
import ProfileName from "@app/components/ProfileName.svelte"
import ProfileCircle from "@app/components/ProfileCircle.svelte"
import ProfileCircles from "@app/components/ProfileCircles.svelte"
import {makeChatPath} from "@app/util/routes"
import {notifications} from "@app/util/notifications"
2025-02-04 00:37:14 +00:00
interface Props {
id: string
pubkeys: string[]
messages: TrustedEvent[]
[key: string]: any
}
const {...props}: Props = $props()
2025-02-04 00:37:14 +00:00
2026-01-06 18:51:37 +00:00
const others = uniq(remove($pubkey!, props.pubkeys))
2025-06-03 23:59:05 +00:00
const active = $derived($page.params.chat === props.id)
2025-02-04 00:37:14 +00:00
const path = makeChatPath(props.pubkeys)
onMount(() => {
for (const pk of others) {
2025-11-20 23:12:16 +00:00
loadMessagingRelayList(pk)
}
})
</script>
2025-02-04 00:37:14 +00:00
<Link class="flex flex-col justify-start gap-1" href={makeChatPath(props.pubkeys)}>
2024-10-25 00:25:28 +00:00
<div
2025-02-04 00:37:14 +00:00
class="cursor-pointer border-t border-solid border-base-100 px-6 py-2 transition-colors hover:bg-base-100 {props.class}"
2024-10-25 00:25:28 +00:00
class:bg-base-100={active}>
<div class="flex flex-col justify-start gap-1">
2024-11-14 18:53:13 +00:00
<div class="flex items-center justify-between gap-2">
2024-10-25 00:25:28 +00:00
<div class="flex min-w-0 items-center gap-2">
2025-01-17 23:01:05 +00:00
{#if others.length === 0}
2025-04-15 18:03:27 +00:00
<ProfileCircle pubkey={$pubkey!} size={5} />
2025-01-17 23:01:05 +00:00
Note to self
{:else if others.length === 1}
2024-10-25 00:25:28 +00:00
<ProfileCircle pubkey={others[0]} size={5} />
2024-10-11 23:18:05 +00:00
<ProfileName pubkey={others[0]} />
2024-10-25 00:25:28 +00:00
{:else}
<ProfileCircles pubkeys={others} size={5} />
<p class="overflow-hidden text-ellipsis whitespace-nowrap">
<ProfileName pubkey={others[0]} />
and {others.length - 1}
{others.length > 2 ? "others" : "other"}
</p>
{/if}
</div>
2024-12-16 19:24:10 +00:00
{#if !active && $notifications.has(path)}
2025-02-03 23:01:42 +00:00
<div class="h-2 w-2 rounded-full bg-primary" transition:fade></div>
2024-11-14 18:53:13 +00:00
{/if}
</div>
2024-10-25 00:25:28 +00:00
<p class="overflow-hidden text-ellipsis whitespace-nowrap text-sm">
2025-12-01 19:09:26 +00:00
<span class="opacity-70">
{#if props.messages[0].pubkey === $pubkey}
You:
{/if}
</span>
2025-02-04 00:37:14 +00:00
{props.messages[0].content}
2024-10-25 00:25:28 +00:00
</p>
2025-12-01 19:09:26 +00:00
<p class="text-xs opacity-70">
{formatTimestamp(props.messages[0].created_at)}
</p>
</div>
2024-10-25 00:25:28 +00:00
</div>
</Link>