cleanup shh/post

Signed-off-by: yenda <eric@status.im>
This commit is contained in:
yenda 2019-08-21 15:30:00 +02:00
parent 75ce7da50c
commit ff2b24b1c6
No known key found for this signature in database
GPG Key ID: 0095623C0069DCE6
4 changed files with 2 additions and 72 deletions

View File

@ -14,13 +14,6 @@
:on-success on-success
:on-error on-error}))
(defn post-message
[{:keys [whisper-message on-success on-error]}]
(json-rpc/call {:method "shh_generateSymKeyFromPassword"
:params [whisper-message]
:on-success on-success
:on-error on-error}))
(defn send-direct-message!
[direct-message success-event error-event messages-count]
(json-rpc/call {:method "shhext_sendDirectMessage"
@ -98,18 +91,6 @@
ethereum/utf8-to-hex)}]
(send-public-message! message success-event error-event)))))
(re-frame/reg-fx
:shh/post
(fn [post-calls]
(doseq [{:keys [message success-event error-event]
:or {error-event :transport/send-status-message-error}} post-calls]
(post-message {:whisper-message (update message :payload (comp ethereum/utf8-to-hex
transit/serialize))
:on-success (if success-event
#(re-frame/dispatch (conj success-event % 1))
#(log/debug :shh/post-success))
:on-error #(re-frame/dispatch [error-event %])}))))
(defn get-sym-key
[{:keys [sym-key-id on-success on-error]}]
(json-rpc/call {:method "shh_getSymKey"

View File

@ -12,7 +12,7 @@
(def ^:private mergable-keys
#{:data-store/tx :chat-received-message/add-fx
:shh/post :filters/load-filters
:filters/load-filters
:pairing/set-installation-metadata
:status-im.data-store.messages/save-message
:shh/send-direct-message :shh/remove-filter

View File

@ -151,25 +151,6 @@
"opened" {:loaded-unviewed-messages-ids #{}}
"1-1" {:loaded-unviewed-messages-ids #{"6" "5" "4"}}}})
#_(deftest mark-messages-seen
(testing "Marking messages seen correctly marks loaded messages as seen and updates absolute unviewed set"
(let [fx (chat/mark-messages-seen {:db test-db} "status")
me (get-in test-db [:multiaccount :public-key])]
(is (= '(true true true)
(map (comp :seen second) (get-in fx [:db :chats "status" :messages]))))
(is (= 1 (count (:data-store/tx fx))))
;; for public chats, no confirmation is sent out
(is (= nil (:shh/post fx)))))
(testing "With empty unviewed set, no effects are produced"
(is (= nil (chat/mark-messages-seen {:db test-db} "opened"))))
#_(testing "For 1-1 chat, we send seen messages confirmation to the
recipient as well"
(is (= #{"4" "5" "6"}
(set (get-in (chat/mark-messages-seen {:db test-db} "1-1")
[:shh/post 0 :message :payload :message-ids]))))))
(deftest update-dock-badge-label
(testing "When user has unseen private messages"
(is (= {:set-dock-badge-label 3}

View File

@ -54,9 +54,7 @@
(testing "it adds the message"
(is message))
(testing "it marks the message as outgoing"
(is (= true (:outgoing message))))
(testing "it does not send a seen confirmation"
(is (not (:shh/post actual))))))))
(is (= true (:outgoing message))))))))
(deftest receive-many-clock-value
(let [db {:multiaccount {:public-key "me"}
@ -176,36 +174,6 @@
(testing "a message with non matching chat-id"
(is (get-in (message/receive-many cofx [bad-chat-id-message]) [:db :chats "not-matching" :messages "1"])))))
(deftest receive-send-seen
(let [cofx {:db {:chats {"chat-id" {}}
:multiaccount {:public-key "a"}
:current-chat-id "chat-id"
:view-id :chat}}
message {:chat-id "chat-id"
:message-type :user-message
:from "chat-id"
:message-id "1"
:clock-value 1
:timestamp 0}
extract-seen (comp :payload :message first :shh/post)]
#_(testing "it sends a seen message when the chat is 1-to-1 and is open"
(is (instance? protocol/MessagesSeen
(extract-seen (message/receive-many cofx [message]))))
(is (= #{"1"} (:message-ids (extract-seen (message/receive-many cofx [message]))))))
(testing "it does not send any when the chat is a group-chat"
(is (nil? (extract-seen
(message/receive-many
(assoc-in cofx [:db :chats "chat-id" :group-chat] true)
[message])))))
(testing "it does not send any when we are in a different chat"
(is (nil? (extract-seen
(message/receive-many (assoc-in cofx [:db :current-chat-id] :different)
[message])))))
(testing "it does not send any when we are not in a chat view"
(is (nil? (extract-seen
(message/receive-many (assoc-in cofx [:db :view-id] :home)
[message])))))))
(deftest delete-message
(let [timestamp (time/now)
cofx1 {:db {:chats {"chat-id" {:messages {0 {:message-id 0