From d16baca64f91267b962af2deaca6acd447921714 Mon Sep 17 00:00:00 2001 From: Parvesh Monu Date: Mon, 30 Jan 2023 19:42:58 +0530 Subject: [PATCH] fix pinned message for community channels (#14885) --- src/status_im/chat/models/input.cljs | 34 +++++++++++-------- .../screens/communities/channel_details.cljs | 2 +- .../ui/screens/profile/contact/views.cljs | 2 +- .../ui/screens/profile/group_chat/views.cljs | 3 +- src/status_im2/contexts/chat/events.cljs | 6 ---- .../contexts/chat/messages/pin/list/view.cljs | 29 ++++++++-------- 6 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/status_im/chat/models/input.cljs b/src/status_im/chat/models/input.cljs index f34463aeef..80cf56309a 100644 --- a/src/status_im/chat/models/input.cljs +++ b/src/status_im/chat/models/input.cljs @@ -217,20 +217,26 @@ :text (i18n/label :t/update-to-see-sticker {"locale" "en"})}))) (rf/defn send-edited-message - [{:keys [db] :as cofx} text {:keys [message-id quoted-message]}] - (rf/merge - cofx - {:json-rpc/call [{:method "wakuext_editMessage" - :params [{:id message-id - :text text - :content-type (if (message-content/emoji-only-content? - {:text text :response-to quoted-message}) - constants/content-type-emoji - constants/content-type-text)}] - :js-response true - :on-error #(log/error "failed to edit message " %) - :on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])}]} - (cancel-message-edit))) + [{:keys [db] :as cofx} text {:keys [message-id quoted-message chat-id]}] + (let [pinned-message (get-in db [:pin-messages chat-id message-id])] + (rf/merge + cofx + {:json-rpc/call [{:method "wakuext_editMessage" + :params [{:id message-id + :text text + :content-type (if (message-content/emoji-only-content? + {:text text :response-to quoted-message}) + constants/content-type-emoji + constants/content-type-text)}] + :js-response true + :on-error #(log/error "failed to edit message " %) + :on-success (fn [result] + (re-frame/dispatch [:sanitize-messages-and-process-response + result]) + (when pinned-message + (re-frame/dispatch [:pin-message/load-pin-messages + chat-id])))}]} + (cancel-message-edit)))) (rf/defn send-current-message "Sends message from current chat input" diff --git a/src/status_im/ui/screens/communities/channel_details.cljs b/src/status_im/ui/screens/communities/channel_details.cljs index e901e750b9..e8ac885dd6 100644 --- a/src/status_im/ui/screens/communities/channel_details.cljs +++ b/src/status_im/ui/screens/communities/channel_details.cljs @@ -64,5 +64,5 @@ :accessory :text :accessory-text (count pinned-messages) :chevron true - :on-press #(re-frame/dispatch [:chat.ui/navigate-to-pinned-messages + :on-press #(re-frame/dispatch [:bottom-sheet/show-sheet :pinned-messages-list chat-id])}]])])))) diff --git a/src/status_im/ui/screens/profile/contact/views.cljs b/src/status_im/ui/screens/profile/contact/views.cljs index 306bd44f11..8ec2f5a0be 100644 --- a/src/status_im/ui/screens/profile/contact/views.cljs +++ b/src/status_im/ui/screens/profile/contact/views.cljs @@ -100,7 +100,7 @@ :accessory :text :accessory-text pin-count :disabled (zero? pin-count) - :on-press #(re-frame/dispatch [:chat.ui/navigate-to-pinned-messages public-key]) + :on-press #(re-frame/dispatch [:bottom-sheet/show-sheet :pinned-messages-list public-key]) :chevron true}]) (defn nickname-settings diff --git a/src/status_im/ui/screens/profile/group_chat/views.cljs b/src/status_im/ui/screens/profile/group_chat/views.cljs index 806f3e363c..11b657be41 100644 --- a/src/status_im/ui/screens/profile/group_chat/views.cljs +++ b/src/status_im/ui/screens/profile/group_chat/views.cljs @@ -215,7 +215,8 @@ :accessory :text :accessory-text (count pinned-messages) :chevron true - :on-press #(re-frame/dispatch [:chat.ui/navigate-to-pinned-messages chat-id])}] + :on-press #(re-frame/dispatch [:bottom-sheet/show-sheet :pinned-messages-list + chat-id])}] (when member? [quo/list-item {:theme :negative diff --git a/src/status_im2/contexts/chat/events.cljs b/src/status_im2/contexts/chat/events.cljs index 9dc645cd33..60f4299991 100644 --- a/src/status_im2/contexts/chat/events.cljs +++ b/src/status_im2/contexts/chat/events.cljs @@ -324,12 +324,6 @@ (rf/dispatch [:bottom-sheet/hide]) (rf/dispatch [:chat.ui/remove-chat chat-id]))}}) -(rf/defn navigate-to-user-pinned-messages - "Takes coeffects map and chat-id, returns effects necessary for navigation and preloading data" - {:events [:chat.ui/navigate-to-pinned-messages]} - [cofx chat-id] - (navigation/navigate-to cofx :chat-pinned-messages {:chat-id chat-id})) - (rf/defn navigate-to-horizontal-images {:events [:chat.ui/navigate-to-horizontal-images]} [cofx messages index] diff --git a/src/status_im2/contexts/chat/messages/pin/list/view.cljs b/src/status_im2/contexts/chat/messages/pin/list/view.cljs index c6e6b8e366..1f2d8a07b2 100644 --- a/src/status_im2/contexts/chat/messages/pin/list/view.cljs +++ b/src/status_im2/contexts/chat/messages/pin/list/view.cljs @@ -10,28 +10,27 @@ (def list-key-fn #(or (:message-id %) (:value %))) (defn message-render-fn - [{:keys [whisper-timestamp message-id chat-id] :as message} + [{:keys [whisper-timestamp] :as message} _ {:keys [group-chat public? community? current-public-key show-input? edit-enabled]}] ;; TODO (flexsurfer) probably we don't want reactions here - (let [message-content-sub (get-in (rf/sub [:chats/chat-messages chat-id]) [message-id :content])] - [message/message-with-reactions - (assoc message :content message-content-sub) - {:group-chat group-chat - :public? public? - :community? community? - :current-public-key current-public-key - :show-input? show-input? - :message-pin-enabled true - :in-pinned-view? true - :pinned true - :timestamp-str (datetime/timestamp->time whisper-timestamp) - :edit-enabled edit-enabled}])) + [message/message-with-reactions + message + {:group-chat group-chat + :public? public? + :community? community? + :current-public-key current-public-key + :show-input? show-input? + :message-pin-enabled true + :in-pinned-view? true + :pinned true + :timestamp-str (datetime/timestamp->time whisper-timestamp) + :edit-enabled edit-enabled}]) (defn pinned-messages-list [chat-id] (let [pinned-messages (vec (vals (rf/sub [:chats/pinned chat-id]))) - current-chat (rf/sub [:chats/current-chat]) + current-chat (rf/sub [:chat-by-id chat-id]) community (rf/sub [:communities/community (:community-id current-chat)])] [rn/view {:accessibility-label :pinned-messages-list} ;; TODO (flexsurfer) this should be a component in quo2