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

This reverts commit 5865b000c0.
This commit is contained in:
Daniel D’Aquino
2024-11-01 11:25:24 -07:00
parent b1b032d905
commit 3b62945e5b
3 changed files with 49 additions and 15 deletions

View File

@@ -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)
}

View File

@@ -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()])
}

View File

@@ -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