diff --git a/Sources/NostrSDK/Events/Calendars/CalendarListEvent.swift b/Sources/NostrSDK/Events/Calendars/CalendarListEvent.swift index a3b7134..0dc763c 100644 --- a/Sources/NostrSDK/Events/Calendars/CalendarListEvent.swift +++ b/Sources/NostrSDK/Events/Calendars/CalendarListEvent.swift @@ -12,7 +12,7 @@ import Foundation /// One may create a calendar to segment calendar events for specific purposes. e.g., personal, work, travel, meetups, and conferences. /// /// See [NIP-52 - Calendar](https://github.com/nostr-protocol/nips/blob/master/52.md#calendar). -public final class CalendarListEvent: NostrEvent, ParameterizedReplaceableEvent, TitleTagInterpreting { +public final class CalendarListEvent: NostrEvent, ParameterizedReplaceableEvent, ImageTagInterpreting, TitleTagInterpreting { public required init(from decoder: Decoder) throws { try super.init(from: decoder) } @@ -45,7 +45,7 @@ public extension EventCreating { /// - Returns: The signed ``CalendarListEvent``. /// /// See [NIP-52](https://github.com/nostr-protocol/nips/blob/master/52.md). - func calendarListEvent(withIdentifier identifier: String = UUID().uuidString, title: String, description: String = "", calendarEventsCoordinates: [EventCoordinates], signedBy keypair: Keypair) throws -> CalendarListEvent { + func calendarListEvent(withIdentifier identifier: String = UUID().uuidString, title: String, description: String = "", calendarEventsCoordinates: [EventCoordinates], imageURL: URL? = nil, signedBy keypair: Keypair) throws -> CalendarListEvent { guard calendarEventsCoordinates.allSatisfy({ $0.kind == .dateBasedCalendarEvent || $0.kind == .timeBasedCalendarEvent }) else { throw EventCreatingError.invalidInput } @@ -54,7 +54,11 @@ public extension EventCreating { Tag(name: .identifier, value: identifier), Tag(name: .title, value: title) ] - + + if let imageURL { + tags.append(Tag(name: .image, value: imageURL.absoluteString)) + } + calendarEventsCoordinates .filter { $0.kind == .dateBasedCalendarEvent || $0.kind == .timeBasedCalendarEvent } .forEach { tags.append($0.tag) } diff --git a/Sources/NostrSDK/Events/Tags/ImageTagInterpreting.swift b/Sources/NostrSDK/Events/Tags/ImageTagInterpreting.swift index e32e9d4..0365299 100644 --- a/Sources/NostrSDK/Events/Tags/ImageTagInterpreting.swift +++ b/Sources/NostrSDK/Events/Tags/ImageTagInterpreting.swift @@ -1,6 +1,6 @@ // // ImageTagInterpreting.swift -// +// // // Created by Terry Yiu on 8/4/24. // diff --git a/Sources/NostrSDK/Events/Tags/SummaryTagInterpreting.swift b/Sources/NostrSDK/Events/Tags/SummaryTagInterpreting.swift index 61c1be6..1efde3e 100644 --- a/Sources/NostrSDK/Events/Tags/SummaryTagInterpreting.swift +++ b/Sources/NostrSDK/Events/Tags/SummaryTagInterpreting.swift @@ -1,6 +1,6 @@ // // SummaryTagInterpreting.swift -// +// // // Created by Terry Yiu on 8/4/24. // diff --git a/Tests/NostrSDKTests/Events/Calendars/CalendarListEventTests.swift b/Tests/NostrSDKTests/Events/Calendars/CalendarListEventTests.swift index e4e86bf..4245537 100644 --- a/Tests/NostrSDKTests/Events/Calendars/CalendarListEventTests.swift +++ b/Tests/NostrSDKTests/Events/Calendars/CalendarListEventTests.swift @@ -24,11 +24,13 @@ final class CalendarListEventTests: XCTestCase, EventCreating, EventVerifying, F let identifier = "family-calendar" let title = "Family Calendar" let description = "All family events." - let calendar = try calendarListEvent(withIdentifier: identifier, title: title, description: description, calendarEventsCoordinates: [dateBasedCalendarEventCoordinates, timeBasedCalendarEventCoordinates], signedBy: Keypair.test) + let imageString = "https://nostrsdk.com/image.png" + let calendar = try calendarListEvent(withIdentifier: identifier, title: title, description: description, calendarEventsCoordinates: [dateBasedCalendarEventCoordinates, timeBasedCalendarEventCoordinates], imageURL: URL(string: imageString), signedBy: Keypair.test) XCTAssertEqual(calendar.identifier, identifier) XCTAssertEqual(calendar.title, title) XCTAssertEqual(calendar.content, description) + XCTAssertEqual(calendar.imageURL?.absoluteString, imageString) XCTAssertEqual(calendar.calendarEventCoordinateList, [dateBasedCalendarEventCoordinates, timeBasedCalendarEventCoordinates]) let expectedReplaceableEventCoordinates = try XCTUnwrap(EventCoordinates(kind: .calendar, pubkey: Keypair.test.publicKey, identifier: identifier)) @@ -72,6 +74,8 @@ final class CalendarListEventTests: XCTestCase, EventCreating, EventVerifying, F XCTAssertEqual(event.title, "Family Calendar") XCTAssertEqual(event.content, "All family events.") + XCTAssertEqual(event.imageURL?.absoluteString, "https://nostrsdk.com/image.png") + let pubkey = try XCTUnwrap(PublicKey(hex: "9947f9659dd80c3682402b612f5447e28249997fb3709500c32a585eb0977340")) let dateBasedCalendarEventCoordinates = try XCTUnwrap(EventCoordinates(kind: .dateBasedCalendarEvent, pubkey: pubkey, identifier: "D5EB0A5A-0B36-44DB-95C3-DB51799894E6")) let timeBasedCalendarEventCoordinates = try XCTUnwrap(EventCoordinates(kind: .timeBasedCalendarEvent, pubkey: pubkey, identifier: "1D355ED3-A45D-41A9-B3A5-709211794EFB")) diff --git a/Tests/NostrSDKTests/Fixtures/calendar.json b/Tests/NostrSDKTests/Fixtures/calendar.json index 38e2961..8acaa58 100644 --- a/Tests/NostrSDKTests/Fixtures/calendar.json +++ b/Tests/NostrSDKTests/Fixtures/calendar.json @@ -12,6 +12,10 @@ "title", "Family Calendar" ], + [ + "image", + "https://nostrsdk.com/image.png" + ], [ "a", "31922:9947f9659dd80c3682402b612f5447e28249997fb3709500c32a585eb0977340:D5EB0A5A-0B36-44DB-95C3-DB51799894E6"