feat(Activity Center): Add support for preview images in chat mentions (#21150)

* fix `clojure.core/type` shadowed

* Remove comment about rn/delay-render
This commit is contained in:
Ulises Manuel 2024-09-04 12:25:14 -06:00 committed by GitHub
parent d5238ac82f
commit 74469c2b61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 55 additions and 36 deletions

View File

@ -9,25 +9,45 @@
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
(defn- mention-text
[literal]
(let [mention (rf/sub [:messages/resolve-mention literal])]
[quo/text
{:style style/mention-text
:size :paragraph-1}
(str "@" mention)]))
(defn- parsed-text->hiccup
[{:keys [literal destination] message-type :type}]
(case message-type
"mention" [mention-text literal]
"link" destination
literal))
(defn- message-body
[message]
(let [parsed-text (get-in message [:content :parsed-text])
parsed-text-children (:children (first parsed-text))]
(into [quo/text
{:number-of-lines 1
:style style/tag-text
:accessibility-label :activity-message-body
:size :paragraph-1}]
(map-indexed (fn [index {:keys [type literal destination]}]
^{:key index}
(case type
"mention" [quo/text
{:style style/mention-text
:size :paragraph-1}
(str "@" (rf/sub [:messages/resolve-mention literal]))]
"link" destination
literal))
parsed-text-children))))
[{:keys [container parsed-text]}]
(into container (map parsed-text->hiccup) parsed-text))
(defn- simple-message
[content]
(let [parsed-text (get-in content [:content :parsed-text 0 :children])]
[message-body
{:container [quo/text
{:number-of-lines 1
:style style/tag-text
:accessibility-label :activity-message-body
:size :paragraph-1}]
:parsed-text parsed-text}]))
(defn- album-message
[content]
(let [parsed-text (get-in content [0 :parsedText 0 :children])
images (map :image content)]
[quo/activity-logs-photos
{:photos images
:message-text [message-body
{:container [:<>]
:parsed-text parsed-text}]}]))
(defn- swipeable
[{:keys [extra-fn]} child]
@ -41,12 +61,12 @@
(defn view
[{:keys [notification extra-fn]}]
(let [{:keys [author chat-name community-id chat-id
message read timestamp]} notification
community-chat? (not (string/blank? community-id))
community-name (rf/sub [:communities/name community-id])
community-logo (rf/sub [:communities/logo community-id])
customization-color (rf/sub [:profile/customization-color])]
(let [{:keys [author chat-name community-id chat-id message read timestamp
album-messages]} notification
community-chat? (not (string/blank? community-id))
community-name (rf/sub [:communities/name community-id])
community-logo (rf/sub [:communities/logo community-id])
customization-color (rf/sub [:profile/customization-color])]
[swipeable {:extra-fn extra-fn}
[gesture/touchable-without-feedback
{:on-press (fn []
@ -74,4 +94,6 @@
:group-name chat-name
:blur? true
:size 24}])]
:message {:body (message-body message)}}]]]))
:message {:body (if album-messages
[album-message album-messages]
[simple-message message])}}]]]))

View File

@ -24,35 +24,32 @@
[utils.re-frame :as rf]))
(defn notification-component
[{:keys [type] :as notification} index]
[{notification-type :type :as notification} index]
(let [extra-fn (rn/use-callback
(fn []
{:notification notification})
[notification])
props {:notification notification
:extra-fn extra-fn}]
;; Notifications are expensive to render. Without `delay-render` the opening
;; animation of the Activity Center can be clunky and the time to open the
;; AC after pressing the bell icon can be high.
[rn/view {:style (style/notification-container index)}
(cond
(= type types/contact-verification)
(= notification-type types/contact-verification)
[contact-verification/view props]
(= type types/contact-request)
(= notification-type types/contact-request)
[contact-requests/view props]
(= type types/mention)
(= notification-type types/mention)
[mentions/view props]
(= type types/reply)
(= notification-type types/reply)
[reply/view props]
(= type types/admin)
(= notification-type types/admin)
[admin/view props]
(some types/membership [type])
(condp = type
(types/membership notification-type)
(condp = notification-type
types/private-group-chat [membership/view props]
types/community-request [community-request/view props]
types/community-kicked [community-kicked/view props]