Skip to content

Commit

Permalink
fix unread badges behavior on Jump-to screen (#17363)
Browse files Browse the repository at this point in the history
  • Loading branch information
Parveshdhull authored Sep 21, 2023
1 parent e5ef15b commit db41eb3
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@
:position :absolute})

(defn unread-dot
[background-color]
[customization-color]
{:width 8
:height 8
:border-radius 4
:background-color background-color})
:background-color (colors/custom-color customization-color 60)})

(def bottom-container
{:position :absolute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@
nil))])

(defn notification-container
[{:keys [notification-indicator counter-label customization-color]}]
[{:keys [notification-indicator counter-label profile-customization-color]}]
[rn/view {:style style/notification-container}
(if (= notification-indicator :counter)
[quo/counter
{:customization-color customization-color}
{:customization-color profile-customization-color}
counter-label]
[rn/view {:style (style/unread-dot customization-color)}])])
[rn/view {:style (style/unread-dot profile-customization-color)}])])

(defn bottom-container
[type {:keys [new-notifications?] :as content}]
Expand Down Expand Up @@ -225,7 +225,7 @@
[]
(let [card-ref (atom nil)]
(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)]
[rn/touchable-opacity
{:on-press #(calculate-card-position-and-open-screen
Expand Down Expand Up @@ -255,8 +255,9 @@
:style style/subtitle}
(subtitle type content)]
[bottom-container type
(merge {:color-50 color-50
:customization-color customization-color}
(merge {:color-50 color-50
:customization-color customization-color
:profile-customization-color profile-customization-color}
content)]]
(when avatar-params
[rn/view {:style style/avatar-container}
Expand Down
119 changes: 70 additions & 49 deletions src/status_im2/subs/shell.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
(first images)))})))

(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}
(: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
(when last-message
(cond
Expand Down Expand Up @@ -72,54 +74,67 @@
content-type)
{:content-type constants/content-type-contact-request}))

{:new-notifications? (pos? (:unviewed-messages-count chat))
:notification-indicator (if (pos? (:unviewed-mentions-count chat))
{:new-notifications? (pos? unviewed-messages-count)
:notification-indicator (if (or
(= (:chat-type chat) constants/one-to-one-chat-type)
(pos? unviewed-mentions-count))
:counter
: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
[contact names profile-picture chat id communities]
[contact names profile-picture chat id communities profile-customization-color]
(let [display-name (first names)]
{:title display-name
:avatar-params {:full-name display-name
:profile-picture profile-picture}
:customization-color (or (:customization-color contact) :primary)
:content (get-card-content
{:chat chat
:communities communities})
:id id}))
{:title display-name
:avatar-params {:full-name display-name
:profile-picture profile-picture}
:customization-color (or (:customization-color contact) :primary)
:content (get-card-content
{:chat chat
:communities communities})
:id id
:profile-customization-color profile-customization-color}))

(defn private-group-chat-card
[chat id communities primary-name]
{:title (:chat-name chat)
:avatar-params {}
:customization-color (or (:color chat) :primary)
:content (get-card-content
{:chat chat
:communities communities
:group-chat? true
:primary-name primary-name})
:id id})
[chat id communities primary-name profile-customization-color]
{:title (:chat-name chat)
:avatar-params {}
:customization-color (or (:color chat) :primary)
:content (get-card-content
{:chat chat
:communities communities
:group-chat? true
:primary-name primary-name})
:id id
:profile-customization-color profile-customization-color})

(defn community-card
[community id]
[community id profile-customization-color]
(let [profile-picture (community-avatar community)]
{:title (:name community)
:banner {:uri (get-in (:images community) [:banner :uri])}
:avatar-params (if profile-picture
{:source profile-picture}
{:name (:name community)})
:customization-color (or (:color community) :primary)
:content {:community-info {:type :permission}}
:id id}))
{:title (:name community)
:banner {:uri (get-in (:images community) [:banner :uri])}
:avatar-params (if profile-picture
{:source profile-picture}
{:name (:name community)})
:customization-color (or (:color community) :primary)
:content (merge
{: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
[community community-id channel channel-id]
[community community-id channel channel-id profile-customization-color]
(merge
(community-card community community-id)
{:content {:community-channel {:emoji (:emoji channel)
:channel-name (str "# " (:name channel))}}
(community-card community community-id profile-customization-color)
{:content (merge
{:community-channel {:emoji (:emoji channel)
:channel-name (str "# " (:name channel))}}
(get-card-content {:chat channel}))
:customization-color (or (:color channel) :primary)
:channel-id channel-id}))

Expand Down Expand Up @@ -151,48 +166,54 @@
(re-frame/subscribe [:contacts/contact-two-names-by-identity id])
(re-frame/subscribe [:chats/photo-path id])
(re-frame/subscribe [:chats/chat id])
(re-frame/subscribe [:communities])])
(fn [[contact names profile-picture chat communities] [_ id]]
(re-frame/subscribe [:communities])
(re-frame/subscribe [:profile/customization-color])])
(fn [[contact names profile-picture chat communities profile-customization-color] [_ id]]
(one-to-one-chat-card contact
names
profile-picture
chat
id
communities)))
communities
profile-customization-color)))

(re-frame/reg-sub
:shell/private-group-chat-card
(fn [[_ id] _]
[(re-frame/subscribe [:chats/chat id])
(re-frame/subscribe [:communities])
(re-frame/subscribe [:contacts/contacts])
(re-frame/subscribe [:profile/profile])])
(fn [[chat communities contacts current-multiaccount] [_ id]]
(re-frame/subscribe [:profile/profile])
(re-frame/subscribe [:profile/customization-color])])
(fn [[chat communities contacts current-multiaccount profile-customization-color] [_ id]]
(let [from (get-in chat [:last-message :from])
contact (when from (multiaccounts/contact-by-identity contacts from))
primary-name (when from
(first (multiaccounts/contact-two-names-by-identity
contact
current-multiaccount
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
:shell/community-card
(fn [[_ id] _]
[(re-frame/subscribe [:communities/community id])])
(fn [[community] [_ id]]
(community-card community id)))
[(re-frame/subscribe [:communities/community id])
(re-frame/subscribe [:communities/unviewed-counts 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
:shell/community-channel-card
(fn [[_ channel-id] _]
[(re-frame/subscribe [:chats/chat channel-id])
(re-frame/subscribe [:communities])])
(fn [[channel communities] [_ channel-id]]
(re-frame/subscribe [:communities])
(re-frame/subscribe [:profile/customization-color])])
(fn [[channel communities profile-customization-color] [_ channel-id]]
(let [community-id (: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
(re-frame/reg-sub
Expand Down

0 comments on commit db41eb3

Please sign in to comment.