diff --git a/resources/console.js b/resources/console.js index acf24a1e70..f54bfe8ebf 100644 --- a/resources/console.js +++ b/resources/console.js @@ -1621,12 +1621,12 @@ function startsWith(str1, str2) { return str1.lastIndexOf(str2, 0) == 0 && str1 != str2; } -function phoneSuggestions(params) { +function phoneSuggestions(params, context) { var ph, suggestions; if (!params.phone || params.phone == "") { - ph = phones; + ph = context.suggestions; } else { - ph = phones.filter(function (phone) { + ph = context.suggestions.filter(function (phone) { return startsWith(phone.number, params.phone); }); } diff --git a/src/status_im/chat/handlers/commands.cljs b/src/status_im/chat/handlers/commands.cljs index 5f2d96b86d..19a33dc41b 100644 --- a/src/status_im/chat/handlers/commands.cljs +++ b/src/status_im/chat/handlers/commands.cljs @@ -18,6 +18,12 @@ (subs content (count cu/command-prefix)) content)) +(defn command-dependent-context-params + [{:keys [name] :as command}] + (case name + "phone" {:suggestions (pn/get-examples)} + {})) + (defn invoke-suggestions-handler! [{:keys [current-chat-id canceled-command] :as db} _] (when-not canceled-command @@ -30,7 +36,8 @@ 0 :suggestions] params {:parameters (or params {}) - :context {:data data}}] + :context (merge {:data data} + (command-dependent-context-params command))}] (status/call-jail current-chat-id path params diff --git a/src/status_im/chat/sign_up.cljs b/src/status_im/chat/sign_up.cljs index 344d5f2f15..6045934545 100644 --- a/src/status_im/chat/sign_up.cljs +++ b/src/status_im/chat/sign_up.cljs @@ -5,7 +5,6 @@ [status-im.utils.random :as random] [status-im.utils.sms-listener :refer [add-sms-listener remove-sms-listener]] - [status-im.utils.phone-number :refer [format-phone-number]] [status-im.constants :refer [console-chat-id text-content-type content-type-command diff --git a/src/status_im/translations/en.cljs b/src/status_im/translations/en.cljs index 035517fe6d..43df175ba7 100644 --- a/src/status_im/translations/en.cljs +++ b/src/status_im/translations/en.cljs @@ -104,6 +104,12 @@ :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!" + ;phone types + :phone-e164 "International 1" + :phone-international "International 2" + :phone-national "National" + :phone-significant "Significant" + ;chats :chats "Chats" :new-chat "New chat" diff --git a/src/status_im/utils/phone_number.cljs b/src/status_im/utils/phone_number.cljs index 0e9ede1756..d97cef559a 100644 --- a/src/status_im/utils/phone_number.cljs +++ b/src/status_im/utils/phone_number.cljs @@ -1,4 +1,5 @@ -(ns status-im.utils.phone-number) +(ns status-im.utils.phone-number + (:require [status-im.i18n :refer [label]])) (def i18n (js/require "react-native-i18n")) (def locale (or (.-locale i18n) "___en")) @@ -7,12 +8,21 @@ ;; todo check wrong numbers, .getNumber returns empty string (defn format-phone-number [number] - (str (.getNumber (awesome-phonenumber. number country-code "international")))) + (str (.getNumber (awesome-phonenumber. number country-code) "international"))) + +(defn get-examples [] + (when-let [example (.getExample awesome-phonenumber country-code "mobile")] + [{:number (.getNumber example) + :description (label :t/phone-e164)} + {:number (.getNumber example "international") + :description (label :t/phone-international)} + {:number (.getNumber example "national") + :description (label :t/phone-national)} + {:number (.getNumber example "significant") + :description (label :t/phone-significant)}])) (defn valid-mobile-number? [number] (when (string? number) - (let [pattern #"^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{2})[-. ]*(\d{2})\s*$" - number-obj (awesome-phonenumber. number country-code "international")] - (and (re-matches pattern number) - (.isValid number-obj) + (let [number-obj (awesome-phonenumber. number country-code)] + (and (.isValid number-obj) (.isMobile number-obj)))))