mirror of
git://jb55.com/damus
synced 2024-09-19 19:46:51 +00:00
fix user notifications from old events immediately shown on install and login
Changelog-Fixed: Fix user notifications from old events immediately shown on install and login Closes: #1106
This commit is contained in:
parent
9847f12c95
commit
43017828e2
@ -24,6 +24,9 @@ struct NewEventsBits: OptionSet {
|
||||
}
|
||||
|
||||
class HomeModel: ObservableObject {
|
||||
// Don't trigger a user notification for events older than a certain age
|
||||
static let event_max_age_for_notification: TimeInterval = 12 * 60 * 60
|
||||
|
||||
var damus_state: DamusState
|
||||
|
||||
var has_event: [String: Set<String>] = [:]
|
||||
@ -543,7 +546,8 @@ class HomeModel: ObservableObject {
|
||||
|
||||
func got_new_dm(notifs: NewEventsBits, ev: NostrEvent) {
|
||||
self.new_events = notifs
|
||||
if damus_state.settings.dm_notification {
|
||||
|
||||
if damus_state.settings.dm_notification && ev.age < HomeModel.event_max_age_for_notification {
|
||||
let convo = ev.decrypted(privkey: self.damus_state.keypair.privkey) ?? NSLocalizedString("New encrypted direct message", comment: "Notification that the user has received a new direct message")
|
||||
let notify = LocalNotification(type: .dm, event: ev, target: ev, content: convo)
|
||||
create_local_notification(profiles: damus_state.profiles, notify: notify)
|
||||
@ -1111,6 +1115,11 @@ func process_local_notification(damus_state: DamusState, event ev: NostrEvent) {
|
||||
if damus_state.muted_threads.isMutedThread(ev, privkey: damus_state.keypair.privkey) {
|
||||
return
|
||||
}
|
||||
|
||||
// Don't show notifications for old events
|
||||
guard ev.age < HomeModel.event_max_age_for_notification else {
|
||||
return
|
||||
}
|
||||
|
||||
if type == .text && damus_state.settings.mention_notification {
|
||||
let blocks = ev.blocks(damus_state.keypair.privkey)
|
||||
|
@ -278,6 +278,11 @@ class NostrEvent: Codable, Identifiable, CustomStringConvertible, Equatable, Has
|
||||
func sign(privkey: String) {
|
||||
self.sig = sign_event(privkey: privkey, ev: self)
|
||||
}
|
||||
|
||||
var age: TimeInterval {
|
||||
let event_date = Date(timeIntervalSince1970: TimeInterval(created_at))
|
||||
return Date.now.timeIntervalSince(event_date)
|
||||
}
|
||||
}
|
||||
|
||||
func sign_event(privkey: String, ev: NostrEvent) -> String {
|
||||
|
Loading…
Reference in New Issue
Block a user