integrate status-go mailserver-topics api
Signed-off-by: yenda <eric@status.im>
This commit is contained in:
parent
1147466362
commit
dbf8d60f8b
|
@ -1,21 +1,17 @@
|
|||
(ns status-im.data-store.core
|
||||
(:require [cljs.core.async :as async]
|
||||
[re-frame.core :as re-frame]
|
||||
[taoensso.timbre :as log]
|
||||
[status-im.data-store.realm.core :as realm]
|
||||
[status-im.utils.keychain.core :as keychain]
|
||||
[status-im.utils.handlers :as handlers]
|
||||
[status-im.utils.security :as security]
|
||||
[status-im.native-module.core :as status]
|
||||
[status-im.multiaccounts.model :as multiaccounts.model]
|
||||
[status-im.utils.types :as types]
|
||||
[status-im.i18n :as i18n]
|
||||
status-im.data-store.chats
|
||||
status-im.data-store.messages
|
||||
status-im.data-store.contacts
|
||||
status-im.data-store.mailservers
|
||||
[status-im.multiaccounts.model :as multiaccounts.model]
|
||||
[status-im.native-module.core :as status]
|
||||
[status-im.protocol.core :as protocol]
|
||||
[status-im.utils.fx :as fx]
|
||||
[status-im.protocol.core :as protocol]))
|
||||
[status-im.utils.handlers :as handlers]
|
||||
[status-im.utils.keychain.core :as keychain]
|
||||
[status-im.utils.security :as security]
|
||||
[status-im.utils.types :as types]
|
||||
[taoensso.timbre :as log]))
|
||||
|
||||
(fx/defn multiaccount-db-removed
|
||||
{:events [::multiaccount-db-removed]}
|
||||
|
@ -201,11 +197,9 @@
|
|||
|
||||
(fx/defn handle-change-multiaccount-success
|
||||
{:events [::multiaccount-change-success]
|
||||
:interceptors [(re-frame/inject-cofx :data-store/mailserver-topics)
|
||||
(re-frame/inject-cofx :data-store/all-chat-requests-ranges)]}
|
||||
[{:data-store/keys [mailserver-topics mailserver-ranges] :as cofx}]
|
||||
(protocol/initialize-protocol cofx {:mailserver-topics mailserver-topics
|
||||
:mailserver-ranges mailserver-ranges}))
|
||||
:interceptors [(re-frame/inject-cofx :data-store/all-chat-requests-ranges)]}
|
||||
[{:data-store/keys [mailserver-ranges] :as cofx}]
|
||||
(protocol/initialize-protocol cofx {:mailserver-ranges mailserver-ranges}))
|
||||
|
||||
(defn change-multiaccount!
|
||||
[address password create-database-if-not-exist?]
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
(ns status-im.data-store.mailservers
|
||||
(:require [cljs.tools.reader.edn :as edn]
|
||||
[re-frame.core :as re-frame]
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[status-im.data-store.realm.core :as core]
|
||||
[status-im.ethereum.json-rpc :as json-rpc]
|
||||
[status-im.utils.fx :as fx]
|
||||
|
@ -44,45 +43,6 @@
|
|||
:on-success #(log/info "deleted gaps successfully")
|
||||
:on-failure #(log/error "failed to delete gap" %)}]})
|
||||
|
||||
(defn deserialize-mailserver-topic
|
||||
[serialized-mailserver-topic]
|
||||
(-> serialized-mailserver-topic
|
||||
(update :chat-ids edn/read-string)))
|
||||
|
||||
(re-frame/reg-cofx
|
||||
:data-store/mailserver-topics
|
||||
(fn [cofx _]
|
||||
(assoc cofx
|
||||
:data-store/mailserver-topics
|
||||
(reduce (fn [acc {:keys [topic] :as mailserver-topic}]
|
||||
(assoc acc topic (deserialize-mailserver-topic mailserver-topic)))
|
||||
{}
|
||||
(-> @core/account-realm
|
||||
(core/get-all :mailserver-topic)
|
||||
(core/all-clj :mailserver-topic))))))
|
||||
|
||||
(defn save-mailserver-topic-tx
|
||||
"Returns tx function for saving mailserver topic"
|
||||
[{:keys [topic mailserver-topic]}]
|
||||
(fn [realm]
|
||||
(log/debug "saving mailserver-topic:" topic mailserver-topic)
|
||||
(core/create realm
|
||||
:mailserver-topic
|
||||
(-> mailserver-topic
|
||||
(assoc :topic topic)
|
||||
(update :chat-ids pr-str))
|
||||
true)))
|
||||
|
||||
(defn delete-mailserver-topic-tx
|
||||
"Returns tx function for deleting mailserver topic"
|
||||
[topic]
|
||||
(fn [realm]
|
||||
(log/debug "deleting mailserver-topic:" topic)
|
||||
(let [mailserver-topic (.objectForPrimaryKey realm
|
||||
"mailserver-topic"
|
||||
topic)]
|
||||
(core/delete realm mailserver-topic))))
|
||||
|
||||
(defn save-chat-requests-range
|
||||
[chat-requests-range]
|
||||
(fn [realm]
|
||||
|
|
|
@ -78,7 +78,10 @@
|
|||
"accounts_saveAccounts" {}
|
||||
"mailservers_addMailserver" {}
|
||||
"mailservers_getMailservers" {}
|
||||
"mailservers_deleteMailserver" {}})
|
||||
"mailservers_deleteMailserver" {}
|
||||
"mailservers_addMailserverTopic" {}
|
||||
"mailservers_getMailserverTopics" {}
|
||||
"mailservers_deleteMailserverTopic" {}})
|
||||
|
||||
(defn call
|
||||
[{:keys [method params on-success on-error] :as p}]
|
||||
|
|
|
@ -734,11 +734,13 @@
|
|||
gaps)))
|
||||
(update :mailserver/planned-gap-requests
|
||||
dissoc gap))
|
||||
:data-store/tx (mapv (fn [[topic mailserver-topic]]
|
||||
(data-store.mailservers/save-mailserver-topic-tx
|
||||
{:topic topic
|
||||
:mailserver-topic mailserver-topic}))
|
||||
mailserver-topics)}
|
||||
::json-rpc/call
|
||||
(mapv (fn [[topic mailserver-topic]]
|
||||
{:method "mailservers_addMailserverTopic"
|
||||
:params [(assoc mailserver-topic :topic topic)]
|
||||
:on-success #(log/debug "added mailserver-topic successfully")
|
||||
:on-failure #(log/error "failed to delete mailserver topic" %)})
|
||||
mailserver-topics)}
|
||||
(process-next-messages-request))))))))
|
||||
|
||||
(fx/defn retry-next-messages-request
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
(ns ^{:doc "Mailserver events and API"}
|
||||
status-im.mailserver.topics
|
||||
(:require
|
||||
[clojure.string :as string]
|
||||
[taoensso.timbre :as log]
|
||||
[status-im.data-store.mailservers :as data-store.mailservers]
|
||||
[status-im.mailserver.constants :as constants]
|
||||
[status-im.utils.fx :as fx]))
|
||||
(:require [status-im.ethereum.json-rpc :as json-rpc]
|
||||
[status-im.mailserver.constants :as constants]
|
||||
[status-im.utils.fx :as fx]
|
||||
[taoensso.timbre :as log]))
|
||||
|
||||
(defn calculate-last-request [{:keys [discovery?]}
|
||||
{:keys [previous-last-request
|
||||
|
@ -27,13 +25,16 @@
|
|||
|
||||
(fx/defn persist [_ {:keys [chat-ids topic filter-ids]
|
||||
:as mailserver-topic}]
|
||||
(let [op (if (or (empty? chat-ids)
|
||||
(empty? filter-ids))
|
||||
(data-store.mailservers/delete-mailserver-topic-tx topic)
|
||||
(data-store.mailservers/save-mailserver-topic-tx
|
||||
{:topic topic
|
||||
:mailserver-topic mailserver-topic}))]
|
||||
{:data-store/tx [op]}))
|
||||
(if (or (empty? chat-ids)
|
||||
(empty? filter-ids))
|
||||
{::json-rpc/call [{:method "mailservers_deleteMailserverTopic"
|
||||
:params [topic]
|
||||
:on-success #(log/debug "deleted mailserver topic successfully")
|
||||
:on-failure #(log/error "failed to delete mailserver topic" %)}]}
|
||||
{::json-rpc/call [{:method "mailservers_addMailserverTopic"
|
||||
:params [mailserver-topic]
|
||||
:on-success #(log/debug "added mailserver-topic successfully")
|
||||
:on-failure #(log/error "failed to delete mailserver topic" %)}]}))
|
||||
|
||||
(defn new-chat-ids? [previous-mailserver-topic new-mailserver-topic]
|
||||
(seq (clojure.set/difference (:chat-ids new-mailserver-topic)
|
||||
|
|
|
@ -8,12 +8,12 @@
|
|||
[status-im.contact.core :as contact]
|
||||
[status-im.data-store.core :as data-store]
|
||||
[status-im.ethereum.json-rpc :as json-rpc]
|
||||
[status-im.protocol.core :as protocol]
|
||||
[status-im.ethereum.transactions.core :as transactions]
|
||||
[status-im.fleet.core :as fleet]
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.native-module.core :as status]
|
||||
[status-im.notifications.core :as notifications]
|
||||
[status-im.protocol.core :as protocol]
|
||||
[status-im.stickers.core :as stickers]
|
||||
[status-im.ui.screens.mobile-network-settings.events :as mobile-network]
|
||||
[status-im.ui.screens.navigation :as navigation]
|
||||
|
@ -27,8 +27,7 @@
|
|||
[status-im.utils.universal-links.core :as universal-links]
|
||||
[status-im.utils.utils :as utils]
|
||||
[status-im.wallet.core :as wallet]
|
||||
[taoensso.timbre :as log]
|
||||
[status-im.mailserver.core :as mailserver]))
|
||||
[taoensso.timbre :as log]))
|
||||
|
||||
(def rpc-endpoint "https://goerli.infura.io/v3/f315575765b14720b32382a61a89341a")
|
||||
(def contract-address "0xfbf4c8e2B41fAfF8c616a0E49Fb4365a5355Ffaf")
|
||||
|
@ -162,7 +161,9 @@
|
|||
{:db (assoc db :chats/loading? true)
|
||||
::data-store/change-multiaccount [address password]
|
||||
::json-rpc/call
|
||||
[{:method "browsers_getBrowsers"
|
||||
[{:method "mailservers_getMailserverTopics"
|
||||
:on-success #(re-frame/dispatch [::protocol/initialize-protocol {:mailserver-topics (or % {})}])}
|
||||
{:method "browsers_getBrowsers"
|
||||
:on-success #(re-frame/dispatch [::initialize-browsers %])}
|
||||
{:method "permissions_getDappPermissions"
|
||||
:on-success #(re-frame/dispatch [::initialize-dapp-permissions %])}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
[status-im.mailserver.core :as mailserver]
|
||||
[status-im.node.core :as node]
|
||||
[status-im.transport.core :as transport]
|
||||
[status-im.tribute-to-talk.core :as tribute-to-talk]
|
||||
[status-im.utils.fx :as fx]))
|
||||
|
||||
;;TODO move this logic to status-go
|
||||
|
@ -48,6 +47,18 @@
|
|||
db
|
||||
custom-mailservers))
|
||||
|
||||
(defn add-mailserver-topics
|
||||
[db mailserver-topics]
|
||||
(assoc db
|
||||
:mailserver/topics
|
||||
(reduce (fn [acc {:keys [topic chat-ids]
|
||||
:as mailserver-topic}]
|
||||
(assoc acc topic
|
||||
(update mailserver-topic :chat-ids
|
||||
#(into #{} %))))
|
||||
{}
|
||||
mailserver-topics)))
|
||||
|
||||
(fx/defn initialize-protocol
|
||||
{:events [::initialize-protocol]}
|
||||
[{:keys [db] :as cofx}
|
||||
|
@ -68,7 +79,7 @@
|
|||
mailserver-ranges
|
||||
(assoc :mailserver/ranges mailserver-ranges)
|
||||
mailserver-topics
|
||||
(assoc :mailserver/topics mailserver-topics)
|
||||
(add-mailserver-topics mailserver-topics)
|
||||
mailservers
|
||||
(add-custom-mailservers mailservers)
|
||||
initialization-complete?
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
"owner": "status-im",
|
||||
"repo": "status-go",
|
||||
"version": "develop",
|
||||
"commit-sha1": "b27779aa4e202a13a387897332dea377bf9b6552",
|
||||
"src-sha256": "0yab9pjsg9583b7x89ywbbyxxw4fy03dyw260ybjb9g26z166064"
|
||||
"commit-sha1": "9df64efe2c3d88596ab5cfe358741ed8f9be86b7",
|
||||
"src-sha256": "0yc76v2kcamxjv7g7b9x4ywmbzch4azzb4sj49rhcdkg0wz8qi5j"
|
||||
}
|
||||
|
|
|
@ -3,11 +3,9 @@
|
|||
flow has been changed. Such changes should be reflected in both these tests
|
||||
and documents which describe the whole \"sign in\" flow."
|
||||
(:require [cljs.test :refer-macros [deftest is testing]]
|
||||
[status-im.ethereum.json-rpc :as json-rpc]
|
||||
[status-im.events :as events]
|
||||
[status-im.data-store.core :as data-store]
|
||||
[status-im.ethereum.json-rpc :as json-rpc]
|
||||
[status-im.multiaccounts.login.core :as login.core]
|
||||
[status-im.signals.core :as signals]
|
||||
[status-im.test.sign-in.data :as data]))
|
||||
|
||||
(deftest on-password-input-submitted
|
||||
|
@ -29,9 +27,7 @@
|
|||
(let [db {:multiaccounts/login {:address "address"
|
||||
:password "password"}
|
||||
:multiaccount data/multiaccount}
|
||||
cofx {:db db
|
||||
:data-store/mailservers []
|
||||
:data-store/mailserver-topics data/topics}
|
||||
cofx {:db db}
|
||||
login-result "{\"error\":\"\"}"
|
||||
efx (login.core/multiaccount-login-success cofx)
|
||||
new-db (:db efx)
|
||||
|
|
Loading…
Reference in New Issue