parent
101448b963
commit
d260117c85
|
@ -1621,12 +1621,12 @@ function startsWith(str1, str2) {
|
||||||
return str1.lastIndexOf(str2, 0) == 0 && str1 != str2;
|
return str1.lastIndexOf(str2, 0) == 0 && str1 != str2;
|
||||||
}
|
}
|
||||||
|
|
||||||
function phoneSuggestions(params) {
|
function phoneSuggestions(params, context) {
|
||||||
var ph, suggestions;
|
var ph, suggestions;
|
||||||
if (!params.phone || params.phone == "") {
|
if (!params.phone || params.phone == "") {
|
||||||
ph = phones;
|
ph = context.suggestions;
|
||||||
} else {
|
} else {
|
||||||
ph = phones.filter(function (phone) {
|
ph = context.suggestions.filter(function (phone) {
|
||||||
return startsWith(phone.number, params.phone);
|
return startsWith(phone.number, params.phone);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,12 @@
|
||||||
(subs content (count cu/command-prefix))
|
(subs content (count cu/command-prefix))
|
||||||
content))
|
content))
|
||||||
|
|
||||||
|
(defn command-dependent-context-params
|
||||||
|
[{:keys [name] :as command}]
|
||||||
|
(case name
|
||||||
|
"phone" {:suggestions (pn/get-examples)}
|
||||||
|
{}))
|
||||||
|
|
||||||
(defn invoke-suggestions-handler!
|
(defn invoke-suggestions-handler!
|
||||||
[{:keys [current-chat-id canceled-command] :as db} _]
|
[{:keys [current-chat-id canceled-command] :as db} _]
|
||||||
(when-not canceled-command
|
(when-not canceled-command
|
||||||
|
@ -30,7 +36,8 @@
|
||||||
0
|
0
|
||||||
:suggestions]
|
:suggestions]
|
||||||
params {:parameters (or params {})
|
params {:parameters (or params {})
|
||||||
:context {:data data}}]
|
:context (merge {:data data}
|
||||||
|
(command-dependent-context-params command))}]
|
||||||
(status/call-jail current-chat-id
|
(status/call-jail current-chat-id
|
||||||
path
|
path
|
||||||
params
|
params
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
[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]]
|
||||||
[status-im.utils.phone-number :refer [format-phone-number]]
|
|
||||||
[status-im.constants :refer [console-chat-id
|
[status-im.constants :refer [console-chat-id
|
||||||
text-content-type
|
text-content-type
|
||||||
content-type-command
|
content-type-command
|
||||||
|
|
|
@ -104,6 +104,12 @@
|
||||||
: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!"
|
: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 "Chats"
|
:chats "Chats"
|
||||||
:new-chat "New chat"
|
:new-chat "New chat"
|
||||||
|
|
|
@ -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 i18n (js/require "react-native-i18n"))
|
||||||
(def locale (or (.-locale i18n) "___en"))
|
(def locale (or (.-locale i18n) "___en"))
|
||||||
|
@ -7,12 +8,21 @@
|
||||||
|
|
||||||
;; todo check wrong numbers, .getNumber returns empty string
|
;; todo check wrong numbers, .getNumber returns empty string
|
||||||
(defn format-phone-number [number]
|
(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]
|
(defn valid-mobile-number? [number]
|
||||||
(when (string? number)
|
(when (string? number)
|
||||||
(let [pattern #"^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{2})[-. ]*(\d{2})\s*$"
|
(let [number-obj (awesome-phonenumber. number country-code)]
|
||||||
number-obj (awesome-phonenumber. number country-code "international")]
|
(and (.isValid number-obj)
|
||||||
(and (re-matches pattern number)
|
|
||||||
(.isValid number-obj)
|
|
||||||
(.isMobile number-obj)))))
|
(.isMobile number-obj)))))
|
||||||
|
|
Loading…
Reference in New Issue