remove realm chat-transport usages
This commit is contained in:
parent
bd3ff3e96a
commit
75ce7da50c
|
@ -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 {})))))
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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))))
|
|
@ -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}]]
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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})
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"]
|
||||
|
|
|
@ -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}])
|
||||
|
|
|
@ -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}})
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue