2024-08-16 22:17:30 +00:00
|
|
|
<script lang="ts" context="module">
|
|
|
|
|
type Element = {
|
|
|
|
|
id: string
|
|
|
|
|
type: "date" | "note"
|
2024-08-19 16:06:39 +00:00
|
|
|
value: string | TrustedEvent
|
2024-08-16 22:17:30 +00:00
|
|
|
showPubkey: boolean
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
2024-08-14 00:58:26 +00:00
|
|
|
<script lang="ts">
|
2024-08-16 18:56:35 +00:00
|
|
|
import {sortBy} from "@welshman/lib"
|
2024-08-19 16:06:39 +00:00
|
|
|
import type {TrustedEvent} from "@welshman/util"
|
2024-08-16 17:50:38 +00:00
|
|
|
import {page} from "$app/stores"
|
|
|
|
|
import {formatTimestampAsDate} from "@lib/util"
|
2024-08-16 22:17:30 +00:00
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
2024-08-16 17:50:38 +00:00
|
|
|
import Spinner from "@lib/components/Spinner.svelte"
|
|
|
|
|
import GroupNote from "@app/components/GroupNote.svelte"
|
2024-08-16 18:56:35 +00:00
|
|
|
import {deriveGroupConversation} from "@app/state"
|
2024-08-15 19:08:07 +00:00
|
|
|
|
2024-08-16 22:17:30 +00:00
|
|
|
const {nom} = $page.params
|
|
|
|
|
const conversation = deriveGroupConversation(nom)
|
2024-08-15 21:30:55 +00:00
|
|
|
|
2024-08-19 16:06:39 +00:00
|
|
|
const assertEvent = (e: any) => e as TrustedEvent
|
2024-08-15 21:30:55 +00:00
|
|
|
|
|
|
|
|
let loading = true
|
|
|
|
|
let elements: Element[] = []
|
|
|
|
|
|
|
|
|
|
$: {
|
|
|
|
|
elements = []
|
|
|
|
|
|
|
|
|
|
let previousDate
|
|
|
|
|
let previousPubkey
|
|
|
|
|
|
|
|
|
|
for (const {event} of sortBy(m => m.event.created_at, $conversation?.messages || [])) {
|
2024-08-16 18:56:35 +00:00
|
|
|
const {id, pubkey, created_at} = event
|
2024-08-15 21:30:55 +00:00
|
|
|
const date = formatTimestampAsDate(created_at)
|
|
|
|
|
|
|
|
|
|
if (date !== previousDate) {
|
2024-08-16 17:50:38 +00:00
|
|
|
elements.push({type: "date", value: date, id: date, showPubkey: false})
|
2024-08-15 21:30:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
elements.push({
|
|
|
|
|
id,
|
2024-08-16 17:50:38 +00:00
|
|
|
type: "note",
|
2024-08-15 21:30:55 +00:00
|
|
|
value: event,
|
|
|
|
|
showPubkey: date !== previousDate || previousPubkey !== pubkey,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
previousDate = date
|
|
|
|
|
previousPubkey = pubkey
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
elements.reverse()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
loading = false
|
|
|
|
|
}, 3000)
|
2024-08-14 00:58:26 +00:00
|
|
|
</script>
|
|
|
|
|
|
2024-08-16 22:17:30 +00:00
|
|
|
<div class="relative flex h-screen flex-col">
|
|
|
|
|
<div class="relative z-feature px-2 pt-4">
|
|
|
|
|
<div class="flex min-h-12 items-center gap-4 rounded-xl bg-base-100 px-4 shadow-xl">
|
|
|
|
|
<div class="flex items-center gap-2">
|
|
|
|
|
<Icon icon="hashtag" />
|
|
|
|
|
<strong>General</strong>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-08-16 17:50:38 +00:00
|
|
|
<div class="flex flex-grow flex-col-reverse overflow-auto">
|
|
|
|
|
{#each elements as { type, id, value, showPubkey } (id)}
|
2024-08-15 21:30:55 +00:00
|
|
|
{#if type === "date"}
|
2024-08-16 22:17:30 +00:00
|
|
|
<div class="flex items-center gap-2 p-2 text-xs opacity-50">
|
|
|
|
|
<div class="h-px flex-grow bg-base-content opacity-25" />
|
2024-08-15 21:30:55 +00:00
|
|
|
<p>{value}</p>
|
2024-08-16 22:17:30 +00:00
|
|
|
<div class="h-px flex-grow bg-base-content opacity-25" />
|
2024-08-15 21:30:55 +00:00
|
|
|
</div>
|
|
|
|
|
{:else}
|
|
|
|
|
<GroupNote event={assertEvent(value)} {showPubkey} />
|
|
|
|
|
{/if}
|
|
|
|
|
{/each}
|
2024-08-16 17:50:38 +00:00
|
|
|
<p class="flex h-10 items-center justify-center py-20">
|
2024-08-15 21:30:55 +00:00
|
|
|
<Spinner {loading}>
|
|
|
|
|
{#if loading}
|
|
|
|
|
Looking for messages...
|
|
|
|
|
{:else}
|
|
|
|
|
End of message history
|
|
|
|
|
{/if}
|
|
|
|
|
</Spinner>
|
|
|
|
|
</p>
|
2024-08-15 19:08:07 +00:00
|
|
|
</div>
|
2024-08-16 22:17:30 +00:00
|
|
|
<div class="relative z-feature border-t border-solid border-base-100 px-2 py-2">
|
|
|
|
|
<div class="shadow-top-xl flex min-h-12 items-center gap-4 rounded-xl bg-base-100 px-4"></div>
|
|
|
|
|
</div>
|
2024-08-15 19:08:07 +00:00
|
|
|
</div>
|