-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Amend NIP-52 to support calendars and RSVPs
- Loading branch information
Showing
15 changed files
with
404 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// CalendarEventRSVP.swift | ||
// | ||
// | ||
// Created by Terry Yiu on 12/1/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public final class CalendarEventRSVP: NostrEvent, IdentifierTagInterpreting { | ||
public var calendarEventIdentifier: String? { | ||
// TODO | ||
return nil | ||
} | ||
|
||
public var status: CalendarEventRSVPStatus? { | ||
guard let statusTag = tags.first(where: { $0.name == "l" && $0.otherParameters.first == "status" }) else { | ||
return nil | ||
} | ||
|
||
return CalendarEventRSVPStatus(rawValue: statusTag.value) | ||
} | ||
|
||
public var freebusy: CalendarEventRSVPFreebusy? { | ||
guard let freebusyTag = tags.first(where: { $0.name == "l" && $0.otherParameters.first == "freebusy" }) else { | ||
return nil | ||
} | ||
|
||
return CalendarEventRSVPFreebusy(rawValue: freebusyTag.value) | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
Sources/NostrSDK/Events/Calendars/CalendarEventRSVPFreebusy.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// CalendarEventRSVPFreebusy.swift | ||
// | ||
// | ||
// Created by Terry Yiu on 12/17/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public enum CalendarEventRSVPFreebusy: RawRepresentable, CaseIterable, Codable, Equatable { | ||
|
||
public typealias RawValue = String | ||
|
||
case free | ||
case busy | ||
case unknown(RawValue) | ||
|
||
static public let allCases: AllCases = [ | ||
.free, | ||
.busy | ||
] | ||
|
||
public init?(rawValue: String) { | ||
self = Self.allCases.first { $0.rawValue == rawValue } | ||
?? .unknown(rawValue) | ||
} | ||
|
||
public var rawValue: String { | ||
switch self { | ||
case .free: return "free" | ||
case .busy: return "busy" | ||
case let .unknown(value): return value | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
Sources/NostrSDK/Events/Calendars/CalendarEventRSVPStatus.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Terry Yiu on 12/17/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public enum CalendarEventRSVPStatus: RawRepresentable, CaseIterable, Codable, Equatable { | ||
|
||
public typealias RawValue = String | ||
|
||
case accepted | ||
case declined | ||
case tentative | ||
case unknown(RawValue) | ||
|
||
static public let allCases: AllCases = [ | ||
.accepted, | ||
.declined, | ||
.tentative | ||
] | ||
|
||
public init?(rawValue: String) { | ||
self = Self.allCases.first { $0.rawValue == rawValue } | ||
?? .unknown(rawValue) | ||
} | ||
|
||
public var rawValue: String { | ||
switch self { | ||
case .accepted: return "accepted" | ||
case .declined: return "declined" | ||
case .tentative: return "tentative" | ||
case let .unknown(value): return value | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Sources/NostrSDK/Events/Calendars/CalendarNostrEvent.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// | ||
// CalendarNostrEvent.swift | ||
// | ||
// | ||
// Created by Terry Yiu on 12/1/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public final class CalendarNostrEvent: NostrEvent, IdentifierTagInterpreting, TitleTagInterpreting { | ||
} |
17 changes: 17 additions & 0 deletions
17
Sources/NostrSDK/Events/Tags/IdentifierTagInterpreting.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// IdentifierTagInterpreting.swift | ||
// | ||
// | ||
// Created by Terry Yiu on 12/8/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public protocol IdentifierTagInterpreting: NostrEvent {} | ||
public extension IdentifierTagInterpreting { | ||
/// The identifier of the event. For parameterized replaceable events, this identifier remains stable across replacements. | ||
/// This identifier is represented by the ``d`` tag, which is distinctly different from the ``id`` field on ``NostrEvent``. | ||
var identifier: String? { | ||
firstValueForTagName(.identifier) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// TitleTagInterpreting.swift | ||
// | ||
// | ||
// Created by Terry Yiu on 12/8/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public protocol TitleTagInterpreting: NostrEvent {} | ||
public extension TitleTagInterpreting { | ||
/// The title of the event. | ||
var title: String? { | ||
firstValueForTagName(.title) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.