[#14869] Options menu is hardly opened on longtap on messages containing image or links with enabled preview (#14908)

This commit is contained in:
flexsurfer 2023-01-26 17:12:26 +01:00 committed by GitHub
parent 48e5c5c0ec
commit 8b358ab7ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 36 additions and 28 deletions

View File

@ -58,6 +58,7 @@
status-im.wallet.custom-tokens.core status-im.wallet.custom-tokens.core
status-im2.contexts.activity-center.events status-im2.contexts.activity-center.events
status-im2.contexts.shell.events status-im2.contexts.shell.events
status-im.chat.models.gaps
[status-im2.navigation.events :as navigation])) [status-im2.navigation.events :as navigation]))
(re-frame/reg-fx (re-frame/reg-fx

View File

@ -471,15 +471,15 @@
(defn generate-gfycat (defn generate-gfycat
"Generate a 3 words random name based on the user public-key, synchronously" "Generate a 3 words random name based on the user public-key, synchronously"
[public-key] [public-key]
{:pre [(utils.db/valid-public-key? public-key)]}
(log/debug "[native-module] generate-gfycat") (log/debug "[native-module] generate-gfycat")
(.generateAlias ^js (status) public-key)) (when (utils.db/valid-public-key? public-key)
(.generateAlias ^js (status) public-key)))
(defn generate-gfycat-async (defn generate-gfycat-async
"Generate a 3 words random name based on the user public-key, asynchronously" "Generate a 3 words random name based on the user public-key, asynchronously"
[public-key callback] [public-key callback]
{:pre [(utils.db/valid-public-key? public-key)]} (when (utils.db/valid-public-key? public-key)
(.generateAliasAsync ^js (status) public-key callback)) (.generateAliasAsync ^js (status) public-key callback)))
(defn identicon (defn identicon
"Generate a icon based on a string, synchronously" "Generate a icon based on a string, synchronously"

View File

@ -42,7 +42,7 @@
{:width (second size-arr) :height (first size-arr) :album-style album-style})) {:width (second size-arr) :height (first size-arr) :album-style album-style}))
(defn album-message (defn album-message
[{:keys [albumize?] :as message}] [{:keys [albumize?] :as message} {:keys [on-long-press] :as context}]
(let [shared-element-id (rf/sub [:shared-element-id]) (let [shared-element-id (rf/sub [:shared-element-id])
first-image (first (:album message)) first-image (first (:album message))
album-style (if (> (:image-width first-image) (:image-height first-image)) album-style (if (> (:image-width first-image) (:image-height first-image))
@ -69,7 +69,8 @@
(rf/dispatch [:chat.ui/update-shared-element-id (:message-id item)]) (rf/dispatch [:chat.ui/update-shared-element-id (:message-id item)])
(js/setTimeout #(rf/dispatch [:chat.ui/navigate-to-horizontal-images (js/setTimeout #(rf/dispatch [:chat.ui/navigate-to-horizontal-images
(:album message) index]) (:album message) index])
100))} 100))
:on-long-press on-long-press}
[rn/image [rn/image
{:style (merge {:style (merge
(style/image dimensions index) (style/image dimensions index)
@ -90,10 +91,10 @@
:size :heading-2 :size :heading-2
:style {:color colors/white}} :style {:color colors/white}}
(str "+" (- images-count (dec max-display-count)))]])])) (str "+" (- images-count (dec max-display-count)))]])]))
(:album message)) (:album message))]
]
[:<> [:<>
(map-indexed (map-indexed
(fn [index item] (fn [index item]
[image/image-message index item]) [image/image-message index item context])
(:album message))]))) (:album message))])))

View File

@ -15,7 +15,7 @@
{:width calculated-width :height calculated-height})))) {:width calculated-width :height calculated-height}))))
(defn image-message (defn image-message
[index {:keys [content image-width image-height message-id] :as message}] [index {:keys [content image-width image-height message-id] :as message} {:keys [on-long-press]}]
(let [dimensions (calculate-dimensions (or image-width 1000) (or image-height 1000)) (let [dimensions (calculate-dimensions (or image-width 1000) (or image-height 1000))
text (:text content)] text (:text content)]
(fn [] (fn []
@ -27,7 +27,8 @@
(rf/dispatch [:chat.ui/update-shared-element-id message-id]) (rf/dispatch [:chat.ui/update-shared-element-id message-id])
(js/setTimeout #(rf/dispatch [:chat.ui/navigate-to-horizontal-images (js/setTimeout #(rf/dispatch [:chat.ui/navigate-to-horizontal-images
[message] 0]) [message] 0])
100))} 100))
:on-long-press on-long-press}
;; This text comp is temporary. Should later use ;; This text comp is temporary. Should later use
;; `status-im2.contexts.chat.messages.content.text.view` ;; `status-im2.contexts.chat.messages.content.text.view`
(when (and (not= text "placeholder") (= index 0)) [rn/text text]) (when (and (not= text "placeholder") (= index 0)) [rn/text text])

View File

@ -5,7 +5,7 @@
[status-im2.contexts.chat.messages.link-preview.view :as link-preview])) [status-im2.contexts.chat.messages.link-preview.view :as link-preview]))
(defn text-content (defn text-content
[message-data] [message-data context]
[rn/view [rn/view
[old-message/render-parsed-text message-data] [old-message/render-parsed-text message-data]
[link-preview/link-preview message-data]]) [link-preview/link-preview message-data context]])

View File

@ -66,16 +66,20 @@
constants/content-type-contact-request [not-implemented/not-implemented constants/content-type-contact-request [not-implemented/not-implemented
[old-message/system-contact-request message-data]]))) [old-message/system-contact-request message-data]])))
(defn message-on-long-press
[message-data context]
(rf/dispatch [:bottom-sheet/show-sheet
{:content (drawers/reactions-and-actions message-data context)}]))
(defn user-message-content (defn user-message-content
[{:keys [content-type quoted-message content] :as message-data} [{:keys [content-type quoted-message content] :as message-data}
{:keys [chat-id] :as context}] {:keys [chat-id] :as context}]
(let [response-to (:response-to content)] (let [context (assoc context :on-long-press #(message-on-long-press message-data context))
response-to (:response-to content)]
[rn/touchable-highlight [rn/touchable-highlight
{:underlay-color (colors/theme-colors colors/neutral-5 colors/neutral-90) {:underlay-color (colors/theme-colors colors/neutral-5 colors/neutral-90)
:style {:border-radius 16} :style {:border-radius 16}
:on-press #() :on-long-press #(message-on-long-press message-data context)}
:on-long-press #(rf/dispatch [:bottom-sheet/show-sheet
{:content (drawers/reactions-and-actions message-data context)}])}
[rn/view {:padding-vertical 8} [rn/view {:padding-vertical 8}
(when (and (seq response-to) quoted-message) (when (and (seq response-to) quoted-message)
[old-message/quoted-message {:message-id response-to :chat-id chat-id} quoted-message]) [old-message/quoted-message {:message-id response-to :chat-id chat-id} quoted-message])
@ -86,7 +90,7 @@
(case content-type (case content-type
constants/content-type-text [not-implemented/not-implemented constants/content-type-text [not-implemented/not-implemented
[content.text/text-content message-data]] [content.text/text-content message-data context]]
constants/content-type-emoji [not-implemented/not-implemented constants/content-type-emoji [not-implemented/not-implemented
[old-message/emoji message-data]] [old-message/emoji message-data]]
@ -94,12 +98,12 @@
constants/content-type-sticker [not-implemented/not-implemented constants/content-type-sticker [not-implemented/not-implemented
[old-message/sticker message-data]] [old-message/sticker message-data]]
constants/content-type-image [image/image-message 0 message-data] constants/content-type-image [image/image-message 0 message-data context]
constants/content-type-audio [not-implemented/not-implemented constants/content-type-audio [not-implemented/not-implemented
[old-message/audio message-data]] [old-message/audio message-data]]
constants/content-type-album [album/album-message message-data] constants/content-type-album [album/album-message message-data context]
[not-implemented/not-implemented [content.unknown/unknown-content message-data]]) [not-implemented/not-implemented [content.unknown/unknown-content message-data]])
[status/status message-data]]]]])) [status/status message-data]]]]]))

View File

@ -87,7 +87,7 @@
[community-preview cached-preview-data]))}))) [community-preview cached-preview-data]))})))
(defn link-preview-loader (defn link-preview-loader
[link] [link {:keys [on-long-press]}]
(reagent/create-class (reagent/create-class
{:component-did-mount {:component-did-mount
(fn [] (fn []
@ -101,7 +101,8 @@
{:style (when-not (is-gif? thumbnail-url) {:style (when-not (is-gif? thumbnail-url)
{:align-self :stretch}) {:align-self :stretch})
:on-press #(when (security/safe-link? link) :on-press #(when (security/safe-link? link)
(rf/dispatch [:browser.ui/message-link-pressed link]))} (rf/dispatch [:browser.ui/message-link-pressed link]))
:on-long-press on-long-press}
[rn/view (style/wrapper) [rn/view (style/wrapper)
(when-not (is-gif? thumbnail-url) (when-not (is-gif? thumbnail-url)
[:<> [:<>
@ -140,7 +141,7 @@
(i18n/label :t/dont-ask)]]) (i18n/label :t/dont-ask)]])
(defn link-preview (defn link-preview
[{:keys [content]}] [{:keys [content]} context]
(let [links (:links content) (let [links (:links content)
ask-user? (rf/sub [:link-preview/link-preview-request-enabled]) ask-user? (rf/sub [:link-preview/link-preview-request-enabled])
enabled-sites (rf/sub [:link-preview/enabled-sites]) enabled-sites (rf/sub [:link-preview/enabled-sites])
@ -154,5 +155,5 @@
link-whitelisted? (and link whitelisted?)] link-whitelisted? (and link whitelisted?)]
(cond (cond
community? [community-preview-loader link] community? [community-preview-loader link]
(and link-whitelisted? enabled?) [link-preview-loader link] (and link-whitelisted? enabled?) [link-preview-loader link context]
(and link-whitelisted? ask-user?) [link-preview-enable-request]))))) (and link-whitelisted? ask-user?) [link-preview-enable-request])))))