fix unread badges behavior on Jump-to screen (#17363)

This commit is contained in:
Parvesh Monu 2023-09-21 17:53:38 +05:30 committed by GitHub
parent e5ef15b531
commit db41eb303d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 79 additions and 57 deletions

View File

@ -80,11 +80,11 @@
:position :absolute}) :position :absolute})
(defn unread-dot (defn unread-dot
[background-color] [customization-color]
{:width 8 {:width 8
:height 8 :height 8
:border-radius 4 :border-radius 4
:background-color background-color}) :background-color (colors/custom-color customization-color 60)})
(def bottom-container (def bottom-container
{:position :absolute {:position :absolute

View File

@ -98,13 +98,13 @@
nil))]) nil))])
(defn notification-container (defn notification-container
[{:keys [notification-indicator counter-label customization-color]}] [{:keys [notification-indicator counter-label profile-customization-color]}]
[rn/view {:style style/notification-container} [rn/view {:style style/notification-container}
(if (= notification-indicator :counter) (if (= notification-indicator :counter)
[quo/counter [quo/counter
{:customization-color customization-color} {:customization-color profile-customization-color}
counter-label] counter-label]
[rn/view {:style (style/unread-dot customization-color)}])]) [rn/view {:style (style/unread-dot profile-customization-color)}])])
(defn bottom-container (defn bottom-container
[type {:keys [new-notifications?] :as content}] [type {:keys [new-notifications?] :as content}]
@ -225,7 +225,7 @@
[] []
(let [card-ref (atom nil)] (let [card-ref (atom nil)]
(fn [{:keys [avatar-params title type customization-color (fn [{:keys [avatar-params title type customization-color
content banner id channel-id]}] content banner id channel-id profile-customization-color]}]
(let [color-50 (colors/custom-color customization-color 50)] (let [color-50 (colors/custom-color customization-color 50)]
[rn/touchable-opacity [rn/touchable-opacity
{:on-press #(calculate-card-position-and-open-screen {:on-press #(calculate-card-position-and-open-screen
@ -255,8 +255,9 @@
:style style/subtitle} :style style/subtitle}
(subtitle type content)] (subtitle type content)]
[bottom-container type [bottom-container type
(merge {:color-50 color-50 (merge {:color-50 color-50
:customization-color customization-color} :customization-color customization-color
:profile-customization-color profile-customization-color}
content)]] content)]]
(when avatar-params (when avatar-params
[rn/view {:style style/avatar-container} [rn/view {:style style/avatar-container}

View File

@ -18,9 +18,11 @@
(first images)))}))) (first images)))})))
(defn get-card-content (defn get-card-content
[{:keys [chat communities group-chat? primary-name]}] [{:keys [chat communities group-chat? primary-name unviewed-messages-count unviewed-mentions-count]}]
(let [{:keys [content-type content deleted? outgoing deleted-for-me?] :as last-message} (let [{:keys [content-type content deleted? outgoing deleted-for-me?] :as last-message}
(:last-message chat)] (:last-message chat)
unviewed-messages-count (or unviewed-messages-count (:unviewed-messages-count chat))
unviewed-mentions-count (or unviewed-mentions-count (:unviewed-mentions-count chat))]
(merge (merge
(when last-message (when last-message
(cond (cond
@ -72,54 +74,67 @@
content-type) content-type)
{:content-type constants/content-type-contact-request})) {:content-type constants/content-type-contact-request}))
{:new-notifications? (pos? (:unviewed-messages-count chat)) {:new-notifications? (pos? unviewed-messages-count)
:notification-indicator (if (pos? (:unviewed-mentions-count chat)) :notification-indicator (if (or
(= (:chat-type chat) constants/one-to-one-chat-type)
(pos? unviewed-mentions-count))
:counter :counter
:unread-dot) :unread-dot)
:counter-label (:unviewed-mentions-count chat)}))) :counter-label (if (= (:chat-type chat) constants/one-to-one-chat-type)
unviewed-messages-count
unviewed-mentions-count)})))
(defn one-to-one-chat-card (defn one-to-one-chat-card
[contact names profile-picture chat id communities] [contact names profile-picture chat id communities profile-customization-color]
(let [display-name (first names)] (let [display-name (first names)]
{:title display-name {:title display-name
:avatar-params {:full-name display-name :avatar-params {:full-name display-name
:profile-picture profile-picture} :profile-picture profile-picture}
:customization-color (or (:customization-color contact) :primary) :customization-color (or (:customization-color contact) :primary)
:content (get-card-content :content (get-card-content
{:chat chat {:chat chat
:communities communities}) :communities communities})
:id id})) :id id
:profile-customization-color profile-customization-color}))
(defn private-group-chat-card (defn private-group-chat-card
[chat id communities primary-name] [chat id communities primary-name profile-customization-color]
{:title (:chat-name chat) {:title (:chat-name chat)
:avatar-params {} :avatar-params {}
:customization-color (or (:color chat) :primary) :customization-color (or (:color chat) :primary)
:content (get-card-content :content (get-card-content
{:chat chat {:chat chat
:communities communities :communities communities
:group-chat? true :group-chat? true
:primary-name primary-name}) :primary-name primary-name})
:id id}) :id id
:profile-customization-color profile-customization-color})
(defn community-card (defn community-card
[community id] [community id profile-customization-color]
(let [profile-picture (community-avatar community)] (let [profile-picture (community-avatar community)]
{:title (:name community) {:title (:name community)
:banner {:uri (get-in (:images community) [:banner :uri])} :banner {:uri (get-in (:images community) [:banner :uri])}
:avatar-params (if profile-picture :avatar-params (if profile-picture
{:source profile-picture} {:source profile-picture}
{:name (:name community)}) {:name (:name community)})
:customization-color (or (:color community) :primary) :customization-color (or (:color community) :primary)
:content {:community-info {:type :permission}} :content (merge
:id id})) {:community-info {:type :permission}}
(get-card-content
{:unviewed-messages-count (:unviewed-messages-count community)
:unviewed-mentions-count (:unviewed-mentions-count community)}))
:id id
:profile-customization-color profile-customization-color}))
(defn community-channel-card (defn community-channel-card
[community community-id channel channel-id] [community community-id channel channel-id profile-customization-color]
(merge (merge
(community-card community community-id) (community-card community community-id profile-customization-color)
{:content {:community-channel {:emoji (:emoji channel) {:content (merge
:channel-name (str "# " (:name channel))}} {:community-channel {:emoji (:emoji channel)
:channel-name (str "# " (:name channel))}}
(get-card-content {:chat channel}))
:customization-color (or (:color channel) :primary) :customization-color (or (:color channel) :primary)
:channel-id channel-id})) :channel-id channel-id}))
@ -151,14 +166,16 @@
(re-frame/subscribe [:contacts/contact-two-names-by-identity id]) (re-frame/subscribe [:contacts/contact-two-names-by-identity id])
(re-frame/subscribe [:chats/photo-path id]) (re-frame/subscribe [:chats/photo-path id])
(re-frame/subscribe [:chats/chat id]) (re-frame/subscribe [:chats/chat id])
(re-frame/subscribe [:communities])]) (re-frame/subscribe [:communities])
(fn [[contact names profile-picture chat communities] [_ id]] (re-frame/subscribe [:profile/customization-color])])
(fn [[contact names profile-picture chat communities profile-customization-color] [_ id]]
(one-to-one-chat-card contact (one-to-one-chat-card contact
names names
profile-picture profile-picture
chat chat
id id
communities))) communities
profile-customization-color)))
(re-frame/reg-sub (re-frame/reg-sub
:shell/private-group-chat-card :shell/private-group-chat-card
@ -166,8 +183,9 @@
[(re-frame/subscribe [:chats/chat id]) [(re-frame/subscribe [:chats/chat id])
(re-frame/subscribe [:communities]) (re-frame/subscribe [:communities])
(re-frame/subscribe [:contacts/contacts]) (re-frame/subscribe [:contacts/contacts])
(re-frame/subscribe [:profile/profile])]) (re-frame/subscribe [:profile/profile])
(fn [[chat communities contacts current-multiaccount] [_ id]] (re-frame/subscribe [:profile/customization-color])])
(fn [[chat communities contacts current-multiaccount profile-customization-color] [_ id]]
(let [from (get-in chat [:last-message :from]) (let [from (get-in chat [:last-message :from])
contact (when from (multiaccounts/contact-by-identity contacts from)) contact (when from (multiaccounts/contact-by-identity contacts from))
primary-name (when from primary-name (when from
@ -175,24 +193,27 @@
contact contact
current-multiaccount current-multiaccount
from)))] from)))]
(private-group-chat-card chat id communities primary-name)))) (private-group-chat-card chat id communities primary-name profile-customization-color))))
(re-frame/reg-sub (re-frame/reg-sub
:shell/community-card :shell/community-card
(fn [[_ id] _] (fn [[_ id] _]
[(re-frame/subscribe [:communities/community id])]) [(re-frame/subscribe [:communities/community id])
(fn [[community] [_ id]] (re-frame/subscribe [:communities/unviewed-counts id])
(community-card community id))) (re-frame/subscribe [:profile/customization-color])])
(fn [[community unviewed-counts profile-customization-color] [_ id]]
(community-card (merge community unviewed-counts) id profile-customization-color)))
(re-frame/reg-sub (re-frame/reg-sub
:shell/community-channel-card :shell/community-channel-card
(fn [[_ channel-id] _] (fn [[_ channel-id] _]
[(re-frame/subscribe [:chats/chat channel-id]) [(re-frame/subscribe [:chats/chat channel-id])
(re-frame/subscribe [:communities])]) (re-frame/subscribe [:communities])
(fn [[channel communities] [_ channel-id]] (re-frame/subscribe [:profile/customization-color])])
(fn [[channel communities profile-customization-color] [_ channel-id]]
(let [community-id (:community-id channel) (let [community-id (:community-id channel)
community (get communities (:community-id channel))] community (get communities (:community-id channel))]
(community-channel-card community community-id channel channel-id)))) (community-channel-card community community-id channel channel-id profile-customization-color))))
;; Bottom tabs ;; Bottom tabs
(re-frame/reg-sub (re-frame/reg-sub