[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
(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]))
(re-frame/reg-sub
:new-topic-error-message
:public-chat.new/topic-error-message
:<- [:get :public-group-topic]
(fn [topic]
(when-not (spec/valid? ::db/topic topic)
(when-not (or (empty? topic)
(db/valid-topic? topic))
(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.toolbar.view :as toolbar]
[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.styles :as add-new.styles]
status-im.utils.db
@ -25,11 +25,8 @@
[react/view common.styles/flex
[text-input.view/text-input-with-label
{:container styles/input-container
:on-change-text #(do
(re-frame/dispatch [:set :public-group-topic-error (when-not (spec/valid? ::v/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))
:on-change-text #(re-frame/dispatch [:set :public-group-topic %])
:on-submit-editing #(when (db/valid-topic? topic)
(re-frame/dispatch [:chat.ui/start-public-chat topic]))
:auto-capitalize :none
:auto-focus false
@ -61,7 +58,7 @@
(views/defview new-public-chat []
(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
[status-bar/status-bar]
[toolbar/simple-toolbar

View File

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

View File

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

View File

@ -4,7 +4,3 @@
(defmethod nav/preload-data! :add-participants-toggle-list
[db _]
(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.",
"status-sent": "Sent",
"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",
"datetime-today": "today",
"dapp-would-like-to-connect-wallet": "would like\n to connect to your wallet",