From 9274ba0ebb843d6cc709a70ec15ea2f4793ff2a3 Mon Sep 17 00:00:00 2001 From: virvar Date: Wed, 18 May 2016 16:45:03 +0300 Subject: [PATCH] Send international phone number to server. Send confirmation code. --- src/syng_im/chat/handlers.cljs | 16 ++++++++++------ src/syng_im/chat/sign_up.cljs | 12 +++++++----- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/syng_im/chat/handlers.cljs b/src/syng_im/chat/handlers.cljs index 1691319b39..0df1412f06 100644 --- a/src/syng_im/chat/handlers.cljs +++ b/src/syng_im/chat/handlers.cljs @@ -12,6 +12,8 @@ [syng-im.models.chats :as chats] [syng-im.navigation.handlers :as nav] [syng-im.models.chats :as c] + [syng-im.handlers.server :as server] + [syng-im.utils.phone-number :refer [format-phone-number]] [syng-im.utils.handlers :as u])) (register-handler :set-show-actions @@ -222,15 +224,17 @@ (assoc db :password-saved true))) (register-handler :sign-up - (-> (fn [db [_ phone-number]] - ;; todo save phone number to db - (assoc db :user-phone-number phone-number)) - ((after (fn [& _] (sign-up-service/on-sign-up-response)))))) + (fn [db [_ phone-number]] + ;; todo save phone number to db + (let [formatted (format-phone-number phone-number)] + (-> db + (assoc :user-phone-number formatted) + (server/sign-up formatted sign-up-service/on-sign-up-response))))) (register-handler :sign-up-confirm (fn [db [_ confirmation-code]] - (sign-up-service/on-send-code-response confirmation-code) - (sign-up-service/set-signed-up db true))) + (server/sign-up-confirm confirmation-code sign-up-service/on-send-code-response) + db)) (register-handler :set-signed-up (fn [db [_ signed-up]] diff --git a/src/syng_im/chat/sign_up.cljs b/src/syng_im/chat/sign_up.cljs index 8cef60aac0..a00f1d3154 100644 --- a/src/syng_im/chat/sign_up.cljs +++ b/src/syng_im/chat/sign_up.cljs @@ -37,19 +37,21 @@ (dispatch [:set-signed-up true])) (defn sync-contacts [] + ;; TODO 'on-sync-contacts' is never called (dispatch [:sync-contacts on-sync-contacts])) (defn on-send-code-response [body] (dispatch [:received-msg {:msg-id (random/id) - ;; todo replace by real check - :content (if (= "1111" body) - "Confirmed" - "Wrong code") + :content (:message body) :content-type text-content-type :outgoing false :from "console" - :to "me"}])) + :to "me"}]) + (when (:confirmed body) + (sync-contacts) + ;; TODO should be called after sync-contacts? + (dispatch [:set-signed-up true]))) ; todo fn name is not too smart, but... (defn command-content