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