Attempt to fix new messages button #114

This commit is contained in:
Jon Staab
2025-02-11 11:49:17 -08:00
parent 622214713b
commit 0ba55f2387
@@ -147,6 +147,12 @@
let newMessagesSeen = false let newMessagesSeen = false
if (events) { if (events) {
const lastUserEvent = $events.find(e => e.pubkey === $pubkey)
// Adjust last checked to account for messages that came from a different device
const adjustedLastChecked =
lastChecked && lastUserEvent ? Math.max(lastUserEvent.created_at, lastChecked) : lastChecked
for (const event of $events.toReversed()) { for (const event of $events.toReversed()) {
if (seen.has(event.id)) { if (seen.has(event.id)) {
continue continue
@@ -156,9 +162,9 @@
if ( if (
!newMessagesSeen && !newMessagesSeen &&
adjustedLastChecked &&
event.pubkey !== $pubkey && event.pubkey !== $pubkey &&
lastChecked && event.created_at > adjustedLastChecked
event.created_at > lastChecked
) { ) {
elements.push({type: "new-messages", id: "new-messages"}) elements.push({type: "new-messages", id: "new-messages"})
newMessagesSeen = true newMessagesSeen = true