Skip to content

Commit

Permalink
[perf] network module
Browse files Browse the repository at this point in the history
  • Loading branch information
rasom committed Jun 13, 2019
1 parent 2204ad5 commit 908f730
Show file tree
Hide file tree
Showing 38 changed files with 356 additions and 281 deletions.
37 changes: 32 additions & 5 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,16 @@
:language-out :es-2015
:modules {:cljs-base {:output-to "index.ios.js"}
:i18n {:entries #{"status_im.goog.i18n"}
:output-to "status-modules/cljs/i18n-raw.js"}}}
:output-to "status-modules/cljs/i18n-raw.js"}
:network {:entries #{"status_im.network.ui.network_details.views"
"status_im.network.ui.edit_network.views"
"status_im.network.ui.edit_network.styles"
"status_im.network.ui.views"
"status_im.network.ui.styles"
"status_im.network.events"
"status_im.network.subs"
"status_im.network.core"}
:output-to "status-modules/cljs/network-raw.js"}}}
:warning-handlers [status-im.utils.build/warning-handler]}
:android
{:source-paths ["components/src" "react-native/src/cljsjs" "react-native/src/mobile" "src" "env/prod" "prod"]
Expand All @@ -143,7 +152,16 @@
:language-out :es-2015
:modules {:cljs-base {:output-to "index.android.js"}
:i18n {:entries #{"status_im.goog.i18n"}
:output-to "status-modules/cljs/i18n-raw.js"}}}
:output-to "status-modules/cljs/i18n-raw.js"}
:network {:entries #{"status_im.network.ui.network_details.views"
"status_im.network.ui.edit_network.views"
"status_im.network.ui.edit_network.styles"
"status_im.network.ui.views"
"status_im.network.ui.styles"
"status_im.network.events"
"status_im.network.subs"
"status_im.network.core"}
:output-to "status-modules/cljs/network-raw.js"}}}
:warning-handlers [status-im.utils.build/warning-handler]}
:desktop
{:source-paths ["components/src" "react-native/src/cljsjs" "react-native/src/desktop" "src" "env/prod" "prod"]
Expand All @@ -160,7 +178,16 @@
:elide-asserts true
:language-in :es-2015
:language-out :es-2015
:modules {:cljs-base {:output-to "index.desktop.js"}
:i18n {:entries #{"status_im.goog.i18n"}
:output-to "status-modules/cljs/i18n-raw.js"}}}
:modules {:cljs-base {:output-to "index.desktop.js"}
:i18n {:entries #{"status_im.goog.i18n"}
:output-to "status-modules/cljs/i18n-raw.js"}
:network {:entries #{"status_im.network.ui.network_details.views"
"status_im.network.ui.edit_network.views"
"status_im.network.ui.edit_network.styles"
"status_im.network.ui.views"
"status_im.network.ui.styles"
"status_im.network.events"
"status_im.network.subs"
"status_im.network.core"}
:output-to "status-modules/cljs/network-raw.js"}}}
:warning-handlers [status-im.utils.build/warning-handler]}}}}})
22 changes: 2 additions & 20 deletions src/status_im/accounts/db.cljs
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
(ns status-im.accounts.db
(:require status-im.utils.db
status-im.ui.screens.network-settings.db
status-im.network.module
status-im.ui.screens.bootnodes-settings.db
status-im.ui.screens.extensions.db
[clojure.string :as string]
[cljs.spec.alpha :as spec]
[status-im.constants :as const]
[status-im.utils.security :as security]))

(defn logged-in? [cofx]
(boolean
(get-in cofx [:db :account/account])))

(defn credentials [cofx]
(select-keys (get-in cofx [:db :accounts/login]) [:address :password :save-password?]))
[status-im.constants :as const]))

(defn valid-length? [password]
(>= (count password) const/min-password-length))

(defn account-creation-next-enabled? [{:keys [step password password-confirm name]}]
(or (and password (= :enter-password step) (spec/valid? ::password (security/safe-unmask-data password)))
(and password-confirm (= :confirm-password step) (spec/valid? ::password password-confirm))
(and name (= :enter-name step) (not (string/blank? name)))))

(defn current-public-key
[cofx]
(get-in cofx [:db :account/account :public-key]))

(spec/def ::password (spec/and :global/not-empty-string valid-length?))

(spec/def :account/address :global/address)
Expand Down
14 changes: 7 additions & 7 deletions src/status_im/accounts/login/core.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns status-im.accounts.login.core
(:require [re-frame.core :as re-frame]
[status-im.accounts.db :as accounts.db]
[status-im.accounts.model :as accounts.model]
[status-im.chaos-mode.core :as chaos-mode]
[status-im.data-store.core :as data-store]
[status-im.ethereum.subscriptions :as ethereum.subscriptions]
Expand Down Expand Up @@ -80,7 +80,7 @@
(get-in [:db :hardwallet :account])
(select-keys [:whisper-private-key :encryption-public-key])
(assoc :on-result #(re-frame/dispatch [:accounts.login.callback/login-success %])))}
(let [{:keys [address password]} (accounts.db/credentials cofx)]
(let [{:keys [address password]} (accounts.model/credentials cofx)]
{:accounts.login/login [address password]})))

(fx/defn initialize-wallet [cofx]
Expand All @@ -94,7 +94,7 @@
(fx/defn user-login-without-creating-db
{:events [:accounts.login.ui/password-input-submitted]}
[{:keys [db] :as cofx}]
(let [{:keys [address password]} (accounts.db/credentials cofx)]
(let [{:keys [address password]} (accounts.model/credentials cofx)]
(fx/merge
cofx
{:db (-> db
Expand All @@ -108,7 +108,7 @@

(fx/defn user-login
[{:keys [db] :as cofx} create-database?]
(let [{:keys [address password]} (accounts.db/credentials cofx)]
(let [{:keys [address password]} (accounts.model/credentials cofx)]
(fx/merge
cofx
{:db (-> db
Expand Down Expand Up @@ -147,7 +147,7 @@
error (:error data)
success (empty? error)
{:keys [address password save-password?]}
(accounts.db/credentials cofx)
(accounts.model/credentials cofx)
network-type (:network/type db)]
;; check if logged into account
(when address
Expand Down Expand Up @@ -208,7 +208,7 @@
(show-migration-error-dialog cofx realm-error)

:database-does-not-exist
(let [{:keys [address password]} (accounts.db/credentials cofx)]
(let [{:keys [address password]} (accounts.model/credentials cofx)]
{:data-store/change-account [address
password
true
Expand Down Expand Up @@ -251,7 +251,7 @@
(fx/defn unknown-realm-error
[cofx {:keys [realm-error erase-button]}]
(let [{:keys [message]} realm-error
{:keys [address]} (accounts.db/credentials cofx)]
{:keys [address]} (accounts.model/credentials cofx)]
{:ui/show-confirmation
{:title (i18n/label :unknown-realm-error)
:content (i18n/label
Expand Down
20 changes: 20 additions & 0 deletions src/status_im/accounts/model.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(ns status-im.accounts.model
(:require [status-im.utils.security :as security]
[cljs.spec.alpha :as spec]
[clojure.string :as string]))

(defn logged-in? [cofx]
(boolean
(get-in cofx [:db :account/account])))

(defn credentials [cofx]
(select-keys (get-in cofx [:db :accounts/login]) [:address :password :save-password?]))

(defn account-creation-next-enabled? [{:keys [step password password-confirm name]}]
(or (and password (= :enter-password step) (spec/valid? :status-im.accounts.db/password (security/safe-unmask-data password)))
(and password-confirm (= :confirm-password step) (spec/valid? :status-im.accounts.db/password password-confirm))
(and name (= :enter-name step) (not (string/blank? name)))))

(defn current-public-key
[cofx]
(get-in cofx [:db :account/account :public-key]))
6 changes: 3 additions & 3 deletions src/status_im/chat/models.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns status-im.chat.models
(:require [re-frame.core :as re-frame]
[status-im.accounts.db :as accounts.db]
[status-im.accounts.model :as accounts.model]
[status-im.contact-code.core :as contact-code]
[status-im.contact.core :as contact.core]
[status-im.data-store.chats :as chats-store]
Expand Down Expand Up @@ -228,7 +228,7 @@
(fx/defn mark-messages-seen
"Marks all unviewed loaded messages as seen in particular chat"
[{:keys [db] :as cofx} chat-id]
(let [public-key (accounts.db/current-public-key cofx)
(let [public-key (accounts.model/current-public-key cofx)
loaded-unviewed-ids (get-in db [:chats chat-id :loaded-unviewed-messages-ids])]
(when (seq loaded-unviewed-ids)
(fx/merge cofx
Expand Down Expand Up @@ -279,7 +279,7 @@
"Start a chat, making sure it exists"
[{:keys [db] :as cofx} chat-id opts]
;; don't allow to open chat with yourself
(when (not= (accounts.db/current-public-key cofx) chat-id)
(when (not= (accounts.model/current-public-key cofx) chat-id)
(if config/use-status-go-protocol?
(fx/merge cofx
{:json-rpc/call [{:method "status_startOneOnOneChat"
Expand Down
2 changes: 0 additions & 2 deletions src/status_im/chat/models/loading.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(ns status-im.chat.models.loading
(:require [re-frame.core :as re-frame]
[status-im.accounts.db :as accounts.db]
[status-im.chat.commands.core :as commands]
[status-im.chat.models :as chat-model]
[status-im.mailserver.core :as mailserver]
Expand Down Expand Up @@ -125,7 +124,6 @@
referenced-messages (into empty-message-map
(get-referenced-messages (get-referenced-ids indexed-messages)))
new-message-ids (keys indexed-messages)
public-key (accounts.db/current-public-key cofx)
loaded-unviewed-messages (get-unviewed-message-ids)]
(fx/merge cofx
{:db (-> db
Expand Down
16 changes: 8 additions & 8 deletions src/status_im/chat/models/message.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns status-im.chat.models.message
(:require [re-frame.core :as re-frame]
[status-im.accounts.db :as accounts.db]
[status-im.accounts.model :as accounts.model]
[status-im.chat.commands.receiving :as commands-receiving]
[status-im.chat.db :as chat.db]
[status-im.chat.models :as chat-model]
Expand Down Expand Up @@ -102,7 +102,7 @@
[{:keys [db] :as cofx}
{{:keys [chat-id message-id clock-value timestamp from] :as message} :message
:keys [current-chat? batch? dedup-id raw-message]}]
(let [current-public-key (accounts.db/current-public-key cofx)
(let [current-public-key (accounts.model/current-public-key cofx)
prepared-message (-> message
(prepare-message chat-id current-chat?)
(add-outgoing-status current-public-key))]
Expand Down Expand Up @@ -156,7 +156,7 @@
old-id->message
{:keys [from message-id chat-id js-obj content dedup-id] :as raw-message}]
(let [{:keys [web3 current-chat-id view-id]} db
current-public-key (accounts.db/current-public-key cofx)
current-public-key (accounts.model/current-public-key cofx)
current-chat? (and (or (= :chat view-id)
(= :chat-modal view-id))
(= current-chat-id chat-id))
Expand Down Expand Up @@ -216,19 +216,19 @@
;; Version 0 does not have a concept of joining, so any message is ok
;; otherwise check we joined
(or (= 0 (get-in cofx [:db :chats chat-id :group-chat-local-version]))
(get-in cofx [:db :chats chat-id :members-joined (accounts.db/current-public-key cofx)])))) chat-id
(get-in cofx [:db :chats chat-id :members-joined (accounts.model/current-public-key cofx)])))) chat-id
(and (= :public-group-user-message message-type)
(get-in cofx [:db :chats chat-id :public?])) chat-id
(and (= :user-message message-type)
(= (accounts.db/current-public-key cofx) from)) chat-id
(= (accounts.model/current-public-key cofx) from)) chat-id
(= :user-message message-type) from))

(defn calculate-unviewed-messages-count
[{:keys [db] :as cofx} chat-id messages]
(let [{:keys [current-chat-id view-id]} db
chat-view? (or (= :chat view-id)
(= :chat-modal view-id))
current-public-key (accounts.db/current-public-key cofx)]
current-public-key (accounts.model/current-public-key cofx)]
(+ (get-in db [:chats chat-id :unviewed-messages-count])
(if (and chat-view? (= current-chat-id chat-id))
0
Expand Down Expand Up @@ -381,7 +381,7 @@
[cofx chat-id message-id fcm-tokens status]
(log/debug "#6772 - send-push-notification" message-id fcm-tokens)
(when (and (seq fcm-tokens) (= status :sent))
(let [payload {:from (accounts.db/current-public-key cofx)
(let [payload {:from (accounts.model/current-public-key cofx)
:to chat-id
:id message-id}]
{:send-notification {:data-payload (notifications/encode-notification-payload payload)
Expand Down Expand Up @@ -444,7 +444,7 @@
(let [{:keys [chats]} db
{:keys [last-clock-value] :as chat} (get chats chat-id)
message-data (-> message
(assoc :from (accounts.db/current-public-key cofx)
(assoc :from (accounts.model/current-public-key cofx)
:timestamp now
:whisper-timestamp (quot now 1000)
:clock-value (utils.clocks/send
Expand Down
4 changes: 2 additions & 2 deletions src/status_im/contact/core.cljs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns status-im.contact.core
(:require [status-im.accounts.db :as accounts.db]
(:require [status-im.accounts.model :as accounts.model]
[status-im.contact-code.core :as contact-code]
[status-im.contact.db :as contact.db]
[status-im.contact.device-info :as device-info]
Expand Down Expand Up @@ -119,7 +119,7 @@
;; for now
(let [timestamp-ms (* timestamp 1000)
prev-last-updated (get-in db [:contacts/contacts public-key :last-updated])
current-public-key (accounts.db/current-public-key cofx)]
current-public-key (accounts.model/current-public-key cofx)]
(when (and (not= current-public-key public-key)
(< prev-last-updated timestamp-ms))
(let [contact (get contacts public-key)
Expand Down
8 changes: 4 additions & 4 deletions src/status_im/contact_code/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[status-im.transport.message.public-chat :as transport.public-chat]
[status-im.data-store.accounts :as data-store.accounts]
[status-im.transport.chat.core :as transport.chat]
[status-im.accounts.db :as accounts.db]
[status-im.accounts.model :as accounts.model]
[status-im.mailserver.core :as mailserver]))

(defn topic [pk]
Expand Down Expand Up @@ -42,7 +42,7 @@
"We can stop listening to contact codes when we don't have any active chat
with the user (one-to-one or group-chat), and it is not in our contacts"
[{:keys [db] :as cofx} their-public-key]
(let [my-public-key (accounts.db/current-public-key cofx)
(let [my-public-key (accounts.model/current-public-key cofx)
active-group-chats (filter (fn [{:keys [is-active members members-joined]}]
(and is-active
(contains? members-joined my-public-key)
Expand All @@ -64,11 +64,11 @@

(fx/defn init [cofx]
(log/debug "initializing contact-code")
(let [current-public-key (accounts.db/current-public-key cofx)]
(let [current-public-key (accounts.model/current-public-key cofx)]
(listen cofx current-public-key)))

(defn publish! [{:keys [web3 now] :as cofx}]
(let [current-public-key (accounts.db/current-public-key cofx)
(let [current-public-key (accounts.model/current-public-key cofx)
chat-id (topic current-public-key)
peers-count (:peers-count @re-frame.db/app-db)
last-published (get-in
Expand Down
Loading

0 comments on commit 908f730

Please sign in to comment.