diff --git a/src/lib/components/ChannelButton.svelte b/src/lib/components/ChannelButton.svelte index 76a8348..f69f3d9 100644 --- a/src/lib/components/ChannelButton.svelte +++ b/src/lib/components/ChannelButton.svelte @@ -20,20 +20,23 @@ onclick?: () => void; } = $props(); - let lastMessage = $derived( - new CoState(Message, channel.mainThread?.timeline?.at(-1), { - resolve: { - content: true, - images: true, - reactions: true - } - }) - ); + const latestEntriesByAccount = $derived(Object.values(channel.mainThread?.timeline?.perAccount ?? {}).sort( + (a, b) => a.madeAt.getTime() - b.madeAt.getTime() + )); + // let lastMessage = $derived( + // new CoState(Message, channel.mainThread?.timeline?.at(-1), { + // resolve: { + // content: true, + // images: true, + // reactions: true + // } + // }) + // ); let isNew = $derived.by(() => { - if (!lastReadDate) return channel.mainThread?.timeline?.length !== 0; - if (!channel.mainThread?.timeline) return false; - let date = lastMessage?.current?.createdAt; + if (!lastReadDate) return latestEntriesByAccount.length !== 0; + if (latestEntriesByAccount.length === 0) return false; + let date = latestEntriesByAccount.at(-1)?.madeAt; if (!date) return false; return new Date(lastReadDate) < date; diff --git a/src/lib/components/ChatInput.svelte b/src/lib/components/ChatInput.svelte index 3ff7b7c..8b7c0fc 100644 --- a/src/lib/components/ChatInput.svelte +++ b/src/lib/components/ChatInput.svelte @@ -93,7 +93,7 @@
{#each images as image}
- +
{/if} -
+
diff --git a/src/routes/[spaceId]/channel/[channelId]/thread/[threadId]/+page.svelte b/src/routes/[spaceId]/channel/[channelId]/thread/[threadId]/+page.svelte index c17df33..9103938 100644 --- a/src/routes/[spaceId]/channel/[channelId]/thread/[threadId]/+page.svelte +++ b/src/routes/[spaceId]/channel/[channelId]/thread/[threadId]/+page.svelte @@ -58,17 +58,6 @@ console.log('no last read'); } } - // svelte-ignore state_referenced_locally - let count = $state(thread.current?.timeline?.length ?? 0); - - $effect(() => { - let newCount = thread.current?.timeline?.length ?? 0; - if (count < newCount) { - count = newCount; - - setLastRead(); - } - }); function handleSubmit() { let newContent = new CoRichText({ @@ -76,8 +65,16 @@ owner: publicGroup() }); + let images: string[] = []; + + if(postImages.length > 0) { + postImages.forEach(image => { + images.push(image.id); + }); + } + // add message to channel - const message = createMessage(newContent, postImages, replyTo?.id); + const message = createMessage(newContent, images, replyTo?.id); postImages = []; @@ -116,10 +113,32 @@ } let postImages = $state([]); + + + let timeline = $derived( + Object.values(thread.current?.timeline.perAccount ?? {}) + .map((accountFeed) => new Array(...accountFeed.all)) + .flat() + .sort((a, b) => a.madeAt.getTime() - b.madeAt.getTime()) + .map((a) => a.value) + ); + + + // svelte-ignore state_referenced_locally + let count = $state(timeline.length ?? 0); + + $effect(() => { + let newCount = timeline.length ?? 0; + if (count < newCount) { + count = newCount; + + setLastRead(); + } + }); {}}