diff --git a/src/app/components/RoomItem.svelte b/src/app/components/RoomItem.svelte index b691aa16..e0e4b35e 100644 --- a/src/app/components/RoomItem.svelte +++ b/src/app/components/RoomItem.svelte @@ -37,6 +37,7 @@ event: TrustedEvent replyTo?: (event: TrustedEvent) => void showPubkey?: boolean + isGrouped?: boolean inert?: boolean canEdit: (event: TrustedEvent) => boolean onEdit: (event: TrustedEvent) => void @@ -47,6 +48,7 @@ event, replyTo = undefined, showPubkey = false, + isGrouped = false, inert = false, canEdit, onEdit, @@ -74,89 +76,153 @@ publishReaction({...template, event, relays: [url], protect: await shouldProtect}) - -
- {#if showPubkey} - - {:else} -
- {/if} -
- {#if showPubkey} -
- - - {#if formatTimestampAsDate(event.created_at) === today} - Today - {:else} - {formatTimestampAsDate(event.created_at)} - {/if} - at {formatTimestampAsTime(event.created_at)} - +{#if isGrouped} + +
+
+
+ + {#if thunk} + + {/if}
- {/if} -
- - {#if thunk} - - {/if}
-
-
- - {#if path && $comments.length > 0} - {@const pubkeys = $comments.map(e => e.pubkey)} - {@const isOwn = $pubkey && pubkeys.includes($pubkey)} - {@const info = displayList(pubkeys.map(pubkey => displayProfileByPubkey(pubkey)))} - {@const tooltip = `${info} commented`} -
- - - {$comments.length} comment{$comments.length === 1 ? "" : "s"} - -
+
+ + {#if path && $comments.length > 0} + {@const pubkeys = $comments.map(e => e.pubkey)} + {@const isOwn = $pubkey && pubkeys.includes($pubkey)} + {@const info = displayList(pubkeys.map(pubkey => displayProfileByPubkey(pubkey)))} + {@const tooltip = `${info} commented`} +
+ + + {$comments.length} comment{$comments.length === 1 ? "" : "s"} + +
+ {/if} +
+ {#if !isMobile} + + {/if} + {#if edit} + + {/if} + + {/if} -
- {#if !isMobile} - + {:else} +
{/if} - {#if edit} - +
+ {#if showPubkey} +
+ + + {#if formatTimestampAsDate(event.created_at) === today} + Today + {:else} + {formatTimestampAsDate(event.created_at)} + {/if} + at {formatTimestampAsTime(event.created_at)} + +
+ {/if} +
+ + {#if thunk} + + {/if} +
+
+
+
+ + {#if path && $comments.length > 0} + {@const pubkeys = $comments.map(e => e.pubkey)} + {@const isOwn = $pubkey && pubkeys.includes($pubkey)} + {@const info = displayList(pubkeys.map(pubkey => displayProfileByPubkey(pubkey)))} + {@const tooltip = `${info} commented`} +
+ + + {$comments.length} comment{$comments.length === 1 ? "" : "s"} + +
{/if} - - - {/if} - +
+ {#if !isMobile} + + {/if} + {#if edit} + + {/if} + + + {/if} + +{/if} diff --git a/src/app/components/RoomMessageBlock.svelte b/src/app/components/RoomMessageBlock.svelte new file mode 100644 index 00000000..6a3a978a --- /dev/null +++ b/src/app/components/RoomMessageBlock.svelte @@ -0,0 +1,60 @@ + + +
+
+ +
+
+ + + {#if formatTimestampAsDate(firstEvent.created_at) === today} + Today + {:else} + {formatTimestampAsDate(firstEvent.created_at)} + {/if} + at {formatTimestampAsTime(firstEvent.created_at)} + +
+
+ {#each events as event (event.id)} + + {/each} +
+
+
+
diff --git a/src/routes/spaces/[relay]/[h]/+page.svelte b/src/routes/spaces/[relay]/[h]/+page.svelte index fca7bd03..898f3019 100644 --- a/src/routes/spaces/[relay]/[h]/+page.svelte +++ b/src/routes/spaces/[relay]/[h]/+page.svelte @@ -24,7 +24,7 @@ import RoomComposeParent from "@app/components/RoomComposeParent.svelte" import RoomImage from "@app/components/RoomImage.svelte" import RoomDetail from "@app/components/RoomDetail.svelte" - import RoomItem from "@app/components/RoomItem.svelte" + import RoomMessageBlock from "@app/components/RoomMessageBlock.svelte" import RoomName from "@app/components/RoomName.svelte" import SpaceSearch from "@app/components/SpaceSearch.svelte" import ThunkToast from "@app/components/ThunkToast.svelte" @@ -242,6 +242,7 @@ let previousPubkey let previousCreatedAt = 0 let newMessagesSeen = false + let currentBlock: TrustedEvent[] = [] if (events) { const lastUserEvent = $events.find(e => e.pubkey === $pubkey) @@ -250,6 +251,17 @@ const adjustedLastChecked = lastChecked && lastUserEvent ? Math.max(lastUserEvent.created_at, lastChecked) : lastChecked + const flushBlock = () => { + if (currentBlock.length > 0) { + elements.push({ + type: "message-block", + id: currentBlock[0].id, + events: [...currentBlock], + }) + currentBlock = [] + } + } + for (const event of $events) { if (seen.has(event.id)) { continue @@ -264,23 +276,26 @@ event.created_at > adjustedLastChecked && event.created_at < mounted ) { + flushBlock() elements.push({type: "new-messages", id: "new-messages"}) newMessagesSeen = true } if (date !== previousDate) { - elements.push({type: "date", value: date, id: date, showPubkey: false}) + flushBlock() + elements.push({type: "date", value: date, id: date}) } - elements.push({ - id: event.id, - type: "note", - value: event, - showPubkey: - previousPubkey !== event.pubkey || - event.created_at - previousCreatedAt > int(3, MINUTE) || - previousKind === ROOM_ADD_MEMBER, - }) + const shouldStartNewBlock = + previousPubkey !== event.pubkey || + event.created_at - previousCreatedAt > int(3, MINUTE) || + previousKind === ROOM_ADD_MEMBER + + if (shouldStartNewBlock) { + flushBlock() + } + + currentBlock.push(event) previousDate = date previousKind = event.kind @@ -288,6 +303,8 @@ previousCreatedAt = event.created_at seen.add(event.id) } + + flushBlock() } elements.reverse() @@ -382,32 +399,31 @@ Looking for messages...

{/if} - {#each elements as { type, id, value, showPubkey } (id)} - {#if type === "new-messages"} + {#each elements as element (element.id)} + {#if element.type === "new-messages"}

New Messages

- {:else if type === "date"} - {value} - {:else} - {@const event = $state.snapshot(value as TrustedEvent)} + {:else if element.type === "date"} + {(element as any).value} + {:else if element.type === "message-block"} +
+ +
+ {:else if (element as any).value} + {@const event = $state.snapshot((element as any).value)} {#if event.kind === ROOM_ADD_MEMBER} - {:else} -
- -
{/if} {/if} {/each} diff --git a/src/routes/spaces/[relay]/chat/+page.svelte b/src/routes/spaces/[relay]/chat/+page.svelte index 8972fe44..ad9c1c39 100644 --- a/src/routes/spaces/[relay]/chat/+page.svelte +++ b/src/routes/spaces/[relay]/chat/+page.svelte @@ -19,7 +19,7 @@ import ThunkToast from "@app/components/ThunkToast.svelte" import SpaceBar from "@app/components/SpaceBar.svelte" import SpaceSearch from "@app/components/SpaceSearch.svelte" - import RoomItem from "@app/components/RoomItem.svelte" + import RoomMessageBlock from "@app/components/RoomMessageBlock.svelte" import RoomItemAddMember from "@src/app/components/RoomItemAddMember.svelte" import RoomCompose from "@app/components/RoomCompose.svelte" @@ -180,6 +180,7 @@ let previousPubkey let previousCreatedAt = 0 let newMessagesSeen = false + let currentBlock: TrustedEvent[] = [] if (events) { const lastUserEvent = $events.find(e => e.pubkey === $pubkey) @@ -188,6 +189,17 @@ const adjustedLastChecked = lastChecked && lastUserEvent ? Math.max(lastUserEvent.created_at, lastChecked) : lastChecked + const flushBlock = () => { + if (currentBlock.length > 0) { + elements.push({ + type: "message-block", + id: currentBlock[0].id, + events: [...currentBlock], + }) + currentBlock = [] + } + } + for (const event of $events) { if (seen.has(event.id)) { continue @@ -202,23 +214,26 @@ event.created_at > adjustedLastChecked && event.created_at < mounted ) { + flushBlock() elements.push({type: "new-messages", id: "new-messages"}) newMessagesSeen = true } if (date !== previousDate) { - elements.push({type: "date", value: date, id: date, showPubkey: false}) + flushBlock() + elements.push({type: "date", value: date, id: date}) } - elements.push({ - id: event.id, - type: "note", - value: event, - showPubkey: - previousPubkey !== event.pubkey || - event.created_at - previousCreatedAt > int(3, MINUTE) || - previousKind === RELAY_ADD_MEMBER, - }) + const shouldStartNewBlock = + previousPubkey !== event.pubkey || + event.created_at - previousCreatedAt > int(3, MINUTE) || + previousKind === RELAY_ADD_MEMBER + + if (shouldStartNewBlock) { + flushBlock() + } + + currentBlock.push(event) previousDate = date previousKind = event.kind @@ -226,6 +241,8 @@ previousCreatedAt = event.created_at seen.add(event.id) } + + flushBlock() } elements.reverse() @@ -295,32 +312,29 @@ Looking for messages...

{/if} - {#each elements as { type, id, value, showPubkey } (id)} - {#if type === "new-messages"} + {#each elements as element (element.id)} + {#if element.type === "new-messages"}

New Messages

- {:else if type === "date"} - {value} - {:else} - {@const event = $state.snapshot(value as TrustedEvent)} + {:else if element.type === "date"} + {(element as any).value} + {:else if element.type === "message-block"} + + {:else if (element as any).value} + {@const event = $state.snapshot((element as any).value)} {#if event.kind === RELAY_ADD_MEMBER} - {:else} -
- -
{/if} {/if} {/each}