From 2932bbea85a2e8a02448359d916669879b6c4a4e Mon Sep 17 00:00:00 2001 From: flexsurfer Date: Tue, 13 Jun 2023 18:21:33 +0200 Subject: [PATCH] =?UTF-8?q?[#15836]=20Images=20not=20displayed=20in=20chat?= =?UTF-8?q?=20when=20received=20by=20user=20with=20app=20=E2=80=A6=20(#162?= =?UTF-8?q?56)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/status_im/utils/http.cljs | 6 ++- .../chat/lightbox/zoomable_image/view.cljs | 5 +- .../chat/messages/content/album/view.cljs | 6 ++- .../chat/messages/content/audio/view.cljs | 50 ++++++++++--------- .../chat/messages/content/image/view.cljs | 8 +-- 5 files changed, 43 insertions(+), 32 deletions(-) diff --git a/src/status_im/utils/http.cljs b/src/status_im/utils/http.cljs index ac429ce598..e299114991 100644 --- a/src/status_im/utils/http.cljs +++ b/src/status_im/utils/http.cljs @@ -188,4 +188,8 @@ (defn topic-from-url [url] - (string/lower-case (apply str (map filter-letters-numbers-and-replace-dot-on-dash (url-host url))))) \ No newline at end of file + (string/lower-case (apply str (map filter-letters-numbers-and-replace-dot-on-dash (url-host url))))) + +(defn replace-port + [url new-port] + (string/replace url #"(:\d+)" (str ":" new-port))) diff --git a/src/status_im2/contexts/chat/lightbox/zoomable_image/view.cljs b/src/status_im2/contexts/chat/lightbox/zoomable_image/view.cljs index e492b55e54..705466ce93 100644 --- a/src/status_im2/contexts/chat/lightbox/zoomable_image/view.cljs +++ b/src/status_im2/contexts/chat/lightbox/zoomable_image/view.cljs @@ -10,7 +10,8 @@ [status-im2.contexts.chat.lightbox.animations :as anim] [status-im2.contexts.chat.lightbox.zoomable-image.constants :as c] [status-im2.contexts.chat.lightbox.zoomable-image.style :as style] - [status-im2.contexts.chat.lightbox.zoomable-image.utils :as utils])) + [status-im2.contexts.chat.lightbox.zoomable-image.utils :as utils] + [status-im.utils.http :as http])) (defn tap-gesture [on-tap] @@ -223,7 +224,7 @@ @set-full-height? (= curr-orientation orientation/portrait))} [reanimated/fast-image - {:source {:uri (:image content)} + {:source {:uri (http/replace-port (:image content) (rf/sub [:mediaserver/port]))} :native-ID (when focused? :shared-element) :style (style/image dimensions animations (:border-value render-data))}]]])) diff --git a/src/status_im2/contexts/chat/messages/content/album/view.cljs b/src/status_im2/contexts/chat/messages/content/album/view.cljs index 997a96a301..f4799644da 100644 --- a/src/status_im2/contexts/chat/messages/content/album/view.cljs +++ b/src/status_im2/contexts/chat/messages/content/album/view.cljs @@ -7,7 +7,8 @@ [status-im2.constants :as constants] [status-im2.contexts.chat.messages.content.image.view :as image] [status-im2.contexts.chat.messages.content.text.view :as text] - [utils.re-frame :as rf])) + [utils.re-frame :as rf] + [status-im.utils.http :as http])) (def rectangular-style-count 3) @@ -54,7 +55,8 @@ :index index}])} [fast-image/fast-image {:style (style/image dimensions index portrait? images-count) - :source {:uri (:image (:content item))} + :source {:uri (http/replace-port (:image (:content item)) + (rf/sub [:mediaserver/port]))} :native-ID (when (and (= shared-element-id (:message-id item)) (< index constants/max-album-photos)) :shared-element)}] diff --git a/src/status_im2/contexts/chat/messages/content/audio/view.cljs b/src/status_im2/contexts/chat/messages/content/audio/view.cljs index 5c9f9c381f..a337c94b39 100644 --- a/src/status_im2/contexts/chat/messages/content/audio/view.cljs +++ b/src/status_im2/contexts/chat/messages/content/audio/view.cljs @@ -78,16 +78,15 @@ (defn play-pause-player [{:keys [player-key player-state progress message-id audio-duration-ms seeking-audio? - user-interaction?] + user-interaction? mediaserver-port] :as params}] - (let [mediaserver-port (rf/sub [:mediaserver/port]) - audio-uri (str media-server-uri-prefix - mediaserver-port - audio-path - uri-param - message-id) - player (@active-players player-key) - playing? (= @player-state :playing)] + (let [audio-uri (str media-server-uri-prefix + mediaserver-port + audio-path + uri-param + message-id) + player (@active-players player-key) + playing? (= @player-state :playing)] (when-not playing? (reset! current-player-key player-key)) (if (and player @@ -134,18 +133,19 @@ (defn f-audio-message [player-state progress seeking-audio? {:keys [audio-duration-ms message-id]} {:keys [in-pinned-view?]}] - (let [player-key (get-player-key message-id in-pinned-view?) - player (@active-players player-key) - duration (if (and player (not (#{:preparing :not-loaded :error} @player-state))) - (audio/get-player-duration player) - audio-duration-ms) - time-secs (quot - (if (or @seeking-audio? (#{:playing :seeking} @player-state)) - (if (<= @progress 1) (* duration @progress) @progress) - duration) - 1000) - paused? (= (audio/get-state player) audio/PAUSED) - app-state (rf/sub [:app-state])] + (let [player-key (get-player-key message-id in-pinned-view?) + player (@active-players player-key) + duration (if (and player (not (#{:preparing :not-loaded :error} @player-state))) + (audio/get-player-duration player) + audio-duration-ms) + time-secs (quot + (if (or @seeking-audio? (#{:playing :seeking} @player-state)) + (if (<= @progress 1) (* duration @progress) @progress) + duration) + 1000) + paused? (= (audio/get-state player) audio/PAUSED) + app-state (rf/sub [:app-state]) + mediaserver-port (rf/sub [:mediaserver/port])] (rn/use-effect (fn [] #(destroy-player player-key))) (rn/use-effect (fn [] @@ -163,8 +163,9 @@ :message-id message-id :audio-duration-ms duration :seeking-audio? seeking-audio? - :user-interaction? false}))) - [@current-player-key app-state]) + :user-interaction? false + :mediaserver-port mediaserver-port}))) + [@current-player-key app-state mediaserver-port]) (if (= @player-state :error) [quo/text {:style style/error-label @@ -183,7 +184,8 @@ :message-id message-id :audio-duration-ms duration :seeking-audio? seeking-audio? - :user-interaction? true}) + :user-interaction? true + :mediaserver-port mediaserver-port}) :style (style/play-pause-container)} [quo/icon (cond diff --git a/src/status_im2/contexts/chat/messages/content/image/view.cljs b/src/status_im2/contexts/chat/messages/content/image/view.cljs index 097165b83c..b5504bc981 100644 --- a/src/status_im2/contexts/chat/messages/content/image/view.cljs +++ b/src/status_im2/contexts/chat/messages/content/image/view.cljs @@ -5,7 +5,8 @@ [react-native.safe-area :as safe-area] [status-im2.constants :as constants] [utils.re-frame :as rf] - [status-im2.contexts.chat.messages.content.text.view :as text])) + [status-im2.contexts.chat.messages.content.text.view :as text] + [status-im.utils.http :as http])) (defn calculate-dimensions [width height] @@ -17,7 +18,8 @@ [index {:keys [content image-width image-height message-id] :as message} on-long-press] (let [insets (safe-area/get-insets) dimensions (calculate-dimensions (or image-width 1000) (or image-height 1000)) - shared-element-id (rf/sub [:shared-element-id])] + shared-element-id (rf/sub [:shared-element-id]) + image-local-url (http/replace-port (:image content) (rf/sub [:mediaserver/port]))] [:<> (when (= index 0) [rn/view {:style {:margin-bottom 10}} [text/text-content message]]) @@ -31,7 +33,7 @@ :index 0 :insets insets}])} [fast-image/fast-image - {:source {:uri (:image content)} + {:source {:uri image-local-url} :style (merge dimensions {:border-radius 12}) :native-ID (when (= shared-element-id message-id) :shared-element) :accessibility-label :image-message}]]]))