NostrEventInfoFromPushNotification.swift (1731B)
1 // 2 // NostrEventInfoFromPushNotification.swift 3 // DamusNotificationService 4 // 5 // Created by Daniel D’Aquino on 2023-11-13. 6 // 7 8 import Foundation 9 10 /// The representation of a JSON-encoded Nostr Event used by the push notification server 11 /// Needs to match with https://gitlab.com/soapbox-pub/strfry-policies/-/raw/433459d8084d1f2d6500fdf916f22caa3b4d7be5/src/types.ts 12 struct NostrEventInfoFromPushNotification: Codable { 13 let id: String // Hex-encoded 14 let sig: String // Hex-encoded 15 let kind: NostrKind 16 let tags: [[String]] 17 let pubkey: String // Hex-encoded 18 let content: String 19 let created_at: Int 20 21 static func from(dictionary: [AnyHashable: Any]) -> NostrEventInfoFromPushNotification? { 22 guard let id = dictionary["id"] as? String, 23 let sig = dictionary["sig"] as? String, 24 let kind_int = dictionary["kind"] as? UInt32, 25 let kind = NostrKind(rawValue: kind_int), 26 let tags = dictionary["tags"] as? [[String]], 27 let pubkey = dictionary["pubkey"] as? String, 28 let content = dictionary["content"] as? String, 29 let created_at = dictionary["created_at"] as? Int else { 30 return nil 31 } 32 return NostrEventInfoFromPushNotification(id: id, sig: sig, kind: kind, tags: tags, pubkey: pubkey, content: content, created_at: created_at) 33 } 34 35 func reactionEmoji() -> String? { 36 guard self.kind == NostrKind.like else { 37 return nil 38 } 39 40 switch self.content { 41 case "", "+": 42 return "❤️" 43 case "-": 44 return "👎" 45 default: 46 return self.content 47 } 48 } 49 }