damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 247270f3d3efdd3eb4f17da56dcfae60d9b68a93
parent 9327068264a332b19a5f2eca098ee40adc413e8e
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 15 Apr 2023 12:40:00 -0700

Introduce LocalNotification

This will be used for local notification data

Diffstat:
Mdamus.xcodeproj/project.pbxproj | 4++++
Adamus/Util/LocalNotification.swift | 47+++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj @@ -193,6 +193,7 @@ 4CD348EF29C3659D00497EB2 /* ImageUploadModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CD348EE29C3659D00497EB2 /* ImageUploadModel.swift */; }; 4CD7641B28A1641400B6928F /* EndBlock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CD7641A28A1641400B6928F /* EndBlock.swift */; }; 4CDA128A29E9D10C0006FA5A /* SignalView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CDA128929E9D10C0006FA5A /* SignalView.swift */; }; + 4CDA128C29EB19C40006FA5A /* LocalNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CDA128B29EB19C40006FA5A /* LocalNotification.swift */; }; 4CE0E2AF29A2E82100DB4CA2 /* EventHolder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE0E2AE29A2E82100DB4CA2 /* EventHolder.swift */; }; 4CE0E2B229A3DF6900DB4CA2 /* LoadMoreButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE0E2B129A3DF6900DB4CA2 /* LoadMoreButton.swift */; }; 4CE0E2B629A3ED5500DB4CA2 /* InnerTimelineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE0E2B529A3ED5500DB4CA2 /* InnerTimelineView.swift */; }; @@ -600,6 +601,7 @@ 4CD348EE29C3659D00497EB2 /* ImageUploadModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageUploadModel.swift; sourceTree = "<group>"; }; 4CD7641A28A1641400B6928F /* EndBlock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EndBlock.swift; sourceTree = "<group>"; }; 4CDA128929E9D10C0006FA5A /* SignalView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignalView.swift; sourceTree = "<group>"; }; + 4CDA128B29EB19C40006FA5A /* LocalNotification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalNotification.swift; sourceTree = "<group>"; }; 4CE0E2AE29A2E82100DB4CA2 /* EventHolder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventHolder.swift; sourceTree = "<group>"; }; 4CE0E2B129A3DF6900DB4CA2 /* LoadMoreButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadMoreButton.swift; sourceTree = "<group>"; }; 4CE0E2B529A3ED5500DB4CA2 /* InnerTimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InnerTimelineView.swift; sourceTree = "<group>"; }; @@ -1006,6 +1008,7 @@ 4C1A9A1929DCA17E00516EAC /* ReplyCounter.swift */, 4C8D00C729DF791C0036AF10 /* CompatibleAttribute.swift */, 4C8D00CB29DF92DF0036AF10 /* Hashtags.swift */, + 4CDA128B29EB19C40006FA5A /* LocalNotification.swift */, ); path = Util; sourceTree = "<group>"; @@ -1650,6 +1653,7 @@ 7C60CAEF298471A1009C80D6 /* CoreSVG.swift in Sources */, 6439E014296790CF0020672B /* ProfilePicImageView.swift in Sources */, 4CE6DF1627F8DEBF00C66700 /* RelayConnection.swift in Sources */, + 4CDA128C29EB19C40006FA5A /* LocalNotification.swift in Sources */, 4C3BEFD6281D995700B3DE84 /* ActionBarModel.swift in Sources */, 4C363AA428296DEE006E126D /* SearchModel.swift in Sources */, 4C8D00CC29DF92DF0036AF10 /* Hashtags.swift in Sources */, diff --git a/damus/Util/LocalNotification.swift b/damus/Util/LocalNotification.swift @@ -0,0 +1,47 @@ +// +// LocalNotification.swift +// damus +// +// Created by William Casarin on 2023-04-15. +// + +import Foundation + +struct LossyLocalNotification { + let type: LocalNotificationType + let event_id: String + + func to_user_info() -> [AnyHashable: Any] { + return [ + "type": self.type.rawValue, + "evid": self.event_id + ] + } + + static func from_user_info(user_info: [AnyHashable: Any]) -> LossyLocalNotification { + let target_id = user_info["evid"] as! String + let typestr = user_info["type"] as! String + let type = LocalNotificationType(rawValue: typestr)! + + return LossyLocalNotification(type: type, event_id: target_id) + } +} + +struct LocalNotification { + let type: LocalNotificationType + let event: NostrEvent + let target: NostrEvent + let content: String + + func to_lossy() -> LossyLocalNotification { + return LossyLocalNotification(type: self.type, event_id: self.target.id) + } +} + +enum LocalNotificationType: String { + case dm + case like + case mention + case repost + case zap +}