From 472f1a949c8f9b01bcfa1d0b77bb0c44ad560fb1 Mon Sep 17 00:00:00 2001 From: flexsurfer Date: Thu, 14 Mar 2024 13:46:00 +0100 Subject: [PATCH] Display discord bridged posts #19233 (#19248) --- .../status_im/data_store/activities_test.cljs | 85 +------------------ src/legacy/status_im/data_store/messages.cljs | 9 +- .../status_im/data_store/messages_test.cljs | 1 + src/status_im/constants.cljs | 1 + .../chat/messenger/messages/content/view.cljs | 33 +++++++ 5 files changed, 44 insertions(+), 85 deletions(-) diff --git a/src/legacy/status_im/data_store/activities_test.cljs b/src/legacy/status_im/data_store/activities_test.cljs index 9d417c76bdb..d95b9d7fd16 100644 --- a/src/legacy/status_im/data_store/activities_test.cljs +++ b/src/legacy/status_im/data_store/activities_test.cljs @@ -1,6 +1,6 @@ (ns legacy.status-im.data-store.activities-test (:require - [cljs.test :refer [deftest is testing]] + [cljs.test :refer [deftest is]] [legacy.status-im.data-store.activities :as store] [status-im.constants :as constants] [status-im.contexts.shell.activity-center.notification-types :as notification-types])) @@ -18,89 +18,6 @@ :name chat-name :replyMessage {}}) -(deftest <-rpc-test - (testing "renames keys" - (is (= {:name chat-name - :chat-id chat-id - :contact-verification-status constants/contact-verification-status-pending} - (-> raw-notification - store/<-rpc - (dissoc :last-message :message :reply-message))))) - - (testing "transforms messages from RPC response" - (is - (= {:last-message {:quoted-message nil - :outgoing-status nil - :command-parameters nil - :link-previews [] - :content {:sticker nil - :rtl? nil - :ens-name nil - :parsed-text nil - :response-to nil - :chat-id nil - :image nil - :line-count nil - :links nil - :text nil} - :outgoing false} - :message nil - :reply-message {:quoted-message nil - :outgoing-status nil - :command-parameters nil - :link-previews [] - :content {:sticker nil - :rtl? nil - :ens-name nil - :parsed-text nil - :response-to nil - :chat-id nil - :image nil - :line-count nil - :links nil - :text nil} - :outgoing false}} - (-> raw-notification - store/<-rpc - (select-keys [:last-message :message :reply-message]))))) - - (testing "augments notification based on its type" - (is (= {:chat-name chat-name - :chat-type constants/private-group-chat-type - :name chat-name} - (-> raw-notification - (assoc :type notification-types/reply) - store/<-rpc - (select-keys [:name :chat-type :chat-name :public? :group-chat])))) - - (is (= {:chat-name chat-name - :chat-type constants/private-group-chat-type - :name chat-name} - (-> raw-notification - (assoc :type notification-types/mention) - store/<-rpc - (select-keys [:name :chat-type :chat-name :public? :group-chat])))) - - (is (= {:chat-name chat-name - :chat-type constants/private-group-chat-type - :group-chat true - :name chat-name - :public? false} - (-> raw-notification - (assoc :type notification-types/private-group-chat) - store/<-rpc - (select-keys [:name :chat-type :chat-name :public? :group-chat])))) - - (is (= {:chat-name chat-name - :chat-type constants/one-to-one-chat-type - :group-chat false - :name chat-name - :public? false} - (-> raw-notification - (assoc :type notification-types/one-to-one-chat) - store/<-rpc - (select-keys [:name :chat-type :chat-name :public? :group-chat])))))) - (deftest remove-pending-contact-request-test (is (true? (store/pending-contact-request? "contact-id" diff --git a/src/legacy/status_im/data_store/messages.cljs b/src/legacy/status_im/data_store/messages.cljs index ef176496c89..94f8d57b636 100644 --- a/src/legacy/status_im/data_store/messages.cljs +++ b/src/legacy/status_im/data_store/messages.cljs @@ -53,7 +53,14 @@ :new :new? :albumImagesCount :album-images-count :displayName :display-name - :linkPreviews :link-previews}) + :linkPreviews :link-previews + :statusLinkPreviews :status-link-previews + :bridgeMessage :bridge-message}) + (update :bridge-message + set/rename-keys + {:bridgeName :bridge-name + :userName :user-name + :userAvatar :user-avatar}) (update :link-previews #(map <-link-preview-rpc %)) (update :quoted-message set/rename-keys diff --git a/src/legacy/status_im/data_store/messages_test.cljs b/src/legacy/status_im/data_store/messages_test.cljs index 7a6e8133dba..ac0b9aafcea 100644 --- a/src/legacy/status_im/data_store/messages_test.cljs +++ b/src/legacy/status_im/data_store/messages_test.cljs @@ -21,6 +21,7 @@ :image nil :response-to "a" :links nil} + :bridge-message nil :whisper-timestamp 1 :contact-verification-state 1 :contact-request-state 2 diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index d8f67736d0d..765a32d48be 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -19,6 +19,7 @@ (def ^:const content-type-system-message-mutual-event-sent 15) (def ^:const content-type-system-message-mutual-event-accepted 16) (def ^:const content-type-system-message-mutual-event-removed 17) +(def ^:const content-type-bridge-message 18) ;; Not implemented in status-go, only used for testing/ui work (def ^:const content-type-gif 100) diff --git a/src/status_im/contexts/chat/messenger/messages/content/view.cljs b/src/status_im/contexts/chat/messenger/messages/content/view.cljs index ef5900ce053..77eb1df483a 100644 --- a/src/status_im/contexts/chat/messenger/messages/content/view.cljs +++ b/src/status_im/contexts/chat/messenger/messages/content/view.cljs @@ -1,10 +1,12 @@ (ns status-im.contexts.chat.messenger.messages.content.view (:require + [clojure.string :as string] [legacy.status-im.ui.screens.chat.message.legacy-view :as old-message] [quo.core :as quo] [quo.foundations.colors :as colors] [quo.theme :as quo.theme] [react-native.core :as rn] + [react-native.fast-image :as fast-image] [react-native.gesture :as gesture] [react-native.platform :as platform] [reagent.core :as reagent] @@ -113,6 +115,34 @@ constants/content-type-system-message-mutual-event-sent [system-message-contact-request message-data :contact-request]))) +(defn bridge-message-content + [{:keys [bridge-message timestamp]}] + (let [{:keys [user-avatar user-name + bridge-name content]} bridge-message + user-name (when (string? user-name) + (-> user-name + (string/replace "" "") + (string/replace "" "")))] + [rn/view + {:style {:flex-direction :row + :padding-horizontal 12 + :padding-top 4}} + [fast-image/fast-image + {:source {:uri user-avatar} + :style {:width 32 + :margin-top 4 + :border-radius 16 + :height 32}}] + [rn/view {:margin-left 8 :flex 1} + [quo/author + {:primary-name (str user-name) + :short-chat-key (str "Bridged from " bridge-name) + :time-str (datetime/timestamp->time timestamp)}] + [quo/text + {:size :paragraph-1 + :style {:line-height 22.75}} + content]]])) + (declare on-long-press) (defn- user-message-content-internal @@ -284,6 +314,9 @@ keyboard-shown?)) context] + (= content-type constants/content-type-bridge-message) + [bridge-message-content message-data] + :else [user-message-content {:message-data message-data