parent
10c205f9f5
commit
8b77fa8870
|
@ -14,14 +14,12 @@
|
||||||
(defn get-pending-messages! []
|
(defn get-pending-messages! []
|
||||||
(->> (r/get-all :account :pending-message)
|
(->> (r/get-all :account :pending-message)
|
||||||
r/realm-collection->list
|
r/realm-collection->list
|
||||||
(map (fn [{:keys [message-id] :as message}]
|
(map (fn [message]
|
||||||
(-> message
|
(update message :topics reader/read-string)))))
|
||||||
(update :topics reader/read-string)
|
|
||||||
(assoc :id message-id))))))
|
|
||||||
|
|
||||||
(defn- get-id
|
(defn- get-id
|
||||||
[message-id to]
|
[message-id to]
|
||||||
(let [to' (if (and to (str/starts-with? "0x" to))
|
(let [to' (if (and to (str/starts-with? to "0x"))
|
||||||
(subs to 2)
|
(subs to 2)
|
||||||
to)
|
to)
|
||||||
to'' (when to' (subs to' 0 7))
|
to'' (when to' (subs to' 0 7))
|
||||||
|
|
|
@ -65,6 +65,7 @@
|
||||||
{:pre [(valid? ::options options)]}
|
{:pre [(valid? ::options options)]}
|
||||||
(debug :init-whisper)
|
(debug :init-whisper)
|
||||||
(stop-watching-all!)
|
(stop-watching-all!)
|
||||||
|
(d/reset-all-pending-messages!)
|
||||||
(let [web3 (u/make-web3 rpc-url)
|
(let [web3 (u/make-web3 rpc-url)
|
||||||
listener-options {:web3 web3
|
listener-options {:web3 web3
|
||||||
:identity identity}]
|
:identity identity}]
|
||||||
|
|
|
@ -63,6 +63,7 @@
|
||||||
(defn contact-request!
|
(defn contact-request!
|
||||||
[{:keys [web3 message]}]
|
[{:keys [web3 message]}]
|
||||||
{:pre [(valid? :contact-request/message message)]}
|
{:pre [(valid? :contact-request/message message)]}
|
||||||
|
(debug :send-command-request!)
|
||||||
(d/add-pending-message!
|
(d/add-pending-message!
|
||||||
web3
|
web3
|
||||||
(assoc message :type :contact-request
|
(assoc message :type :contact-request
|
||||||
|
|
|
@ -23,8 +23,8 @@
|
||||||
:identity public-key
|
:identity public-key
|
||||||
:groups groups
|
:groups groups
|
||||||
:callback #(dispatch [:incoming-message %1 %2])
|
:callback #(dispatch [:incoming-message %1 %2])
|
||||||
:ack-not-received-s-interval 17
|
:ack-not-received-s-interval 125
|
||||||
:default-ttl 15
|
:default-ttl 120
|
||||||
:send-online-s-interval 180
|
:send-online-s-interval 180
|
||||||
:ttl {}
|
:ttl {}
|
||||||
:max-attempts-number 3
|
:max-attempts-number 3
|
||||||
|
@ -51,8 +51,12 @@
|
||||||
(case type
|
(case type
|
||||||
:message (dispatch [:received-protocol-message! message])
|
:message (dispatch [:received-protocol-message! message])
|
||||||
:group-message (dispatch [:received-protocol-message! message])
|
:group-message (dispatch [:received-protocol-message! message])
|
||||||
:ack (when (#{:message :group-message} (:type payload))
|
:ack (cond
|
||||||
(dispatch [:message-delivered message]))
|
(#{:message :group-message} (:type payload))
|
||||||
|
(dispatch [:message-delivered message])
|
||||||
|
|
||||||
|
(= :contact-request (:type payload))
|
||||||
|
(dispatch [:pending-message-remove message]))
|
||||||
:seen (dispatch [:message-seen message])
|
:seen (dispatch [:message-seen message])
|
||||||
:group-invitation (dispatch [:group-chat-invite-received message])
|
:group-invitation (dispatch [:group-chat-invite-received message])
|
||||||
:leave-group (dispatch [:participant-left-group message])
|
:leave-group (dispatch [:participant-left-group message])
|
||||||
|
|
|
@ -73,29 +73,44 @@
|
||||||
::attempts ::was-sent?]))
|
::attempts ::was-sent?]))
|
||||||
|
|
||||||
(defn add-prepeared-pending-message!
|
(defn add-prepeared-pending-message!
|
||||||
[web3 {:keys [id to] :as pending-message}]
|
[web3 {:keys [message-id to] :as pending-message}]
|
||||||
{:pre [(valid? :delivery/pending-message pending-message)]}
|
{:pre [(valid? :delivery/pending-message pending-message)]}
|
||||||
(debug :add-prepeared-pending-message!)
|
(debug :add-prepeared-pending-message!)
|
||||||
(let [message (select-keys pending-message [:from :to :topics :payload])
|
(let [message (select-keys pending-message [:from :to :topics :payload])
|
||||||
pending-message' (assoc pending-message :message message)]
|
pending-message' (assoc pending-message :message message
|
||||||
(swap! messages assoc-in [web3 id to] pending-message')
|
:id message-id)]
|
||||||
|
(swap! messages assoc-in [web3 message-id to] pending-message')
|
||||||
(when to
|
(when to
|
||||||
(swap! recipient->pending-message
|
(swap! recipient->pending-message
|
||||||
update to set/union #{[web3 id to]}))))
|
update to set/union #{[web3 message-id to]}))))
|
||||||
|
|
||||||
(defn remove-pending-message! [web3 id to]
|
(defn remove-pending-message! [web3 id to]
|
||||||
(swap! messages update-in [web3 id] dissoc to)
|
(swap! messages update web3
|
||||||
|
(fn [messages]
|
||||||
|
(when messages
|
||||||
|
(let [message (messages id)
|
||||||
|
message' (dissoc message to)]
|
||||||
|
(if (seq message')
|
||||||
|
(assoc messages id message')
|
||||||
|
(dissoc messages id))))))
|
||||||
(when to
|
(when to
|
||||||
(swap! recipient->pending-message
|
(swap! recipient->pending-message
|
||||||
update to set/difference #{[web3 id to]})))
|
update to set/difference #{[web3 id to]})))
|
||||||
|
|
||||||
(defn message-was-sent! [web3 id to]
|
(defn message-was-sent! [web3 id to]
|
||||||
(let [messages' (swap! messages update-in [web3 id to]
|
(let [messages' (swap! messages update web3
|
||||||
(fn [message]
|
(fn [messages]
|
||||||
(assoc message :was-sent? true
|
(let [message (get-in messages [id to])
|
||||||
:attemps 1)))]
|
message' (when message
|
||||||
|
(assoc message :was-sent? true
|
||||||
|
:attemps 1))]
|
||||||
|
(if message'
|
||||||
|
(assoc-in messages [id to] message')
|
||||||
|
messages))))]
|
||||||
(when @pending-mesage-callback
|
(when @pending-mesage-callback
|
||||||
(@pending-mesage-callback :sent (get-in messages' [web3 id to])))))
|
(let [message (get-in messages' [web3 id to])]
|
||||||
|
(when message
|
||||||
|
(@pending-mesage-callback :sent message))))))
|
||||||
|
|
||||||
(defn attempt-was-made! [web3 id to]
|
(defn attempt-was-made! [web3 id to]
|
||||||
(debug :attempt-was-made id)
|
(debug :attempt-was-made id)
|
||||||
|
@ -191,3 +206,6 @@
|
||||||
(update-in messages key assoc
|
(update-in messages key assoc
|
||||||
:last-attempt 0
|
:last-attempt 0
|
||||||
:attempts 0))))))
|
:attempts 0))))))
|
||||||
|
|
||||||
|
(defn reset-all-pending-messages! []
|
||||||
|
(reset! messages {}))
|
||||||
|
|
|
@ -13,5 +13,5 @@
|
||||||
(defn post-message!
|
(defn post-message!
|
||||||
[web3 message callback]
|
[web3 message callback]
|
||||||
{:pre [(valid? :shh/message message)]}
|
{:pre [(valid? :shh/message message)]}
|
||||||
(debug :post-message web3 message)
|
(debug :post-message message)
|
||||||
(.post (u/shh web3) (clj->js message) callback))
|
(.post (u/shh web3) (clj->js message) callback))
|
||||||
|
|
Loading…
Reference in New Issue