remove realm chat-transport usages

This commit is contained in:
yenda 2019-08-21 15:27:26 +02:00
parent bd3ff3e96a
commit 75ce7da50c
No known key found for this signature in database
GPG Key ID: 0095623C0069DCE6
17 changed files with 13 additions and 186 deletions

View File

@ -179,9 +179,6 @@
(deactivate-chat chat-id) (deactivate-chat chat-id)
(clear-history chat-id) (clear-history chat-id)
(transport.filters/stop-listening 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)) (when (not (= (:view-id db) :home))
(navigation/navigate-to-cofx :home {}))))) (navigation/navigate-to-cofx :home {})))))

View File

@ -13,7 +13,6 @@
status-im.data-store.chats status-im.data-store.chats
status-im.data-store.messages status-im.data-store.messages
status-im.data-store.contacts status-im.data-store.contacts
status-im.data-store.transport
status-im.data-store.mailservers status-im.data-store.mailservers
[status-im.utils.fx :as fx] [status-im.utils.fx :as fx]
[status-im.protocol.core :as protocol])) [status-im.protocol.core :as protocol]))
@ -203,7 +202,6 @@
(fx/defn handle-change-multiaccount-success (fx/defn handle-change-multiaccount-success
{:events [::multiaccount-change-success] {:events [::multiaccount-change-success]
:interceptors [(re-frame/inject-cofx :data-store/get-all-mailservers) :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)]} (re-frame/inject-cofx :data-store/mailserver-topics)]}
[cofx] [cofx]
(protocol/initialize-protocol cofx)) (protocol/initialize-protocol cofx))

View File

@ -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))))

View File

@ -1,7 +1,6 @@
(ns status-im.multiaccounts.update.core (ns status-im.multiaccounts.update.core
(:require [status-im.contact.db :as contact.db] (:require [status-im.contact.db :as contact.db]
[status-im.contact.device-info :as device-info] [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.ethereum.json-rpc :as json-rpc]
[status-im.transport.message.contact :as message.contact] [status-im.transport.message.contact :as message.contact]
[status-im.transport.message.protocol :as protocol] [status-im.transport.message.protocol :as protocol]
@ -22,19 +21,10 @@
(fx/defn send-contact-update-fx (fx/defn send-contact-update-fx
[{:keys [db] :as cofx} chat-id payload] [{:keys [db] :as cofx} chat-id payload]
(when-let [chat (get-in cofx [:db :transport/chats chat-id])] (protocol/send-with-pubkey cofx
(let [updated-chat (assoc chat :resend? "contact-update") {:chat-id chat-id
tx [(transport-store/save-transport-tx {:chat-id chat-id :payload payload
:chat updated-chat})] :success-event [:transport/contact-message-sent chat-id]}))
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})))))
(fx/defn contact-public-keys [{:keys [db]}] (fx/defn contact-public-keys [{:keys [db]}]
(reduce (fn [acc [_ {:keys [public-key] :as contact}]] (reduce (fn [acc [_ {:keys [public-key] :as contact}]]

View File

@ -64,14 +64,13 @@
(semaphores/lock :check-sync-state?)))) (semaphores/lock :check-sync-state?))))
(fx/defn initialize-protocol (fx/defn initialize-protocol
[{:data-store/keys [transport mailserver-topics mailservers] [{:data-store/keys [mailserver-topics mailservers]
:keys [db] :as cofx}] :keys [db] :as cofx}]
(let [network (get-in db [:multiaccount :network]) (let [network (get-in db [:multiaccount :network])
network-id (str (get-in db [:multiaccount :networks/networks network :config :NetworkId]))] network-id (str (get-in db [:multiaccount :networks/networks network :config :NetworkId]))]
(fx/merge cofx (fx/merge cofx
{:db (assoc db {:db (assoc db
:rpc-url constants/ethereum-rpc-url :rpc-url constants/ethereum-rpc-url
:transport/chats transport
:mailserver/topics mailserver-topics) :mailserver/topics mailserver-topics)
::json-rpc/call ::json-rpc/call
[{:method "net_version" [{:method "net_version"

View File

@ -28,7 +28,6 @@
{:db (assoc db {:db (assoc db
:peers-summary peers-summary :peers-summary peers-summary
:peers-count peers-count)} :peers-count peers-count)}
(transport.message/resend-contact-messages previous-summary)
(mailserver/peers-summary-change previous-summary)))) (mailserver/peers-summary-change previous-summary))))
(fx/defn process (fx/defn process

View File

@ -42,8 +42,7 @@
(fetch-node-info-fx) (fetch-node-info-fx)
(pairing/init) (pairing/init)
(publisher/start-fx) (publisher/start-fx)
(mailserver/connect-to-mailserver) (mailserver/connect-to-mailserver)))
(message/resend-contact-messages [])))
(fx/defn stop-whisper (fx/defn stop-whisper
"Stops whisper protocol" "Stops whisper protocol"

View File

@ -8,15 +8,7 @@
[status-im.utils.clocks :as utils.clocks] [status-im.utils.clocks :as utils.clocks]
[status-im.constants :as constants])) [status-im.constants :as constants]))
;; required
(spec/def ::resend? (spec/nilable #{"contact-request" "contact-request-confirmation" "contact-update"}))
;; optional ;; 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? (spec/def :transport/filter-id (spec/or :keyword keyword?
:chat-id :global/not-empty-string)) :chat-id :global/not-empty-string))
(spec/def :transport/filter any?) (spec/def :transport/filter any?)
@ -35,8 +27,6 @@
(spec/def :pairing/installation-id :global/not-empty-string) (spec/def :pairing/installation-id :global/not-empty-string)
(spec/def :pairing/device-type :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))) (spec/def :transport/filters (spec/map-of :transport/filter-id (spec/coll-of :transport/filter)))
(defn create-chat (defn create-chat

View File

@ -3,7 +3,6 @@
[status-im.utils.fx :as fx] [status-im.utils.fx :as fx]
[status-im.pairing.core :as pairing] [status-im.pairing.core :as pairing]
[status-im.multiaccounts.update.core :as multiaccounts.update] [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.db :as transport.db]
[status-im.transport.message.pairing :as transport.pairing] [status-im.transport.message.pairing :as transport.pairing]
[status-im.transport.message.contact :as transport.contact] [status-im.transport.message.contact :as transport.contact]
@ -34,9 +33,6 @@
nil nil
nil)] nil)]
(fx/merge cofx (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 (protocol/send-with-pubkey {:chat-id chat-id
:payload this :payload this
:success-event [:transport/contact-message-sent chat-id]}) :success-event [:transport/contact-message-sent chat-id]})
@ -51,17 +47,8 @@
[chat-id]) [chat-id])
nil nil
nil) nil)
success-event [:transport/contact-message-sent chat-id] 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}))]
(fx/merge cofx (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 (protocol/send-with-pubkey {:chat-id chat-id
:payload this :payload this
:success-event success-event}) :success-event success-event})

View File

@ -5,7 +5,6 @@
[status-im.chat.models.message :as models.message] [status-im.chat.models.message :as models.message]
[status-im.contact.device-info :as device-info] [status-im.contact.device-info :as device-info]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.data-store.transport :as transport-store]
[status-im.ethereum.core :as ethereum] [status-im.ethereum.core :as ethereum]
[status-im.transport.message.contact :as contact] [status-im.transport.message.contact :as contact]
[status-im.transport.message.protocol :as protocol] [status-im.transport.message.protocol :as protocol]
@ -90,14 +89,6 @@
[{:keys [db] :as cofx} envelope-hash] [{:keys [db] :as cofx} envelope-hash]
{:db (update db :transport/message-envelopes dissoc 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 (fx/defn check-confirmations
[{:keys [db] :as cofx} status chat-id message-id] [{:keys [db] :as cofx} status chat-id message-id]
(when-let [{:keys [pending-confirmations not-sent]} (when-let [{:keys [pending-confirmations not-sent]}
@ -127,9 +118,7 @@
(case message-type (case message-type
:contact-message :contact-message
(when (= :sent status) (when (= :sent status)
(fx/merge cofx (remove-hash cofx envelope-hash))
(remove-hash envelope-hash)
(update-resend-contact-message chat-id)))
(when-let [{:keys [from]} (get-in db [:chats chat-id :messages message-id])] (when-let [{:keys [from]} (get-in db [:chats chat-id :messages message-id])]
(let [{:keys [fcm-token]} (get-in db [:contacts/contacts chat-id]) (let [{:keys [fcm-token]} (get-in db [:contacts/contacts chat-id])
@ -182,33 +171,6 @@
(protocol/send (contact/map->ContactRequest own-info) (protocol/send (contact/map->ContactRequest own-info)
chat-id cofx)) 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 (re-frame/reg-fx
:transport/confirm-messages-processed :transport/confirm-messages-processed
(fn [confirmations] (fn [confirmations]

View File

@ -6,7 +6,6 @@
[status-im.ethereum.core :as ethereum] [status-im.ethereum.core :as ethereum]
[status-im.transport.db :as transport.db] [status-im.transport.db :as transport.db]
[status-im.utils.pairing :as pairing.utils] [status-im.utils.pairing :as pairing.utils]
[status-im.data-store.transport :as transport-store]
[status-im.transport.utils :as transport.utils] [status-im.transport.utils :as transport.utils]
[status-im.tribute-to-talk.whitelist :as whitelist] [status-im.tribute-to-talk.whitelist :as whitelist]
[status-im.utils.config :as config] [status-im.utils.config :as config]
@ -29,24 +28,6 @@
:powTarget config/pow-target :powTarget config/pow-target
:powTime config/pow-time}) :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 (defn send-public-message
"Sends the payload to topic" "Sends the payload to topic"
[cofx chat-id success-event payload] [cofx chat-id success-event payload]

View File

@ -42,7 +42,6 @@
:network constants/default-network :network constants/default-network
:networks/networks constants/default-networks :networks/networks constants/default-networks
:my-profile/editing? false :my-profile/editing? false
:transport/chats {}
:transport/filters {} :transport/filters {}
:transport/message-envelopes {} :transport/message-envelopes {}
:mailserver/mailservers (fleet/default-mailservers {}) :mailserver/mailservers (fleet/default-mailservers {})
@ -242,7 +241,6 @@
:chat/last-outgoing-message-sent-at :chat/last-outgoing-message-sent-at
:chat/spam-messages-frequency :chat/spam-messages-frequency
:transport/message-envelopes :transport/message-envelopes
:transport/chats
:transport/filters :transport/filters
:mailserver.edit/mailserver :mailserver.edit/mailserver
:mailserver/mailservers :mailserver/mailservers

View File

@ -101,8 +101,7 @@
(deftest remove-chat-test (deftest remove-chat-test
(let [chat-id "1" (let [chat-id "1"
cofx {:db {:transport/chats {chat-id {}} cofx {:db {:chats {chat-id {:messages {"1" {:clock-value 1}
:chats {chat-id {:messages {"1" {:clock-value 1}
"2" {:clock-value 10} "2" {:clock-value 10}
"3" {:clock-value 2}}}}}}] "3" {:clock-value 2}}}}}}]
(testing "it deletes all the messages" (testing "it deletes all the messages"
@ -114,28 +113,10 @@
(testing "it sets the chat as inactive" (testing "it sets the chat as inactive"
(let [actual (chat/remove-chat cofx chat-id)] (let [actual (chat/remove-chat cofx chat-id)]
(is (= false (get-in actual [:db :chats chat-id :is-active]))))) (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" (testing "it adds the relevant transactions for realm"
(let [actual (chat/remove-chat cofx chat-id)] (let [actual (chat/remove-chat cofx chat-id)]
(is (:data-store/tx actual)) (is (:data-store/tx actual))
(is (= 3 (count (:data-store/tx actual)))))))) (is (= 2 (count (:data-store/tx actual))))))))
(deftest multi-user-chat? (deftest multi-user-chat?
(let [chat-id "1"] (let [chat-id "1"]

View File

@ -38,7 +38,6 @@
(rf/reg-fx :data-store/save-chat (constantly nil)) (rf/reg-fx :data-store/save-chat (constantly nil))
(rf/reg-fx :data-store/save-message (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/save-contact (constantly nil))
(rf/reg-fx :data-store.transport/save (constantly nil))
(rf/reg-fx :data-store/update-message (constantly nil)) (rf/reg-fx :data-store/update-message (constantly nil))
(rf/dispatch [:contact.ui/send-message-pressed {:public-key contact-public-key}]) (rf/dispatch [:contact.ui/send-message-pressed {:public-key contact-public-key}])

View File

@ -157,20 +157,11 @@
(def transport (def transport
{"0x04d6e56a475cd35f512d6ce0bf76c2c2af435c85ff48c2b9bdefd129f620e051a436f50961eae5717b2a750e59c3f5b60647d927da46d0b8b11621640b5678fc24" {"0x04d6e56a475cd35f512d6ce0bf76c2c2af435c85ff48c2b9bdefd129f620e051a436f50961eae5717b2a750e59c3f5b60647d927da46d0b8b11621640b5678fc24"
{:sym-key nil {:resend? nil}
:resend? nil
:topic nil
:sym-key-id nil}
"0x043ae31038ff45a31b096a91d3f8290e079366fbbae76a00fbbd349cd0e5b8d7598965d206772ec4504f68908649a08383cdc51a52cdae5e9ccc744ace4d37020f" "0x043ae31038ff45a31b096a91d3f8290e079366fbbae76a00fbbd349cd0e5b8d7598965d206772ec4504f68908649a08383cdc51a52cdae5e9ccc744ace4d37020f"
{:sym-key nil {:resend? nil}
:resend? nil
:topic nil
:sym-key-id nil}
"status" "status"
{:sym-key "0x36224048e42c49e5c59c57bba5024fbb8822d6b4ee6ac5fbefd8b77f5323ecc4" {:resend? nil}})
:resend? nil
:topic "0xcd423760"
:sym-key-id "2091c39cac37211987f63391b93d0bd021b9df247da50728bfd766946993849d"}})
(def topics {"0xf8946aac" {:chat-ids #{:discovery-topic} (def topics {"0xf8946aac" {:chat-ids #{:discovery-topic}
:last-request 1547319670}}) :last-request 1547319670}})

View File

@ -32,7 +32,6 @@
:semaphores #{}} :semaphores #{}}
cofx {:db db cofx {:db db
:data-store/mailservers [] :data-store/mailservers []
:data-store/transport data/transport
:data-store/mailserver-topics data/topics} :data-store/mailserver-topics data/topics}
login-result "{\"error\":\"\"}" login-result "{\"error\":\"\"}"
efx (login.core/multiaccount-login-success cofx) efx (login.core/multiaccount-login-success cofx)

View File

@ -7,12 +7,6 @@
(deftest init-whisper (deftest init-whisper
(let [cofx {:db {:multiaccount {:public-key "1"} (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 #{}}}] :semaphores #{}}}]
(testing "custom mailservers" (testing "custom mailservers"
(let [ms-1 {:id "1" (let [ms-1 {:id "1"