From 103c4b46536a500d725519f0166ca6fc76242ea5 Mon Sep 17 00:00:00 2001 From: Sean Hagstrom Date: Tue, 12 Mar 2024 17:42:11 +0000 Subject: [PATCH 1/2] chore: decode emoji-hash and bio from contact payload (#19030) --- src/status_im/contexts/chat/contacts/events.cljs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/status_im/contexts/chat/contacts/events.cljs b/src/status_im/contexts/chat/contacts/events.cljs index 87a0d5358cc..d050b7ee583 100644 --- a/src/status_im/contexts/chat/contacts/events.cljs +++ b/src/status_im/contexts/chat/contacts/events.cljs @@ -23,7 +23,9 @@ :blocked? (oops/oget js-contact "blocked") :added? (oops/oget js-contact "added") :has-added-us? (oops/oget js-contact "hasAddedUs") - :mutual? (oops/oget js-contact "mutual")}) + :mutual? (oops/oget js-contact "mutual") + :emoji-hash (oops/oget js-contact "emojiHash") + :bio (oops/oget js-contact "bio")}) (defn prepare-events-for-contact [db chats-js] From 2009199c250a05c86e860e22cde54bc8d530f815 Mon Sep 17 00:00:00 2001 From: Ibrahem Khalil Date: Wed, 13 Mar 2024 00:49:19 +0200 Subject: [PATCH 2/2] feat: Add internal link preview for communities (#18484) --- .../status_im/data_store/activities_test.cljs | 62 +++++------ src/legacy/status_im/data_store/messages.cljs | 36 ++++++- .../status_im/data_store/messages_test.cljs | 28 ++++- src/legacy/status_im/subs/root.cljs | 1 + .../ui/screens/communities/invite.cljs | 4 +- .../internal_link_card/community/style.cljs | 4 +- .../links/link_preview/component_spec.cljs | 6 -- .../components/links/link_preview/view.cljs | 35 ++++-- .../components/links/url_preview/style.cljs | 1 + .../components/links/url_preview/view.cljs | 35 ++++-- .../links/url_preview_list/view.cljs | 5 +- .../common/biometric/events_test.cljs | 2 +- src/status_im/constants.cljs | 2 + .../chat/messenger/composer/events.cljs | 100 +++++++++++++----- .../composer/link_preview/events.cljs | 39 +++++-- .../composer/link_preview/events_test.cljs | 12 ++- .../messenger/composer/link_preview/view.cljs | 22 ++-- .../messages/content/link_preview/view.cljs | 3 +- .../content/status_link_preview/view.cljs | 28 +++++ .../messenger/messages/content/text/view.cljs | 4 +- .../messenger/messages/transport/events.cljs | 40 +++---- src/status_im/subs/chats.cljs | 12 ++- src/status_im/subs/messages.cljs | 15 +++ src/status_im/subs/messages_test.cljs | 16 +++ .../integration_test/standard_auth_test.cljs | 2 +- status-go-version.json | 6 +- 26 files changed, 388 insertions(+), 132 deletions(-) create mode 100644 src/status_im/contexts/chat/messenger/messages/content/status_link_preview/view.cljs diff --git a/src/legacy/status_im/data_store/activities_test.cljs b/src/legacy/status_im/data_store/activities_test.cljs index 9d417c76bdb..10df433a098 100644 --- a/src/legacy/status_im/data_store/activities_test.cljs +++ b/src/legacy/status_im/data_store/activities_test.cljs @@ -29,37 +29,39 @@ (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} + (= {:last-message {:quoted-message nil + :outgoing-status nil + :command-parameters nil + :link-previews [] + :status-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}} + :reply-message {:quoted-message nil + :outgoing-status nil + :command-parameters nil + :link-previews [] + :status-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]))))) diff --git a/src/legacy/status_im/data_store/messages.cljs b/src/legacy/status_im/data_store/messages.cljs index ef176496c89..d5d389e99fa 100644 --- a/src/legacy/status_im/data_store/messages.cljs +++ b/src/legacy/status_im/data_store/messages.cljs @@ -16,13 +16,41 @@ :community-id :communityId :clock-value :clock}))) +(defn- <-status-link-previews-rpc + [preview] + (-> preview + (update :community + set/rename-keys + {:communityId :community-id + :displayName :display-name + :membersCount :members-count + :activeMembersCount :active-members-count}) + (update-in [:community :banner] set/rename-keys {:dataUri :data-uri}) + (update-in [:community :icon] set/rename-keys {:dataUri :data-uri}))) + +(defn ->status-link-previews-rpc + [preview] + (-> preview + (update :community + set/rename-keys + {:community-id :communityId + :display-name :displayName + :members-count :membersCount + :active-members-count :activeMembersCount}) + (update-in [:community :banner] set/rename-keys {:data-uri :dataUri}) + (update-in [:community :icon] set/rename-keys {:data-uri :dataUri}))) + (defn- <-link-preview-rpc [preview] - (update preview :thumbnail set/rename-keys {:dataUri :data-uri})) + (-> preview + (update :thumbnail set/rename-keys {:dataUri :data-uri}) + (update :favicon set/rename-keys {:dataUri :data-uri}))) (defn ->link-preview-rpc [preview] - (update preview :thumbnail set/rename-keys {:data-uri :dataUri})) + (-> preview + (update :thumbnail set/rename-keys {:data-uri :dataUri}) + (update :favicon set/rename-keys {:data-uri :dataUri}))) (defn <-rpc [message] @@ -53,8 +81,10 @@ :new :new? :albumImagesCount :album-images-count :displayName :display-name - :linkPreviews :link-previews}) + :linkPreviews :link-previews + :statusLinkPreviews :status-link-previews}) (update :link-previews #(map <-link-preview-rpc %)) + (update :status-link-previews #(map <-status-link-previews-rpc %)) (update :quoted-message set/rename-keys {:parsedText :parsed-text diff --git a/src/legacy/status_im/data_store/messages_test.cljs b/src/legacy/status_im/data_store/messages_test.cljs index 7a6e8133dba..3b5b496aeb5 100644 --- a/src/legacy/status_im/data_store/messages_test.cljs +++ b/src/legacy/status_im/data_store/messages_test.cljs @@ -37,7 +37,19 @@ :compressed-key "c" :timestamp 3 :link-previews [{:thumbnail {:url "http://localhost" - :data-uri "data:image/png"}}]} + :data-uri "data:image/png"} + :favicon nil}] + :status-link-previews [{:url "http://localhost" + :community {:community-id "0x01" + :display-name "Test Comm" + :members-count 12 + :active-members-count 12 + :banner + {:data-uri + "data:image/png"} + :icon + {:data-uri + "data:image/png"}}}]} message {:id message-id :whisperTimestamp 1 :parsedText "parsed-text" @@ -61,5 +73,17 @@ :timestamp 3 :outgoingStatus "sending" :linkPreviews [{:thumbnail {:url "http://localhost" - :dataUri "data:image/png"}}]}] + :dataUri "data:image/png"} + :favicon nil}] + :statusLinkPreviews [{:url "http://localhost" + :community {:communityId "0x01" + :displayName "Test Comm" + :membersCount 12 + :activeMembersCount 12 + :banner + {:dataUri + "data:image/png"} + :icon + {:dataUri + "data:image/png"}}}]}] (is (= expected (m/<-rpc message)))))) diff --git a/src/legacy/status_im/subs/root.cljs b/src/legacy/status_im/subs/root.cljs index a5705bb6a96..817c3758923 100644 --- a/src/legacy/status_im/subs/root.cljs +++ b/src/legacy/status_im/subs/root.cljs @@ -100,6 +100,7 @@ ;;; Link previews (reg-root-key-sub :link-previews-whitelist :link-previews-whitelist) (reg-root-key-sub :chat/link-previews :chat/link-previews) +(reg-root-key-sub :chat/status-link-previews :chat/status-link-previews) ;;commands (reg-root-key-sub :commands/select-account :commands/select-account) diff --git a/src/legacy/status_im/ui/screens/communities/invite.cljs b/src/legacy/status_im/ui/screens/communities/invite.cljs index 5972b6e5613..3eefc294ffe 100644 --- a/src/legacy/status_im/ui/screens/communities/invite.cljs +++ b/src/legacy/status_im/ui/screens/communities/invite.cljs @@ -85,9 +85,7 @@ :accessibility-label :share-community-link :type :secondary :on-press #(debounce/throttle-and-dispatch - [(if can-invite? - ::communities/invite-people-confirmation-pressed - ::communities/share-community-confirmation-pressed) @user-pk + [::communities/share-community-confirmation-pressed @user-pk selected] 3000)} (i18n/label (if can-invite? :t/invite :t/share))]}]])))) diff --git a/src/quo/components/links/internal_link_card/community/style.cljs b/src/quo/components/links/internal_link_card/community/style.cljs index 84507c4651d..c809f40d07a 100644 --- a/src/quo/components/links/internal_link_card/community/style.cljs +++ b/src/quo/components/links/internal_link_card/community/style.cljs @@ -60,8 +60,8 @@ :padding-horizontal 12 :padding-top 10 :padding-bottom 12 - :height (if (= :message size) 245 266) - :width (if (= :message size) 295 335)}) + :width (if (= :message size) 295 335) + :flex 1}) (def header-container {:flex-direction :row diff --git a/src/quo/components/links/link_preview/component_spec.cljs b/src/quo/components/links/link_preview/component_spec.cljs index 6d5b1253528..5c391147044 100644 --- a/src/quo/components/links/link_preview/component_spec.cljs +++ b/src/quo/components/links/link_preview/component_spec.cljs @@ -7,7 +7,6 @@ {:title "Some title" :description "Some description" :link "status.im" - :logo "data:image/png,logo-x" :thumbnail "data:image/png,whatever"}) (h/describe "Links - Link Preview" @@ -21,17 +20,12 @@ (h/is-truthy (h/query-by-text (:title props))) (h/is-truthy (h/query-by-text (:description props))) (h/is-truthy (h/query-by-text (:link props))) - (h/is-truthy (h/query-by-label-text :logo)) (h/is-truthy (h/query-by-label-text :thumbnail))) (h/test "does not render thumbnail if prop is not present" (h/render [view/view (dissoc props :thumbnail)]) (h/is-null (h/query-by-label-text :thumbnail))) - (h/test "does not render logo if prop is not present" - (h/render [view/view (dissoc props :logo)]) - (h/is-null (h/query-by-label-text :logo))) - (h/test "shows button to enable preview when preview is disabled" (h/render [view/view (assoc props diff --git a/src/quo/components/links/link_preview/view.cljs b/src/quo/components/links/link_preview/view.cljs index a3993f02851..d4852ded51f 100644 --- a/src/quo/components/links/link_preview/view.cljs +++ b/src/quo/components/links/link_preview/view.cljs @@ -1,9 +1,14 @@ (ns quo.components.links.link-preview.view (:require + ["react-native-blob-util" :default ReactNativeBlobUtil] + [oops.core :as oops] [quo.components.buttons.button.view :as button] [quo.components.links.link-preview.style :as style] [quo.components.markdown.text :as text] - [react-native.core :as rn])) + [react-native.core :as rn] + [react-native.platform :as platform] + [react-native.svg :as svg] + [taoensso.timbre :as log])) (defn- button-disabled [disabled-text on-enable] @@ -51,14 +56,30 @@ thumbnail) :accessibility-label :thumbnail}]) +(defn- get-image-data + [logo set-is-svg on-success] + (-> (.config ReactNativeBlobUtil (clj->js {:trusty platform/ios?})) + (.fetch "GET" logo) + (.then (fn [imgObj] + (set-is-svg (= "image/svg" + (oops/oget imgObj + ["respInfo" "headers" "Content-Type"]))) + (on-success (oops/oget imgObj "data")))) + (.catch #(log/error "could not fetch favicon " logo)))) + (defn- logo-comp [logo] - [rn/image - {:accessibility-label :logo - :source (if (string? logo) - {:uri logo} - logo) - :style style/logo}]) + (let [[image-data set-image-data] (rn/use-state nil) + [is-svg? set-is-svg] (rn/use-state nil) + on-success (fn [data-uri] + (set-image-data data-uri)) + _get-image-data (get-image-data logo set-is-svg on-success)] + (if is-svg? + [svg/svg-xml (merge style/logo {:xml image-data})] + [rn/image + {:accessibility-label :logo + :source {:uri (str "data:image/png;base64," image-data)} + :style style/logo}]))) (defn view [{:keys [title logo description link thumbnail diff --git a/src/quo/components/links/url_preview/style.cljs b/src/quo/components/links/url_preview/style.cljs index 454774bb66a..7632753339f 100644 --- a/src/quo/components/links/url_preview/style.cljs +++ b/src/quo/components/links/url_preview/style.cljs @@ -21,6 +21,7 @@ :border-radius 12 :border-style :dashed :align-items :center + :flex-direction :row :justify-content :center :align-self :stretch :padding horizontal-padding diff --git a/src/quo/components/links/url_preview/view.cljs b/src/quo/components/links/url_preview/view.cljs index 70b46407139..808ee0704e0 100644 --- a/src/quo/components/links/url_preview/view.cljs +++ b/src/quo/components/links/url_preview/view.cljs @@ -1,19 +1,31 @@ (ns quo.components.links.url-preview.view (:require + [clojure.string :as string] [quo.components.icon :as icon] [quo.components.links.url-preview.style :as style] [quo.components.markdown.text :as text] [quo.foundations.colors :as colors] - [react-native.core :as rn])) + [react-native.core :as rn] + [react-native.svg :as svg])) + +(def base64-svg-prefix "data:image/svg;base64,") (defn- logo-comp [{:keys [logo]}] - [rn/image - {:accessibility-label :logo - :source (if (string? logo) - {:uri logo} - logo) - :style style/logo}]) + (if (and (string? logo) + (string/starts-with? logo base64-svg-prefix)) + [svg/svg-xml + (merge style/logo + {:xml (-> logo + (string/replace base64-svg-prefix "") + js/atob)})] + [rn/image + {:accessibility-label :logo + :source (if (string? logo) + {:uri logo} + logo) + :style style/logo + :resize-mode :cover}])) (defn- content [{:keys [title body]}] @@ -50,6 +62,10 @@ [rn/view {:accessibility-label :url-preview-loading :style (merge (style/loading-container) container-style)} + [icon/icon :i/loading + {:size 12 + :color (colors/theme-colors colors/neutral-50 colors/neutral-40) + :container-style {:margin-right 8}}] [rn/text {:size :paragraph-2 :weight :medium @@ -60,6 +76,9 @@ {:accessibility-label :url-preview :style (merge (style/container) container-style)} (when logo - [logo-comp {:logo logo}]) + [logo-comp + {:logo (if (map? logo) + (:data-uri logo) + logo)}]) [content {:title title :body body}] [clear-button {:on-press on-clear}]])) diff --git a/src/quo/components/links/url_preview_list/view.cljs b/src/quo/components/links/url_preview_list/view.cljs index 1978d0fe972..eb668500526 100644 --- a/src/quo/components/links/url_preview_list/view.cljs +++ b/src/quo/components/links/url_preview_list/view.cljs @@ -32,7 +32,7 @@ [rn/view {:style style/url-preview-separator}]) (defn- item-component - [{:keys [title body loading? logo]} _ _ + [{:keys [title body loading? logo url]} _ _ {:keys [width on-clear loading-message container-style]}] [url-preview/view {:logo logo @@ -41,7 +41,8 @@ :loading? loading? :loading-message loading-message :on-clear on-clear - :container-style (merge container-style {:width width})}]) + :container-style (merge container-style {:width width}) + :url url}]) (defn- f-view [] diff --git a/src/status_im/common/biometric/events_test.cljs b/src/status_im/common/biometric/events_test.cljs index c83a7bea901..98574561206 100644 --- a/src/status_im/common/biometric/events_test.cljs +++ b/src/status_im/common/biometric/events_test.cljs @@ -1,5 +1,5 @@ (ns status-im.common.biometric.events-test - (:require [cljs.test :refer [deftest testing is]] + (:require [cljs.test :refer [deftest is testing]] matcher-combinators.test [status-im.common.biometric.events :as sut] [status-im.constants :as constants] diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index 975b8ded536..e6ef92c5a1a 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -467,3 +467,5 @@ (def ^:const bridge-name-erc-721-transfer "ERC721Transfer") (def ^:const alert-banner-height 40) + +(def ^:const status-hostname "status.app") diff --git a/src/status_im/contexts/chat/messenger/composer/events.cljs b/src/status_im/contexts/chat/messenger/composer/events.cljs index eb57dd99a37..164dd981edf 100644 --- a/src/status_im/contexts/chat/messenger/composer/events.cljs +++ b/src/status_im/contexts/chat/messenger/composer/events.cljs @@ -1,7 +1,7 @@ (ns status-im.contexts.chat.messenger.composer.events (:require [clojure.string :as string] [legacy.status-im.chat.models.mentions :as mentions] - [legacy.status-im.data-store.messages :as data-store-messages] + [legacy.status-im.data-store.messages :as data-store.messages] [status-im.constants :as constants] [status-im.contexts.chat.messenger.composer.link-preview.events :as link-preview] [status-im.contexts.chat.messenger.messages.transport.events :as messages.transport] @@ -132,6 +132,37 @@ :response-to message-id}) images))) +(defn- build-status-link-previews + [status-link-previews] + (map (fn [{{:keys [community-id color description display-name + members-count active-members-count icon banner]} + :community + url :url}] + {:url url + :community + {:community-id community-id + :color color + :description description + :display-name display-name + :members-count members-count + :active-members-count active-members-count + :icon {:data-uri (:data-uri icon) + :width (:width icon) + :height (:height icon)} + :banner {:data-uri (:data-uri banner) + :width (:width banner) + :height (:height banner)}}}) + status-link-previews)) + +(defn- build-link-previews + [link-previews] + (->> link-previews + (map #(select-keys % + [:url :title :description :thumbnail + :status-link-preview? :favicon])) + (filter (fn [{:keys [status-link-preview?]}] + (not status-link-preview?))))) + (defn build-text-message [{:keys [db]} input-text current-chat-id] (when-not (string/blank? input-text) @@ -140,15 +171,16 @@ preferred-name (get-in db [:profile/profile :preferred-name]) emoji? (emoji-only-content? {:text input-text :response-to message-id})] - {:chat-id current-chat-id - :content-type (if emoji? - constants/content-type-emoji - constants/content-type-text) - :text input-text - :response-to message-id - :ens-name preferred-name - :link-previews (map #(select-keys % [:url :title :description :thumbnail]) - (get-in db [:chat/link-previews :unfurled]))}))) + {:chat-id current-chat-id + :content-type (if emoji? + constants/content-type-emoji + constants/content-type-text) + :text input-text + :response-to message-id + :ens-name preferred-name + :link-previews (build-link-previews (get-in db [:chat/link-previews :unfurled])) + :status-link-previews (build-status-link-previews + (get-in db [:chat/status-link-previews :unfurled]))}))) (rf/defn send-messages [{:keys [db] :as cofx} input-text current-chat-id] @@ -181,29 +213,41 @@ (when message-id {:response-to message-id}))]))))) +(defn- process-link-previews + [link-previews] + (->> link-previews + (map #(select-keys % + [:url :title :description :thumbnail + :status-link-preview? :favicon])) + (map data-store.messages/->link-preview-rpc) + (filter (fn [{:keys [status-link-preview?]}] + (not status-link-preview?))))) + (rf/defn send-edited-message [{:keys [db] :as cofx} text {:keys [message-id quoted-message chat-id]}] (rf/merge cofx - {:json-rpc/call [{:method "wakuext_editMessage" - :params [{:id message-id - :text text - :content-type (if (emoji-only-content? - {:text text - :response-to quoted-message}) - constants/content-type-emoji - constants/content-type-text) - :linkPreviews (map #(-> % - (select-keys [:url :title :description - :thumbnail]) - data-store-messages/->link-preview-rpc) - (get-in db [:chat/link-previews :unfurled]))}] - :js-response true - :on-error #(log/error "failed to edit message " %) - :on-success (fn [result] - (rf/dispatch [:sanitize-messages-and-process-response - result]))}]} + {:json-rpc/call + [{:method "wakuext_editMessage" + :params [{:id message-id + :text text + :content-type (if (emoji-only-content? + {:text text + :response-to quoted-message}) + constants/content-type-emoji + constants/content-type-text) + :linkPreviews (process-link-previews (get-in db + [:chat/link-previews :unfurled])) + :statusLinkPreviews (map data-store.messages/->status-link-previews-rpc + (get-in db + [:chat/status-link-previews + :unfurled]))}] + :js-response true + :on-error #(log/error "failed to edit message " %) + :on-success (fn [result] + (rf/dispatch [:sanitize-messages-and-process-response + result]))}]} (link-preview/reset-unfurled) (cancel-message-edit))) diff --git a/src/status_im/contexts/chat/messenger/composer/link_preview/events.cljs b/src/status_im/contexts/chat/messenger/composer/link_preview/events.cljs index 2c67867c6b0..8f3eb801f2e 100644 --- a/src/status_im/contexts/chat/messenger/composer/link_preview/events.cljs +++ b/src/status_im/contexts/chat/messenger/composer/link_preview/events.cljs @@ -80,24 +80,51 @@ [] curr-previews)) +(defn- merge-preview-types + [new-previews new-status-link-previews] + (-> (map + (fn [{{:keys [display-name members-count banner icon + description]} :community + url :url}] + ;; Other types of previews need to be done here too + ;; Like User link preview and Channel link preview + {:url url + :display-name display-name + :members-count members-count + :banner banner + :icon icon + :description description + ;; Need to set status-link-preview? + ;; to true to not send status-link-previews + ;; with normal link-previews + :status-link-preview? true}) + new-status-link-previews) + (concat new-previews))) + (rf/defn unfurl-parsed-urls-success {:events [:link-preview/unfurl-parsed-urls-success]} - [{:keys [db]} request-id {new-previews :linkPreviews}] + [{:keys [db]} request-id {new-previews :linkPreviews status-link-previews :statusLinkPreviews}] (when (= request-id (get-in db [:chat/link-previews :request-id])) - (let [new-previews (map data-store.messages/<-link-preview-rpc new-previews) - curr-previews (get-in db [:chat/link-previews :unfurled]) - indexed-new-previews (utils.collection/index-by :url new-previews)] + (let [new-previews (map data-store.messages/<-link-preview-rpc new-previews) + new-status-link-previews (map data-store.messages/<-status-link-previews-rpc + status-link-previews) + merged-preview-types (merge-preview-types new-previews new-status-link-previews) + curr-previews (get-in db [:chat/link-previews :unfurled]) + indexed-new-previews (utils.collection/index-by :url merged-preview-types)] (log/debug "URLs unfurled" + :chat/link-previews {:event :link-preview/unfurl-parsed-urls-success - :previews (map #(update % :thumbnail dissoc :data-uri) new-previews) + :previews (map #(update % :thumbnail dissoc :data-uri) merged-preview-types) :request-id request-id}) {:db (-> db + (assoc-in [:chat/status-link-previews :unfurled] new-status-link-previews) (update-in [:chat/link-previews :unfurled] reconcile-unfurled indexed-new-previews) (update-in [:chat/link-previews :cache] merge indexed-new-previews (utils.collection/index-by :url - (failed-previews curr-previews new-previews))))}))) + (failed-previews curr-previews + merged-preview-types))))}))) (rf/defn unfurl-parsed-urls-error {:events [:link-preview/unfurl-parsed-urls-error]} diff --git a/src/status_im/contexts/chat/messenger/composer/link_preview/events_test.cljs b/src/status_im/contexts/chat/messenger/composer/link_preview/events_test.cljs index a20aeeee067..1c09222311f 100644 --- a/src/status_im/contexts/chat/messenger/composer/link_preview/events_test.cljs +++ b/src/status_im/contexts/chat/messenger/composer/link_preview/events_test.cljs @@ -6,6 +6,8 @@ (def url-github "https://github.com") (def url-gitlab "https://gitlab.com") +(def url-community + "https://status.app/c/iyKACkQKB0Rvb2RsZXMSJ0NvbG9yaW5nIHRoZSB3b3JsZCB3aXRoIGpveSDigKIg4bSXIOKAohiYohsiByMxMzFEMkYqAwEhMwM=#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11") (def preview-github {:url url-github :thumbnail nil}) (def preview-gitlab {:url url-gitlab :thumbnail nil}) (def request-id "abc123") @@ -31,7 +33,15 @@ (is (match? {:json-rpc/call [{:method "wakuext_getTextURLs" :params [url-github]}]} (remove-rpc-callbacks - (events/unfurl-urls cofx url-github))))))) + (events/unfurl-urls cofx url-github)))))) + (testing "fetches status community URLs" + (let [cofx {:db {:chat/link-previews {:unfurled {} + :cache {} + :request-id "123"}}}] + (is (match? {:json-rpc/call [{:method "wakuext_getTextURLs" + :params [url-community]}]} + (remove-rpc-callbacks + (events/unfurl-urls cofx url-community))))))) (deftest unfurl-parsed-urls-test (with-redefs [events/new-request-id (constantly request-id)] diff --git a/src/status_im/contexts/chat/messenger/composer/link_preview/view.cljs b/src/status_im/contexts/chat/messenger/composer/link_preview/view.cljs index 84c61a67542..f2cce2370ad 100644 --- a/src/status_im/contexts/chat/messenger/composer/link_preview/view.cljs +++ b/src/status_im/contexts/chat/messenger/composer/link_preview/view.cljs @@ -1,8 +1,11 @@ (ns status-im.contexts.chat.messenger.composer.link-preview.view (:require + [clojure.string :as string] [quo.core :as quo] [react-native.core :as rn] [react-native.reanimated :as reanimated] + [status-im.common.resources :as resources] + [status-im.constants] [status-im.contexts.chat.messenger.composer.constants :as constants] [status-im.contexts.chat.messenger.composer.link-preview.events] [status-im.contexts.chat.messenger.composer.link-preview.style :as style] @@ -33,13 +36,18 @@ :horizontal-spacing style/padding-horizontal :loading-message (i18n/label :t/link-preview-loading-message) :on-clear #(rf/dispatch [:link-preview/clear]) - :data (map (fn [{:keys [title thumbnail hostname loading? url]}] - {:title title - :body hostname - :loading? loading? - :thumbnail (:data-uri thumbnail) - :url url}) - previews)}]])) + :data (map + (fn [{:keys [title display-name thumbnail hostname loading? url favicon]}] + {:title (or display-name title) + :body (or (when-not display-name hostname) + status-im.constants/status-hostname) + :logo (if (string/starts-with? url "https://status.app") + (resources/get-mock-image :status-logo) + favicon) + :loading? loading? + :thumbnail (:data-uri thumbnail) + :url url}) + previews)}]])) (defn view [] diff --git a/src/status_im/contexts/chat/messenger/messages/content/link_preview/view.cljs b/src/status_im/contexts/chat/messenger/messages/content/link_preview/view.cljs index e4397dc8d67..74e98feccc4 100644 --- a/src/status_im/contexts/chat/messenger/messages/content/link_preview/view.cljs +++ b/src/status_im/contexts/chat/messenger/messages/content/link_preview/view.cljs @@ -16,12 +16,13 @@ (let [previews (rf/sub [:chats/message-link-previews chat-id message-id])] (when (seq previews) [:<> - (for [{:keys [url title description thumbnail hostname]} previews] + (for [{:keys [url title description thumbnail hostname favicon]} previews] ^{:key url} [quo/link-preview {:title title :description description :link hostname + :logo (:url favicon) :thumbnail (:url thumbnail) :thumbnail-size (when (nearly-square? thumbnail) :large) :container-style {:margin-top 8}}])]))) diff --git a/src/status_im/contexts/chat/messenger/messages/content/status_link_preview/view.cljs b/src/status_im/contexts/chat/messenger/messages/content/status_link_preview/view.cljs new file mode 100644 index 00000000000..9b70190e232 --- /dev/null +++ b/src/status_im/contexts/chat/messenger/messages/content/status_link_preview/view.cljs @@ -0,0 +1,28 @@ +(ns status-im.contexts.chat.messenger.messages.content.status-link-preview.view + (:require [quo.core :as quo] + [react-native.core :as rn] + [utils.re-frame :as rf])) + +(defn view + [{:keys [chat-id message-id]}] + (let [status-link-previews (rf/sub [:chats/message-status-link-previews chat-id message-id]) + link-previews? (rf/sub [:chats/message-link-previews? chat-id message-id])] + (when (seq status-link-previews) + [rn/view {:style {:margin-top (when link-previews? 8)}} + (for [{:keys [url community]} status-link-previews] + (when community + (let [{community-description :description + community-icon :icon + community-banner :banner + community-name :display-name + members-count :members-count} community] + ^{:key url} + [quo/internal-link-card + {:type :community + :size :message + :description community-description + :members-count members-count + :title community-name + :banner (:url community-banner) + :icon (:url community-icon) + :on-press #(rf/dispatch [:universal-links/handle-url url])}])))]))) diff --git a/src/status_im/contexts/chat/messenger/messages/content/text/view.cljs b/src/status_im/contexts/chat/messenger/messages/content/text/view.cljs index fe154959d01..acfe39e74d4 100644 --- a/src/status_im/contexts/chat/messenger/messages/content/text/view.cljs +++ b/src/status_im/contexts/chat/messenger/messages/content/text/view.cljs @@ -5,6 +5,7 @@ [react-native.core :as rn] [react-native.platform :as platform] [status-im.contexts.chat.messenger.messages.content.link-preview.view :as link-preview] + [status-im.contexts.chat.messenger.messages.content.status-link-preview.view :as status-link-preview] [status-im.contexts.chat.messenger.messages.content.text.style :as style] [utils.i18n :as i18n] [utils.re-frame :as rf])) @@ -165,4 +166,5 @@ [message-data] [:<> [render-parsed-text message-data] - [link-preview/view message-data]]) + [link-preview/view message-data] + [status-link-preview/view message-data]]) diff --git a/src/status_im/contexts/chat/messenger/messages/transport/events.cljs b/src/status_im/contexts/chat/messenger/messages/transport/events.cljs index ec2e555ad4e..5eb56e47884 100644 --- a/src/status_im/contexts/chat/messenger/messages/transport/events.cljs +++ b/src/status_im/contexts/chat/messenger/messages/transport/events.cljs @@ -8,6 +8,7 @@ [legacy.status-im.data-store.chats :as data-store.chats] [legacy.status-im.data-store.communities :as data-store.communities] [legacy.status-im.data-store.invitations :as data-store.invitations] + [legacy.status-im.data-store.messages :as data-store.messages] [legacy.status-im.group-chats.core :as models.group] [legacy.status-im.multiaccounts.update.core :as update.core] [legacy.status-im.pairing.core :as models.pairing] @@ -356,32 +357,35 @@ (conj set-hash-fxs #(sanitize-messages-and-process-response % response-js false))))) +(defn- image->rpc [image] (set/rename-keys image {:data-uri :dataUri})) + (defn- link-preview->rpc [preview] - (update preview - :thumbnail - (fn [thumbnail] - (set/rename-keys thumbnail {:data-uri :dataUri})))) + (-> preview + (update :thumbnail image->rpc) + (update :favicon image->rpc))) (defn build-message [msg] (-> msg (update :link-previews #(map link-preview->rpc %)) + (update :status-link-previews #(set (map data-store.messages/->status-link-previews-rpc %))) (set/rename-keys - {:album-id :albumId - :audio-duration-ms :audioDurationMs - :audio-path :audioPath - :chat-id :chatId - :community-id :communityId - :content-type :contentType - :ens-name :ensName - :image-height :imageHeight - :image-path :imagePath - :image-width :imageWidth - :link-previews :linkPreviews - :response-to :responseTo - :sticker :sticker - :text :text}))) + {:album-id :albumId + :audio-duration-ms :audioDurationMs + :audio-path :audioPath + :chat-id :chatId + :community-id :communityId + :content-type :contentType + :ens-name :ensName + :image-height :imageHeight + :image-path :imagePath + :image-width :imageWidth + :link-previews :linkPreviews + :status-link-previews :statusLinkPreviews + :response-to :responseTo + :sticker :sticker + :text :text}))) (rf/defn send-chat-messages [_ messages] diff --git a/src/status_im/subs/chats.cljs b/src/status_im/subs/chats.cljs index 3dd2243a900..c864c3f02e3 100644 --- a/src/status_im/subs/chats.cljs +++ b/src/status_im/subs/chats.cljs @@ -423,11 +423,19 @@ (fn [previews] (get previews :unfurled))) +(re-frame/reg-sub + :chats/status-link-previews-unfurled + :<- [:chat/status-link-previews] + (fn [previews] + (:unfurled previews))) + (re-frame/reg-sub :chats/link-previews? :<- [:chats/link-previews-unfurled] - (fn [previews] - (boolean (seq previews)))) + :<- [:chats/status-link-previews-unfurled] + (fn [previews status-link-previews] + (boolean (or (seq status-link-previews) + (seq previews))))) (re-frame/reg-sub :chat/check-channel-muted? diff --git a/src/status_im/subs/messages.cljs b/src/status_im/subs/messages.cljs index 2283f920958..f06d7352673 100644 --- a/src/status_im/subs/messages.cljs +++ b/src/status_im/subs/messages.cljs @@ -102,6 +102,21 @@ (fn [messages [_ chat-id message-id]] (get-in messages [chat-id message-id :link-previews]))) +(re-frame/reg-sub + :chats/message-link-previews? + :<- [:messages/messages] + (fn [messages [_ chat-id message-id]] + (-> messages + (get-in [chat-id message-id :link-previews]) + count + pos?))) + +(re-frame/reg-sub + :chats/message-status-link-previews + :<- [:messages/messages] + (fn [messages [_ chat-id message-id]] + (get-in messages [chat-id message-id :status-link-previews]))) + (re-frame/reg-sub :chats/pinned :<- [:messages/pin-messages] diff --git a/src/status_im/subs/messages_test.cljs b/src/status_im/subs/messages_test.cljs index 5b7c4234922..29bc798f96c 100644 --- a/src/status_im/subs/messages_test.cljs +++ b/src/status_im/subs/messages_test.cljs @@ -159,3 +159,19 @@ :pinned-at nil :pinned-by :test-user}] (rf/sub [sub-name :0xChat]))))) + +(def message-with-link-previews + {:0xChat {:0x01 {:content {:response-to nil} + :quoted-message nil + :message-id "0x1" + :from :xyz + :timestamp-str "14:00" + :content-type constants/content-type-text + :chat-id :0xChat + :link-previews [{:dummy-link-preview 1}]}}}) + +(h/deftest-sub :chats/message-link-previews? + [sub-name] + (testing "It returns true if link previews exists in a message" + (swap! rf-db/app-db assoc :messages message-with-link-previews) + (is (rf/sub [sub-name :0xChat :0x01])))) diff --git a/src/tests/integration_test/standard_auth_test.cljs b/src/tests/integration_test/standard_auth_test.cljs index 31b289777f6..23d55997077 100644 --- a/src/tests/integration_test/standard_auth_test.cljs +++ b/src/tests/integration_test/standard_auth_test.cljs @@ -1,6 +1,6 @@ (ns tests.integration-test.standard-auth-test (:require - [cljs.test :refer [deftest testing is]] + [cljs.test :refer [deftest is testing]] [day8.re-frame.test :as rf-test] re-frame.core [test-helpers.integration :as h] diff --git a/status-go-version.json b/status-go-version.json index 6b3cea54268..c619dd4bc8f 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -3,7 +3,7 @@ "_comment": "Instead use: scripts/update-status-go.sh ", "owner": "status-im", "repo": "status-go", - "version": "v0.176.6", - "commit-sha1": "200d5f054096518848adabca82d56105af97086f", - "src-sha256": "02c04j7dd29wd0sxbk97yfwq8gj3hwjvlrj07b188cqkq08p920f" + "version": "v0.176.8", + "commit-sha1": "8c0e24dc260031a822604f7a2771f22daea79aa4", + "src-sha256": "1c6r5gizcvixawl1c0lxd022wg54m5qxw8rr1q1i9221pzbfmmsl" }