added unread mentions counter

This commit is contained in:
Volodymyr Kozieiev 2023-02-03 18:24:09 +00:00
parent bf932e6825
commit 5f119c4b3a
No known key found for this signature in database
GPG Key ID: 82B04968DF4C0535
2 changed files with 28 additions and 18 deletions

View File

@ -224,16 +224,19 @@
(fn [[{:keys [joined categories chats]} full-chats-data] [_ community-id]] (fn [[{:keys [joined categories chats]} full-chats-data] [_ community-id]]
(reduce (reduce
(fn [acc [_ {:keys [name categoryID id emoji can-post?]}]] (fn [acc [_ {:keys [name categoryID id emoji can-post?]}]]
(let [category (keyword (get-in categories (let [category (keyword
[categoryID :name] (get-in categories
(i18n/label :t/none))) [categoryID :name]
{:keys [unviewed-messages-count]} (get full-chats-data (str community-id id))] (i18n/label :t/none)))
{:keys [unviewed-messages-count unviewed-mentions-count]} (get full-chats-data
(str community-id id))]
(update acc (update acc
category category
#(vec (conj %1 %2)) #(vec (conj %1 %2))
{:name name {:name name
:emoji emoji :emoji emoji
:unread-messages? (pos? unviewed-messages-count) :unread-messages? (pos? unviewed-messages-count)
:mentions-count (or unviewed-mentions-count 0)
:locked? (or (not joined) (not can-post?)) :locked? (or (not joined) (not can-post?))
:id id}))) :id id})))
{} {}

View File

@ -150,10 +150,13 @@
:categories {1 {:id 1 :name "category1"} :categories {1 {:id 1 :name "category1"}
2 {:id 2 :name "category2"}} 2 {:id 2 :name "category2"}}
:joined true}}) :joined true}})
(is (= {:category1 [{:name "chat1" :emoji nil :locked? false :id "0x1" :unread-messages? false} (is
{:name "chat2" :emoji nil :locked? true :id "0x2" :unread-messages? false}] (= {:category1
:category2 [{:name "chat3" :emoji nil :locked? false :id "0x3" :unread-messages? false}]} [{:name "chat1" :emoji nil :locked? false :id "0x1" :unread-messages? false :mentions-count 0}
(rf/sub [sub-name "0x1"])))) {: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" (testing "Channels without categories"
(swap! rf-db/app-db assoc (swap! rf-db/app-db assoc
:communities/enabled? true :communities/enabled? true
@ -165,11 +168,13 @@
:categories {1 {:id 1 :name "category1"} :categories {1 {:id 1 :name "category1"}
2 {:id 2 :name "category2"}} 2 {:id 2 :name "category2"}}
:joined true}}) :joined true}})
(is (= {:category1 [{:name "chat1" :emoji nil :locked? false :id "0x1" :unread-messages? false} (is
{:name "chat2" :emoji nil :locked? true :id "0x2" :unread-messages? false}] (= {:category1
(keyword (i18n/label :t/none)) [{:name "chat1" :emoji nil :locked? false :id "0x1" :unread-messages? false :mentions-count 0}
[{:name "chat3" :emoji nil :locked? false :id "0x3" :unread-messages? false}]} {:name "chat2" :emoji nil :locked? true :id "0x2" :unread-messages? false :mentions-count 0}]
(rf/sub [sub-name "0x1"])))) (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" (testing "Unread messages"
(swap! rf-db/app-db assoc (swap! rf-db/app-db assoc
:communities/enabled? true :communities/enabled? true
@ -180,8 +185,10 @@
:categories {1 {:id 1 :name "category1"}} :categories {1 {:id 1 :name "category1"}}
:joined true}} :joined true}}
:chats :chats
{"0x10x1" {:unviewed-messages-count 1} {"0x10x1" {:unviewed-messages-count 1 :unviewed-mentions-count 2}
"0x10x2" {:unviewed-messages-count 0}}) "0x10x2" {:unviewed-messages-count 0 :unviewed-mentions-count 0}})
(is (= {:category1 [{:name "chat1" :emoji nil :locked? false :id "0x1" :unread-messages? true} (is
{:name "chat2" :emoji nil :locked? true :id "0x2" :unread-messages? false}]} (= {:category1
(rf/sub [sub-name "0x1"]))))) [{: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"])))))