-
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
19 changed files
with
781 additions
and
86 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
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,49 @@ | ||
// | ||
// CalendarEventRSVP.swift | ||
// | ||
// | ||
// Created by Terry Yiu on 12/1/23. | ||
// | ||
|
||
import Foundation | ||
|
||
/// A calendar event RSVP is a response to a calendar event to indicate a user's attendance intention. | ||
/// See [NIP-52 - Calendar Event RSVP](https://github.com/nostr-protocol/nips/blob/master/52.md#calendar-event-rsvp). | ||
public final class CalendarEventRSVP: NostrEvent, IdentifierTagInterpreting { | ||
public required init(from decoder: Decoder) throws { | ||
try super.init(from: decoder) | ||
} | ||
|
||
@available(*, unavailable, message: "This initializer is unavailable for this class.") | ||
override init(kind: EventKind, content: String, tags: [Tag] = [], createdAt: Int64 = Int64(Date.now.timeIntervalSince1970), signedBy keypair: Keypair) throws { | ||
try super.init(kind: kind, content: content, tags: tags, createdAt: createdAt, signedBy: keypair) | ||
} | ||
|
||
public init(content: String, tags: [Tag] = [], createdAt: Int64 = Int64(Date.now.timeIntervalSince1970), signedBy keypair: Keypair) throws { | ||
try super.init(kind: .calendarEventRSVP, content: content, tags: tags, createdAt: createdAt, signedBy: keypair) | ||
} | ||
|
||
/// Event coordinates to the calendar event this RSVP responds to. | ||
public var calendarEventCoordinates: EventCoordinates? { | ||
tags.compactMap { EventCoordinates(eventCoordinatesTag: $0) } | ||
.first { $0.kind == .dateBasedCalendarEvent || $0.kind == .timeBasedCalendarEvent } | ||
} | ||
|
||
/// Determines attendance status to the referenced calendar event. | ||
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) | ||
} | ||
|
||
/// Determines if the user would be free or busy for the duration of the calendar event. | ||
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) | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
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,41 @@ | ||
// | ||
// CalendarEventRSVPFreebusy.swift | ||
// | ||
// | ||
// Created by Terry Yiu on 12/17/23. | ||
// | ||
|
||
import Foundation | ||
|
||
/// Determines if the user would be free or busy for the duration of the calendar event. | ||
public enum CalendarEventRSVPFreebusy: RawRepresentable, CaseIterable, Codable, Equatable { | ||
|
||
public typealias RawValue = String | ||
|
||
/// The user is free for the duration of the calendar event. | ||
case free | ||
|
||
/// The user is busy for the duration of the calendar event. | ||
case busy | ||
|
||
/// Unknown freebusy state. | ||
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: RawValue { | ||
switch self { | ||
case .free: return "free" | ||
case .busy: return "busy" | ||
case let .unknown(value): return value | ||
} | ||
} | ||
} |
Oops, something went wrong.