Fix the #p issue so only trusted contacts and the user's pubkey are in the list; and are not abbreviated.

This commit is contained in:
Robert C. Martin 2023-03-21 15:57:00 -05:00
parent d2150312d8
commit a9e5378dec
2 changed files with 33 additions and 20 deletions

View File

@ -1,13 +1,21 @@
(ns more-speech.nostr.protocol-spec
(:require [speclj.core :refer :all]
[more-speech.mem :as mem]
[more-speech.nostr.protocol :refer :all]
[more-speech.nostr.util :as util]
[more-speech.relay :as relay]))
[more-speech.relay :as relay]
[more-speech.config :as config]
[more-speech.db.in-memory :as in-memory]
[more-speech.db.gateway :as gateway]))
(declare now)
(declare now db)
(describe "protocol utilities"
(with-stubs)
(with now 100)
(with db (in-memory/get-db))
(before-all (config/set-db! :in-memory))
(before (in-memory/clear-db @db))
(before (mem/clear-mem))
(it "increments relay retries on un-retried relays"
(with-redefs [util/get-now-ms (stub :get-now {:return @now})]
(should= {"relay" {:retries 1, :retry-time @now}}
@ -35,28 +43,31 @@
)
(context "sending subscriptions"
(it "has some comments to be removed..."
(pending "delete them."))
(it "sends subscriptions for authors"
(with-redefs [relay/send (stub :send)]
(send-subscription :relay 0 100 [:author1 :author2])
(mem/set-mem :pubkey 1)
(gateway/add-contacts @db 1 [{:pubkey 2}])
(send-subscription :relay 0 100 ["author1xxxxx" "author2xxxxxxxx"])
(should-have-invoked
:send {:with [:relay ["REQ" "ms-past"
{"since" 0
"until" 100
"authors" #{:author1 :author2}}
#_{"since" 0
"authors" #{"author1xxx" "author2xxx"}}
{"since" 0
"until" 100
"#p" #{:author1 :author2}}]]})
"#p" #{"0000000000000000000000000000000000000000000000000000000000000001"
"0000000000000000000000000000000000000000000000000000000000000002"}}]]})
(should-have-invoked
:send {:with [:relay ["REQ" "ms-future"
{"since" 100
"authors" #{:author1 :author2}}
#_{"since" 100
"#p" #{:author1 :author2}}]]})))
"authors" #{"author1xxx" "author2xxx"}}
{"since" 100
"#p" #{"0000000000000000000000000000000000000000000000000000000000000001"
"0000000000000000000000000000000000000000000000000000000000000002"}}]]})))
(it "sends subscriptions without authors"
(with-redefs [relay/send (stub :send)]
(mem/set-mem :pubkey 1)
(send-subscription :relay 0 100)
(should-have-invoked :send {:with [:relay
["REQ" "ms-past"

View File

@ -40,16 +40,19 @@
([relay since now who]
(let [past-filter {"since" since "until" now}
future-filter {"since" now}
past-author-filter (add-trustees "authors" past-filter who)
future-author-filter (add-trustees "authors" future-filter who)
past-mention-filter (add-trustees "#p" past-filter who)
future-mention-filter (add-trustees "#p" future-filter who)]
short-who (map #(subs % 0 10) who)
trustees (contact-list/get-trustees)
trustees (if (empty? trustees) [] (map util/hexify trustees))
past-author-filter (add-trustees "authors" past-filter short-who)
future-author-filter (add-trustees "authors" future-filter short-who)
past-mention-filter (add-trustees "#p" past-filter trustees)
future-mention-filter (add-trustees "#p" future-filter trustees)]
(when (> now since)
(if (some? who)
(relay/send relay ["REQ" "ms-past" past-author-filter #_past-mention-filter])
(relay/send relay ["REQ" "ms-past" past-author-filter past-mention-filter])
(relay/send relay ["REQ" "ms-past" past-filter])))
(if (some? who)
(relay/send relay ["REQ" "ms-future" future-author-filter #_future-mention-filter])
(relay/send relay ["REQ" "ms-future" future-author-filter future-mention-filter])
(relay/send relay ["REQ" "ms-future" future-filter])))))
(defn subscribe-all
@ -61,9 +64,8 @@
(send-subscription relay since now)))
(defn subscribe-to-pubkeys [relay since now pubkeys]
(let [trustees (map util/hexify pubkeys)
short-trustees (map #(subs % 0 10) trustees)]
(send-subscription relay since now short-trustees)))
(let [trustees (map util/hexify pubkeys)]
(send-subscription relay since now trustees)))
(defn subscribe-trusted [relay since now]
(subscribe-to-pubkeys relay since now (contact-list/get-trustees)))