diff --git a/src/routes/spaces/[relay]/[h]/+page.svelte b/src/routes/spaces/[relay]/[h]/+page.svelte index e2cb7c06..a9f3b919 100644 --- a/src/routes/spaces/[relay]/[h]/+page.svelte +++ b/src/routes/spaces/[relay]/[h]/+page.svelte @@ -230,7 +230,12 @@ } const manageScrollPosition = () => { - showScrollButton = !isNaN(at) || Math.abs(element?.scrollTop || 0) > 1500 + // Only treat an `at` jump as "scrolled up" when it targets an event below the + // newest one; jumping to the most recent message already lands us at the bottom. + const newestEvent = $events[$events.length - 1] + const atIsBelowNewest = !isNaN(at) && newestEvent !== undefined && at < newestEvent.created_at + + showScrollButton = atIsBelowNewest || Math.abs(element?.scrollTop || 0) > 1500 const newMessages = document.getElementById("new-messages") @@ -316,7 +321,7 @@ let newMessagesSeen = false if (events) { - const lastUserEvent = $events.find(e => e.pubkey === $pubkey) + const lastUserEvent = $events.findLast(e => e.pubkey === $pubkey) // Adjust last checked to account for messages that came from a different device const adjustedLastChecked = diff --git a/src/routes/spaces/[relay]/chat/+page.svelte b/src/routes/spaces/[relay]/chat/+page.svelte index a86d9e12..0bf01237 100644 --- a/src/routes/spaces/[relay]/chat/+page.svelte +++ b/src/routes/spaces/[relay]/chat/+page.svelte @@ -113,7 +113,12 @@ } const manageScrollPosition = () => { - showScrollButton = !isNaN(at) || Math.abs(element?.scrollTop || 0) > 1500 + // Only treat an `at` jump as "scrolled up" when it targets an event below the + // newest one; jumping to the most recent message already lands us at the bottom. + const newestEvent = $events[$events.length - 1] + const atIsBelowNewest = !isNaN(at) && newestEvent !== undefined && at < newestEvent.created_at + + showScrollButton = atIsBelowNewest || Math.abs(element?.scrollTop || 0) > 1500 const newMessages = document.getElementById("new-messages") @@ -197,7 +202,7 @@ let newMessagesSeen = false if (events) { - const lastUserEvent = $events.find(e => e.pubkey === $pubkey) + const lastUserEvent = $events.findLast(e => e.pubkey === $pubkey) // Adjust last checked to account for messages that came from a different device const adjustedLastChecked =