[fix 6009] do not allow public chat named with valid contact key

Signed-off-by: yenda <eric@status.im>
This commit is contained in:
yenda 2018-09-26 14:29:09 +02:00
parent 4c426d9c2b
commit 720a65e3ab
No known key found for this signature in database
GPG Key ID: 0095623C0069DCE6
7 changed files with 27 additions and 29 deletions

View File

@ -8,3 +8,8 @@
(spec/def ::topic (spec/and :global/not-empty-string (spec/def ::topic (spec/and :global/not-empty-string
(partial re-matches #"[a-z0-9\-]+"))) (partial re-matches #"[a-z0-9\-]+")))
(defn valid-topic? [topic]
(and topic
(spec/valid? ::topic topic)
(not (spec/valid? :global/public-key topic))))

View File

@ -5,8 +5,9 @@
[cljs.spec.alpha :as spec])) [cljs.spec.alpha :as spec]))
(re-frame/reg-sub (re-frame/reg-sub
:new-topic-error-message :public-chat.new/topic-error-message
:<- [:get :public-group-topic] :<- [:get :public-group-topic]
(fn [topic] (fn [topic]
(when-not (spec/valid? ::db/topic topic) (when-not (or (empty? topic)
(db/valid-topic? topic))
(i18n/label :topic-name-error)))) (i18n/label :topic-name-error))))

View File

@ -9,7 +9,7 @@
[status-im.ui.components.text-input.view :as text-input.view] [status-im.ui.components.text-input.view :as text-input.view]
[status-im.ui.components.toolbar.view :as toolbar] [status-im.ui.components.toolbar.view :as toolbar]
[status-im.ui.components.tooltip.views :as tooltip] [status-im.ui.components.tooltip.views :as tooltip]
[status-im.ui.screens.add-new.new-public-chat.db :as v] [status-im.ui.screens.add-new.new-public-chat.db :as db]
[status-im.ui.screens.add-new.new-public-chat.styles :as styles] [status-im.ui.screens.add-new.new-public-chat.styles :as styles]
[status-im.ui.screens.add-new.styles :as add-new.styles] [status-im.ui.screens.add-new.styles :as add-new.styles]
status-im.utils.db status-im.utils.db
@ -25,11 +25,8 @@
[react/view common.styles/flex [react/view common.styles/flex
[text-input.view/text-input-with-label [text-input.view/text-input-with-label
{:container styles/input-container {:container styles/input-container
:on-change-text #(do :on-change-text #(re-frame/dispatch [:set :public-group-topic %])
(re-frame/dispatch [:set :public-group-topic-error (when-not (spec/valid? ::v/topic %) :on-submit-editing #(when (db/valid-topic? topic)
(i18n/label :t/topic-name-error))])
(re-frame/dispatch [:set :public-group-topic %]))
:on-submit-editing #(when (and topic (spec/valid? ::v/topic topic))
(re-frame/dispatch [:chat.ui/start-public-chat topic])) (re-frame/dispatch [:chat.ui/start-public-chat topic]))
:auto-capitalize :none :auto-capitalize :none
:auto-focus false :auto-focus false
@ -61,7 +58,7 @@
(views/defview new-public-chat [] (views/defview new-public-chat []
(views/letsubs [topic [:get :public-group-topic] (views/letsubs [topic [:get :public-group-topic]
error [:get :public-group-topic-error]] error [:public-chat.new/topic-error-message]]
[react/keyboard-avoiding-view styles/group-container [react/keyboard-avoiding-view styles/group-container
[status-bar/status-bar] [status-bar/status-bar]
[toolbar/simple-toolbar [toolbar/simple-toolbar

View File

@ -87,17 +87,17 @@
:width 5 :width 5
:height 16 :height 16
:margin-bottom -16}) :margin-bottom -16})
(def tooltip-container (def tooltip-container
{:position :absolute {:position :absolute
:align-items :center :align-items :center
:align-self :center :align-self :center
:top -34}) :bottom 34})
(def tooltip-icon-text (def tooltip-icon-text
{:justify-content :center {:justify-content :center
:align-items :center :align-items :center
:flex 1 :flex 1
:height 24
:border-radius 8 :border-radius 8
:padding-left 10 :padding-left 10
:padding-right 10 :padding-right 10

View File

@ -9,7 +9,7 @@
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.ui.screens.desktop.main.add-new.styles :as styles] [status-im.ui.screens.desktop.main.add-new.styles :as styles]
[status-im.ui.screens.add-new.new-public-chat.view :refer [default-public-chats]] [status-im.ui.screens.add-new.new-public-chat.view :refer [default-public-chats]]
[status-im.ui.screens.add-new.new-public-chat.db :as public-chat-db] [status-im.ui.screens.add-new.new-public-chat.db :as public-chat.db]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[status-im.ui.components.react :as react] [status-im.ui.components.react :as react]
[status-im.ui.components.colors :as colors])) [status-im.ui.components.colors :as colors]))
@ -30,9 +30,6 @@
(defn topic-input-placeholder [] (defn topic-input-placeholder []
[react/text {:style styles/topic-placeholder} "#"]) [react/text {:style styles/topic-placeholder} "#"])
(defn on-topic-change [e]
(let [text (.. e -nativeEvent -text)]
(re-frame/dispatch [:set :public-group-topic text])))
(views/defview error-tooltip [text] (views/defview error-tooltip [text]
[react/view {:style styles/tooltip-container} [react/view {:style styles/tooltip-container}
[react/view {:style styles/tooltip-icon-text} [react/view {:style styles/tooltip-icon-text}
@ -45,7 +42,7 @@
contacts [:all-added-people-contacts] contacts [:all-added-people-contacts]
chat-error [:new-identity-error] chat-error [:new-identity-error]
topic [:get :public-group-topic] topic [:get :public-group-topic]
topic-error [:new-topic-error-message]] topic-error [:public-chat.new/topic-error-message]]
{:component-will-unmount #(re-frame/dispatch [:new-chat/set-new-identity nil])} {:component-will-unmount #(re-frame/dispatch [:new-chat/set-new-identity nil])}
[react/scroll-view [react/scroll-view
[react/view {:style styles/new-contact-view} [react/view {:style styles/new-contact-view}
@ -103,13 +100,12 @@
(i18n/label :new-public-group-chat)]] (i18n/label :new-public-group-chat)]]
[react/text {:style styles/new-contact-subtitle} (i18n/label :public-group-topic)] [react/text {:style styles/new-contact-subtitle} (i18n/label :public-group-topic)]
[react/view {:style styles/new-contact-separator}] [react/view {:style styles/new-contact-separator}]
(let [disable? (or (not (string/blank? topic-error)) (let [disable? (or topic-error
(string/blank? topic)) (string/blank? topic))
show-error-tooltip? (and topic-error (not (string/blank? topic))) show-error-tooltip? topic-error
create-public-chat #(when-not topic-error create-public-chat #(when (public-chat.db/valid-topic? topic)
(do (re-frame/dispatch [:set :public-group-topic nil])
(re-frame/dispatch [:set :public-group-topic nil]) (re-frame/dispatch [:chat.ui/start-public-chat topic]))]
(re-frame/dispatch [:chat.ui/start-public-chat topic])))]
[react/view {:style styles/add-contact-edit-view} [react/view {:style styles/add-contact-edit-view}
[react/view {:flex 1 [react/view {:flex 1
:style (styles/add-pub-chat-input show-error-tooltip?)} :style (styles/add-pub-chat-input show-error-tooltip?)}
@ -120,8 +116,11 @@
:font :default :font :default
:selection-color colors/blue :selection-color colors/blue
:placeholder "" :placeholder ""
:on-change on-topic-change :on-change (fn [e]
:on-submit-editing (when-not disable? create-public-chat)}]] (let [text (.. e -nativeEvent -text)]
(re-frame/dispatch [:set :public-group-topic text])))
:on-submit-editing (when-not disable?
create-public-chat)}]]
[react/touchable-highlight {:disabled disable? [react/touchable-highlight {:disabled disable?
:on-press create-public-chat} :on-press create-public-chat}
[react/view {:style (styles/add-contact-button disable?)} [react/view {:style (styles/add-contact-button disable?)}

View File

@ -4,7 +4,3 @@
(defmethod nav/preload-data! :add-participants-toggle-list (defmethod nav/preload-data! :add-participants-toggle-list
[db _] [db _]
(assoc db :selected-participants #{})) (assoc db :selected-participants #{}))
(defmethod nav/preload-data! :new-public-chat
[db]
(dissoc db :public-group-topic :public-group-topic-error))

View File

@ -516,7 +516,7 @@
"word-n-description": "In order to check if you have backed up your recovery phrase correctly, enter the word #{{number}} above.", "word-n-description": "In order to check if you have backed up your recovery phrase correctly, enter the word #{{number}} above.",
"status-sent": "Sent", "status-sent": "Sent",
"status-prompt": "Set your status. Using #hastags will help others discover you and talk about what's on your mind", "status-prompt": "Set your status. Using #hastags will help others discover you and talk about what's on your mind",
"topic-name-error": "Topic names use only lowercase letters (a to z) & dashes (-)", "topic-name-error": "Use only lowercase letters (a to z), numbers & dashes (-). Do not use contact codes",
"delete-contact-confirmation": "This contact will be removed from your contacts", "delete-contact-confirmation": "This contact will be removed from your contacts",
"datetime-today": "today", "datetime-today": "today",
"dapp-would-like-to-connect-wallet": "would like\n to connect to your wallet", "dapp-would-like-to-connect-wallet": "would like\n to connect to your wallet",