Merge 'fix: regression that dropped q tags from quote reposts' #2617

William Casarin (2):
      fix: regression that dropped q tags from quote reposts
This commit is contained in:
William Casarin
2024-10-26 11:30:45 -07:00
3 changed files with 15 additions and 49 deletions

View File

@@ -484,34 +484,6 @@ 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 references: [RefId] = []
@State var pubkeys: [Pubkey] = []
@State var filtered_pubkeys: Set<Pubkey> = []
@State var focusWordAttributes: (String?, NSRange?) = (nil, nil)
@State var newCursorIndex: Int?
@@ -100,12 +100,8 @@ struct PostView: View {
// don't add duplicate pubkeys but retain order
var pkset = Set<Pubkey>()
// we only want pubkeys really
let pks = references.reduce(into: Array<Pubkey>()) { acc, ref in
guard case .pubkey(let pk) = ref else {
return
}
// only unique and non-filtered pubkeys
let pks = pubkeys.reduce(into: Array<Pubkey>()) { acc, pk in
if pkset.contains(pk) || filtered_pubkeys.contains(pk) {
return
}
@@ -401,16 +397,6 @@ 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) {
@@ -494,14 +480,14 @@ struct PostView: View {
switch action {
case .replying_to(let replying_to):
references = gather_reply_ids(our_pubkey: damus_state.pubkey, from: replying_to)
break
case .quoting(let quoting):
references = gather_quote_ids(our_pubkey: damus_state.pubkey, from: quoting)
break
case .posting(let target):
guard !loaded_draft else { break }
fill_target_content(target: target)
case .highlighting(let draft):
references = [draft.source.ref()]
break
}
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
@@ -721,6 +707,8 @@ 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,7 +153,13 @@ 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