Compare commits

...

1 Commits

Author SHA1 Message Date
7ee970ea9e 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>
2025-04-18 16:21:50 -07:00
3 changed files with 19 additions and 2 deletions

View File

@@ -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 /// Generic filter with various tweakable settings
struct ContentFilters { struct ContentFilters {
var filters: [(NostrEvent) -> Bool] var filters: [(NostrEvent) -> Bool]
@@ -66,6 +72,7 @@ extension ContentFilters {
filters.append(nsfw_tag_filter) filters.append(nsfw_tag_filter)
} }
filters.append(get_repost_of_muted_user_filter(damus_state: damus_state)) filters.append(get_repost_of_muted_user_filter(damus_state: damus_state))
filters.append(timestamp_filter)
return filters return filters
} }
} }

View File

@@ -54,7 +54,14 @@ func should_display_notification(state: HeadlessDamusState, event ev: NostrEvent
guard ev.age < EVENT_MAX_AGE_FOR_NOTIFICATION else { guard ev.age < EVENT_MAX_AGE_FOR_NOTIFICATION else {
return false 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 return true
} }

View File

@@ -41,7 +41,10 @@ class NotificationFilter: ObservableObject, Equatable {
if let item = item.filter({ ev in if let item = item.filter({ ev in
self.friend_filter.filter(contacts: contacts, pubkey: ev.pubkey) && 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) acc.append(item)
} }