mirror of
https://github.com/unclebob/more-speech.git
synced 2024-09-30 10:30:56 +00:00
Keeps track of event history in event-agent :event-history and :back-count. This is in preparation for the forward and back buttons. Also set up the s/defs for the event-agent. And I'm seriously considering replacing the agent with an atom because I keep having to add 'await event-agent' stuff. Ugh.
This commit is contained in:
parent
3a060484e0
commit
3b063f4401
@ -3,7 +3,8 @@
|
|||||||
[more-speech.ui.swing.article-tree :refer :all]
|
[more-speech.ui.swing.article-tree :refer :all]
|
||||||
[more-speech.ui.swing.article-tree-util :refer :all]
|
[more-speech.ui.swing.article-tree-util :refer :all]
|
||||||
[more-speech.nostr.util :as util]
|
[more-speech.nostr.util :as util]
|
||||||
[more-speech.ui.swing.ui-context :refer :all])
|
[more-speech.ui.swing.ui-context :refer :all]
|
||||||
|
[more-speech.ui.swing.article-panel :as article-panel])
|
||||||
(:import (javax.swing.tree DefaultMutableTreeNode)))
|
(:import (javax.swing.tree DefaultMutableTreeNode)))
|
||||||
|
|
||||||
(describe "header tree"
|
(describe "header tree"
|
||||||
@ -293,18 +294,42 @@
|
|||||||
(should-not (node-contains? node 2))))
|
(should-not (node-contains? node 2))))
|
||||||
|
|
||||||
(it "finds children from beginning to end"
|
(it "finds children from beginning to end"
|
||||||
(let [node (DefaultMutableTreeNode. nil)
|
(let [node (DefaultMutableTreeNode. nil)
|
||||||
child1 (DefaultMutableTreeNode. 1)
|
child1 (DefaultMutableTreeNode. 1)
|
||||||
child2 (DefaultMutableTreeNode. 2)
|
child2 (DefaultMutableTreeNode. 2)
|
||||||
child3 (DefaultMutableTreeNode. 3)
|
child3 (DefaultMutableTreeNode. 3)
|
||||||
_ (.add node child1)
|
_ (.add node child1)
|
||||||
_ (.add node child2)
|
_ (.add node child2)
|
||||||
_ (.add node child3)]
|
_ (.add node child3)]
|
||||||
(should (node-contains? node 1))
|
(should (node-contains? node 1))
|
||||||
(should (node-contains? node 2))
|
(should (node-contains? node 2))
|
||||||
(should (node-contains? node 3))
|
(should (node-contains? node 3))
|
||||||
(should-not (node-contains? node 4))))
|
(should-not (node-contains? node 4)))))
|
||||||
|
|
||||||
)
|
|
||||||
|
|
||||||
|
(context "selecting nodes"
|
||||||
|
(with-stubs)
|
||||||
|
(it "remembers which articles have been read and loads article"
|
||||||
|
(with-redefs
|
||||||
|
[article-panel/load-article-info
|
||||||
|
(stub :load-article-info {:return nil})]
|
||||||
|
(let [event-agent (agent {:read-event-ids #{}
|
||||||
|
:selected-event nil
|
||||||
|
:event-history []
|
||||||
|
:back-count 1})
|
||||||
|
_ (reset! ui-context {:event-agent event-agent})
|
||||||
|
selected-event-id 1
|
||||||
|
selected-node (DefaultMutableTreeNode. selected-event-id)
|
||||||
|
tab-name :bob-tab
|
||||||
|
_ (select-article tab-name selected-node)
|
||||||
|
_ (await event-agent) ;ugh.
|
||||||
|
event-state @event-agent
|
||||||
|
read-event-ids (:read-event-ids event-state)
|
||||||
|
selected-event (:selected-event event-state)
|
||||||
|
event-history (:event-history event-state)
|
||||||
|
back-count (:back-count event-state)]
|
||||||
|
(should-have-invoked :load-article-info {:with [selected-event-id]})
|
||||||
|
(should= read-event-ids #{selected-event-id})
|
||||||
|
(should= selected-event selected-event-id)
|
||||||
|
(should= [[tab-name selected-event-id]] event-history)
|
||||||
|
(should= 0 back-count)))))
|
||||||
)
|
)
|
@ -15,13 +15,16 @@
|
|||||||
(s/def ::tag (s/tuple keyword? number?))
|
(s/def ::tag (s/tuple keyword? number?))
|
||||||
(s/def ::tags (s/coll-of ::tag))
|
(s/def ::tags (s/coll-of ::tag))
|
||||||
(s/def ::references (s/coll-of number?))
|
(s/def ::references (s/coll-of number?))
|
||||||
|
(s/def ::relay-url string?)
|
||||||
|
(s/def ::relays (s/coll-of ::relay-url))
|
||||||
(s/def ::event (s/keys :req-un [::id
|
(s/def ::event (s/keys :req-un [::id
|
||||||
::pubkey
|
::pubkey
|
||||||
::created-at
|
::created-at
|
||||||
::content
|
::content
|
||||||
::sig
|
::sig
|
||||||
::tags
|
::tags
|
||||||
::references]))
|
::references]
|
||||||
|
:opt-un [::relays]))
|
||||||
(defn hexify [n]
|
(defn hexify [n]
|
||||||
(util/num32->hex-string n))
|
(util/num32->hex-string n))
|
||||||
|
|
||||||
@ -33,6 +36,32 @@
|
|||||||
(declare process-text-event
|
(declare process-text-event
|
||||||
process-name-event)
|
process-name-event)
|
||||||
|
|
||||||
|
(s/def ::chronological-text-events (s/coll-of ::id))
|
||||||
|
(s/def ::text-event-map (s/map-of :id :event))
|
||||||
|
(s/def ::nicknames (s/map-of ::id string?))
|
||||||
|
(s/def ::name string?)
|
||||||
|
(s/def ::about string?)
|
||||||
|
(s/def ::picture string?)
|
||||||
|
(s/def ::public-key string?)
|
||||||
|
(s/def ::private-key string?)
|
||||||
|
(s/def ::keys (s/keys :req-un [::name ::about ::picture ::public-key ::private-key]))
|
||||||
|
(s/def ::read-event-ids (s/coll-of ::id :kind set?))
|
||||||
|
(s/def ::selected (s/coll-of ::id))
|
||||||
|
(s/def ::blocked (s/coll-of ::id))
|
||||||
|
(s/def ::tab (s/keys :req-un [::selected ::blocked]))
|
||||||
|
(s/def ::tabs (s/map-of keyword? ::tab))
|
||||||
|
(s/def ::event-history (s/coll-of (s/tuple keyword? ::id)))
|
||||||
|
(s/def ::back-count number?)
|
||||||
|
|
||||||
|
(s/def ::event-agent (s/keys :req-un [::chronological-text-events
|
||||||
|
::text-event-map
|
||||||
|
::nicknames
|
||||||
|
::keys
|
||||||
|
::read-event-ids
|
||||||
|
::tabs
|
||||||
|
::event-history
|
||||||
|
::back-count]))
|
||||||
|
|
||||||
(defn make-event-agent [event-agent-map]
|
(defn make-event-agent [event-agent-map]
|
||||||
(agent (merge {:chronological-text-events []
|
(agent (merge {:chronological-text-events []
|
||||||
:text-event-map {}
|
:text-event-map {}
|
||||||
@ -40,13 +69,18 @@
|
|||||||
:keys {}
|
:keys {}
|
||||||
:read-event-ids #{}
|
:read-event-ids #{}
|
||||||
:tabs {}
|
:tabs {}
|
||||||
|
:event-history []
|
||||||
|
:back-count 0
|
||||||
}
|
}
|
||||||
event-agent-map)))
|
event-agent-map)))
|
||||||
|
|
||||||
(defn select-event [event-state id]
|
(defn select-event
|
||||||
|
"called when an event has been selected, but not by back/forward traversal."
|
||||||
|
[event-state tab-name id]
|
||||||
(-> event-state
|
(-> event-state
|
||||||
(update :read-event-ids conj id)
|
(update :read-event-ids conj id)
|
||||||
(assoc :selected-event id)))
|
(update :event-history conj [tab-name id])
|
||||||
|
(assoc :selected-event id :back-count 0)))
|
||||||
|
|
||||||
(defn to-json [o]
|
(defn to-json [o]
|
||||||
(json/write-str o :escape-slash false :escape-unicode false))
|
(json/write-str o :escape-slash false :escape-unicode false))
|
||||||
|
@ -41,11 +41,14 @@
|
|||||||
(with-out-str
|
(with-out-str
|
||||||
(clojure.pprint/pprint event))))
|
(clojure.pprint/pprint event))))
|
||||||
|
|
||||||
(defn select-article [tab-name selected-node]
|
(defn select-article
|
||||||
|
"This should not be called for back/forward traversal because
|
||||||
|
event/select-event adds to the event history."
|
||||||
|
[tab-name selected-node]
|
||||||
(let [selected-id (.getUserObject selected-node)
|
(let [selected-id (.getUserObject selected-node)
|
||||||
event-agent (:event-agent @ui-context)]
|
event-agent (:event-agent @ui-context)]
|
||||||
(swap! ui-context assoc :selected-tab tab-name)
|
(swap! ui-context assoc :selected-tab tab-name)
|
||||||
(send event-agent events/select-event selected-id)
|
(send event-agent events/select-event tab-name selected-id)
|
||||||
(article-panel/load-article-info selected-id)))
|
(article-panel/load-article-info selected-id)))
|
||||||
|
|
||||||
(defn node-selected [tab-name e]
|
(defn node-selected [tab-name e]
|
||||||
|
Loading…
Reference in New Issue
Block a user