flotilla/src/app/components/ChatItem.svelte

81 lines
2.7 KiB
Svelte
Raw Normal View History

<script lang="ts">
import {onMount} from "svelte"
import cx from "classnames"
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"
2026-03-23 21:21:04 +00:00
import Button from "@lib/components/Button.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"
2026-06-08 21:14:40 +00:00
import {makeChatPath, goToChat} from "@app/routes"
import {notifications} from "@app/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)
2026-03-23 21:21:04 +00:00
const openChat = () => goToChat(props.pubkeys)
onMount(() => {
for (const pk of others) {
2025-11-20 23:12:16 +00:00
loadMessagingRelayList(pk)
}
})
</script>
2026-03-30 17:51:46 +00:00
<Button class="flex flex-col justify-start gap-1 w-full" onclick={openChat}>
2024-10-25 00:25:28 +00:00
<div
class={cx(
"cursor-pointer border-t border-solid px-3 py-2 transition-colors hover:bg-surface",
props.class,
{"bg-surface": active},
)}
style="border-color: var(--line)">
2024-10-25 00:25:28 +00:00
<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)}
<div class="h-2 w-2 rounded-full bg-primary text-primary-content" 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>
2026-03-23 21:21:04 +00:00
</Button>