[#15545] Show proper user name in pinned message
This commit is contained in:
parent
fe4f4463c8
commit
d4bef47804
|
@ -3,19 +3,41 @@
|
|||
[utils.i18n :as i18n]
|
||||
[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
|
||||
[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 (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
|
||||
pins-count (count pinned-messages)
|
||||
|
||||
latest-pin-text
|
||||
(cond deleted? (i18n/label :t/message-deleted-for-everyone)
|
||||
deleted-for-me? (i18n/label :t/message-deleted-for-you)
|
||||
:else latest-pin-text)]
|
||||
:else (resolve-message latest-pin-text))]
|
||||
[quo/banner
|
||||
{:latest-pin-text latest-pin-text
|
||||
:pins-count pins-count
|
||||
|
|
|
@ -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"))))))
|
Loading…
Reference in New Issue