[#15545] Show proper user name in pinned message

This commit is contained in:
Roman Volosovskyi 2023-04-11 17:20:15 +02:00
parent fe4f4463c8
commit d4bef47804
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
2 changed files with 58 additions and 2 deletions

View File

@ -3,19 +3,41 @@
[utils.i18n :as i18n] [utils.i18n :as i18n]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
(defn resolve-message
[parsed-text]
(reduce
(fn [acc {:keys [type literal destination] :as some-text}]
(str acc
(case type
"paragraph"
(resolve-message (:children some-text))
"mention"
(rf/sub [:messages/resolve-mention literal])
"status-tag"
(str "#" literal)
"link"
destination
literal)))
""
parsed-text))
(defn banner (defn banner
[chat-id] [chat-id]
(let [pinned-messages (rf/sub [:chats/pinned-sorted-list chat-id]) (let [pinned-messages (rf/sub [:chats/pinned-sorted-list chat-id])
latest-pinned-message-id (-> pinned-messages last :message-id) latest-pinned-message-id (-> pinned-messages last :message-id)
latest-pinned-message (get (rf/sub [:chats/chat-messages chat-id]) latest-pinned-message-id) latest-pinned-message (get (rf/sub [:chats/chat-messages chat-id]) latest-pinned-message-id)
latest-pin-text (get-in latest-pinned-message [:content :text]) latest-pin-text (get-in latest-pinned-message [:content :parsed-text])
{:keys [deleted? deleted-for-me?]} latest-pinned-message {:keys [deleted? deleted-for-me?]} latest-pinned-message
pins-count (count pinned-messages) pins-count (count pinned-messages)
latest-pin-text latest-pin-text
(cond deleted? (i18n/label :t/message-deleted-for-everyone) (cond deleted? (i18n/label :t/message-deleted-for-everyone)
deleted-for-me? (i18n/label :t/message-deleted-for-you) deleted-for-me? (i18n/label :t/message-deleted-for-you)
:else latest-pin-text)] :else (resolve-message latest-pin-text))]
[quo/banner [quo/banner
{:latest-pin-text latest-pin-text {:latest-pin-text latest-pin-text
:pins-count pins-count :pins-count pins-count

View File

@ -0,0 +1,34 @@
(ns status-im2.contexts.chat.messages.pin.banner.view-test
(:require [status-im2.contexts.chat.messages.pin.banner.view :as view]
[cljs.test :as t]
[utils.re-frame :as rf]))
(def mentions
{"0xsome_id" "foobar"})
(defn sub
[[_ mention]]
(get mentions mention mention))
(def parsed-text
[{:type "paragraph"
:children
[{:literal ""}
{:type "mention"
:literal
"0xsome_id"}
{:literal " i just mention you here to debug this issue "}
{:type "link"
:children
[{:literal "https://foo.bar"}]
:literal ""
:title ""
:destination "https://foo.bar"}
{:literal " , no worries"}]}])
(t/deftest test-resolve-message
(with-redefs [rf/sub sub]
(t/testing ""
(let [text (view/resolve-message parsed-text)]
(t/is (= text
"foobar i just mention you here to debug this issue https://foo.bar , no worries"))))))