Prevent #links to work except in community chats and allow redirection from channel to another when clicked (#15069)

This commit is contained in:
Ibrahem Khalil 2023-02-20 11:47:26 +02:00 committed by GitHub
parent bea93f4a7a
commit bc5f0ccda6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 12 deletions

View File

@ -198,6 +198,15 @@
%)
(re-frame/dispatch [::failed-to-leave %]))}]}))
(rf/defn status-tag-pressed
{:events [:communities/status-tag-pressed]}
[{:keys [db]} community-id literal]
(let [current-chat-id (:current-chat-id db)
{:keys [id]} (some #(when (= (:name %) literal) %)
(vals (get-in db [:communities community-id :chats])))]
(when-not (= current-chat-id (str community-id id))
{:dispatch [:chat/navigate-to-chat (str community-id id)]})))
(rf/defn fetch
[_]
{:json-rpc/call [{:method "wakuext_communities"

View File

@ -38,7 +38,8 @@
(rf/sub [:contacts/contact-name-by-identity from]))
(defn render-inline
[_message-text content-type acc {:keys [type literal destination]}]
[_message-text content-type acc {:keys [type literal destination]}
community-id]
(case type
""
(conj acc literal)
@ -80,9 +81,10 @@
"status-tag"
(conj acc
[rn/text
(when community-id
{:style {:color :blue
:text-decoration-line :underline}
:on-press #(rf/dispatch [:chat.ui/start-public-chat literal])}
:on-press #(rf/dispatch [:communities/status-tag-pressed community-id literal])})
"#"
literal])
@ -94,13 +96,20 @@
;; TEXT
(defn render-block
[{:keys [content content-type edited-at in-popover?]} acc
{:keys [type ^js literal children]}]
{:keys [type ^js literal children]}
community-id]
(case type
"paragraph"
(conj acc
(reduce
(fn [acc e] (render-inline (:text content) content-type acc e))
(fn [acc e]
(render-inline (:text content)
content-type
acc
e
community-id))
[rn/text (style/text-style content-type in-popover?)]
(conj
children
@ -121,11 +130,16 @@
acc))
(defn render-parsed-text
[{:keys [content] :as message-data}]
[{:keys [content chat-id]
:as message-data}]
(let [community-id (rf/sub [:community-id-by-chat-id chat-id])]
(reduce (fn [acc e]
(render-block message-data acc e))
(render-block message-data
acc
e
community-id))
[:<>]
(:parsed-text content)))
(:parsed-text content))))
(defn quoted-message
[{:keys [message-id chat-id]} reply pin?]
@ -234,7 +248,7 @@
[rn/view style/status-container
[rn/text {:style (style/status-text)}
(reduce
(fn [acc e] (render-inline (:text content) content-type acc e))
(fn [acc e] (render-inline (:text content) content-type acc e nil))
[rn/text {:style (style/status-text)}]
(-> content :parsed-text peek :children))]])

View File

@ -20,6 +20,14 @@
(fn [chats [_ chat-id]]
(get chats chat-id)))
(re-frame/reg-sub
:community-id-by-chat-id
:<- [:chats/chats]
(fn [chats [_ chat-id]]
(-> chats
(get chat-id)
:community-id)))
(re-frame/reg-sub
:chats/by-community-id
:<- [:chats/chats]