Skip to content

Commit

Permalink
Merge pull request #4752 from status-im/fix/4250-add-contact-code-val…
Browse files Browse the repository at this point in the history
…idation

Add contact code/topic validation
  • Loading branch information
Vitaliy Vlasov authored Jul 10, 2018
2 parents 9e4e929 + 9af908b commit 179cc96
Show file tree
Hide file tree
Showing 14 changed files with 347 additions and 73 deletions.
4 changes: 4 additions & 0 deletions src/status_im/translations/en.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
:active-unknown "Unknown"
:available "Available"
:no-messages "No messages"
:no-messages-yet "No messages yet"
:suggestions-requests "Requests"
:suggestions-commands "Commands"
:faucet-success "Faucet request has been received"
Expand Down Expand Up @@ -229,6 +230,7 @@
;;chats
:new "New"
:new-chat "New chat"
:start-chat "Start chat"
:start-new-chat "Start new chat"
:start-group-chat "Start group chat"
:invite-friends "Invite friends"
Expand All @@ -241,6 +243,7 @@
:delete-group-chat-confirmation "Are you sure you want to delete this group chat?"
:new-group-chat "New group chat"
:new-public-group-chat "Join public chat"
:selected-for-you "Selected for you"
:public-chat "Public chat"
:edit-chats "Edit chats"
:search-chats "Search chats"
Expand Down Expand Up @@ -290,6 +293,7 @@
:search-contacts "Search contacts"
:contacts-group-new-chat "Start new chat"
:choose-from-contacts "Choose from contacts"
:or-choose-a-contact "Or choose a contact"
:no-contacts "No contacts yet"
:show-qr "Show QR code"
:copy-qr "Copy code"
Expand Down
6 changes: 4 additions & 2 deletions src/status_im/ui/components/desktop/tabs.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(ns status-im.ui.components.desktop.tabs
(:require [re-frame.core :as re-frame]
[status-im.ui.components.icons.vector-icons :as icons]
[taoensso.timbre :as log]
[status-im.ui.components.colors :as colors]
[status-im.ui.components.react :as react]
[status-im.ui.screens.main-tabs.styles :as tabs.styles])
(:require-macros [status-im.utils.views :as views]))
Expand All @@ -26,7 +28,7 @@
[react/view {:style tabs.styles/tab-container}
(let [icon (if active? icon-active icon-inactive)]
[react/view
[icons/icon icon {:color (:color (tabs.styles/tab-icon active?))}]])
[icons/icon icon {:style {:tint-color (if active? colors/blue colors/gray-icon)}}]])
[react/view
[react/text {:style (tabs.styles/tab-title active?)}
title]]]))
Expand All @@ -43,7 +45,7 @@
[content active?]]])

(views/defview main-tabs []
(views/letsubs [current-tab [:get :left-view-id]]
(views/letsubs [current-tab [:get-in [:desktop/desktop :tab-view-id]]]
[react/view
[react/view {:style tabs.styles/tabs-container}
(for [[index {:keys [content view-id]}] tabs-list-indexed]
Expand Down
15 changes: 8 additions & 7 deletions src/status_im/ui/screens/add_new/new_chat/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
[clojure.string :as string]))

(defn- validate-pub-key [whisper-identity {:keys [address public-key]}]
(when (and whisper-identity (not (string/blank? whisper-identity)))
(cond
(#{(hex/normalize-hex address) (hex/normalize-hex public-key)}
(hex/normalize-hex whisper-identity))
(i18n/label :t/can-not-add-yourself)
(cond
(string/blank? whisper-identity)
(i18n/label :t/use-valid-contact-code)
(#{(hex/normalize-hex address) (hex/normalize-hex public-key)}
(hex/normalize-hex whisper-identity))
(i18n/label :t/can-not-add-yourself)

(not (spec/valid? :global/public-key whisper-identity))
(i18n/label :t/use-valid-contact-code))))
(not (spec/valid? :global/public-key whisper-identity))
(i18n/label :t/use-valid-contact-code)))
2 changes: 1 addition & 1 deletion src/status_im/ui/screens/add_new/new_chat/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
:<- [:get :contacts/new-identity]
:<- [:get-current-account]
(fn [[new-identity account]]
(db/validate-pub-key new-identity account)))
(db/validate-pub-key new-identity account)))
12 changes: 12 additions & 0 deletions src/status_im/ui/screens/add_new/new_public_chat/subs.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(ns status-im.ui.screens.add-new.new-public-chat.subs
(:require [re-frame.core :as re-frame]
[status-im.i18n :as i18n]
[status-im.ui.screens.add-new.new-public-chat.db :as db]
[cljs.spec.alpha :as spec]))

(re-frame/reg-sub
:new-topic-error-message
:<- [:get :public-group-topic]
(fn [topic]
(when-not (spec/valid? ::db/topic topic)
(i18n/label :topic-name-error))))
72 changes: 72 additions & 0 deletions src/status_im/ui/screens/desktop/main/add_new/styles.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
(ns status-im.ui.screens.desktop.main.add-new.styles
(:require [status-im.ui.components.colors :as colors]))

(def new-contact-view
{:flex 1
:background-color colors/white
:margin-left 24
:margin-right 37})

(def new-contact-title
{:height 64
:align-items :flex-start
:justify-content :center})

(def new-contact-title-text
{:font-size 20
:color :black
:font-weight "600"})

(def new-contact-subtitle
{:font-size 14})

(def new-contact-separator
{:height 1
:background-color colors/gray-light})

(def add-contact-edit-view
{:height 45
:margin-bottom 32
:background-color colors/white
:border-radius 12
:flex-direction :row
:margin-top 16})

(def add-contact-input
{:font-size 14
:background-color colors/gray-lighter
:margin-right 12
:border-radius 8})

(defn add-contact-button [error?]
{:width 140
:height 45
:border-radius 8
:background-color (if error? colors/gray-lighter colors/blue)
:align-items :center
:justify-content :center})

(defn add-contact-button-text [error?]
{:font-size 16
:color (if error? colors/gray colors/white)})

(def suggested-contact-view
{:flex-direction "row"
:align-items :center
:margin-bottom 16})

(def suggested-contact-image
{:width 46
:height 46
:border-radius 46
:margin-right 16})

(def suggested-topic-image
(merge suggested-contact-image
{:background-color colors/blue
:align-items :center
:justify-content :center}))

(def suggested-topic-text
{:font-size 25.6
:color colors/white})
124 changes: 86 additions & 38 deletions src/status_im/ui/screens/desktop/main/add_new/views.cljs
Original file line number Diff line number Diff line change
@@ -1,49 +1,97 @@
(ns status-im.ui.screens.desktop.main.add-new.views
(:require-macros [status-im.utils.views :as views])
(:require [status-im.ui.components.icons.vector-icons :as icons]
[status-im.ui.screens.add-new.new-public-chat.view :as public-chat]
[status-im.ui.components.list.views :as list]
[clojure.string :as string]
[status-im.i18n :as i18n]
[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]
[taoensso.timbre :as log]
[status-im.ui.components.react :as react]))

(views/defview new-contact []
(views/letsubs [new-contact-identity [:get :contacts/new-identity]
topic [:get :public-group-topic]]
[react/view {:style {:flex 1 :background-color "#eef2f5"}}
^{:key "newcontact"}
[react/view {:style {:height 64 :align-items :center :padding-horizontal 11 :justify-content :center}}
[react/text {:style {:font-size 16 :color :black :font-weight "600"}}
"Add new contact"]]
[react/view {:style {:height 1 :background-color "#e8ebec" :margin-horizontal 16}}]
[react/view {:style {:height 90 :margin-horizontal 16 :margin-bottom 16 :background-color :white :border-radius 12}}
;:box-shadow "0 0.5px 4.5px 0 rgba(0, 0, 0, 0.04)"}}
[react/view {:style {:flex-direction :row :margin-horizontal 16 :margin-top 16}}
contacts [:all-added-people-contacts]
chat-error [:new-contact-error-message]
topic [:get :public-group-topic]
topic-error [:new-topic-error-message]
account [:get-current-account]
topic-input-ref (atom nil)]
[react/scroll-view
[react/view {:style styles/new-contact-view}
^{:key "newcontact"}
[react/view {:style styles/new-contact-title}
[react/text {:style styles/new-contact-title-text}
(i18n/label :new-chat)]]
[react/text {:style styles/new-contact-subtitle} (i18n/label :contact-code)]
[react/view {:style styles/new-contact-separator}]
[react/view {:style styles/add-contact-edit-view}
[react/text-input {:placeholder "0x..."
:flex 1
:style styles/add-contact-input
:on-change (fn [e]
(let [native-event (.-nativeEvent e)
text (.-text native-event)]
(re-frame/dispatch [:set :contacts/new-identity text])))}]
[react/touchable-highlight {:disabled chat-error :on-press #(when-not chat-error (re-frame/dispatch [:add-contact-handler new-contact-identity]))}
[react/view
{:style (styles/add-contact-button chat-error)}
[react/text
{:style (styles/add-contact-button-text chat-error)}
(i18n/label :start-chat)]]]]
^{:key "choosecontact"}
[react/view
(when (seq contacts) [react/text {:style styles/new-contact-subtitle} (i18n/label :or-choose-a-contact)])
[react/view {:style {:margin-top 12}}
(doall
(for [c contacts]
^{:key (:whisper-identity c)}
[react/touchable-highlight {:on-press #(do
(re-frame/dispatch [:set :contacts/new-identity (:whisper-identity c)])
(re-frame/dispatch [:add-contact-handler (:whisper-identity c)]))}
[react/view {:style styles/suggested-contact-view}
[react/image {:style styles/suggested-contact-image
:source {:uri (:photo-path c)}}]
[react/text {:style styles/new-contact-subtitle} (:name c)]]]))]]
^{:key "publicchat"}
[react/view {:style styles/new-contact-title}
[react/text {:style styles/new-contact-title-text}
(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}]
[react/view {:style styles/add-contact-edit-view}
[react/view {:style {:flex 1}}
[react/text-input {:placeholder "Contact key"
:flex 1
[react/text-input {:flex 1
:ref #(when (and (nil? @topic-input-ref) %)
(.setNativeProps % (js-obj "text" "#"))
(reset! topic-input-ref %))
:style styles/add-contact-input
:on-change (fn [e]
(let [native-event (.-nativeEvent e)
text (.-text native-event)]
(re-frame/dispatch [:set :contacts/new-identity text])))}]]
[react/touchable-highlight {:on-press #(re-frame/dispatch [:add-contact-handler new-contact-identity])}
[react/view {:style {:margin-left 16 :width 30 :height 30 :border-radius 15 :background-color "#eef2f5" :align-items :center
:justify-content :center}}
[icons/icon :icons/ok]]]]]
^{:key "publicchat"}
[react/view {:style {:height 64 :align-items :center :padding-horizontal 11 :justify-content :center}}
[react/text {:style {:font-size 16 :color :black :font-weight "600"}}
"Join to public chat"]]
[react/view {:style {:height 1 :background-color "#e8ebec" :margin-horizontal 16}}]
[react/view {:style {:height 90 :margin-horizontal 16 :margin-bottom 16 :background-color :white :border-radius 12}}
;:box-shadow "0 0.5px 4.5px 0 rgba(0, 0, 0, 0.04)"}}
[react/view {:style {:flex-direction :row :margin-horizontal 16 :margin-top 16}}
[react/text "#"]
[react/view {:style {:flex 1}}
[react/text-input {:placeholder "topic"
:flex 1
:on-change (fn [e]
(let [native-event (.-nativeEvent e)
text (.-text native-event)]
(re-frame/dispatch [:set :public-group-topic text])))}]]
[react/touchable-highlight {:on-press #(re-frame/dispatch [:create-new-public-chat topic])}
[react/view {:style {:margin-left 16 :width 30 :height 30 :border-radius 15 :background-color "#eef2f5" :align-items :center
:justify-content :center}}
[icons/icon :icons/ok]]]]]]))
text (.-text native-event)
[_ before after] (first (re-seq #"(.*)\#(.*)" text))]
(.setNativeProps @topic-input-ref (js-obj "text" (str "#" before after)))
(re-frame/dispatch [:set :public-group-topic (subs text 1)])))}]]
[react/touchable-highlight {:disabled topic-error
:on-press #(when-not topic-error
(do
(re-frame/dispatch [:set :public-group-topic nil])
(re-frame/dispatch [:create-new-public-chat topic])))}
[react/view {:style (styles/add-contact-button topic-error)}
[react/text {:style (styles/add-contact-button-text topic-error)}
(i18n/label :new-public-group-chat)]]]]
[react/text {:style styles/new-contact-subtitle} (i18n/label :selected-for-you)]
[react/view {:style {:margin-top 12}}
(doall
(for [topic public-chat/default-public-chats]
^{:key topic}
[react/touchable-highlight {:on-press #(do
(re-frame/dispatch [:set :public-group-topic nil])
(re-frame/dispatch [:create-new-public-chat topic]))}
[react/view {:style styles/suggested-contact-view}
[react/view {:style styles/suggested-topic-image}
[react/text {:style styles/suggested-topic-text} (string/capitalize (first topic))]]
[react/text {:style styles/new-contact-subtitle} topic]]]))]]]))
6 changes: 4 additions & 2 deletions src/status_im/ui/screens/desktop/main/chat/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@

(defn message [text me? {:keys [message-id chat-id message-status user-statuses from
current-public-key content-type group-chat outgoing type value] :as message}]
(when (nil? message-id)
(log/debug "nil?" message))
(if (= type :datemark)
^{:key (str "datemark" message-id)}
[message.datemark/chat-datemark value]
Expand Down Expand Up @@ -136,8 +138,8 @@
:ref #(reset! scroll-ref %)}
[react/view {:style {:padding-vertical 46}}
(doall
(for [[index {:keys [from content message-id] :as message-obj}] (map-indexed vector (reverse @messages))]
^{:key (or message-id "0")}
(for [[index {:keys [from content message-id type value] :as message-obj}] (map-indexed vector (reverse @messages))]
^{:key (or message-id (str type value))}
[message content (= from @current-public-key) (assoc message-obj :group-chat group-chat)]))]]])))

(views/defview chat-text-input []
Expand Down
14 changes: 14 additions & 0 deletions src/status_im/ui/screens/desktop/main/styles.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(ns status-im.ui.screens.desktop.main.styles
(:require [status-im.ui.components.colors :as colors]))

(def main-views
{:flex 1
:flex-direction :row})

(def left-sidebar
{:width 340
:background-color colors/white})

(def pane-separator
{:width 1
:background-color colors/gray-light})
Loading

0 comments on commit 179cc96

Please sign in to comment.