Skip to content

Commit

Permalink
Show replies on activity center
Browse files Browse the repository at this point in the history
  • Loading branch information
briansztamfater committed Jul 8, 2021
1 parent 5ff854c commit ccce06a
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 56 deletions.
Binary file added resources/images/icons/tiny_reply@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/icons/tiny_reply@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/status_im/constants.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,4 @@
(def ^:const activity-center-notification-type-one-to-one-chat 1)
(def ^:const activity-center-notification-type-private-group-chat 2)
(def ^:const activity-center-notification-type-mention 3)
(def ^:const activity-center-notification-type-reply 4)
12 changes: 10 additions & 2 deletions src/status_im/data_store/activities.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
clojure.set))

(defn rpc->type [{:keys [type name] :as chat}]
(println chat "fdsfjdsio")
(cond
(= constants/activity-center-notification-type-reply type)
(assoc chat
:chat-name name
:chat-type constants/private-group-chat-type)

(= constants/activity-center-notification-type-mention type)
(assoc chat
:chat-type constants/private-group-chat-type
Expand All @@ -28,9 +34,11 @@
(defn <-rpc [item]
(-> item
rpc->type
(clojure.set/rename-keys {:lastMessage :last-message
:chatId :chat-id})
(clojure.set/rename-keys {:lastMessage :last-message
:replyMessage :reply-message
:chatId :chat-id})
(assoc :color (rand-nth colors/chat-colors))
(update :last-message #(when % (messages/<-rpc %)))
(update :message #(when % (messages/<-rpc %)))
(update :reply-message #(when % (messages/<-rpc %)))
(dissoc :chatId)))
22 changes: 22 additions & 0 deletions src/status_im/ui/screens/notifications_center/styles.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
:font-size 15
:color (:text-01 @quo-colors/theme)})

(def notification-reply-text
{:line-height 20
:font-size 13
:color colors/text-gray})

(def mention-text
{:color colors/blue})

Expand Down Expand Up @@ -37,6 +42,20 @@
:padding-right 5
:flex-direction :row})

(def reply-message-container
{:height 22
:align-self :baseline
:align-items :center
:border-radius 11
:border-color colors/gray-transparent-40
:border-width 1
:margin-top 6
:margin-bottom 10
:margin-right 15
:padding-left 5
:padding-right 5
:flex-direction :row})

(defn notification-container [read]
{:min-height 64
:background-color (when-not read colors/blue-light)})
Expand All @@ -61,6 +80,9 @@
(def group-icon
{:margin-right 4})

(def reply-icon
{:margin-right 1})

(def community-info-container
{:flex-direction :row
:align-items :center})
117 changes: 66 additions & 51 deletions src/status_im/ui/screens/notifications_center/views/notification.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,23 @@

(def max-notification-length 160)
(def max-notification-lines 2)
(def max-reply-lines 1)

(defn add-parsed-to-message [acc {:keys [type destination literal children]}]
(defn add-parsed-to-message [acc style text-weight {:keys [type destination literal children]}]
(let [result (case type
"paragraph"
(reduce
(fn [{:keys [_ length] :as acc-paragraph} parsed-child]
(if (>= length max-notification-length)
(reduced acc-paragraph)
(add-parsed-to-message acc-paragraph parsed-child)))
{:components [quo/text]
(add-parsed-to-message acc-paragraph style text-weight parsed-child)))
{:components [quo/text {:style style
:weight text-weight}]
:length 0}
children)

"mention"
{:components [quo/text {:style styles/mention-text} [mention-element literal]]
{:components [quo/text {:style (merge style styles/mention-text)} [mention-element literal]]
:length 4} ;; we can't predict name length so take the smallest possible

"status-tag"
Expand All @@ -47,35 +49,35 @@
:length (+ (:length acc) (:length result))}))

(defn message-wrapper
([] (message-wrapper 1))
([number-of-lines]
[react/text-class {:style styles/notification-message-text
:number-of-lines number-of-lines
:ellipsize-mode :tail
:accessibility-label :chat-message-text}]))

(defn render-notification-message
"Render the preview of a notification message to a maximum of max-length characters"
([parsed-text] (render-notification-message parsed-text max-notification-length 1))
([parsed-text max-length number-of-lines]
([] (message-wrapper 1 styles/notification-reply-text))
([number-of-lines style]
[react/text {:style style
:number-of-lines number-of-lines
:ellipsize-mode :tail
:accessibility-label :chat-message-text}]))

(defn render-message
"Render the preview of a message with a maximum length, maximum lines, style and font weight"
([parsed-text] (render-message parsed-text max-notification-length max-notification-lines styles/notification-message-text :regular))
([parsed-text max-length number-of-lines style text-weight]
(let [result
(reduce
(fn [{:keys [_ length] :as acc-text} new-text-chunk]
(if (>= length max-length)
(reduced acc-text)
(add-parsed-to-message acc-text new-text-chunk)))
{:components (message-wrapper number-of-lines)
(add-parsed-to-message acc-text style text-weight new-text-chunk)))
{:components (message-wrapper number-of-lines style)
:length 0}
parsed-text)]
(:components result))))

(defn message-content-text [{:keys [content content-type community-id]}]
(defn message-content-text [{:keys [content content-type community-id]} max-number-of-lines style text-weight]
[react/view
(cond

(not (and content content-type))
[react/text {:style (merge
styles/notification-message-text
style
{:color colors/gray})
:accessibility-label :no-messages-text}
(i18n/label :t/no-messages)]
Expand All @@ -86,31 +88,31 @@
:source {:uri (contenthash/url (-> content :sticker :hash))}}]

(= constants/content-type-image content-type)
[react/text {:style styles/notification-message-text
[react/text {:style style
:accessibility-label :no-messages-text}
(i18n/label :t/image)]

(= constants/content-type-audio content-type)
[react/text {:style styles/notification-message-text
[react/text {:style style
:accessibility-label :no-messages-text}
(i18n/label :t/audio)]

(= constants/content-type-community content-type)
(let [{:keys [name]}
@(re-frame/subscribe [:communities/community community-id])]
[react/text {:style styles/notification-message-text
[react/text {:style style
:accessibility-label :no-messages-text}
(i18n/label :t/community-message-preview {:community-name name})])

(string/blank? (:text content))
[react/text {:style styles/notification-message-text}
[react/text {:style style}
""]

(:text content)
(render-notification-message (:parsed-text content) max-notification-length max-notification-lines))])
(render-message (:parsed-text content) max-notification-length max-number-of-lines style text-weight))])

(defn activity-text-item [home-item opts]
(let [{:keys [chat-id chat-name message last-message muted read group-chat timestamp type]} home-item
(let [{:keys [chat-id chat-name message last-message reply-message muted read group-chat timestamp type]} home-item
message (or message last-message)
{:keys [community-id]} (<sub [:chat-by-id chat-id])
{:keys [name]} @(re-frame/subscribe [:communities/community community-id])
Expand All @@ -129,7 +131,9 @@
:ellipsize-mode :tail
:number-of-lines 1
:style styles/title-text}
(if (= type constants/activity-center-notification-type-mention)
(if (or
(= type constants/activity-center-notification-type-mention)
(= type constants/activity-center-notification-type-reply))
sender
[home-item/chat-item-title chat-id muted group-chat chat-name])]
[react/text {:style styles/datetime-text
Expand All @@ -138,28 +142,39 @@
;;TODO (perf) move to event
(home-item/memo-timestamp timestamp)]
[react/view {:style styles/notification-message-container}
[message-content-text (select-keys message [:content :content-type :community-id])]
(when (= type constants/activity-center-notification-type-mention)
[react/view {:style styles/group-info-container
:accessibility-label :chat-name-container}
[icons/icon
(if community-id :main-icons/tiny-community :main-icons/tiny-group)
{:color colors/gray
:width 16
:height 16
:container-style styles/group-icon}]
(when community-id
[react/view {:style styles/community-info-container}
[quo/text {:color :secondary
:weight :medium
:size :small}
name]
[icons/icon
:main-icons/chevron-down
{:color colors/gray
:width 16
:height 22}]])
[quo/text {:color :secondary
:weight :medium
:size :small}
(str (when community-id "#") chat-name)]])]]]))
[message-content-text (select-keys message [:content :content-type :community-id]) max-notification-lines styles/notification-message-text]
(cond (= type constants/activity-center-notification-type-mention)
[react/view {:style styles/group-info-container
:accessibility-label :chat-name-container}
[icons/icon
(if community-id :main-icons/tiny-community :main-icons/tiny-group)
{:color colors/gray
:width 16
:height 16
:container-style styles/group-icon}]
(when community-id
[react/view {:style styles/community-info-container}
[quo/text {:color :secondary
:weight :medium
:size :small}
name]
[icons/icon
:main-icons/chevron-down
{:color colors/gray
:width 16
:height 22}]])
[quo/text {:color :secondary
:weight :medium
:size :small}
(str (when community-id "#") chat-name)]]

(= type constants/activity-center-notification-type-reply)
[react/view {:style styles/reply-message-container
:accessibility-label :reply-message-container}
[icons/icon
:main-icons/tiny-reply
{:color colors/gray
:width 18
:height 18
:container-style styles/reply-icon}]
[message-content-text (select-keys reply-message [:content :content-type :community-id]) max-reply-lines styles/notification-reply-text :medium]])]]]))
6 changes: 3 additions & 3 deletions status-go-version.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
"owner": "status-im",
"repo": "status-go",
"version": "v0.81.0",
"commit-sha1": "58e39adf0389da0f222b91b0f20a3aa2b3b14f94",
"src-sha256": "1wh2vv216jjpk9a229m0kqkxw1bwihfkwlvc96015bm3v9a2ffhn"
"version": "feat/add-reply-message-notification",
"commit-sha1": "dc04bb5ffe54003437be0c8a4be121bc6a8f1af8",
"src-sha256": "1akkzg48fnh4wpsh6zx02qf1bx3bbm52cnhdv9g1ggilmj62yq56"
}

0 comments on commit ccce06a

Please sign in to comment.