damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 3b62945e5b4ccbed8ecf3f67a1634332a5615d2e
parent b1b032d9057ba91059a5bf6351283dec5791ac13
Author: Daniel D’Aquino <daniel@daquino.me>
Date:   Fri,  1 Nov 2024 11:25:24 -0700

Revert "fix: regression that dropped q tags from quote reposts"

This reverts commit 5865b000c03278be1d3ae5ba542fe3a37e2759b8.

Diffstat:
Mdamus/Nostr/NostrEvent.swift | 28++++++++++++++++++++++++++++
Mdamus/Views/PostView.swift | 28++++++++++++++++++++--------
MdamusTests/PostViewTests.swift | 8+-------
3 files changed, 49 insertions(+), 15 deletions(-)

diff --git a/damus/Nostr/NostrEvent.swift b/damus/Nostr/NostrEvent.swift @@ -484,6 +484,34 @@ func uniq<T: Hashable>(_ xs: [T]) -> [T] { return ys } +func gather_reply_ids(our_pubkey: Pubkey, from: NostrEvent) -> [RefId] { + var ids: [RefId] = from.referenced_ids.first.map({ ref in [ .event(ref) ] }) ?? [] + + let pks = from.referenced_pubkeys.reduce(into: [RefId]()) { rs, pk in + if pk == our_pubkey { + return + } + rs.append(.pubkey(pk)) + } + + ids.append(.event(from.id)) + ids.append(contentsOf: uniq(pks)) + + if from.pubkey != our_pubkey { + ids.append(.pubkey(from.pubkey)) + } + + return ids +} + +func gather_quote_ids(our_pubkey: Pubkey, from: NostrEvent) -> [RefId] { + var ids: [RefId] = [.quote(from.id.quote_id)] + if from.pubkey != our_pubkey { + ids.append(.pubkey(from.pubkey)) + } + return ids +} + func event_from_json(dat: String) -> NostrEvent? { return NostrEvent.owned_from_json(json: dat) } diff --git a/damus/Views/PostView.swift b/damus/Views/PostView.swift @@ -56,7 +56,7 @@ struct PostView: View { @State var image_upload_confirm: Bool = false @State var imagePastedFromPasteboard: UIImage? = nil @State var imageUploadConfirmPasteboard: Bool = false - @State var pubkeys: [Pubkey] = [] + @State var references: [RefId] = [] @State var filtered_pubkeys: Set<Pubkey> = [] @State var focusWordAttributes: (String?, NSRange?) = (nil, nil) @State var newCursorIndex: Int? @@ -100,8 +100,12 @@ struct PostView: View { // don't add duplicate pubkeys but retain order var pkset = Set<Pubkey>() - // only unique and non-filtered pubkeys - let pks = pubkeys.reduce(into: Array<Pubkey>()) { acc, pk in + // we only want pubkeys really + let pks = references.reduce(into: Array<Pubkey>()) { acc, ref in + guard case .pubkey(let pk) = ref else { + return + } + if pkset.contains(pk) || filtered_pubkeys.contains(pk) { return } @@ -397,6 +401,16 @@ struct PostView: View { self.tagModel.diff = post.string.count } + var pubkeys: [Pubkey] { + self.references.reduce(into: [Pubkey]()) { pks, ref in + guard case .pubkey(let pk) = ref else { + return + } + + pks.append(pk) + } + } + var body: some View { GeometryReader { (deviceSize: GeometryProxy) in VStack(alignment: .leading, spacing: 0) { @@ -490,14 +504,14 @@ struct PostView: View { switch action { case .replying_to(let replying_to): - break + references = gather_reply_ids(our_pubkey: damus_state.pubkey, from: replying_to) case .quoting(let quoting): - break + references = gather_quote_ids(our_pubkey: damus_state.pubkey, from: quoting) case .posting(let target): guard !loaded_draft else { break } fill_target_content(target: target) case .highlighting(let draft): - break + references = [draft.source.ref()] } DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { @@ -728,8 +742,6 @@ func build_post(state: DamusState, post: NSMutableAttributedString, action: Post case .quoting(let ev): content.append(" nostr:" + bech32_note_id(ev.id)) - tags.append(["q", ev.id.hex()]); - if let quoted_ev = state.events.lookup(ev.id) { tags.append(["p", quoted_ev.pubkey.hex()]) } diff --git a/damusTests/PostViewTests.swift b/damusTests/PostViewTests.swift @@ -153,13 +153,7 @@ final class PostViewTests: XCTestCase { XCTAssertNil(newManuallyEditedContent.attribute(.link, at: 11, effectiveRange: nil)) }) } - - func testQuoteRepost() { - let post = build_post(state: test_damus_state, post: .init(), action: .quoting(test_note), uploadedMedias: [], pubkeys: []) - - XCTAssertEqual(post.tags, [["q", test_note.id.hex()]]) - } - + func testMentionLinkEditorHandling_noWhitespaceAfterLink2_addsWhitespace() { var content: NSMutableAttributedString