Skip to content

Commit

Permalink
Parse display_name (#82)
Browse files Browse the repository at this point in the history
* Parse display_name

* Add Warning in Documentation for `display_name`

Co-authored-by: Bryan Montz <[email protected]>

---------

Co-authored-by: Bryan Montz <[email protected]>
  • Loading branch information
joelklabo and bryanmontz authored Aug 21, 2023
1 parent 8d9c7ad commit 797f285
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Sources/NostrSDK/Events/SetMetadataEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public struct UserMetadata: Codable {
/// The user's name.
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.
public let about: String?

Expand All @@ -35,10 +39,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
Expand Down
2 changes: 2 additions & 0 deletions Tests/NostrSDKTests/EventCreatingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: "[email protected]",
Expand All @@ -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, "[email protected]")
Expand Down
1 change: 1 addition & 0 deletions Tests/NostrSDKTests/EventDecodingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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, "[email protected]")
Expand Down

0 comments on commit 797f285

Please sign in to comment.