From e0313ef9c62523e6c5054128897294873c59fdf9 Mon Sep 17 00:00:00 2001 From: Alexander Pantyukhov Date: Mon, 21 Nov 2016 23:48:42 +0300 Subject: [PATCH] Aliases in discovery (#477) --- src/status_im/discovery/screen.cljs | 21 ++++++++++++------- src/status_im/discovery/search_results.cljs | 6 ++++-- .../discovery/views/discovery_list_item.cljs | 13 ++++++++++-- .../discovery/views/popular_list.cljs | 6 ++++-- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/status_im/discovery/screen.cljs b/src/status_im/discovery/screen.cljs index 35b3319300..c0be799897 100644 --- a/src/status_im/discovery/screen.cljs +++ b/src/status_im/discovery/screen.cljs @@ -61,7 +61,7 @@ :font :medium} (label label-kw)]]) -(defview discovery-popular [{:keys [contacts]}] +(defview discovery-popular [{:keys [contacts current-account]}] [popular-tags [:get-popular-tags 10]] [view st/popular-container [title :t/popular-tags false] @@ -70,31 +70,36 @@ :gap 0 :sneak (if (> (count popular-tags) 1) 16 8)} (for [{:keys [name]} popular-tags] - [discovery-popular-list {:tag name - :contacts contacts}])] + [discovery-popular-list {:tag name + :contacts contacts + :current-account current-account}])] [text (label :t/none)])]) -(defview discovery-recent [{:keys [contacts]}] +(defview discovery-recent [{:keys [current-account]}] [discoveries [:get-recent-discoveries]] (when (seq discoveries) [view st/recent-container [title :t/recent true] [view st/recent-list (let [discoveries (map-indexed vector discoveries)] - (for [[i {:keys [message-id] :as discovery}] discoveries] + (for [[i {:keys [message-id] :as message}] discoveries] ^{:key (str "message-" message-id)} - [discovery-list-item discovery (not= (inc i) (count discoveries))]))]])) + [discovery-list-item {:message message + :show-separator? (not= (inc i) (count discoveries)) + :current-account current-account}]))]])) (defview discovery [] [show-search? [:get ::show-search?] contacts [:get :contacts] + current-account [:get-current-account] discoveries [:get-recent-discoveries]] [view st/discovery-container [discovery-toolbar show-search?] (if discoveries [scroll-view st/scroll-view-container - [discovery-popular {:contacts contacts}] - [discovery-recent {:contacts contacts}]] + [discovery-popular {:contacts contacts + :current-account current-account}] + [discovery-recent {:current-account current-account}]] [view contacts-styles/empty-contact-groups ;; todo change icon [icon :group_big contacts-styles/empty-contacts-icon] diff --git a/src/status_im/discovery/search_results.cljs b/src/status_im/discovery/search_results.cljs index 90b10e562a..45df478ba2 100644 --- a/src/status_im/discovery/search_results.cljs +++ b/src/status_im/discovery/search_results.cljs @@ -37,7 +37,8 @@ (defview discovery-search-results [] [discoveries [:get-popular-discoveries 250] - tags [:get :discovery-search-tags]] + tags [:get :discovery-search-tags] + current-account [:get-current-account]] (let [discoveries (:discoveries discoveries) datasource (to-datasource discoveries)] [view st/discovery-tag-container @@ -55,6 +56,7 @@ (label :t/no-statuses-found)]] [list-view {:dataSource datasource :renderRow (fn [row _ _] - (list-item [discovery-list-item row])) + (list-item [discovery-list-item {:message row + :current-account current-account}])) :renderSeparator render-separator :style st/recent-list}])])) diff --git a/src/status_im/discovery/views/discovery_list_item.cljs b/src/status_im/discovery/views/discovery_list_item.cljs index 71e8c9baab..f55ec28d6c 100644 --- a/src/status_im/discovery/views/discovery_list_item.cljs +++ b/src/status_im/discovery/views/discovery_list_item.cljs @@ -26,8 +26,15 @@ ^{:key (str "item-" message-id "-" i)} (str status " ")))]) -(defview discovery-list-item [{:keys [name photo-path whisper-id] :as message} - show-separator?] +(defview discovery-list-item [{{:keys [name + photo-path + whisper-id] + :as message} :message + show-separator? :show-separator? + {account-photo-path :photo-path + account-address :public-key + account-name :name + :as current-account} :current-account}] [{contact-name :name contact-photo-path :photo-path} [:get-in [:contacts whisper-id]]] (let [item-style (get-in platform-specific [:component-styles :discovery :item])] @@ -38,6 +45,7 @@ :font :medium :number-of-lines 1} (cond + (= account-address whisper-id) account-name (not (str/blank? contact-name)) contact-name (not (str/blank? name)) name :else (generate-gfy))] @@ -47,6 +55,7 @@ [touchable-highlight {:on-press #(dispatch [:start-chat whisper-id])} [view [ci/chat-icon (cond + (= account-address whisper-id) account-photo-path (not (str/blank? contact-photo-path)) contact-photo-path (not (str/blank? photo-path)) photo-path :else (identicon whisper-id)) diff --git a/src/status_im/discovery/views/popular_list.cljs b/src/status_im/discovery/views/popular_list.cljs index 8e2c6e1691..72fd268386 100644 --- a/src/status_im/discovery/views/popular_list.cljs +++ b/src/status_im/discovery/views/popular_list.cljs @@ -12,7 +12,7 @@ [status-im.discovery.views.discovery-list-item :refer [discovery-list-item]] [status-im.utils.platform :refer [platform-specific]])) -(defview discovery-popular-list [{:keys [tag contacts]}] +(defview discovery-popular-list [{:keys [tag contacts current-account]}] [discoveries [:get-popular-discoveries 3 [tag]]] [view (merge st/popular-list-container (get-in platform-specific [:component-styles :discovery :popular])) @@ -31,4 +31,6 @@ (let [discoveries (map-indexed vector (:discoveries discoveries))] (for [[i {:keys [message-id] :as discovery}] discoveries] ^{:key (str "message-" message-id)} - [discovery-list-item discovery (not= (inc i) (count discoveries))]))]) + [discovery-list-item {:message discovery + :show-separator? (not= (inc i) (count discoveries)) + :current-account current-account}]))])