status: fix status events not expiring locally
Changelog-Fixed: Fix status events not expiring locally
This commit is contained in:
@@ -19,15 +19,22 @@ struct UserStatus {
|
||||
let type: UserStatusType
|
||||
let expires_at: Date?
|
||||
let content: String
|
||||
let created_at: UInt32
|
||||
|
||||
func to_note(keypair: FullKeypair) -> NostrEvent? {
|
||||
return make_user_status_note(status: self, keypair: keypair)
|
||||
}
|
||||
|
||||
init(type: UserStatusType, expires_at: Date?, content: String) {
|
||||
init(type: UserStatusType, expires_at: Date?, content: String, created_at: UInt32) {
|
||||
self.type = type
|
||||
self.expires_at = expires_at
|
||||
self.content = content
|
||||
self.created_at = created_at
|
||||
}
|
||||
|
||||
func expired() -> Bool {
|
||||
guard let expires_at else { return false }
|
||||
return Date.now >= expires_at
|
||||
}
|
||||
|
||||
init?(ev: NostrEvent) {
|
||||
@@ -54,6 +61,7 @@ struct UserStatus {
|
||||
}
|
||||
|
||||
self.content = ev.content
|
||||
self.created_at = ev.created_at
|
||||
}
|
||||
|
||||
}
|
||||
@@ -77,6 +85,16 @@ class UserStatusModel: ObservableObject {
|
||||
}
|
||||
}
|
||||
|
||||
func try_expire() {
|
||||
if let general, general.expired() {
|
||||
self.general = nil
|
||||
}
|
||||
|
||||
if let music, music.expired() {
|
||||
self.music = nil
|
||||
}
|
||||
}
|
||||
|
||||
var _playing_enabled: Bool
|
||||
var playing_enabled: Bool {
|
||||
set {
|
||||
|
||||
@@ -45,7 +45,7 @@ struct UserStatusSheet: View {
|
||||
Binding(get: {
|
||||
status.general?.content ?? ""
|
||||
}, set: { v in
|
||||
status.general = UserStatus(type: .general, expires_at: duration.expiration, content: v)
|
||||
status.general = UserStatus(type: .general, expires_at: duration.expiration, content: v, created_at: UInt32(Date.now.timeIntervalSince1970))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user