Phone fixes (#539, #566, #634)

This commit is contained in:
alwx 2017-01-17 13:23:13 +03:00 committed by Roman Volosovskyi
parent 101448b963
commit d260117c85
5 changed files with 33 additions and 11 deletions

View File

@ -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);
});
}

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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)))))