Correct :shh/post accumulation
Signed-off-by: Igor Mandrigin <i@mandrigin.ru>
This commit is contained in:
parent
06789a862b
commit
84208aeb85
|
@ -171,6 +171,8 @@
|
||||||
(keep :js-obj)
|
(keep :js-obj)
|
||||||
(apply array))]
|
(apply array))]
|
||||||
(when (pos? (.-length js-messages))
|
(when (pos? (.-length js-messages))
|
||||||
(.. web3
|
(.confirmMessagesProcessed (transport.utils/shh web3)
|
||||||
-shh
|
js-messages
|
||||||
(confirmMessagesProcessed js-messages (fn [_ _])))))))
|
(fn [err resp]
|
||||||
|
(when err
|
||||||
|
(log/info "Confirming message processed failed"))))))))
|
||||||
|
|
|
@ -33,25 +33,25 @@
|
||||||
;; we assume that the chat contains the contact public-key
|
;; we assume that the chat contains the contact public-key
|
||||||
(let [{:keys [current-public-key web3]} db
|
(let [{:keys [current-public-key web3]} db
|
||||||
{:keys [sym-key-id topic]} (get-in db [:transport/chats chat-id])]
|
{:keys [sym-key-id topic]} (get-in db [:transport/chats chat-id])]
|
||||||
{:shh/post {:web3 web3
|
{:shh/post [{:web3 web3
|
||||||
:success-event success-event
|
:success-event success-event
|
||||||
:message (merge {:sig current-public-key
|
:message (merge {:sig current-public-key
|
||||||
:symKeyID sym-key-id
|
:symKeyID sym-key-id
|
||||||
:payload payload
|
:payload payload
|
||||||
:topic topic}
|
:topic topic}
|
||||||
whisper-opts)}}))
|
whisper-opts)}]}))
|
||||||
|
|
||||||
(defn send-with-pubkey
|
(defn send-with-pubkey
|
||||||
"Sends the payload using asymetric key (`:current-public-key` in db) and fixed discovery topic"
|
"Sends the payload using asymetric key (`:current-public-key` in db) and fixed discovery topic"
|
||||||
[{:keys [payload chat-id success-event]} {:keys [db] :as cofx}]
|
[{:keys [payload chat-id success-event]} {:keys [db] :as cofx}]
|
||||||
(let [{:keys [current-public-key web3]} db]
|
(let [{:keys [current-public-key web3]} db]
|
||||||
{:shh/post {:web3 web3
|
{:shh/post [{:web3 web3
|
||||||
:success-event success-event
|
:success-event success-event
|
||||||
:message (merge {:sig current-public-key
|
:message (merge {:sig current-public-key
|
||||||
:pubKey chat-id
|
:pubKey chat-id
|
||||||
:payload payload
|
:payload payload
|
||||||
:topic (transport.utils/get-topic constants/contact-discovery)}
|
:topic (transport.utils/get-topic constants/contact-discovery)}
|
||||||
whisper-opts)}}))
|
whisper-opts)}]}))
|
||||||
|
|
||||||
(defn- prepare-recipients [public-keys db]
|
(defn- prepare-recipients [public-keys db]
|
||||||
(map (fn [public-key]
|
(map (fn [public-key]
|
||||||
|
|
|
@ -60,15 +60,16 @@
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
:shh/post
|
:shh/post
|
||||||
(fn [{:keys [web3 message success-event error-event]
|
(fn [post-calls]
|
||||||
:or {error-event :protocol/send-status-message-error}}]
|
(doseq [{:keys [web3 message success-event error-event]
|
||||||
|
:or {error-event :protocol/send-status-message-error}} post-calls]
|
||||||
(post-message {:web3 web3
|
(post-message {:web3 web3
|
||||||
:whisper-message (update message :payload (comp transport.utils/from-utf8
|
:whisper-message (update message :payload (comp transport.utils/from-utf8
|
||||||
transit/serialize))
|
transit/serialize))
|
||||||
:on-success (if success-event
|
:on-success (if success-event
|
||||||
#(re-frame/dispatch (conj success-event %))
|
#(re-frame/dispatch (conj success-event %))
|
||||||
#(log/debug :shh/post-success))
|
#(log/debug :shh/post-success))
|
||||||
:on-error #(re-frame/dispatch [error-event %])})))
|
:on-error #(re-frame/dispatch [error-event %])}))))
|
||||||
|
|
||||||
;; This event params contain a recipients key because it's a vector of map with public-key and topic keys.
|
;; This event params contain a recipients key because it's a vector of map with public-key and topic keys.
|
||||||
;; the :shh/post event has public-key and topic keys at the top level of the args map.
|
;; the :shh/post event has public-key and topic keys at the top level of the args map.
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
|
|
||||||
(def ^:private mergable-keys
|
(def ^:private mergable-keys
|
||||||
#{:data-store/tx :data-store/base-tx :chat-received-message/add-fx
|
#{:data-store/tx :data-store/base-tx :chat-received-message/add-fx
|
||||||
:shh/add-new-sym-keys :call-jail :shh/get-new-sym-keys
|
:shh/add-new-sym-keys :shh/get-new-sym-keys :shh/post
|
||||||
:confirm-message-processed})
|
:confirm-message-processed :call-jail})
|
||||||
|
|
||||||
(defn safe-merge [fx new-fx]
|
(defn safe-merge [fx new-fx]
|
||||||
(if (:merging-fx-with-common-keys fx)
|
(if (:merging-fx-with-common-keys fx)
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
message {:chat-id "chat-id"
|
message {:chat-id "chat-id"
|
||||||
:from "a"
|
:from "a"
|
||||||
:message-id "1"}
|
:message-id "1"}
|
||||||
extract-seen (comp :payload :message :shh/post)]
|
extract-seen (comp :payload :message first :shh/post)]
|
||||||
(testing "it send a seen message when the chat is 1-to-1 and is open"
|
(testing "it send a seen message when the chat is 1-to-1 and is open"
|
||||||
(is (instance? protocol/MessagesSeen
|
(is (instance? protocol/MessagesSeen
|
||||||
(extract-seen (message/receive message db))))
|
(extract-seen (message/receive message db))))
|
||||||
|
|
Loading…
Reference in New Issue