Unfurl profile name on remote push notifications
This commit adds support for the unfurling of author profile names on remote push notifications It also makes the following changes: - Notification extension now uses NdbNote - Some of the logic between push notifications and local notifications was unified Testing ------- Device: iPhone 15 Pro simulator iOS: 17.0.1 Damus: This commit Coverage: 1. Basic smoke tests on the app by browsing different notes and different tabs 2. Sent test push notifications for mentions and DMs to check the unfurling of profile names 3. Ran unit tests Closes: https://github.com/damus-io/damus/issues/1703 Changelog-Added: Unfurl profile name on remote push notifications Signed-off-by: Daniel D’Aquino <daniel@daquino.me> Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
committed by
William Casarin
parent
460f536fa3
commit
4171252b18
@@ -7,6 +7,8 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
let NDB_NOTE_JSON_USER_INFO_KEY = "ndb_note_json"
|
||||
|
||||
struct LossyLocalNotification {
|
||||
let type: LocalNotificationType
|
||||
let mention: MentionRef
|
||||
@@ -19,8 +21,8 @@ struct LossyLocalNotification {
|
||||
}
|
||||
|
||||
static func from_user_info(user_info: [AnyHashable: Any]) -> LossyLocalNotification? {
|
||||
if let encoded_nostr_event_push_data = user_info["nostr_event_info"] as? String {
|
||||
return self.from(encoded_nostr_event_push_data: encoded_nostr_event_push_data)
|
||||
if let encoded_ndb_note = user_info[NDB_NOTE_JSON_USER_INFO_KEY] as? String {
|
||||
return self.from(json_encoded_ndb_note: encoded_ndb_note)
|
||||
}
|
||||
guard let id = user_info["id"] as? String,
|
||||
let target_id = MentionRef.from_bech32(str: id) else {
|
||||
@@ -32,18 +34,16 @@ struct LossyLocalNotification {
|
||||
return LossyLocalNotification(type: type, mention: target_id)
|
||||
}
|
||||
|
||||
static func from(encoded_nostr_event_push_data: String) -> LossyLocalNotification? {
|
||||
guard let json_data = encoded_nostr_event_push_data.data(using: .utf8),
|
||||
let nostr_event_push_data = try? JSONDecoder().decode(NostrEventInfoFromPushNotification.self, from: json_data) else {
|
||||
static func from(json_encoded_ndb_note: String) -> LossyLocalNotification? {
|
||||
guard let ndb_note = NdbNote.owned_from_json(json: json_encoded_ndb_note) else {
|
||||
return nil
|
||||
}
|
||||
return self.from(nostr_event_push_data: nostr_event_push_data)
|
||||
return self.from(ndb_note: ndb_note)
|
||||
}
|
||||
|
||||
static func from(nostr_event_push_data: NostrEventInfoFromPushNotification) -> LossyLocalNotification? {
|
||||
guard let type = LocalNotificationType.from(nostr_kind: nostr_event_push_data.kind) else { return nil }
|
||||
guard let note_id: NoteId = NoteId.init(hex: nostr_event_push_data.id) else { return nil }
|
||||
let target: MentionRef = .note(note_id)
|
||||
static func from(ndb_note: NdbNote) -> LossyLocalNotification? {
|
||||
guard let known_kind = ndb_note.known_kind, let type = LocalNotificationType.from(nostr_kind: known_kind) else { return nil }
|
||||
let target: MentionRef = .note(ndb_note.id)
|
||||
return LossyLocalNotification(type: type, mention: target)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user