diff --git a/src/status_im/subs.cljs b/src/status_im/subs.cljs index 2bbca38ba0..229bb29c7a 100644 --- a/src/status_im/subs.cljs +++ b/src/status_im/subs.cljs @@ -969,16 +969,11 @@ (re-frame/reg-sub :home-items - :<- [:chats/active-chats] :<- [:search/home-filter] :<- [:search/filtered-chats] - (fn [[chats search-filter filtered-chats]] - (if (or (nil? search-filter) - (and platform/desktop? (empty? search-filter))) - {:all-home-items - (sort-by #(-> % second :timestamp) > chats)} - {:search-filter search-filter - :chats filtered-chats}))) + (fn [[search-filter filtered-chats]] + {:search-filter search-filter + :chats filtered-chats})) ;;PAIRING ============================================================================================================== @@ -1802,12 +1797,38 @@ (sort-by-timestamp results) results))) +(defn filter-chat + [contacts search-filter {:keys [group-chat alias name chat-id]}] + (let [alias (if-not group-chat + (string/lower-case (or alias + (get-in contacts [chat-id :alias]) + (gfycat/generate-gfy chat-id))) + "")] + + (or + (string/includes? (string/lower-case (str name)) search-filter) + (string/includes? (string/lower-case alias) search-filter) + (and + (get-in contacts [chat-id :ens-verified]) + (string/includes? (string/lower-case + (str (get-in contacts [chat-id :name]))) + search-filter))))) (re-frame/reg-sub :search/filtered-chats :<- [:chats/active-chats] + :<- [::contacts] :<- [:search/home-filter] - (fn [[chats search-filter]] - (apply-filter search-filter chats extract-chat-attributes true))) + (fn [[chats contacts search-filter]] + ;; Short-circuit if search-filter is empty + (let [filtered-chats (if (seq search-filter) + (filter + (partial filter-chat + contacts + (string/lower-case search-filter)) + (vals chats)) + (vals chats))] + + (sort-by :timestamp > filtered-chats)))) (defn extract-currency-attributes [currency] (let [{:keys [code display-name]} (val currency)] diff --git a/src/status_im/ui/screens/home/views.cljs b/src/status_im/ui/screens/home/views.cljs index 28fc9f98af..266fc8178c 100644 --- a/src/status_im/ui/screens/home/views.cljs +++ b/src/status_im/ui/screens/home/views.cljs @@ -99,24 +99,26 @@ (views/defview chats-list [] (views/letsubs [loading? [:chats/loading?] - {:keys [chats all-home-items search-filter]} [:home-items] + {:keys [chats search-filter]} [:home-items] {:keys [hide-home-tooltip?]} [:multiaccount]] (if loading? [react/view {:flex 1 :align-items :center :justify-content :center} [react/activity-indicator {:animating true}]] - (if (and (empty? all-home-items) hide-home-tooltip? (not @search-active?)) + (if (and (empty? chats) + (empty? search-filter) + hide-home-tooltip? + (not @search-active?)) [welcome-blank-page] - (let [data (if @search-active? chats all-home-items)] - [list/flat-list - {:key-fn first - :keyboard-should-persist-taps :always - :data data - :render-fn inner-item/home-list-item - :header (when (or (not-empty data) @search-active?) - [search-input-wrapper search-filter]) - :footer (if (and (not hide-home-tooltip?) (not @search-active?)) - [home-tooltip-view] - [react/view {:height 68}])}]))))) + [list/flat-list + {:key-fn :chat-id + :keyboard-should-persist-taps :always + :data chats + :render-fn inner-item/home-list-item + :header (when (or (seq chats) @search-active?) + [search-input-wrapper search-filter]) + :footer (if (and (not hide-home-tooltip?) (not @search-active?)) + [home-tooltip-view] + [react/view {:height 68}])}])))) (views/defview plus-button [] (views/letsubs [logging-in? [:multiaccounts/login]] diff --git a/src/status_im/ui/screens/home/views/inner_item.cljs b/src/status_im/ui/screens/home/views/inner_item.cljs index 9483e72921..1a77c14f0f 100644 --- a/src/status_im/ui/screens/home/views/inner_item.cljs +++ b/src/status_im/ui/screens/home/views/inner_item.cljs @@ -106,7 +106,7 @@ :accessibility-label :unviewed-messages-public}] [badge/message-counter unviewed-messages-count]))) -(defn home-list-item [[_ home-item]] +(defn home-list-item [home-item] (let [{:keys [chat-id chat-name color online group-chat public? timestamp last-message]} home-item