From 5f119c4b3ae0cd96a22894104b627c536d40fdb1 Mon Sep 17 00:00:00 2001 From: Volodymyr Kozieiev Date: Fri, 3 Feb 2023 18:24:09 +0000 Subject: [PATCH] added unread mentions counter --- src/status_im2/subs/communities.cljs | 11 ++++--- src/status_im2/subs/communities_test.cljs | 35 ++++++++++++++--------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/status_im2/subs/communities.cljs b/src/status_im2/subs/communities.cljs index fdf069b2b3..626bd22cc4 100644 --- a/src/status_im2/subs/communities.cljs +++ b/src/status_im2/subs/communities.cljs @@ -224,16 +224,19 @@ (fn [[{:keys [joined categories chats]} full-chats-data] [_ community-id]] (reduce (fn [acc [_ {:keys [name categoryID id emoji can-post?]}]] - (let [category (keyword (get-in categories - [categoryID :name] - (i18n/label :t/none))) - {:keys [unviewed-messages-count]} (get full-chats-data (str community-id id))] + (let [category (keyword + (get-in categories + [categoryID :name] + (i18n/label :t/none))) + {:keys [unviewed-messages-count unviewed-mentions-count]} (get full-chats-data + (str community-id id))] (update acc category #(vec (conj %1 %2)) {:name name :emoji emoji :unread-messages? (pos? unviewed-messages-count) + :mentions-count (or unviewed-mentions-count 0) :locked? (or (not joined) (not can-post?)) :id id}))) {} diff --git a/src/status_im2/subs/communities_test.cljs b/src/status_im2/subs/communities_test.cljs index df6c714ce0..c6c81f0907 100644 --- a/src/status_im2/subs/communities_test.cljs +++ b/src/status_im2/subs/communities_test.cljs @@ -150,10 +150,13 @@ :categories {1 {:id 1 :name "category1"} 2 {:id 2 :name "category2"}} :joined true}}) - (is (= {:category1 [{:name "chat1" :emoji nil :locked? false :id "0x1" :unread-messages? false} - {:name "chat2" :emoji nil :locked? true :id "0x2" :unread-messages? false}] - :category2 [{:name "chat3" :emoji nil :locked? false :id "0x3" :unread-messages? false}]} - (rf/sub [sub-name "0x1"])))) + (is + (= {:category1 + [{:name "chat1" :emoji nil :locked? false :id "0x1" :unread-messages? false :mentions-count 0} + {:name "chat2" :emoji nil :locked? true :id "0x2" :unread-messages? false :mentions-count 0}] + :category2 + [{:name "chat3" :emoji nil :locked? false :id "0x3" :unread-messages? false :mentions-count 0}]} + (rf/sub [sub-name "0x1"])))) (testing "Channels without categories" (swap! rf-db/app-db assoc :communities/enabled? true @@ -165,11 +168,13 @@ :categories {1 {:id 1 :name "category1"} 2 {:id 2 :name "category2"}} :joined true}}) - (is (= {:category1 [{:name "chat1" :emoji nil :locked? false :id "0x1" :unread-messages? false} - {:name "chat2" :emoji nil :locked? true :id "0x2" :unread-messages? false}] - (keyword (i18n/label :t/none)) - [{:name "chat3" :emoji nil :locked? false :id "0x3" :unread-messages? false}]} - (rf/sub [sub-name "0x1"])))) + (is + (= {:category1 + [{:name "chat1" :emoji nil :locked? false :id "0x1" :unread-messages? false :mentions-count 0} + {:name "chat2" :emoji nil :locked? true :id "0x2" :unread-messages? false :mentions-count 0}] + (keyword (i18n/label :t/none)) + [{:name "chat3" :emoji nil :locked? false :id "0x3" :unread-messages? false :mentions-count 0}]} + (rf/sub [sub-name "0x1"])))) (testing "Unread messages" (swap! rf-db/app-db assoc :communities/enabled? true @@ -180,8 +185,10 @@ :categories {1 {:id 1 :name "category1"}} :joined true}} :chats - {"0x10x1" {:unviewed-messages-count 1} - "0x10x2" {:unviewed-messages-count 0}}) - (is (= {:category1 [{:name "chat1" :emoji nil :locked? false :id "0x1" :unread-messages? true} - {:name "chat2" :emoji nil :locked? true :id "0x2" :unread-messages? false}]} - (rf/sub [sub-name "0x1"]))))) + {"0x10x1" {:unviewed-messages-count 1 :unviewed-mentions-count 2} + "0x10x2" {:unviewed-messages-count 0 :unviewed-mentions-count 0}}) + (is + (= {:category1 + [{:name "chat1" :emoji nil :locked? false :id "0x1" :unread-messages? true :mentions-count 2} + {:name "chat2" :emoji nil :locked? true :id "0x2" :unread-messages? false :mentions-count 0}]} + (rf/sub [sub-name "0x1"])))))