This commit is contained in:
Adrian Tiberius 2016-07-18 19:50:13 +03:00
parent fac008b087
commit cff3349c7d
11 changed files with 11 additions and 34 deletions

View File

@ -12,6 +12,7 @@
[status-im.persistence.realm.core :as realm] [status-im.persistence.realm.core :as realm]
[status-im.i18n :refer [label]] [status-im.i18n :refer [label]]
[status-im.constants :refer [content-type-command-request]] [status-im.constants :refer [content-type-command-request]]
status-im.accounts.login.handlers
[clojure.string :as str])) [clojure.string :as str]))

View File

@ -1,4 +1,4 @@
(ns status-im.login.handlers (ns status-im.accounts.login.handlers
(:require [re-frame.core :refer [register-handler after dispatch]] (:require [re-frame.core :refer [register-handler after dispatch]]
[status-im.utils.handlers :as u])) [status-im.utils.handlers :as u]))

View File

@ -1,4 +1,4 @@
(ns status-im.login.screen (ns status-im.accounts.login.screen
(:require-macros [status-im.utils.views :refer [defview]]) (:require-macros [status-im.utils.views :refer [defview]])
(:require [re-frame.core :refer [subscribe dispatch dispatch-sync]] (:require [re-frame.core :refer [subscribe dispatch dispatch-sync]]
[status-im.components.react :refer [view [status-im.components.react :refer [view
@ -22,7 +22,7 @@
white-form-text-input]] white-form-text-input]]
[status-im.qr-scanner.views.scan-button :refer [scan-button]] [status-im.qr-scanner.views.scan-button :refer [scan-button]]
[status-im.i18n :refer [label]] [status-im.i18n :refer [label]]
[status-im.login.styles :as st])) [status-im.accounts.login.styles :as st]))
(def toolbar-title (def toolbar-title
[view toolbar-title-container [view toolbar-title-container

View File

@ -1,4 +1,4 @@
(ns status-im.login.styles (ns status-im.accounts.login.styles
(:require [status-im.components.styles :refer [font (:require [status-im.components.styles :refer [font
title-font title-font
text1-color text1-color

View File

@ -14,7 +14,7 @@
[status-im.discovery.screen :refer [discovery]] [status-im.discovery.screen :refer [discovery]]
[status-im.discovery.tag :refer [discovery-tag]] [status-im.discovery.tag :refer [discovery-tag]]
[status-im.chat.screen :refer [chat]] [status-im.chat.screen :refer [chat]]
[status-im.login.screen :refer [login]] [status-im.accounts.login.screen :refer [login]]
[status-im.accounts.screen :refer [accounts]] [status-im.accounts.screen :refer [accounts]]
[status-im.chats-list.screen :refer [chats-list]] [status-im.chats-list.screen :refer [chats-list]]
[status-im.new-group.screen :refer [new-group]] [status-im.new-group.screen :refer [new-group]]

View File

@ -6,7 +6,6 @@
[status-im.models.chats :as c] [status-im.models.chats :as c]
[status-im.components.styles :refer [default-chat-color]] [status-im.components.styles :refer [default-chat-color]]
[status-im.utils.utils :refer [on-error http-post toast]] [status-im.utils.utils :refer [on-error http-post toast]]
[status-im.utils.logging :as log]
[status-im.utils.random :as random] [status-im.utils.random :as random]
[status-im.utils.sms-listener :refer [add-sms-listener [status-im.utils.sms-listener :refer [add-sms-listener
remove-sms-listener]] remove-sms-listener]]
@ -199,7 +198,6 @@
(defn create-chat [handler] (defn create-chat [handler]
(fn [db] (fn [db]
(let [{:keys [new-chat] :as db'} (handler db)] (let [{:keys [new-chat] :as db'} (handler db)]
(log/debug new-chat)
(when new-chat (when new-chat
(c/create-chat new-chat)) (c/create-chat new-chat))
(dissoc db' :new-chat)))) (dissoc db' :new-chat))))

View File

@ -13,16 +13,12 @@
(defn load-commands! (defn load-commands!
[_ [identity]] [_ [identity]]
(let [is-console? (= identity "console")
schema (if is-console?
:base
:account)]
(dispatch [::fetch-commands! identity]) (dispatch [::fetch-commands! identity])
;; todo uncomment ;; todo uncomment
#_(if-let [{:keys [file]} (realm/get-one-by-field schema :commands #_(if-let [{:keys [file]} (realm/get-one-by-field :account :commands
:chat-id identity)] :chat-id identity)]
(dispatch [::parse-commands! identity file]) (dispatch [::parse-commands! identity file])
(dispatch [::fetch-commands! identity])))) (dispatch [::fetch-commands! identity])))
(defn fetch-commands! (defn fetch-commands!
[db [identity]] [db [identity]]
@ -77,11 +73,7 @@
(defn save-commands-js! (defn save-commands-js!
[_ [id file]] [_ [id file]]
(let [is-console? (= id "console") (realm/create-object :account :commands {:chat-id id :file file}))
schema (if is-console?
:base
:account)]
(realm/create-object schema :commands {:chat-id id :file file})))
(defn loading-failed! (defn loading-failed!
[db [id reason details]] [db [id reason details]]

View File

@ -66,13 +66,13 @@
(fn [_ _] (fn [_ _]
(assoc app-db (assoc app-db
:signed-up (storage/get kv/kv-store :signed-up) :signed-up (storage/get kv/kv-store :signed-up)
:user-identity (protocol/stored-identity nil)
:password (storage/get kv/kv-store :password)))) :password (storage/get kv/kv-store :password))))
(register-handler :initialize-account (register-handler :initialize-account
(u/side-effect! (u/side-effect!
(fn [_ [_ account]] (fn [_ [_ account]]
(dispatch [:initialize-protocol account]) (dispatch [:initialize-protocol account])
(dispatch [:initialize-account-db])
(dispatch [:initialize-chats]) (dispatch [:initialize-chats])
(dispatch [:load-contacts]) (dispatch [:load-contacts])
(dispatch [:init-chat])))) (dispatch [:init-chat]))))

View File

@ -42,10 +42,8 @@
(defn create-chat (defn create-chat
([{:keys [last-msg-id] :as chat}] ([{:keys [last-msg-id] :as chat}]
(let [chat (assoc chat :last-msg-id (or last-msg-id ""))] (let [chat (assoc chat :last-msg-id (or last-msg-id ""))]
(log/debug "Creating chat" chat)
(r/write :account #(r/create :account :chats chat)))) (r/write :account #(r/create :account :chats chat))))
([db chat-id identities group-chat? chat-name] ([db chat-id identities group-chat? chat-name]
(log/debug "Creating chat" chat-id)
(when-not (chat-exists? chat-id) (when-not (chat-exists? chat-id)
(let [chat-name (or chat-name (let [chat-name (or chat-name
(get-chat-name chat-id identities)) (get-chat-name chat-id identities))

View File

@ -30,7 +30,6 @@
(str/ends-with? path realm_file))) (str/ends-with? path realm_file)))
(defn realm [schema] (defn realm [schema]
(log/debug "Schema: " schema)
(case schema (case schema
:base base-realm :base base-realm
:account @account-realm)) :account @account-realm))
@ -59,12 +58,10 @@
(defn change-account-realm [address handler] (defn change-account-realm [address handler]
(let [path (.-path @account-realm) (let [path (.-path @account-realm)
realm-file (str new-account-filename ".realm") realm-file (str new-account-filename ".realm")
_ (log/debug "account realm path: " path address)
is-new-account? (str/ends-with? path realm-file)] is-new-account? (str/ends-with? path realm-file)]
(close-account-realm) (close-account-realm)
(if is-new-account? (if is-new-account?
(let [new-path (str/replace path realm-file (str address ".realm"))] (let [new-path (str/replace path realm-file (str address ".realm"))]
(log/debug "account new path: " new-path)
(fs/move-file path new-path #(move-file-handler address % handler))) (fs/move-file path new-path #(move-file-handler address % handler)))
(do (do
(reset! account-realm (create-account-realm address)) (reset! account-realm (create-account-realm address))
@ -115,24 +112,20 @@
query)) query))
(defn get-by-filter [schema schema-name filter] (defn get-by-filter [schema schema-name filter]
(log/debug "Get by filter: " schema schema-name)
(-> (.objects (realm schema) (name schema-name)) (-> (.objects (realm schema) (name schema-name))
(.filtered filter))) (.filtered filter)))
(defn get-by-field [schema schema-name field value] (defn get-by-field [schema schema-name field value]
(log/debug "Get by field: " schema schema-name field value)
(let [q (to-query schema schema-name :eq field value)] (let [q (to-query schema schema-name :eq field value)]
(.filtered (.objects (realm schema) (name schema-name)) q))) (.filtered (.objects (realm schema) (name schema-name)) q)))
(defn get-by-fields [schema schema-name fields] (defn get-by-fields [schema schema-name fields]
(log/debug "Get by fields: " schema schema-name fields)
(let [queries (map (fn [[k v]] (let [queries (map (fn [[k v]]
(to-query schema schema-name :eq k v)) (to-query schema schema-name :eq k v))
fields)] fields)]
(.filtered (.objects (realm schema) (name schema-name)) (and-q queries)))) (.filtered (.objects (realm schema) (name schema-name)) (and-q queries))))
(defn get-all [schema schema-name] (defn get-all [schema schema-name]
(log/debug "Get all: " schema schema-name)
(.objects (realm schema) (to-string schema-name))) (.objects (realm schema) (to-string schema-name)))
(defn sorted [results field-name order] (defn sorted [results field-name order]
@ -173,7 +166,6 @@
(.-length objs)) (.-length objs))
(defn get-list [schema schema-name] (defn get-list [schema schema-name]
(log/debug "Get list: " schema schema-name)
(vals (js->clj (.objects (realm schema) (to-string schema-name)) :keywordize-keys true))) (vals (js->clj (.objects (realm schema) (to-string schema-name)) :keywordize-keys true)))
(defn collection->map [collection] (defn collection->map [collection]

View File

@ -26,11 +26,7 @@
{:name :kv-store {:name :kv-store
:primaryKey :key :primaryKey :key
:properties {:key "string" :properties {:key "string"
:value "string"}} :value "string"}}]
{:name :commands
:primaryKey :chat-id
:properties {:chat-id "string"
:file "string"}}]
:schemaVersion 0}) :schemaVersion 0})
(def account {:schema [{:name :contacts (def account {:schema [{:name :contacts