get rid of some ui-context references. More to come.

This commit is contained in:
Robert C. Martin 2023-01-29 08:32:56 -06:00
parent 1afeae504a
commit 1103548acb
3 changed files with 42 additions and 28 deletions

View File

@ -1,34 +1,41 @@
(ns more-speech.nostr.trust-updater-spec
(:require [speclj.core :refer :all]
[more-speech.nostr.trust-updater :refer :all]
[more-speech.ui.swing.ui-context :refer :all]))
[more-speech.ui.swing.ui-context :refer :all]
[more-speech.db.in-memory :as in-memory]
[more-speech.db.gateway :as gateway]))
(declare db)
(describe "Setting Trust"
(with-stubs)
(with db (in-memory/get-db))
(before (in-memory/clear-db @db))
(it "establishes new trust with a petname."
(let [my-pubkey 1
contact-lists {1 [{:pubkey 2}]}
event-state {:pubkey my-pubkey :contact-lists contact-lists}]
(reset! ui-context {:event-context (atom event-state)}))
(let [my-pubkey 1]
(set-mem :pubkey my-pubkey)
(gateway/add-contacts @db my-pubkey [{:pubkey 2}])
(entrust 3 "the-petname")
(let [my-contacts (get (:contact-lists @(:event-context @ui-context)) 1)]
(let [my-contacts (gateway/get-contacts @db my-pubkey)]
(should= (set [{:pubkey 2}
{:pubkey 3 :petname "the-petname"}])
(set my-contacts)))
)
))
(it "restablishes trust with a new petname."
(let [my-pubkey 1
contact-lists {1 [{:pubkey 1}
contacts [{:pubkey 1}
{:pubkey 3 :petname "the-old-petname"}
{:pubkey 2}]}
event-state {:pubkey my-pubkey :contact-lists contact-lists}]
(reset! ui-context {:event-context (atom event-state)}))
{:pubkey 2}]
]
(set-mem :pubkey my-pubkey)
(gateway/add-contacts @db my-pubkey contacts)
(entrust 3 "the-new-petname")
(let [my-contacts (get (:contact-lists @(:event-context @ui-context)) 1)]
(let [my-contacts
(gateway/get-contacts @db my-pubkey)
]
(should= (set [{:pubkey 1}
{:pubkey 2}
{:pubkey 3 :petname "the-new-petname"}])
(set my-contacts)))
)
(set my-contacts)))))
)

View File

@ -17,7 +17,9 @@
(describe "header tree"
(with db (in-memory/get-db))
(before (reset! ui-context {:event-context (atom nil)}))
(before (in-memory/clear-db @db)
(clear-mem)
(swap! ui-context assoc :node-map {} :orphaned-references {}))
(context "finding chronological insertion point"
(it "returns zero if empty tree"
@ -149,8 +151,8 @@
(let [event-id 1N
node-map {}
orphaned-references {}
_ (reset! ui-context {:node-map node-map
:orphaned-references orphaned-references})]
_ (swap! ui-context assoc :node-map node-map
:orphaned-references orphaned-references)]
(resolve-any-orphans event-id)
(should= {} (:node-map @ui-context))
(should= {} (:orphaned-references @ui-context)))
@ -164,8 +166,9 @@
node-map {orphan-id [original-orphan-node]
parent-id [parent-node]}
orphaned-references {parent-id #{orphan-id}}
_ (reset! ui-context {:node-map node-map
:orphaned-references orphaned-references})
_ (swap! ui-context assoc
:node-map node-map
:orphaned-references orphaned-references)
_ (resolve-any-orphans parent-id)
orphan-nodes (get-in @ui-context [:node-map orphan-id])
new-orphan-node (second orphan-nodes)

View File

@ -1,10 +1,14 @@
(ns more-speech.ui.swing.ui-context
(:require [clojure.spec.alpha :as s]))
(def ui-context (atom {:event-context (atom nil)
(defn make-ui-context []
(atom {:event-context (atom nil)
:node-map {}
:orphaned-references {}}))
(def ui-context (make-ui-context))
(s/def ::id number?)
(s/def ::orphaned-references (s/map-of ::id (s/coll-of ::id :kind set?)))