Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse display_name #82

Merged
merged 2 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
joelklabo marked this conversation as resolved.
Show resolved Hide resolved
/// > 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
Loading