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

This commit is contained in:
Ibrahem Khalil 2023-03-13 20:09:38 +02:00 committed by GitHub
parent 9e4d9a05a7
commit 4810e1d7bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 59 additions and 17 deletions

View File

@ -202,6 +202,16 @@
%) %)
(re-frame/dispatch [::failed-to-leave %]))}]})) (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 (and id
(not= current-chat-id (str community-id id)))
{:dispatch [:chat/navigate-to-chat (str community-id id)]})))
(rf/defn fetch (rf/defn fetch
[_] [_]
{:json-rpc/call [{:method "wakuext_communities" {:json-rpc/call [{:method "wakuext_communities"

View File

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

View File

@ -10,7 +10,7 @@
(defn render-inline (defn render-inline
[units {:keys [type literal destination]}] [units {:keys [type literal destination]} chat-id]
(case (keyword type) (case (keyword type)
:code :code
(conj units [rn/view {:style (merge style/block (style/code))} [quo/text {:weight :code} literal]]) (conj units [rn/view {:style (merge style/block (style/code))} [quo/text {:weight :code} literal]])
@ -59,17 +59,28 @@
:color (colors/theme-colors colors/neutral-40 :color (colors/theme-colors colors/neutral-40
colors/neutral-50)}} colors/neutral-50)}}
literal]) literal])
:status-tag
(let [community-id (rf/sub [:community-id-by-chat-id chat-id])]
(conj units
[rn/text
(when community-id
{:style {:color :blue
:text-decoration-line :underline}
:on-press #(rf/dispatch [:communities/status-tag-pressed community-id literal])})
"#"
literal]))
(conj units literal))) (conj units literal)))
(defn render-block (defn render-block
[blocks {:keys [type ^js literal children]} edited-at] [blocks {:keys [type literal children]} chat-id edited-at]
(case (keyword type) (case (keyword type)
:paragraph :paragraph
(conj blocks (conj blocks
(reduce (reduce
render-inline (fn [acc e]
(render-inline acc e chat-id))
[quo/text] [quo/text]
children)) children))
@ -110,9 +121,9 @@
:type :edited})))) :type :edited}))))
(defn render-parsed-text (defn render-parsed-text
[{:keys [content edited-at]}] [{:keys [content chat-id edited-at]}]
(reduce (fn [acc e] (reduce (fn [acc e]
(render-block acc e edited-at)) (render-block acc e chat-id edited-at))
[:<>] [:<>]
(cond-> (:parsed-text content) (cond-> (:parsed-text content)
edited-at add-edited-tag))) edited-at add-edited-tag)))

View File

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