-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add types: TextNoteRepostEvent (kind 6) and GenericRepostEvent (kind 16)
- Loading branch information
1 parent
f61b157
commit f637ffc
Showing
6 changed files
with
113 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// GenericRepostEvent.swift | ||
// | ||
// | ||
// Created by Bryan Montz on 8/3/23. | ||
// | ||
|
||
import Foundation | ||
|
||
/// A generic repost event (kind 16) can include any kind of event inside other than kind 1. | ||
/// > Note: Generic reposts SHOULD contain a `k` tag with the stringified kind number of the reposted event as its value. | ||
/// See [NIP-18](https://github.com/nostr-protocol/nips/blob/master/18.md#generic-reposts). | ||
public class GenericRepostEvent: NostrEvent { | ||
/// The pubkey of the reposted event. | ||
var repostedEventPubkey: String? { | ||
tags.first(where: { $0.name == .pubkey })?.value | ||
} | ||
|
||
/// The note that is being reposted. | ||
var repostedEvent: NostrEvent? { | ||
guard let jsonData = content.data(using: .utf8), | ||
let note: NostrEvent = try? JSONDecoder().decode(NostrEvent.self, from: jsonData) else { | ||
return nil | ||
} | ||
return note | ||
} | ||
|
||
/// The id of the event that is being reposted. | ||
var repostedEventId: String? { | ||
tags.first(where: { $0.name == .event })?.value | ||
} | ||
|
||
/// The relay URL at which to fetch the reposted event. | ||
var repostedEventRelayURL: String? { | ||
tags.first(where: { $0.name == .event })?.otherParameters.first | ||
} | ||
} |
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,23 @@ | ||
// | ||
// TextNoteRepostEvent.swift | ||
// | ||
// | ||
// Created by Bryan Montz on 8/3/23. | ||
// | ||
|
||
import Foundation | ||
|
||
/// A repost is a kind 6 event that is used to signal to followers that a kind 1 text note is worth reading. | ||
/// | ||
/// See [NIP-18](https://github.com/nostr-protocol/nips/blob/master/18.md#reposts). | ||
public final class TextNoteRepostEvent: GenericRepostEvent { | ||
|
||
/// The note that is being reposted. | ||
var repostedNote: TextNoteEvent? { | ||
guard let jsonData = content.data(using: .utf8), | ||
let note: TextNoteEvent = try? JSONDecoder().decode(TextNoteEvent.self, from: jsonData) else { | ||
return nil | ||
} | ||
return note | ||
} | ||
} |
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,19 @@ | ||
{ | ||
"content": "{\"pubkey\":\"reposted-event-pubkey\",\"content\":\"wss:\/\/relay.test\",\"id\":\"test-id\",\"created_at\":1660947193,\"sig\":\"e46223e4324c910e9325b095093e3e8ef5122e223940b040553893124c66e3afb815599af97cc58f2b93cb240e37c42d75fb7747e896c6d51753b93aefb5f22a\",\"kind\":2,\"tags\":[[\"e\",\"9941b55c2844f275b7b8714a1c39859088a425ce798f740ea8fea879f9098641\"]]}", | ||
"created_at": 1660947401, | ||
"id": "f366fce0c21d201d7a2e3fc25d5a20ab481992ccced7de606965543a66c8643f", | ||
"kind": 16, | ||
"pubkey": "3efdaebb1d8923ebd99c9e7ace3b4194ab45512e2be79c1b7d68d9243e0d2681", | ||
"sig": "8f073e7ba13ad6d4709cac193a6bc6f8d7a1427114cb84547aa5c19af9e804a59a7432fc2669b1e2bf0cf6393243689a8dddb0eaeca754f35d6dc28bc8ca7d16", | ||
"tags": [ | ||
[ | ||
"e", | ||
"test-id", | ||
"wss://reposted.relay" | ||
], | ||
[ | ||
"p", | ||
"reposted-event-pubkey" | ||
] | ||
] | ||
} |