damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 33150a42c5a39a121a5dbd97f7b648148662b55d
parent e7fe4ab9b4d5ecb35306179a1db97a3cfd78b3d1
Author: Terry Yiu <git@tyiu.xyz>
Date:   Mon,  7 Apr 2025 21:42:31 -0400

Hide future notes from timeline

Changelog-Fixed: Hide future notes from timeline

Closes: https://github.com/damus-io/damus/issues/2949
Signed-off-by: Terry Yiu <git@tyiu.xyz>

Diffstat:
Mdamus/Models/ContentFilters.swift | 7+++++++
Mdamus/Models/NotificationsManager.swift | 9++++++++-
Mdamus/Views/Notifications/NotificationsView.swift | 5++++-
3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/damus/Models/ContentFilters.swift b/damus/Models/ContentFilters.swift @@ -40,6 +40,12 @@ func get_repost_of_muted_user_filter(damus_state: DamusState) -> ((_ ev: NostrEv } } +func timestamp_filter(ev: NostrEvent) -> Bool { + // Allow notes that are created no more than 3 seconds in the future + // to account for natural clock skew between sender and receiver. + ev.age >= -3 +} + /// Generic filter with various tweakable settings struct ContentFilters { var filters: [(NostrEvent) -> Bool] @@ -66,6 +72,7 @@ extension ContentFilters { filters.append(nsfw_tag_filter) } filters.append(get_repost_of_muted_user_filter(damus_state: damus_state)) + filters.append(timestamp_filter) return filters } } diff --git a/damus/Models/NotificationsManager.swift b/damus/Models/NotificationsManager.swift @@ -54,7 +54,14 @@ func should_display_notification(state: HeadlessDamusState, event ev: NostrEvent guard ev.age < EVENT_MAX_AGE_FOR_NOTIFICATION else { return false } - + + // Don't show notifications for future events. + // Allow notes that are created no more than 3 seconds in the future + // to account for natural clock skew between sender and receiver. + guard ev.age >= -3 else { + return false + } + return true } diff --git a/damus/Views/Notifications/NotificationsView.swift b/damus/Views/Notifications/NotificationsView.swift @@ -41,7 +41,10 @@ class NotificationFilter: ObservableObject, Equatable { if let item = item.filter({ ev in self.friend_filter.filter(contacts: contacts, pubkey: ev.pubkey) && - (!hellthread_notifications_disabled || !ev.is_hellthread(max_pubkeys: hellthread_notification_max_pubkeys)) + (!hellthread_notifications_disabled || !ev.is_hellthread(max_pubkeys: hellthread_notification_max_pubkeys)) && + // Allow notes that are created no more than 3 seconds in the future + // to account for natural clock skew between sender and receiver. + ev.age >= -3 }) { acc.append(item) }