notify: add typesafe notifications

This commit is contained in:
William Casarin
2023-07-30 10:48:56 -07:00
parent df3b94a1fc
commit 80063af19a
28 changed files with 795 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
//
// AttachedWalletNotify.swift
// damus
//
// Created by William Casarin on 2023-07-30.
//
import Foundation
struct AttachedWalletNotify: Notify {
typealias Payload = WalletConnectURL
var payload: Payload
}
extension NotifyHandler {
static var attached_wallet: NotifyHandler<AttachedWalletNotify> {
.init()
}
}
extension Notifications {
static func attached_wallet(_ payload: WalletConnectURL) -> Notifications<AttachedWalletNotify> {
.init(.init(payload: payload))
}
}

View File

@@ -0,0 +1,25 @@
//
// BroadcastEventNotify.swift
// damus
//
// Created by William Casarin on 2023-07-30.
//
import Foundation
struct BroadcastNotify: Notify {
typealias Payload = NostrEvent
var payload: Payload
}
extension NotifyHandler {
static var broadcast: NotifyHandler<BroadcastNotify> {
.init()
}
}
extension Notifications {
static func broadcast(_ event: NostrEvent) -> Notifications<BroadcastNotify> {
.init(.init(payload: event))
}
}

View File

@@ -0,0 +1,25 @@
//
// ComposeNotify.swift
// damus
//
// Created by William Casarin on 2023-07-30.
//
import Foundation
struct ComposeNotify: Notify {
typealias Payload = PostAction
var payload: Payload
}
extension NotifyHandler {
static var compose: NotifyHandler<ComposeNotify> {
.init()
}
}
extension Notifications {
static func compose(_ payload: PostAction) -> Notifications<ComposeNotify> {
.init(.init(payload: payload))
}
}

View File

@@ -0,0 +1,26 @@
//
// FollowNotify.swift
// damus
//
// Created by William Casarin on 2023-07-30.
//
import Foundation
struct FollowNotify: Notify {
typealias Payload = FollowTarget
var payload: Payload
}
extension NotifyHandler {
static var follow: NotifyHandler<FollowNotify> {
NotifyHandler<FollowNotify>()
}
}
extension Notifications {
static func follow(_ target: FollowTarget) -> Notifications<FollowNotify> {
.init(.init(payload: target))
}
}

View File

@@ -0,0 +1,25 @@
//
// FollowedNotify.swift
// damus
//
// Created by William Casarin on 2023-07-30.
//
import Foundation
struct FollowedNotify: Notify {
typealias Payload = FollowRef
var payload: FollowRef
}
extension NotifyHandler {
static var followed: NotifyHandler<FollowedNotify> {
.init()
}
}
extension Notifications {
static func followed(_ ref: FollowRef) -> Notifications<FollowedNotify> {
.init(.init(payload: ref))
}
}

View File

@@ -0,0 +1,27 @@
//
// LikedNotify.swift
// damus
//
// Created by William Casarin on 2023-07-30.
//
import Foundation
struct LikedNotify: Notify {
typealias Payload = Counted
var payload: Counted
}
extension NotifyHandler {
static var liked: NotifyHandler<LikedNotify> {
.init()
}
}
extension Notifications {
static func liked(_ counted: Counted) -> Notifications<LikedNotify> {
.init(.init(payload: counted))
}
}

View File

@@ -0,0 +1,25 @@
//
// LocalNotificationNotify.swift
// damus
//
// Created by William Casarin on 2023-07-30.
//
import Foundation
struct LocalNotificationNotify: Notify {
typealias Payload = LossyLocalNotification
var payload: Payload
}
extension NotifyHandler {
static var local_notification: NotifyHandler<LocalNotificationNotify> {
.init()
}
}
extension Notifications {
static func local_notification(_ payload: LossyLocalNotification) -> Notifications<LocalNotificationNotify> {
.init(.init(payload: payload))
}
}

View File

@@ -0,0 +1,25 @@
//
// LoginNotify.swift
// damus
//
// Created by William Casarin on 2023-07-30.
//
import Foundation
struct LoginNotify: Notify {
typealias Payload = Keypair
var payload: Keypair
}
extension NotifyHandler {
static var login: NotifyHandler<LoginNotify> {
.init()
}
}
extension Notifications {
static func login(_ keypair: Keypair) -> Notifications<LoginNotify> {
.init(.init(payload: keypair))
}
}

View File

@@ -0,0 +1,26 @@
//
// LogoutNotify.swift
// damus
//
// Created by William Casarin on 2023-07-30.
//
import Foundation
struct LogoutNotify: Notify {
typealias Payload = ()
var payload: ()
}
extension NotifyHandler {
static var logout: NotifyHandler<LogoutNotify> {
.init()
}
}
extension Notifications {
/// Sign out of damus. Goes back to the login screen.
static var logout: Notifications<LogoutNotify> {
.init(.init(payload: ()))
}
}

View File

@@ -0,0 +1,26 @@
//
// MuteNotify.swift
// damus
//
// Created by William Casarin on 2023-07-30.
//
import Foundation
struct MuteNotify: Notify {
typealias Payload = Pubkey
var payload: Payload
}
extension NotifyHandler {
static var mute: NotifyHandler<MuteNotify> {
NotifyHandler<MuteNotify>()
}
}
extension Notifications {
static func mute(_ target: Pubkey) -> Notifications<MuteNotify> {
.init(.init(payload: target))
}
}

View File

@@ -0,0 +1,26 @@
//
// MuteThreadNotify.swift
// damus
//
// Created by William Casarin on 2023-07-30.
//
import Foundation
struct MuteThreadNotify: Notify {
typealias Payload = NostrEvent
var payload: Payload
}
extension NotifyHandler {
static var mute_thread: NotifyHandler<MuteThreadNotify> {
.init()
}
}
extension Notifications {
static func mute_thread(_ note: NostrEvent) -> Notifications<MuteThreadNotify> {
.init(.init(payload: note))
}
}

View File

@@ -0,0 +1,25 @@
//
// NewMutesNotify.swift
// damus
//
// Created by William Casarin on 2023-07-30.
//
import Foundation
struct NewMutesNotify: Notify {
typealias Payload = Set<Pubkey>
var payload: Payload
}
extension NotifyHandler {
static var new_mutes: NotifyHandler<NewMutesNotify> {
.init()
}
}
extension Notifications {
static func new_mutes(_ pubkeys: Set<Pubkey>) -> Notifications<NewMutesNotify> {
.init(.init(payload: pubkeys))
}
}

View File

@@ -0,0 +1,25 @@
//
// NewUnmutesNotify.swift
// damus
//
// Created by William Casarin on 2023-07-30.
//
import Foundation
struct NewUnmutesNotify: Notify {
typealias Payload = Set<Pubkey>
var payload: Payload
}
extension NotifyHandler {
static var new_unmutes: NotifyHandler<NewUnmutesNotify> {
.init()
}
}
extension Notifications {
static func new_unmutes(_ pubkeys: Set<Pubkey>) -> Notifications<NewUnmutesNotify> {
.init(.init(payload: pubkeys))
}
}

View File

@@ -0,0 +1,25 @@
//
// OnlyZapsNotify.swift
// damus
//
// Created by William Casarin on 2023-07-30.
//
import Foundation
struct OnlyZapsNotify: Notify {
typealias Payload = Bool
var payload: Bool
}
extension NotifyHandler {
static var onlyzaps_mode: NotifyHandler<OnlyZapsNotify> {
.init()
}
}
extension Notifications {
static func onlyzaps_mode(_ on: Bool) -> Notifications<OnlyZapsNotify> {
.init(.init(payload: on))
}
}

View File

@@ -0,0 +1,25 @@
//
// PostNotify.swift
// damus
//
// Created by William Casarin on 2023-07-30.
//
import Foundation
struct PostNotify: Notify {
typealias Payload = NostrPostResult
var payload: NostrPostResult
}
extension NotifyHandler {
static var post: NotifyHandler<PostNotify> {
.init()
}
}
extension Notifications {
static func post(_ result: NostrPostResult) -> Notifications<PostNotify> {
.init(.init(payload: result))
}
}

View File

@@ -0,0 +1,25 @@
//
// PresentSheetNotify.swift
// damus
//
// Created by William Casarin on 2023-07-30.
//
import Foundation
struct PresentSheetNotify: Notify {
typealias Payload = Sheets
var payload: Payload
}
extension NotifyHandler {
static var present_sheet: NotifyHandler<PresentSheetNotify> {
.init()
}
}
extension Notifications {
static func present_sheet(_ sheet: Sheets) -> Notifications<PresentSheetNotify> {
.init(.init(payload: sheet))
}
}

View File

@@ -0,0 +1,25 @@
//
// ProfileNotify.swift
// damus
//
// Created by William Casarin on 2023-07-30.
//
import Foundation
struct ProfileUpdatedNotify: Notify {
typealias Payload = ProfileUpdate
var payload: Payload
}
extension NotifyHandler {
static var profile_updated: NotifyHandler<ProfileUpdatedNotify> {
.init()
}
}
extension Notifications {
static func profile_updated(pubkey: Pubkey, profile: Profile) -> Notifications<ProfileUpdatedNotify> {
.init(.init(payload: ProfileUpdate(pubkey: pubkey, profile: profile)))
}
}

View File

@@ -0,0 +1,26 @@
//
// RelaysChangedNotify.swift
// damus
//
// Created by William Casarin on 2023-07-30.
//
import Foundation
struct RelaysChangedNotify: Notify {
typealias Payload = ()
var payload: Payload
}
extension NotifyHandler {
static var relays_changed: NotifyHandler<RelaysChangedNotify> {
.init()
}
}
extension Notifications {
static var relays_changed: Notifications<RelaysChangedNotify> {
.init(.init(payload: ()))
}
}

View File

@@ -0,0 +1,25 @@
//
// ReportNotify.swift
// damus
//
// Created by William Casarin on 2023-07-30.
//
import Foundation
struct ReportNotify: Notify {
typealias Payload = ReportTarget
var payload: ReportTarget
}
extension NotifyHandler {
static var report: NotifyHandler<ReportNotify> {
.init()
}
}
extension Notifications {
static func report(_ target: ReportTarget) -> Notifications<ReportNotify> {
.init(.init(payload: target))
}
}

View File

@@ -0,0 +1,26 @@
//
// BoostedNotify.swift
// damus
//
// Created by William Casarin on 2023-07-30.
//
import Foundation
struct RepostedNotify: Notify {
typealias Payload = Counted
var payload: Payload
}
extension NotifyHandler {
static var reposted: NotifyHandler<RepostedNotify> {
.init()
}
}
extension Notifications {
static func reposted(_ counts: Counted) -> Notifications<RepostedNotify> {
.init(.init(payload: counts))
}
}

View File

@@ -0,0 +1,25 @@
//
// ScrollToTopNotify.swift
// damus
//
// Created by William Casarin on 2023-07-30.
//
import Foundation
struct ScrollToTopNotify: Notify {
typealias Payload = ()
var payload: ()
}
extension NotifyHandler {
static var scroll_to_top: NotifyHandler<ScrollToTopNotify> {
.init()
}
}
extension Notifications {
static var scroll_to_top: Notifications<ScrollToTopNotify> {
.init(.init(payload: ()))
}
}

View File

@@ -0,0 +1,25 @@
//
// SwitchedTimelineNotify.swift
// damus
//
// Created by William Casarin on 2023-07-30.
//
import Foundation
struct SwitchedTimelineNotify: Notify {
typealias Payload = Timeline
var payload: Payload
}
extension NotifyHandler {
static var switched_timeline: NotifyHandler<SwitchedTimelineNotify> {
.init()
}
}
extension Notifications {
static func switched_timeline(_ timeline: Timeline) -> Notifications<SwitchedTimelineNotify> {
.init(.init(payload: timeline))
}
}

View File

@@ -0,0 +1,26 @@
//
// UnfollowNotify.swift
// damus
//
// Created by William Casarin on 2023-07-30.
//
import Foundation
/// Notification sent when an unfollow action is initiatied. Not to be confused with unfollowed
struct UnfollowNotify: Notify {
typealias Payload = FollowTarget
var payload: Payload
}
extension NotifyHandler {
static var unfollow: NotifyHandler<UnfollowNotify> {
.init()
}
}
extension Notifications {
static func unfollow(_ target: FollowTarget) -> Notifications<UnfollowNotify> {
.init(.init(payload: target))
}
}

View File

@@ -0,0 +1,25 @@
//
// UnfollowedNotify.swift
// damus
//
// Created by William Casarin on 2023-07-30.
//
import Foundation
struct UnfollowedNotify: Notify {
typealias Payload = FollowRef
var payload: Payload
}
extension NotifyHandler {
static var unfollowed: NotifyHandler<UnfollowedNotify> {
.init()
}
}
extension Notifications {
static func unfollowed(_ payload: FollowRef) -> Notifications<UnfollowedNotify> {
.init(.init(payload: payload))
}
}

View File

@@ -0,0 +1,26 @@
//
// UnmuteThreadNotify.swift
// damus
//
// Created by William Casarin on 2023-07-30.
//
import Foundation
struct UnmuteThreadNotify: Notify {
typealias Payload = NostrEvent
var payload: Payload
}
extension NotifyHandler {
static var unmute_thread: NotifyHandler<UnmuteThreadNotify> {
.init()
}
}
extension Notifications {
static func unmute_thread(_ note: NostrEvent) -> Notifications<UnmuteThreadNotify> {
.init(.init(payload: note))
}
}

View File

@@ -0,0 +1,26 @@
//
// UpdateStatsNotify.swift
// damus
//
// Created by William Casarin on 2023-07-30.
//
import Foundation
struct UpdateStatsNotify: Notify {
typealias Payload = NoteId
var payload: Payload
}
extension NotifyHandler {
static var update_stats: NotifyHandler<UpdateStatsNotify> {
.init()
}
}
extension Notifications {
static func update_stats(note_id: NoteId) -> Notifications<UpdateStatsNotify> {
.init(.init(payload: note_id))
}
}

View File

@@ -0,0 +1,26 @@
//
// ZappingNotify.swift
// damus
//
// Created by William Casarin on 2023-07-30.
//
import Foundation
struct ZappingNotify: Notify {
typealias Payload = ZappingEvent
var payload: Payload
}
extension NotifyHandler {
static var zapping: NotifyHandler<ZappingNotify> {
NotifyHandler<ZappingNotify>()
}
}
extension Notifications {
static func zapping(_ event: ZappingEvent) -> Notifications<ZappingNotify> {
.init(.init(payload: event))
}
}