From 0b2d0d45ed54eb73edee5000e670acbccadd1dbd Mon Sep 17 00:00:00 2001 From: andrey Date: Fri, 1 Oct 2021 12:17:34 +0200 Subject: [PATCH] [#12649] Mention preview is displayed as @0x... instead of user name/ENS on the home screen and in the Activity center Signed-off-by: andrey --- src/status_im/data_store/chats.cljs | 24 +++---- .../ui/screens/communities/views.cljs | 1 - src/status_im/ui/screens/home/views.cljs | 3 +- .../ui/screens/home/views/inner_item.cljs | 64 +++++++++++++++++-- status-go-version.json | 6 +- 5 files changed, 77 insertions(+), 21 deletions(-) diff --git a/src/status_im/data_store/chats.cljs b/src/status_im/data_store/chats.cljs index a51b972adf..e0af9cfd3d 100644 --- a/src/status_im/data_store/chats.cljs +++ b/src/status_im/data_store/chats.cljs @@ -4,7 +4,8 @@ [status-im.ethereum.json-rpc :as json-rpc] [status-im.constants :as constants] [status-im.utils.fx :as fx] - [taoensso.timbre :as log])) + [taoensso.timbre :as log] + [status-im.utils.types :as types])) (defn rpc->type [{:keys [chat-type name] :as chat}] (cond @@ -82,18 +83,19 @@ :muted (.-muted chat) :joined (.-joined chat) - :chat-id (.-id chat) - :community-id (.-communityId chat) - :synced-from (.-syncedFrom chat) - :synced-to (.-syncedTo chat) - :deleted-at-clock-value (.-deletedAtClockValue chat) - :chat-type (.-chatType chat) + :chat-id (.-id chat) + :community-id (.-communityId chat) + :synced-from (.-syncedFrom chat) + :synced-to (.-syncedTo chat) + :deleted-at-clock-value (.-deletedAtClockValue chat) + :chat-type (.-chatType chat) :unviewed-messages-count (.-unviewedMessagesCount chat) :unviewed-mentions-count (.-unviewedMentionsCount chat) - :last-message {:content {:text (.-text chat)} - :content-type (.-contentType chat)} - :last-clock-value (.-lastClockValue chat) - :profile-public-key (.-profile chat)} + :last-message {:content {:text (.-text chat) + :parsed-text (types/js->clj (.-parsedText chat))} + :content-type (.-contentType chat)} + :last-clock-value (.-lastClockValue chat) + :profile-public-key (.-profile chat)} rpc->type unmarshal-members)) diff --git a/src/status_im/ui/screens/communities/views.cljs b/src/status_im/ui/screens/communities/views.cljs index dbb400bd96..ecbe00102f 100644 --- a/src/status_im/ui/screens/communities/views.cljs +++ b/src/status_im/ui/screens/communities/views.cljs @@ -160,7 +160,6 @@ community-key]]])) (defn render-featured-community [{:keys [name id]}] - ^{:key id} [react/touchable-highlight {:on-press #(>evt [:navigate-to :community {:community-id id}]) :accessibility-label :chat-item} [react/view {:padding-right 8 diff --git a/src/status_im/ui/screens/home/views.cljs b/src/status_im/ui/screens/home/views.cljs index 7484f09ddf..dd16b41ce8 100644 --- a/src/status_im/ui/screens/home/views.cljs +++ b/src/status_im/ui/screens/home/views.cljs @@ -61,7 +61,8 @@ [react/view {:flex-direction :row :flex-wrap :wrap :justify-content :center :margin-top 10 :margin-bottom 18} - (for [community communities/featured] + (for [{:keys [id] :as community} communities/featured] + ^{:key id} [communities.views/render-featured-community community])]])]) (defn welcome-blank-page [] diff --git a/src/status_im/ui/screens/home/views/inner_item.cljs b/src/status_im/ui/screens/home/views/inner_item.cljs index 8542fcf5de..2787722dfa 100644 --- a/src/status_im/ui/screens/home/views/inner_item.cljs +++ b/src/status_im/ui/screens/home/views/inner_item.cljs @@ -19,6 +19,58 @@ :accessibility-label :no-messages-text} (i18n/label label-key)]) +(def max-subheader-length 100) + +(defn truncate-literal [literal] + (when literal + (let [size (min max-subheader-length (.-length literal))] + {:components (.substring literal 0 size) + :length size}))) + +(defn add-parsed-to-subheader [acc {:keys [type destination literal children]}] + (let [result (case type + "paragraph" + (reduce + (fn [{:keys [_ length] :as acc-paragraph} parsed-child] + (if (>= length max-subheader-length) + (reduced acc-paragraph) + (add-parsed-to-subheader acc-paragraph parsed-child))) + {:components [react/text-class] + :length 0} + children) + + "mention" + {:components [react/text-class @(re-frame/subscribe [:contacts/contact-name-by-identity literal])] + :length 4} ;; we can't predict name length so take the smallest possible + + "status-tag" + (truncate-literal (str "#" literal)) + + "link" + (truncate-literal destination) + + (truncate-literal literal))] + {:components (conj (:components acc) (:components result)) + :length (+ (:length acc) (:length result))})) + +(defn render-subheader + "Render the preview of a last message to a maximum of max-subheader-length characters" + [parsed-text] + (println "PARSED" parsed-text) + (let [result + (reduce + (fn [{:keys [_ length] :as acc-text} new-text-chunk] + (if (>= length max-subheader-length) + (reduced acc-text) + (add-parsed-to-subheader acc-text new-text-chunk))) + {:components [react/text-class {:style styles/last-message-text + :number-of-lines 1 + :ellipsize-mode :tail + :accessibility-label :chat-message-text}] + :length 0} + parsed-text)] + (:components result))) + (defn message-content-text [{:keys [content content-type]} absolute] [react/view (when absolute {:position :absolute :left 72 :top 32 :right 80}) (cond @@ -27,11 +79,13 @@ (and (= constants/content-type-text content-type) (not (string/blank? (:text content)))) - [react/text-class {:style styles/last-message-text - :number-of-lines 1 - :ellipsize-mode :tail - :accessibility-label :chat-message-text} - (:text content)] + (if (string/blank? (:parsed-text content)) + [react/text-class {:style styles/last-message-text + :number-of-lines 1 + :ellipsize-mode :tail + :accessibility-label :chat-message-text} + (:text content)] + [render-subheader (:parsed-text content)]) (= constants/content-type-sticker content-type) [preview-label :t/sticker] diff --git a/status-go-version.json b/status-go-version.json index e1a4a89772..d621961e5c 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -3,7 +3,7 @@ "_comment": "Instead use: scripts/update-status-go.sh ", "owner": "status-im", "repo": "status-go", - "version": "v0.89.5", - "commit-sha1": "c3ced098390f3d4e8d4850d9c0bf6e7dbd627c20", - "src-sha256": "10bpf87sshji6azf9vpmx90vbgwf2c8agcrcvc7x5qrqkpnbmd9p" + "version": "v0.89.6", + "commit-sha1": "7701368b142ad073f76d678095114b1388cce4b3", + "src-sha256": "0cgl5vhbn943sbzxzrnmpipxgyvlp4p3k96m5qp86cpw40rnhv9w" }