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]]
(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})))
{}

View File

@ -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"])))))