diff --git a/src/quo/components/links/link_preview/view.cljs b/src/quo/components/links/link_preview/view.cljs index a3993f0285..50c0d21cbb 100644 --- a/src/quo/components/links/link_preview/view.cljs +++ b/src/quo/components/links/link_preview/view.cljs @@ -1,9 +1,15 @@ (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] + [reagent.core :as reagent] + [taoensso.timbre :as log])) (defn- button-disabled [disabled-text on-enable] @@ -53,12 +59,26 @@ (defn- logo-comp [logo] - [rn/image - {:accessibility-label :logo - :source (if (string? logo) - {:uri logo} - logo) - :style style/logo}]) + (let [xml-data (reagent/atom nil) + is-svg? (reagent/atom nil) + on-success (fn [xml-string] + (reset! xml-data xml-string)) + _get-svg (-> (.config ReactNativeBlobUtil (clj->js {:trusty platform/ios?})) + (.fetch "GET" logo) + (.then #(do + (reset! is-svg? (= "image/svg" + (oops/oget % ["respInfo" "headers" "Content-Type"]))) + (on-success (oops/oget % "data")))) + (.catch #(log/error "could not fetch favicon " logo)))] + (fn [] + (if @is-svg? + [svg/svg-xml (merge style/logo {:xml @xml-data})] + [rn/image + {:accessibility-label :logo + :source (if (string? logo) + {:uri logo} + logo) + :style style/logo}])))) (defn view [{:keys [title logo description link thumbnail diff --git a/src/quo/components/links/url_preview/view.cljs b/src/quo/components/links/url_preview/view.cljs index 14377b9f3f..3aecb8a1d5 100644 --- a/src/quo/components/links/url_preview/view.cljs +++ b/src/quo/components/links/url_preview/view.cljs @@ -6,12 +6,15 @@ [quo.components.markdown.text :as text] [quo.foundations.colors :as colors] [react-native.core :as rn] - [react-native.svg :as svg])) + [react-native.svg :as svg] + [status-im.constants :as constants])) (defn- logo-comp [{:keys [logo]}] - (if (string/starts-with? logo " logo + (string/replace constants/base64-svg-prefix "") + js/atob)})] [rn/image {:accessibility-label :logo :source (if (string? logo) diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index 552f1010db..f35ecb2dfc 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -366,6 +366,8 @@ "We prefix our keys with 0xe701 prior to serialisation them" "0xe701") +(def base64-svg-prefix "data:image/svg;base64,") + (def ^:const theme-type-system 0) (def ^:const theme-type-light 1) (def ^:const theme-type-dark 2) diff --git a/src/status_im/contexts/chat/messenger/composer/events.cljs b/src/status_im/contexts/chat/messenger/composer/events.cljs index ab943135ae..18262f4a66 100644 --- a/src/status_im/contexts/chat/messenger/composer/events.cljs +++ b/src/status_im/contexts/chat/messenger/composer/events.cljs @@ -159,7 +159,7 @@ (->> link-previews (map #(select-keys % [:url :title :description :thumbnail - :status-link-preview?])) + :status-link-preview? :favicon])) (filter (fn [preview] (not (:status-link-preview? preview)))))) 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 e4397dc8d6..3a1cddbc2a 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 favicon :thumbnail (:url thumbnail) :thumbnail-size (when (nearly-square? thumbnail) :large) :container-style {:margin-top 8}}])]))) diff --git a/status-go-version.json b/status-go-version.json index 1496a18607..c583f89cf9 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -4,6 +4,6 @@ "owner": "status-im", "repo": "status-go", "version": "add-favicons-to-link-previews", - "commit-sha1": "55b2907a722f872dd21c42198a25be927a22e03d", - "src-sha256": "0ll52y37rvc3j6w3bdvfnhjw9sgfsp0m5wc26j428pb2xgipr6jd" + "commit-sha1": "b5d40d654f5eae3ad7cd6269a7a69a8e24415819", + "src-sha256": "1i9maz8dzfvjczlw0a66ch7112hiism4nrvb6z420rbxcjnk9pad" }