From 75ce7da50c7c00cb4521fd494a2fba835a404626 Mon Sep 17 00:00:00 2001 From: yenda Date: Wed, 21 Aug 2019 15:27:26 +0200 Subject: [PATCH] remove realm chat-transport usages --- src/status_im/chat/models.cljs | 3 -- src/status_im/data_store/core.cljs | 2 - src/status_im/data_store/transport.cljs | 37 ----------------- src/status_im/multiaccounts/update/core.cljs | 18 ++------- src/status_im/protocol/core.cljs | 3 +- src/status_im/signals/core.cljs | 1 - src/status_im/transport/core.cljs | 3 +- src/status_im/transport/db.cljs | 10 ----- src/status_im/transport/impl/send.cljs | 15 +------ src/status_im/transport/message/core.cljs | 40 +------------------ src/status_im/transport/message/protocol.cljs | 19 --------- src/status_im/ui/screens/db.cljs | 2 - test/cljs/status_im/test/chat/models.cljs | 23 +---------- test/cljs/status_im/test/protocol/core.cljs | 1 - test/cljs/status_im/test/sign_in/data.cljs | 15 ++----- test/cljs/status_im/test/sign_in/flow.cljs | 1 - test/cljs/status_im/test/transport/core.cljs | 6 --- 17 files changed, 13 insertions(+), 186 deletions(-) delete mode 100644 src/status_im/data_store/transport.cljs diff --git a/src/status_im/chat/models.cljs b/src/status_im/chat/models.cljs index ae2d259c8d..f52b95edfc 100644 --- a/src/status_im/chat/models.cljs +++ b/src/status_im/chat/models.cljs @@ -179,9 +179,6 @@ (deactivate-chat chat-id) (clear-history chat-id) (transport.filters/stop-listening chat-id) - ;; TODO: this is not accurate, if there's a pending contact - ;; request it will not be sent anymore - (transport.protocol/remove-chat chat-id) (when (not (= (:view-id db) :home)) (navigation/navigate-to-cofx :home {}))))) diff --git a/src/status_im/data_store/core.cljs b/src/status_im/data_store/core.cljs index ac81696086..063b510b46 100644 --- a/src/status_im/data_store/core.cljs +++ b/src/status_im/data_store/core.cljs @@ -13,7 +13,6 @@ status-im.data-store.chats status-im.data-store.messages status-im.data-store.contacts - status-im.data-store.transport status-im.data-store.mailservers [status-im.utils.fx :as fx] [status-im.protocol.core :as protocol])) @@ -203,7 +202,6 @@ (fx/defn handle-change-multiaccount-success {:events [::multiaccount-change-success] :interceptors [(re-frame/inject-cofx :data-store/get-all-mailservers) - (re-frame/inject-cofx :data-store/transport) (re-frame/inject-cofx :data-store/mailserver-topics)]} [cofx] (protocol/initialize-protocol cofx)) diff --git a/src/status_im/data_store/transport.cljs b/src/status_im/data_store/transport.cljs deleted file mode 100644 index e28b75605d..0000000000 --- a/src/status_im/data_store/transport.cljs +++ /dev/null @@ -1,37 +0,0 @@ -(ns status-im.data-store.transport - (:require [re-frame.core :as re-frame] - [taoensso.timbre :as log] - [status-im.data-store.realm.core :as core])) - -(defn deserialize-chat [serialized-chat] - (dissoc serialized-chat :chat-id)) - -(re-frame/reg-cofx - :data-store/transport - (fn [cofx _] - (assoc cofx - :data-store/transport - (reduce (fn [acc {:keys [chat-id] :as chat}] - (assoc acc chat-id (deserialize-chat chat))) - {} - (-> @core/account-realm - (core/get-all :transport) - (core/all-clj :transport)))))) - -(defn save-transport-tx - "Returns tx function for saving transport" - [{:keys [chat-id chat]}] - (fn [realm] - (log/debug "saving transport, chat-id:" chat-id "chat" chat) - (core/create realm - :transport - (assoc chat :chat-id chat-id) - true))) - -(defn delete-transport-tx - "Returns tx function for deleting transport" - [chat-id] - (fn [realm] - (log/debug "deleting transport, chat-id:" chat-id) - (let [transport (.objectForPrimaryKey realm "transport" chat-id)] - (core/delete realm transport)))) diff --git a/src/status_im/multiaccounts/update/core.cljs b/src/status_im/multiaccounts/update/core.cljs index c712fc5880..445e370196 100644 --- a/src/status_im/multiaccounts/update/core.cljs +++ b/src/status_im/multiaccounts/update/core.cljs @@ -1,7 +1,6 @@ (ns status-im.multiaccounts.update.core (:require [status-im.contact.db :as contact.db] [status-im.contact.device-info :as device-info] - [status-im.data-store.transport :as transport-store] [status-im.ethereum.json-rpc :as json-rpc] [status-im.transport.message.contact :as message.contact] [status-im.transport.message.protocol :as protocol] @@ -22,19 +21,10 @@ (fx/defn send-contact-update-fx [{:keys [db] :as cofx} chat-id payload] - (when-let [chat (get-in cofx [:db :transport/chats chat-id])] - (let [updated-chat (assoc chat :resend? "contact-update") - tx [(transport-store/save-transport-tx {:chat-id chat-id - :chat updated-chat})] - success-event [:transport/contact-message-sent chat-id]] - (fx/merge cofx - {:db (assoc-in db - [:transport/chats chat-id :resend?] - "contact-update") - :data-store/tx tx} - (protocol/send-with-pubkey {:chat-id chat-id - :payload payload - :success-event success-event}))))) + (protocol/send-with-pubkey cofx + {:chat-id chat-id + :payload payload + :success-event [:transport/contact-message-sent chat-id]})) (fx/defn contact-public-keys [{:keys [db]}] (reduce (fn [acc [_ {:keys [public-key] :as contact}]] diff --git a/src/status_im/protocol/core.cljs b/src/status_im/protocol/core.cljs index 0649db6fd9..0c2c053f7a 100644 --- a/src/status_im/protocol/core.cljs +++ b/src/status_im/protocol/core.cljs @@ -64,14 +64,13 @@ (semaphores/lock :check-sync-state?)))) (fx/defn initialize-protocol - [{:data-store/keys [transport mailserver-topics mailservers] + [{:data-store/keys [mailserver-topics mailservers] :keys [db] :as cofx}] (let [network (get-in db [:multiaccount :network]) network-id (str (get-in db [:multiaccount :networks/networks network :config :NetworkId]))] (fx/merge cofx {:db (assoc db :rpc-url constants/ethereum-rpc-url - :transport/chats transport :mailserver/topics mailserver-topics) ::json-rpc/call [{:method "net_version" diff --git a/src/status_im/signals/core.cljs b/src/status_im/signals/core.cljs index 3ddc74f348..6b8b78c1b0 100644 --- a/src/status_im/signals/core.cljs +++ b/src/status_im/signals/core.cljs @@ -28,7 +28,6 @@ {:db (assoc db :peers-summary peers-summary :peers-count peers-count)} - (transport.message/resend-contact-messages previous-summary) (mailserver/peers-summary-change previous-summary)))) (fx/defn process diff --git a/src/status_im/transport/core.cljs b/src/status_im/transport/core.cljs index b729ab5881..5ac932b21d 100644 --- a/src/status_im/transport/core.cljs +++ b/src/status_im/transport/core.cljs @@ -42,8 +42,7 @@ (fetch-node-info-fx) (pairing/init) (publisher/start-fx) - (mailserver/connect-to-mailserver) - (message/resend-contact-messages []))) + (mailserver/connect-to-mailserver))) (fx/defn stop-whisper "Stops whisper protocol" diff --git a/src/status_im/transport/db.cljs b/src/status_im/transport/db.cljs index 664761098e..cab7fa631f 100644 --- a/src/status_im/transport/db.cljs +++ b/src/status_im/transport/db.cljs @@ -8,15 +8,7 @@ [status-im.utils.clocks :as utils.clocks] [status-im.constants :as constants])) -;; required -(spec/def ::resend? (spec/nilable #{"contact-request" "contact-request-confirmation" "contact-update"})) - ;; optional -(spec/def ::topic (spec/nilable string?)) -(spec/def ::topics (spec/coll-of ::topic :min-count 1)) -(spec/def ::sym-key-id (spec/nilable string?)) -;;TODO (yenda) remove once go implements persistence -(spec/def ::sym-key (spec/nilable string?)) (spec/def :transport/filter-id (spec/or :keyword keyword? :chat-id :global/not-empty-string)) (spec/def :transport/filter any?) @@ -35,8 +27,6 @@ (spec/def :pairing/installation-id :global/not-empty-string) (spec/def :pairing/device-type :global/not-empty-string) -(spec/def :transport/chat (spec/keys :opt-un [::resend?])) -(spec/def :transport/chats (spec/map-of :global/not-empty-string :transport/chat)) (spec/def :transport/filters (spec/map-of :transport/filter-id (spec/coll-of :transport/filter))) (defn create-chat diff --git a/src/status_im/transport/impl/send.cljs b/src/status_im/transport/impl/send.cljs index 65741b53f5..4b970e6ff9 100644 --- a/src/status_im/transport/impl/send.cljs +++ b/src/status_im/transport/impl/send.cljs @@ -3,7 +3,6 @@ [status-im.utils.fx :as fx] [status-im.pairing.core :as pairing] [status-im.multiaccounts.update.core :as multiaccounts.update] - [status-im.data-store.transport :as transport-store] [status-im.transport.db :as transport.db] [status-im.transport.message.pairing :as transport.pairing] [status-im.transport.message.contact :as transport.contact] @@ -34,9 +33,6 @@ nil nil)] (fx/merge cofx - (protocol/init-chat {:chat-id chat-id - :one-to-one true - :resend? "contact-request"}) (protocol/send-with-pubkey {:chat-id chat-id :payload this :success-event [:transport/contact-message-sent chat-id]}) @@ -51,17 +47,8 @@ [chat-id]) nil nil) - success-event [:transport/contact-message-sent chat-id] - chat (get-in db [:transport/chats chat-id]) - updated-chat (if chat - (assoc chat :resend? "contact-request-confirmation") - (transport.db/create-chat {:resend? "contact-request-confirmation" - :one-to-one true}))] + success-event [:transport/contact-message-sent chat-id]] (fx/merge cofx - {:db (assoc-in db - [:transport/chats chat-id] updated-chat) - :data-store/tx [(transport-store/save-transport-tx {:chat-id chat-id - :chat updated-chat})]} (protocol/send-with-pubkey {:chat-id chat-id :payload this :success-event success-event}) diff --git a/src/status_im/transport/message/core.cljs b/src/status_im/transport/message/core.cljs index 9c387e5d0a..eeb0cd3453 100644 --- a/src/status_im/transport/message/core.cljs +++ b/src/status_im/transport/message/core.cljs @@ -5,7 +5,6 @@ [status-im.chat.models.message :as models.message] [status-im.contact.device-info :as device-info] [status-im.ethereum.json-rpc :as json-rpc] - [status-im.data-store.transport :as transport-store] [status-im.ethereum.core :as ethereum] [status-im.transport.message.contact :as contact] [status-im.transport.message.protocol :as protocol] @@ -90,14 +89,6 @@ [{:keys [db] :as cofx} envelope-hash] {:db (update db :transport/message-envelopes dissoc envelope-hash)}) -(fx/defn update-resend-contact-message - [{:keys [db] :as cofx} chat-id] - (let [chat (get-in db [:transport/chats chat-id]) - updated-chat (assoc chat :resend? nil)] - {:db (assoc-in db [:transport/chats chat-id :resend?] nil) - :data-store/tx [(transport-store/save-transport-tx {:chat-id chat-id - :chat updated-chat})]})) - (fx/defn check-confirmations [{:keys [db] :as cofx} status chat-id message-id] (when-let [{:keys [pending-confirmations not-sent]} @@ -127,9 +118,7 @@ (case message-type :contact-message (when (= :sent status) - (fx/merge cofx - (remove-hash envelope-hash) - (update-resend-contact-message chat-id))) + (remove-hash cofx envelope-hash)) (when-let [{:keys [from]} (get-in db [:chats chat-id :messages message-id])] (let [{:keys [fcm-token]} (get-in db [:contacts/contacts chat-id]) @@ -182,33 +171,6 @@ (protocol/send (contact/map->ContactRequest own-info) chat-id cofx)) -(fx/defn resend-contact-message - [cofx own-info chat-id] - (let [{:keys [resend?] :as chat} (get-in cofx [:db :transport/chats chat-id])] - (case resend? - "contact-request" - (resend-contact-request cofx own-info chat-id chat) - "contact-request-confirmation" - (protocol/send (contact/map->ContactRequestConfirmed own-info) - chat-id - cofx) - "contact-update" - (protocol/send-with-pubkey cofx - {:chat-id chat-id - :payload (contact/map->ContactUpdate own-info)}) - nil))) - -(fx/defn resend-contact-messages - [{:keys [db] :as cofx} previous-summary] - (when (and (zero? (count previous-summary)) - (= :online (:network-status db)) - (pos? (count (:peers-summary db)))) - (let [own-info (own-info db) - resend-contact-message-fxs (map (fn [chat-id] - (resend-contact-message own-info chat-id)) - (keys (:transport/chats db)))] - (apply fx/merge cofx resend-contact-message-fxs)))) - (re-frame/reg-fx :transport/confirm-messages-processed (fn [confirmations] diff --git a/src/status_im/transport/message/protocol.cljs b/src/status_im/transport/message/protocol.cljs index 69e9c528cf..1501448098 100644 --- a/src/status_im/transport/message/protocol.cljs +++ b/src/status_im/transport/message/protocol.cljs @@ -6,7 +6,6 @@ [status-im.ethereum.core :as ethereum] [status-im.transport.db :as transport.db] [status-im.utils.pairing :as pairing.utils] - [status-im.data-store.transport :as transport-store] [status-im.transport.utils :as transport.utils] [status-im.tribute-to-talk.whitelist :as whitelist] [status-im.utils.config :as config] @@ -29,24 +28,6 @@ :powTarget config/pow-target :powTime config/pow-time}) -(fx/defn init-chat - "Initialises chat on protocol layer." - [{:keys [db now]} - {:keys [chat-id resend?]}] - (let [transport-chat (transport.db/create-chat {:resend? resend?})] - {:db (assoc-in db - [:transport/chats chat-id] - transport-chat) - - :data-store/tx [(transport-store/save-transport-tx {:chat-id chat-id - :chat transport-chat})]})) - -(fx/defn remove-chat - [{:keys [db]} chat-id] - (when (get-in db [:transport/chats chat-id]) - {:db (update db :transport/chats dissoc chat-id) - :data-store/tx [(transport-store/delete-transport-tx chat-id)]})) - (defn send-public-message "Sends the payload to topic" [cofx chat-id success-event payload] diff --git a/src/status_im/ui/screens/db.cljs b/src/status_im/ui/screens/db.cljs index de4eaa5363..6ef7bbfddf 100644 --- a/src/status_im/ui/screens/db.cljs +++ b/src/status_im/ui/screens/db.cljs @@ -42,7 +42,6 @@ :network constants/default-network :networks/networks constants/default-networks :my-profile/editing? false - :transport/chats {} :transport/filters {} :transport/message-envelopes {} :mailserver/mailservers (fleet/default-mailservers {}) @@ -242,7 +241,6 @@ :chat/last-outgoing-message-sent-at :chat/spam-messages-frequency :transport/message-envelopes - :transport/chats :transport/filters :mailserver.edit/mailserver :mailserver/mailservers diff --git a/test/cljs/status_im/test/chat/models.cljs b/test/cljs/status_im/test/chat/models.cljs index b11c17a5a8..e9f65df91f 100644 --- a/test/cljs/status_im/test/chat/models.cljs +++ b/test/cljs/status_im/test/chat/models.cljs @@ -101,8 +101,7 @@ (deftest remove-chat-test (let [chat-id "1" - cofx {:db {:transport/chats {chat-id {}} - :chats {chat-id {:messages {"1" {:clock-value 1} + cofx {:db {:chats {chat-id {:messages {"1" {:clock-value 1} "2" {:clock-value 10} "3" {:clock-value 2}}}}}}] (testing "it deletes all the messages" @@ -114,28 +113,10 @@ (testing "it sets the chat as inactive" (let [actual (chat/remove-chat cofx chat-id)] (is (= false (get-in actual [:db :chats chat-id :is-active]))))) - (testing "it removes it from transport if it's a public chat" - (let [actual (chat/remove-chat (update-in - cofx - [:db :chats chat-id] - assoc - :group-chat true - :public? true) - chat-id)] - (is (not (get-in actual [:db :transport/chats chat-id]))))) - #_(testing "it sends a leave group request if it's a group-chat" - (let [actual (chat/remove-chat (assoc-in - cofx - [:db :chats chat-id :group-chat] - true) - chat-id)] - (is (:shh/post actual)) - (testing "it does not remove transport, only after send is successful" - (is (get-in actual [:db :transport/chats chat-id]))))) (testing "it adds the relevant transactions for realm" (let [actual (chat/remove-chat cofx chat-id)] (is (:data-store/tx actual)) - (is (= 3 (count (:data-store/tx actual)))))))) + (is (= 2 (count (:data-store/tx actual)))))))) (deftest multi-user-chat? (let [chat-id "1"] diff --git a/test/cljs/status_im/test/protocol/core.cljs b/test/cljs/status_im/test/protocol/core.cljs index fc8b6adbee..c6d0d180a4 100644 --- a/test/cljs/status_im/test/protocol/core.cljs +++ b/test/cljs/status_im/test/protocol/core.cljs @@ -38,7 +38,6 @@ (rf/reg-fx :data-store/save-chat (constantly nil)) (rf/reg-fx :data-store/save-message (constantly nil)) (rf/reg-fx :data-store/save-contact (constantly nil)) - (rf/reg-fx :data-store.transport/save (constantly nil)) (rf/reg-fx :data-store/update-message (constantly nil)) (rf/dispatch [:contact.ui/send-message-pressed {:public-key contact-public-key}]) diff --git a/test/cljs/status_im/test/sign_in/data.cljs b/test/cljs/status_im/test/sign_in/data.cljs index 885865901a..48f7879b41 100644 --- a/test/cljs/status_im/test/sign_in/data.cljs +++ b/test/cljs/status_im/test/sign_in/data.cljs @@ -157,20 +157,11 @@ (def transport {"0x04d6e56a475cd35f512d6ce0bf76c2c2af435c85ff48c2b9bdefd129f620e051a436f50961eae5717b2a750e59c3f5b60647d927da46d0b8b11621640b5678fc24" - {:sym-key nil - :resend? nil - :topic nil - :sym-key-id nil} + {:resend? nil} "0x043ae31038ff45a31b096a91d3f8290e079366fbbae76a00fbbd349cd0e5b8d7598965d206772ec4504f68908649a08383cdc51a52cdae5e9ccc744ace4d37020f" - {:sym-key nil - :resend? nil - :topic nil - :sym-key-id nil} + {:resend? nil} "status" - {:sym-key "0x36224048e42c49e5c59c57bba5024fbb8822d6b4ee6ac5fbefd8b77f5323ecc4" - :resend? nil - :topic "0xcd423760" - :sym-key-id "2091c39cac37211987f63391b93d0bd021b9df247da50728bfd766946993849d"}}) + {:resend? nil}}) (def topics {"0xf8946aac" {:chat-ids #{:discovery-topic} :last-request 1547319670}}) diff --git a/test/cljs/status_im/test/sign_in/flow.cljs b/test/cljs/status_im/test/sign_in/flow.cljs index 5b8aa73316..34bde7818f 100644 --- a/test/cljs/status_im/test/sign_in/flow.cljs +++ b/test/cljs/status_im/test/sign_in/flow.cljs @@ -32,7 +32,6 @@ :semaphores #{}} cofx {:db db :data-store/mailservers [] - :data-store/transport data/transport :data-store/mailserver-topics data/topics} login-result "{\"error\":\"\"}" efx (login.core/multiaccount-login-success cofx) diff --git a/test/cljs/status_im/test/transport/core.cljs b/test/cljs/status_im/test/transport/core.cljs index efd09aeb47..27276b7932 100644 --- a/test/cljs/status_im/test/transport/core.cljs +++ b/test/cljs/status_im/test/transport/core.cljs @@ -7,12 +7,6 @@ (deftest init-whisper (let [cofx {:db {:multiaccount {:public-key "1"} - :transport/chats {"1" {:topic "topic-1" - :sym-key "sk1"} - "2" {} - "3" {:topic "topic-3" - :sym-key "sk3"} - "4" {:topic "topic-4"}} :semaphores #{}}}] (testing "custom mailservers" (let [ms-1 {:id "1"