[15166] Show message edited status (#15190)

This commit is contained in:
Ibrahem Khalil 2023-03-08 12:42:12 +02:00 committed by GitHub
parent 5fe3029ad8
commit 7a299b9b86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 110 additions and 67 deletions

View File

@ -1,6 +1,5 @@
(ns status-im2.contexts.chat.messages.content.text.style (ns status-im2.contexts.chat.messages.content.text.style
(:require (:require [quo2.foundations.colors :as colors]))
[quo2.foundations.colors :as colors]))
(def block (def block
{:border-radius 6 {:border-radius 6

View File

@ -5,7 +5,8 @@
[react-native.core :as rn] [react-native.core :as rn]
[status-im2.contexts.chat.messages.content.text.style :as style] [status-im2.contexts.chat.messages.content.text.style :as style]
[status-im2.contexts.chat.messages.link-preview.view :as link-preview] [status-im2.contexts.chat.messages.link-preview.view :as link-preview]
[utils.re-frame :as rf])) [utils.re-frame :as rf]
[utils.i18n :as i18n]))
(defn render-inline (defn render-inline
@ -48,11 +49,22 @@
:style {:color (colors/theme-colors colors/primary-50 colors/primary-60)}} :style {:color (colors/theme-colors colors/primary-50 colors/primary-60)}}
(rf/sub [:messages/resolve-mention literal])]]) (rf/sub [:messages/resolve-mention literal])]])
:edited
(conj units
[quo/text
{:weight :medium
:style {:font-size 11 ; Font-size must be used instead of props or the
; styles will clash with original message text
:color (colors/theme-colors colors/neutral-40
colors/neutral-50)}}
literal])
(conj units literal))) (conj units literal)))
(defn render-block (defn render-block
[blocks {:keys [type ^js literal children]}] [blocks {:keys [type ^js literal children]} edited-at]
(case (keyword type) (case (keyword type)
:paragraph :paragraph
(conj blocks (conj blocks
@ -64,19 +76,46 @@
:blockquote :blockquote
(conj blocks (conj blocks
[rn/view {:style style/quote} [rn/view {:style style/quote}
[quo/text literal]]) [quo/text literal]]
(when edited-at
[quo/text
{:weight :medium
:style {:font-size 11
:margin-top 4
:color (colors/theme-colors colors/neutral-40 colors/neutral-50)}}
(str " (" (i18n/label :t/edited) ")")]))
:codeblock :codeblock
(conj blocks (conj blocks
[rn/view {:style (merge style/block (style/code))} [rn/view {:style (merge style/block (style/code))}
[quo/text (subs literal 0 (dec (count literal)))]]) [quo/text (subs literal 0 (dec (count literal)))]]
(when edited-at
[quo/text
{:weight :medium
:style {:font-size 11
:margin-top 4
:color (colors/theme-colors colors/neutral-40 colors/neutral-50)}}
(str " (" (i18n/label :t/edited) ")")]))
blocks)) blocks))
(defn add-edited-tag
[parsed-text]
(update parsed-text
(dec (count parsed-text))
(fn [last-literal]
(update last-literal
:children
conj
{:literal (str " (" (i18n/label :t/edited) ")")
:type :edited}))))
(defn render-parsed-text (defn render-parsed-text
[{:keys [content]}] [{:keys [content edited-at]}]
(reduce render-block (reduce (fn [acc e]
(render-block acc e edited-at))
[:<>] [:<>]
(:parsed-text content))) (cond-> (:parsed-text content)
edited-at add-edited-tag)))
(defn text-content (defn text-content
[message-data context] [message-data context]

View File

@ -84,11 +84,10 @@
context)}])) context)}]))
(defn user-message-content (defn user-message-content
[{:keys [content-type quoted-message content outgoing outgoing-status] :as message-data} []
{:keys [chat-id] :as context}]
[:f>
(let [show-delivery-state? (reagent/atom false)] (let [show-delivery-state? (reagent/atom false)]
(fn [] (fn [{:keys [content-type quoted-message content outgoing outgoing-status] :as message-data}
{:keys [chat-id] :as context}]
(let [first-image (first (:album message-data)) (let [first-image (first (:album message-data))
outgoing-status (if (= content-type constants/content-type-album) outgoing-status (if (= content-type constants/content-type-album)
(:outgoing-status first-image) (:outgoing-status first-image)
@ -107,7 +106,7 @@
:opacity (if (and outgoing (= outgoing-status :sending)) 0.5 1)} :opacity (if (and outgoing (= outgoing-status :sending)) 0.5 1)}
:on-press (fn [] :on-press (fn []
(when (and outgoing (when (and outgoing
(not (= outgoing-status :sending)) (not= outgoing-status :sending)
(not @show-delivery-state?)) (not @show-delivery-state?))
(reset! show-delivery-state? true) (reset! show-delivery-state? true)
(js/setTimeout #(reset! show-delivery-state? false) (js/setTimeout #(reset! show-delivery-state? false)
@ -145,7 +144,7 @@
[not-implemented/not-implemented [content.unknown/unknown-content message-data]]) [not-implemented/not-implemented [content.unknown/unknown-content message-data]])
(when @show-delivery-state? (when @show-delivery-state?
[status/status outgoing-status])]]]])))]) [status/status outgoing-status])]]]]))))
(defn message-with-reactions (defn message-with-reactions
[{:keys [pinned-by mentioned in-pinned-view? content-type last-in-group? message-id] :as message-data} [{:keys [pinned-by mentioned in-pinned-view? content-type last-in-group? message-id] :as message-data}

View File

@ -87,13 +87,19 @@
[community-preview cached-preview-data]))}))) [community-preview cached-preview-data]))})))
(defn link-preview-loader (defn link-preview-loader
[link {:keys [on-long-press]}] [link _]
(reagent/create-class (reagent/create-class
{:component-did-mount {:component-did-mount
(fn [] (fn []
(rf/dispatch [:chat.ui/load-link-preview-data link])) (rf/dispatch [:chat.ui/load-link-preview-data link]))
:component-did-update
(fn [this [_ previous-props]]
(let [[_ props] (.-argv (.-props ^js this))
refresh-photo? (not= previous-props props)]
(when refresh-photo?
(rf/dispatch [:chat.ui/load-link-preview-data props]))))
:reagent-render :reagent-render
(fn [] (fn [link {:keys [on-long-press]}]
(let [cached-preview-data (rf/sub [:link-preview/cache link])] (let [cached-preview-data (rf/sub [:link-preview/cache link])]
(when-let [{:keys [site title thumbnail-url error] :as preview-data} cached-preview-data] (when-let [{:keys [site title thumbnail-url error] :as preview-data} cached-preview-data]
(when (and (not error) site title) (when (and (not error) site title)
@ -141,8 +147,8 @@
(i18n/label :t/dont-ask)]]) (i18n/label :t/dont-ask)]])
(defn link-preview (defn link-preview
[{:keys [content]} context] [{:keys [message-id chat-id]} context]
(let [links (:links content) (let [links (get-in (rf/sub [:chats/chat-messages chat-id]) [message-id :content :links])
ask-user? (rf/sub [:link-preview/link-preview-request-enabled]) ask-user? (rf/sub [:link-preview/link-preview-request-enabled])
enabled-sites (rf/sub [:link-preview/enabled-sites]) enabled-sites (rf/sub [:link-preview/enabled-sites])
whitelist (rf/sub [:link-previews-whitelist])] whitelist (rf/sub [:link-previews-whitelist])]