Merge pull request #419 from status-im/bug/console#415
Fix bugs related to console chat (#415)
This commit is contained in:
commit
21aa16b842
|
@ -16,7 +16,8 @@
|
||||||
[status-im.utils.handlers :as u :refer [get-hashtags]]
|
[status-im.utils.handlers :as u :refer [get-hashtags]]
|
||||||
[status-im.accounts.statuses :as statuses]
|
[status-im.accounts.statuses :as statuses]
|
||||||
[status-im.utils.gfycat.core :refer [generate-gfy]]
|
[status-im.utils.gfycat.core :refer [generate-gfy]]
|
||||||
[status-im.constants :refer [console-chat-id]]))
|
[status-im.constants :refer [console-chat-id]]
|
||||||
|
[status-im.utils.scheduler :as s]))
|
||||||
|
|
||||||
|
|
||||||
(defn save-account [_ [_ account]]
|
(defn save-account [_ [_ account]]
|
||||||
|
@ -29,29 +30,29 @@
|
||||||
(update db :accounts assoc address account))))
|
(update db :accounts assoc address account))))
|
||||||
|
|
||||||
(defn account-created [result password]
|
(defn account-created [result password]
|
||||||
(let [data (json->clj result)
|
(let [data (json->clj result)
|
||||||
public-key (:pubkey data)
|
public-key (:pubkey data)
|
||||||
address (:address data)
|
address (:address data)
|
||||||
mnemonic (:mnemonic data)
|
mnemonic (:mnemonic data)
|
||||||
{:keys [public private]} (protocol/new-keypair!)
|
{:keys [public private]} (protocol/new-keypair!)
|
||||||
account {:public-key public-key
|
account {:public-key public-key
|
||||||
:address address
|
:address address
|
||||||
:name (generate-gfy)
|
:name (generate-gfy)
|
||||||
:status (rand-nth statuses/data)
|
:status (rand-nth statuses/data)
|
||||||
:signed-up? true
|
:signed-up? true
|
||||||
:updates-public-key public
|
:updates-public-key public
|
||||||
:updates-private-key private
|
:updates-private-key private
|
||||||
:photo-path (identicon public-key)}]
|
:photo-path (identicon public-key)}]
|
||||||
(log/debug "account-created")
|
(log/debug "account-created")
|
||||||
(when-not (str/blank? public-key)
|
(when-not (str/blank? public-key)
|
||||||
(do
|
(dispatch [:show-mnemonic mnemonic])
|
||||||
(dispatch [:add-account account])
|
(dispatch [:add-account account])
|
||||||
(dispatch [:show-mnemonic mnemonic])
|
(dispatch [:login-account address password true]))))
|
||||||
(dispatch [:login-account address password])))))
|
|
||||||
|
|
||||||
(register-handler :create-account
|
(register-handler :create-account
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
(fn [_ [_ password]]
|
(fn [_ [_ password]]
|
||||||
|
(s/execute-later #(dispatch [:account-generation-message]) 400)
|
||||||
(status/create-account
|
(status/create-account
|
||||||
password
|
password
|
||||||
#(account-created % password)))))
|
#(account-created % password)))))
|
||||||
|
@ -89,7 +90,7 @@
|
||||||
(register-handler
|
(register-handler
|
||||||
:account-update
|
:account-update
|
||||||
(-> (fn [{:keys [current-account-id accounts] :as db} [_ data]]
|
(-> (fn [{:keys [current-account-id accounts] :as db} [_ data]]
|
||||||
(let [data (assoc data :last-updated (time/now-ms))
|
(let [data (assoc data :last-updated (time/now-ms))
|
||||||
account (merge (get accounts current-account-id) data)]
|
account (merge (get accounts current-account-id) data)]
|
||||||
(assoc-in db [:accounts current-account-id] account)))
|
(assoc-in db [:accounts current-account-id] account)))
|
||||||
((after save-account!))
|
((after save-account!))
|
||||||
|
@ -100,7 +101,7 @@
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
(fn [{:keys [current-account-id accounts]} _]
|
(fn [{:keys [current-account-id accounts]} _]
|
||||||
(let [{:keys [last-updated]} (get accounts current-account-id)
|
(let [{:keys [last-updated]} (get accounts current-account-id)
|
||||||
now (time/now-ms)
|
now (time/now-ms)
|
||||||
needs-update? (> (- now last-updated) time/week)]
|
needs-update? (> (- now last-updated) time/week)]
|
||||||
(log/info "Need to send account-update: " needs-update?)
|
(log/info "Need to send account-update: " needs-update?)
|
||||||
(when needs-update?
|
(when needs-update?
|
||||||
|
|
|
@ -49,7 +49,7 @@
|
||||||
|
|
||||||
(register-handler
|
(register-handler
|
||||||
:login-account
|
:login-account
|
||||||
(u/side-effect!
|
(after
|
||||||
(fn [db [_ address password]]
|
(fn [db [_ address password]]
|
||||||
(status/login address password
|
(status/login address password
|
||||||
(fn [result]
|
(fn [result]
|
||||||
|
@ -59,4 +59,6 @@
|
||||||
(log/debug "Logged in account: ")
|
(log/debug "Logged in account: ")
|
||||||
(if success
|
(if success
|
||||||
(logged-in db address)
|
(logged-in db address)
|
||||||
(dispatch [:set-in [:login :error] error]))))))))
|
(dispatch [:set-in [:login :error] error])))))))
|
||||||
|
(fn [db [_ _ _ account-creation?]]
|
||||||
|
(assoc db :account-creation? account-creation?)))
|
||||||
|
|
|
@ -205,6 +205,7 @@
|
||||||
(if (chats console-chat-id)
|
(if (chats console-chat-id)
|
||||||
db
|
db
|
||||||
(do
|
(do
|
||||||
|
(dispatch [:add-contacts [sign-up-service/console-contact]])
|
||||||
(chats/save new-chat)
|
(chats/save new-chat)
|
||||||
(contacts/save-all [sign-up-service/console-contact])
|
(contacts/save-all [sign-up-service/console-contact])
|
||||||
(sign-up-service/intro)
|
(sign-up-service/intro)
|
||||||
|
@ -220,10 +221,17 @@
|
||||||
(fn [db _]
|
(fn [db _]
|
||||||
(init-console-chat db false)))
|
(init-console-chat db false)))
|
||||||
|
|
||||||
|
(register-handler :account-generation-message
|
||||||
|
(u/side-effect!
|
||||||
|
(fn [{:keys [chats]}]
|
||||||
|
(when (> 4 (count (get-in chats [console-chat-id :messages])))
|
||||||
|
(sign-up-service/account-generation-message)))))
|
||||||
|
|
||||||
(register-handler :show-mnemonic
|
(register-handler :show-mnemonic
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
(fn [_ [_ mnemonic]]
|
(fn [{:keys [chats]} [_ mnemonic]]
|
||||||
(sign-up-service/passpharse-messages mnemonic))))
|
(let [messages-count (count (get-in chats [console-chat-id :messages]))]
|
||||||
|
(sign-up-service/passpharse-messages mnemonic messages-count)))))
|
||||||
|
|
||||||
(register-handler :sign-up
|
(register-handler :sign-up
|
||||||
(after (fn [_ [_ phone-number]]
|
(after (fn [_ [_ phone-number]]
|
||||||
|
@ -277,23 +285,27 @@
|
||||||
((after load-commands!))))
|
((after load-commands!))))
|
||||||
|
|
||||||
(defn initialize-chats
|
(defn initialize-chats
|
||||||
[{:keys [loaded-chats] :as db} _]
|
[{:keys [loaded-chats account-creation? chats] :as db} _]
|
||||||
(let [chats (->> loaded-chats
|
(let [chats' (if account-creation?
|
||||||
(map (fn [{:keys [chat-id] :as chat}]
|
chats
|
||||||
(let [last-message (messages/get-last-message chat-id)]
|
(->> loaded-chats
|
||||||
[chat-id (assoc chat :last-message last-message)])))
|
(map (fn [{:keys [chat-id] :as chat}]
|
||||||
(into {}))
|
(let [last-message (messages/get-last-message db chat-id)]
|
||||||
ids (set (keys chats))]
|
[chat-id (assoc chat :last-message last-message)])))
|
||||||
|
(into {})))
|
||||||
|
ids (set (keys chats'))]
|
||||||
|
|
||||||
(-> db
|
(-> db
|
||||||
(assoc :chats chats)
|
(assoc :chats chats')
|
||||||
(assoc :chats-ids ids)
|
(assoc :chats-ids ids)
|
||||||
(dissoc :loaded-chats)
|
(dissoc :loaded-chats)
|
||||||
(init-console-chat true))))
|
(init-console-chat true))))
|
||||||
|
|
||||||
(defn load-chats!
|
(defn load-chats!
|
||||||
[db _]
|
[{:keys [account-creation?] :as db} _]
|
||||||
(assoc db :loaded-chats (chats/get-all)))
|
(if account-creation?
|
||||||
|
db
|
||||||
|
(assoc db :loaded-chats (chats/get-all))))
|
||||||
|
|
||||||
;TODO: check if its new account / signup status / create console chat
|
;TODO: check if its new account / signup status / create console chat
|
||||||
(register-handler :initialize-chats
|
(register-handler :initialize-chats
|
||||||
|
|
|
@ -9,7 +9,8 @@
|
||||||
content-type-command-request]]
|
content-type-command-request]]
|
||||||
[cljs.reader :refer [read-string]]
|
[cljs.reader :refer [read-string]]
|
||||||
[status-im.data-store.chats :as chats]
|
[status-im.data-store.chats :as chats]
|
||||||
[taoensso.timbre :as log]))
|
[taoensso.timbre :as log]
|
||||||
|
[status-im.utils.scheduler :as s]))
|
||||||
|
|
||||||
(defn check-preview [{:keys [content] :as message}]
|
(defn check-preview [{:keys [content] :as message}]
|
||||||
(if-let [preview (:preview content)]
|
(if-let [preview (:preview content)]
|
||||||
|
@ -44,7 +45,7 @@
|
||||||
(not= from current-identity)
|
(not= from current-identity)
|
||||||
(or (not exists?) active?))
|
(or (not exists?) active?))
|
||||||
(let [group-chat? (not (nil? group-id))
|
(let [group-chat? (not (nil? group-id))
|
||||||
previous-message (messages/get-last-message chat-id')
|
previous-message (messages/get-last-message db chat-id')
|
||||||
message' (assoc (->> message
|
message' (assoc (->> message
|
||||||
(cu/check-author-direction previous-message)
|
(cu/check-author-direction previous-message)
|
||||||
(check-preview))
|
(check-preview))
|
||||||
|
@ -73,9 +74,9 @@
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
(fn [_ [_ {:keys [from to payload]}]]
|
(fn [_ [_ {:keys [from to payload]}]]
|
||||||
(dispatch [:received-message (merge payload
|
(dispatch [:received-message (merge payload
|
||||||
{:from from
|
{:from from
|
||||||
:to to
|
:to to
|
||||||
:chat-id from})]))))
|
:chat-id from})]))))
|
||||||
|
|
||||||
(register-handler :received-message
|
(register-handler :received-message
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
|
@ -85,3 +86,17 @@
|
||||||
(register-handler ::add-message
|
(register-handler ::add-message
|
||||||
(fn [db [_ add-to-chat-id {:keys [chat-id new?] :as message}]]
|
(fn [db [_ add-to-chat-id {:keys [chat-id new?] :as message}]]
|
||||||
(cu/add-message-to-db db add-to-chat-id chat-id message new?)))
|
(cu/add-message-to-db db add-to-chat-id chat-id message new?)))
|
||||||
|
|
||||||
|
(defn commands-loaded? [db chat-id]
|
||||||
|
(get-in db [:chats chat-id :commands-loaded]))
|
||||||
|
|
||||||
|
(def timeout 50)
|
||||||
|
|
||||||
|
(register-handler :received-message-when-commands-loaded
|
||||||
|
(u/side-effect!
|
||||||
|
(fn [db [_ chat-id message]]
|
||||||
|
(if (commands-loaded? db chat-id)
|
||||||
|
(dispatch [:received-message message])
|
||||||
|
(s/execute-later
|
||||||
|
#(dispatch [:received-message-when-commands-loaded chat-id message])
|
||||||
|
timeout)))))
|
||||||
|
|
|
@ -105,16 +105,27 @@
|
||||||
:to "me"}])))
|
:to "me"}])))
|
||||||
|
|
||||||
;; -- Saving password ----------------------------------------
|
;; -- Saving password ----------------------------------------
|
||||||
(defn passpharse-messages [mnemonic]
|
(defn account-generation-message []
|
||||||
(dispatch [:received-message
|
(dispatch [:received-message
|
||||||
{:message-id (random/id)
|
{:message-id (random/id)
|
||||||
:content (label :t/here-is-your-passphrase)
|
:content (label :t/account-generation-message)
|
||||||
:content-type text-content-type
|
:content-type text-content-type
|
||||||
:outgoing false
|
:outgoing false
|
||||||
:chat-id console-chat-id
|
:chat-id console-chat-id
|
||||||
:from console-chat-id
|
:from console-chat-id
|
||||||
:to "me"
|
:to "me"}]))
|
||||||
:new? false}])
|
|
||||||
|
(defn passpharse-messages [mnemonic messages-count]
|
||||||
|
(dispatch [:received-message
|
||||||
|
{:message-id (random/id)
|
||||||
|
:content (if (> messages-count 3)
|
||||||
|
(label :t/phew-here-is-your-passphrase)
|
||||||
|
(label :t/here-is-your-passphrase))
|
||||||
|
:content-type text-content-type
|
||||||
|
:outgoing false
|
||||||
|
:chat-id console-chat-id
|
||||||
|
:from console-chat-id
|
||||||
|
:to "me"}])
|
||||||
(dispatch [:received-message
|
(dispatch [:received-message
|
||||||
{:message-id (random/id)
|
{:message-id (random/id)
|
||||||
:content mnemonic
|
:content mnemonic
|
||||||
|
@ -122,8 +133,7 @@
|
||||||
:outgoing false
|
:outgoing false
|
||||||
:chat-id console-chat-id
|
:chat-id console-chat-id
|
||||||
:from console-chat-id
|
:from console-chat-id
|
||||||
:to "me"
|
:to "me"}])
|
||||||
:new? false}])
|
|
||||||
;; TODO highlight '!phone'
|
;; TODO highlight '!phone'
|
||||||
(start-signup))
|
(start-signup))
|
||||||
|
|
||||||
|
@ -138,7 +148,8 @@
|
||||||
|
|
||||||
(defn intro []
|
(defn intro []
|
||||||
(dispatch [:received-message intro-status])
|
(dispatch [:received-message intro-status])
|
||||||
(dispatch [:received-message
|
(dispatch [:received-message-when-commands-loaded
|
||||||
|
console-chat-id
|
||||||
{:chat-id console-chat-id
|
{:chat-id console-chat-id
|
||||||
:message-id "intro-message1"
|
:message-id "intro-message1"
|
||||||
:content (command-content
|
:content (command-content
|
||||||
|
|
|
@ -266,4 +266,4 @@
|
||||||
(defn new-message-container [margin on-top?]
|
(defn new-message-container [margin on-top?]
|
||||||
{:background-color color-white
|
{:background-color color-white
|
||||||
:margin-bottom margin
|
:margin-bottom margin
|
||||||
:elevation (if on-top? 6 5)})
|
:elevation (if on-top? 6 5)})
|
||||||
|
|
|
@ -53,7 +53,7 @@
|
||||||
:loop? loop?}]
|
:loop? loop?}]
|
||||||
(r/create-class
|
(r/create-class
|
||||||
{:component-did-mount
|
{:component-did-mount
|
||||||
(if @answered? #(request-button-animation-logic context) (fn []))
|
(if @answered? (fn []) #(request-button-animation-logic context))
|
||||||
:component-will-unmount
|
:component-will-unmount
|
||||||
#(reset! loop? false)
|
#(reset! loop? false)
|
||||||
:reagent-render
|
:reagent-render
|
||||||
|
|
|
@ -80,10 +80,12 @@
|
||||||
message))))))
|
message))))))
|
||||||
|
|
||||||
(defn get-last-message
|
(defn get-last-message
|
||||||
[chat-id]
|
[{:keys [chats] :as db} chat-id]
|
||||||
(let [{:keys [content-type] :as message} (data-store/get-last-message chat-id)]
|
(if-let [message (first (get-in db [:chats chat-id :messages]))]
|
||||||
(when (and message (command-type? content-type))
|
message
|
||||||
(clojure.core/update message :content str-to-map))))
|
(let [{:keys [content-type] :as message} (data-store/get-last-message chat-id)]
|
||||||
|
(when (and message (command-type? content-type))
|
||||||
|
(clojure.core/update message :content str-to-map)))))
|
||||||
|
|
||||||
(defn get-unviewed
|
(defn get-unviewed
|
||||||
[]
|
[]
|
||||||
|
|
|
@ -42,15 +42,16 @@
|
||||||
(assoc-in db [:animations k] v)))
|
(assoc-in db [:animations k] v)))
|
||||||
|
|
||||||
(register-handler :initialize-db
|
(register-handler :initialize-db
|
||||||
(fn [_ _]
|
(fn [{:keys [status-module-initialized?]} _]
|
||||||
(data-store/init)
|
(data-store/init)
|
||||||
(assoc app-db :current-account-id nil)))
|
(let [db' (assoc app-db :current-account-id nil)]
|
||||||
|
(if status-module-initialized?
|
||||||
|
(assoc db' :status-module-initialized? true)
|
||||||
|
db'))))
|
||||||
|
|
||||||
(register-handler :initialize-account-db
|
(register-handler :initialize-account-db
|
||||||
(fn [db _]
|
(fn [db _]
|
||||||
(assoc db
|
(assoc db :current-chat-id console-chat-id)))
|
||||||
:chats {}
|
|
||||||
:current-chat-id console-chat-id)))
|
|
||||||
|
|
||||||
(register-handler :initialize-account
|
(register-handler :initialize-account
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
|
|
|
@ -85,11 +85,13 @@
|
||||||
:incorrect-code (str "Sorry the code was incorrect, please enter again")
|
:incorrect-code (str "Sorry the code was incorrect, please enter again")
|
||||||
:generate-passphrase (str "I'll generate a passphrase for you so you can restore your "
|
:generate-passphrase (str "I'll generate a passphrase for you so you can restore your "
|
||||||
"access or log in from another device")
|
"access or log in from another device")
|
||||||
|
:phew-here-is-your-passphrase "*Phew* that was hard, here is your passphrase, *write this down and keep this safe!* You will need it to recover your account."
|
||||||
:here-is-your-passphrase "Here is your passphrase, *write this down and keep this safe!* You will need it to recover your account."
|
:here-is-your-passphrase "Here is your passphrase, *write this down and keep this safe!* You will need it to recover your account."
|
||||||
:written-down "Make sure you had securely written it down"
|
:written-down "Make sure you had securely written it down"
|
||||||
:phone-number-required "Tap here to enter your phone number & I'll find your friends"
|
:phone-number-required "Tap here to enter your phone number & I'll find your friends"
|
||||||
:intro-status "Chat with me to setup your account and change your settings!"
|
:intro-status "Chat with me to setup your account and change your settings!"
|
||||||
:intro-message1 "Welcome to Status\nTap this message to set your password & get started!"
|
:intro-message1 "Welcome to Status\nTap this message to set your password & get started!"
|
||||||
|
:account-generation-message "Gimmie a sec, I gotta do some crazy math to generate your account!"
|
||||||
|
|
||||||
;chats
|
;chats
|
||||||
:chats "Chats"
|
:chats "Chats"
|
||||||
|
|
Loading…
Reference in New Issue