From c22ac18380b5d8c5850647cedf0f6df5906e224a Mon Sep 17 00:00:00 2001 From: Jonathan Staab Date: Wed, 31 May 2023 09:24:33 -0700 Subject: [PATCH] Group notifications better, prefer followed users when mentioning people --- CHANGELOG.md | 4 ++ src/app/views/Notifications.svelte | 65 ++++++++++++++++-------------- src/partials/Compose.svelte | 17 +++++++- src/util/misc.ts | 2 +- 4 files changed, 54 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1916078..b8798c3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +# 0.2.30 + +- [x] Prefer followed users when mentioning people + # 0.2.29 - [x] Register url handler for web+nostr and use that for sharing diff --git a/src/app/views/Notifications.svelte b/src/app/views/Notifications.svelte index 1deafe58..03eaafe8 100644 --- a/src/app/views/Notifications.svelte +++ b/src/app/views/Notifications.svelte @@ -32,48 +32,51 @@ const notifications = watch("notifications", t => { updateLastChecked() - // Sort by rounded timestamp so we can group reactions to the same parent + // Sort by hour so we can group clustered reactions to the same parent return reverse( sortBy( - e => formatTimestampAsLocalISODate(e.created_at) + findReplyId(e), + e => formatTimestampAsLocalISODate(e.created_at).slice(0, 13) + findReplyId(e), user.applyMutes(t.all()) ) ) }) // Group notifications so we're only showing the parent once per chunk - $: events = $notifications - .slice(0, limit) - .map(e => [e, userEvents.get(findReplyId(e))]) - .filter(([e, ref]) => { - if (ref && ref.kind !== 1) { - return false - } + $: events = sortBy( + ({notifications}) => -notifications.reduce((a, b) => Math.max(a, b.created_at), 0), + $notifications + .slice(0, limit) + .map(e => [e, userEvents.get(findReplyId(e))]) + .filter(([e, ref]) => { + if (ref && ref.kind !== 1) { + return false + } - if (activeTab === tabs[0]) { - return [1].includes(e.kind) - } else { - return [7, 9735].includes(e.kind) && ref - } - }) - .reduce((r, [e, ref]) => { - const prev = last(r) - const prevTimestamp = pluck("created_at", prev?.notifications || []).reduce(max, 0) + if (activeTab === tabs[0]) { + return [1].includes(e.kind) + } else { + return [7, 9735].includes(e.kind) && ref + } + }) + .reduce((r, [e, ref]) => { + const prev = last(r) + const prevTimestamp = pluck("created_at", prev?.notifications || []).reduce(max, 0) - if (ref && prev?.ref === ref) { - prev.notifications.push(e) - } else { - r = r.concat({ - ref, - key: e.id, - notifications: [e], - dateDisplay: formatTimestampAsDate(e.created_at), - showLine: e.created_at < prevChecked && prevTimestamp >= prevChecked, - }) - } + if (ref && prev?.ref === ref) { + prev.notifications.push(e) + } else { + r = r.concat({ + ref, + key: e.id, + notifications: [e], + dateDisplay: formatTimestampAsDate(e.created_at), + showLine: e.created_at < prevChecked && prevTimestamp >= prevChecked, + }) + } - return r - }, []) + return r + }, []) + ) const setActiveTab = tab => navigate(`/notifications/${tab}`) diff --git a/src/partials/Compose.svelte b/src/partials/Compose.svelte index 0e6b122b..7a5e78b8 100644 --- a/src/partials/Compose.svelte +++ b/src/partials/Compose.svelte @@ -1,17 +1,20 @@