commit 4821ba61a5f86334ed76bb12621aaaae6c0c1935
parent 15849e290e185d4340fd6338123d58e6922070bf
Author: William Casarin <jb55@jb55.com>
Date:   Mon, 17 Apr 2023 14:28:24 -0700
reply_p_tags: Use uniq instead of Set to preserve order
Diffstat:
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/damus/Nostr/NostrEvent.swift b/damus/Nostr/NostrEvent.swift
@@ -720,11 +720,26 @@ func make_zap_request_event(keypair: FullKeypair, content: String, relays: [Rela
     return ev
 }
 
+func uniq<T: Hashable>(_ xs: [T]) -> [T] {
+    var s = Set<T>()
+    var ys: [T] = []
+    
+    for x in xs {
+        if s.contains(x) {
+            continue
+        }
+        s.insert(x)
+        ys.append(x)
+    }
+    
+    return ys
+}
+
 func gather_reply_ids(our_pubkey: String, from: NostrEvent) -> [ReferencedId] {
     var ids = get_referenced_ids(tags: from.tags, key: "e").first.map { [$0] } ?? []
 
     ids.append(ReferencedId(ref_id: from.id, relay_id: nil, key: "e"))
-    ids.append(contentsOf: Set(from.referenced_pubkeys.filter { $0.ref_id != our_pubkey }))
+    ids.append(contentsOf: uniq(from.referenced_pubkeys.filter { $0.ref_id != our_pubkey }))
     if from.pubkey != our_pubkey {
         ids.append(ReferencedId(ref_id: from.pubkey, relay_id: nil, key: "p"))
     }