From 57e40e3e28d503ea54afbb6b34ed0c5f1e31f33e Mon Sep 17 00:00:00 2001 From: Joel Klabo Date: Sun, 20 Aug 2023 22:41:53 -0700 Subject: [PATCH 1/2] Parse display_name --- Sources/NostrSDK/Events/SetMetadataEvent.swift | 7 ++++++- Tests/NostrSDKTests/EventCreatingTests.swift | 2 ++ Tests/NostrSDKTests/EventDecodingTests.swift | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Sources/NostrSDK/Events/SetMetadataEvent.swift b/Sources/NostrSDK/Events/SetMetadataEvent.swift index 126b8b5..05efe1d 100644 --- a/Sources/NostrSDK/Events/SetMetadataEvent.swift +++ b/Sources/NostrSDK/Events/SetMetadataEvent.swift @@ -13,6 +13,9 @@ public struct UserMetadata: Codable { /// The user's name. public let name: String? + /// The user's display name. + public let displayName: String? + /// The user's description of themself. public let about: String? @@ -35,10 +38,12 @@ public struct UserMetadata: Codable { case nostrAddress = "nip05" case pictureURL = "picture" case bannerPictureURL = "banner" + case displayName = "display_name" } - public init(name: String?, about: String?, website: URL?, nostrAddress: String?, pictureURL: URL?, bannerPictureURL: URL?) { + public init(name: String?, displayName: String?, about: String?, website: URL?, nostrAddress: String?, pictureURL: URL?, bannerPictureURL: URL?) { self.name = name + self.displayName = displayName self.about = about self.website = website self.nostrAddress = nostrAddress diff --git a/Tests/NostrSDKTests/EventCreatingTests.swift b/Tests/NostrSDKTests/EventCreatingTests.swift index 5bf2d25..5e4c630 100644 --- a/Tests/NostrSDKTests/EventCreatingTests.swift +++ b/Tests/NostrSDKTests/EventCreatingTests.swift @@ -13,6 +13,7 @@ final class EventCreatingTests: XCTestCase, EventCreating, EventVerifying, Fixtu func testCreateSetMetadataEvent() throws { let meta = UserMetadata(name: "Nostr SDK Test", + displayName: "Nostr SDK Display Name", about: "I'm a test account. I'm used to test the Nostr SDK for Apple platforms.", website: URL(string: "https://github.com/nostr-sdk/nostr-sdk-ios")!, nostrAddress: "test@nostr.com", @@ -22,6 +23,7 @@ final class EventCreatingTests: XCTestCase, EventCreating, EventVerifying, Fixtu let event = try setMetadataEvent(withUserMetadata: meta, signedBy: Keypair.test) XCTAssertEqual(event.userMetadata?.name, "Nostr SDK Test") + XCTAssertEqual(event.userMetadata?.displayName, "Nostr SDK Display Name") XCTAssertEqual(event.userMetadata?.about, "I'm a test account. I'm used to test the Nostr SDK for Apple platforms.") XCTAssertEqual(event.userMetadata?.website, URL(string: "https://github.com/nostr-sdk/nostr-sdk-ios")) XCTAssertEqual(event.userMetadata?.nostrAddress, "test@nostr.com") diff --git a/Tests/NostrSDKTests/EventDecodingTests.swift b/Tests/NostrSDKTests/EventDecodingTests.swift index 2d03d95..47543ae 100644 --- a/Tests/NostrSDKTests/EventDecodingTests.swift +++ b/Tests/NostrSDKTests/EventDecodingTests.swift @@ -24,6 +24,7 @@ final class EventDecodingTests: XCTestCase, FixtureLoading { // access metadata properties from raw dictionary XCTAssertEqual(event.rawUserMetadata["name"] as? String, "cameri") + XCTAssertEqual(event.rawUserMetadata["display_name"] as? String, "Cameri 🦦⚡️") XCTAssertEqual(event.rawUserMetadata["about"] as? String, "@HodlWithLedn. All opinions are my own.\nBitcoiner class of 2021. Core Nostr Developer. Author of Nostream. Professional Relay Operator.") XCTAssertEqual(event.rawUserMetadata["website"] as? String, "https://primal.net/cameri") XCTAssertEqual(event.rawUserMetadata["nip05"] as? String, "cameri@elder.nostr.land") From acff48ddab28314ac332bde69987e6eaf114e20b Mon Sep 17 00:00:00 2001 From: klabo Date: Mon, 21 Aug 2023 09:50:34 -0700 Subject: [PATCH 2/2] Add Warning in Documentation for `display_name` Co-authored-by: Bryan Montz --- Sources/NostrSDK/Events/SetMetadataEvent.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/NostrSDK/Events/SetMetadataEvent.swift b/Sources/NostrSDK/Events/SetMetadataEvent.swift index 05efe1d..67656f1 100644 --- a/Sources/NostrSDK/Events/SetMetadataEvent.swift +++ b/Sources/NostrSDK/Events/SetMetadataEvent.swift @@ -14,6 +14,7 @@ public struct UserMetadata: Codable { public let name: String? /// The user's display name. + /// > Warning: This property is not part of the Nostr specifications. public let displayName: String? /// The user's description of themself.