[#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 <motor4ik@gmail.com>
This commit is contained in:
andrey 2021-10-01 12:17:34 +02:00
parent cd35af4e00
commit 0b2d0d45ed
No known key found for this signature in database
GPG Key ID: 89B67245FD2F0272
5 changed files with 77 additions and 21 deletions

View File

@ -4,7 +4,8 @@
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.utils.fx :as fx] [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}] (defn rpc->type [{:keys [chat-type name] :as chat}]
(cond (cond
@ -90,7 +91,8 @@
:chat-type (.-chatType chat) :chat-type (.-chatType chat)
:unviewed-messages-count (.-unviewedMessagesCount chat) :unviewed-messages-count (.-unviewedMessagesCount chat)
:unviewed-mentions-count (.-unviewedMentionsCount chat) :unviewed-mentions-count (.-unviewedMentionsCount chat)
:last-message {:content {:text (.-text chat)} :last-message {:content {:text (.-text chat)
:parsed-text (types/js->clj (.-parsedText chat))}
:content-type (.-contentType chat)} :content-type (.-contentType chat)}
:last-clock-value (.-lastClockValue chat) :last-clock-value (.-lastClockValue chat)
:profile-public-key (.-profile chat)} :profile-public-key (.-profile chat)}

View File

@ -160,7 +160,6 @@
community-key]]])) community-key]]]))
(defn render-featured-community [{:keys [name id]}] (defn render-featured-community [{:keys [name id]}]
^{:key id}
[react/touchable-highlight {:on-press #(>evt [:navigate-to :community {:community-id id}]) [react/touchable-highlight {:on-press #(>evt [:navigate-to :community {:community-id id}])
:accessibility-label :chat-item} :accessibility-label :chat-item}
[react/view {:padding-right 8 [react/view {:padding-right 8

View File

@ -61,7 +61,8 @@
[react/view {:flex-direction :row :flex-wrap :wrap :justify-content :center [react/view {:flex-direction :row :flex-wrap :wrap :justify-content :center
:margin-top 10 :margin-top 10
:margin-bottom 18} :margin-bottom 18}
(for [community communities/featured] (for [{:keys [id] :as community} communities/featured]
^{:key id}
[communities.views/render-featured-community community])]])]) [communities.views/render-featured-community community])]])])
(defn welcome-blank-page [] (defn welcome-blank-page []

View File

@ -19,6 +19,58 @@
:accessibility-label :no-messages-text} :accessibility-label :no-messages-text}
(i18n/label label-key)]) (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] (defn message-content-text [{:keys [content content-type]} absolute]
[react/view (when absolute {:position :absolute :left 72 :top 32 :right 80}) [react/view (when absolute {:position :absolute :left 72 :top 32 :right 80})
(cond (cond
@ -27,11 +79,13 @@
(and (= constants/content-type-text content-type) (and (= constants/content-type-text content-type)
(not (string/blank? (:text content)))) (not (string/blank? (:text content))))
(if (string/blank? (:parsed-text content))
[react/text-class {:style styles/last-message-text [react/text-class {:style styles/last-message-text
:number-of-lines 1 :number-of-lines 1
:ellipsize-mode :tail :ellipsize-mode :tail
:accessibility-label :chat-message-text} :accessibility-label :chat-message-text}
(:text content)] (:text content)]
[render-subheader (:parsed-text content)])
(= constants/content-type-sticker content-type) (= constants/content-type-sticker content-type)
[preview-label :t/sticker] [preview-label :t/sticker]

View File

@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>", "_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im", "owner": "status-im",
"repo": "status-go", "repo": "status-go",
"version": "v0.89.5", "version": "v0.89.6",
"commit-sha1": "c3ced098390f3d4e8d4850d9c0bf6e7dbd627c20", "commit-sha1": "7701368b142ad073f76d678095114b1388cce4b3",
"src-sha256": "10bpf87sshji6azf9vpmx90vbgwf2c8agcrcvc7x5qrqkpnbmd9p" "src-sha256": "0cgl5vhbn943sbzxzrnmpipxgyvlp4p3k96m5qp86cpw40rnhv9w"
} }