Skip to content

Commit

Permalink
Display discord bridged posts #19233 (#19248)
Browse files Browse the repository at this point in the history
  • Loading branch information
flexsurfer authored and cammellos committed Mar 14, 2024
1 parent 43573d1 commit 472f1a9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 85 deletions.
85 changes: 1 addition & 84 deletions src/legacy/status_im/data_store/activities_test.cljs
Original file line number Diff line number Diff line change
@@ -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]))
Expand All @@ -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"
Expand Down
9 changes: 8 additions & 1 deletion src/legacy/status_im/data_store/messages.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/legacy/status_im/data_store/messages_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/status_im/constants.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
33 changes: 33 additions & 0 deletions src/status_im/contexts/chat/messenger/messages/content/view.cljs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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 "<b>" "")
(string/replace "</b>" "")))]
[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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 472f1a9

Please sign in to comment.