Don't make inability to unfurl url a user's problem

Signed-off-by: Volodymyr Kozieiev <vkjr.sp@gmail.com>
This commit is contained in:
Volodymyr Kozieiev 2020-11-12 16:17:22 +02:00
parent 61105e15f6
commit a91bdfb047
No known key found for this signature in database
GPG Key ID: 82B04968DF4C0535
2 changed files with 25 additions and 24 deletions

View File

@ -23,16 +23,17 @@
{::json-rpc/call [{:method (json-rpc/call-ext-method "getLinkPreviewData") {::json-rpc/call [{:method (json-rpc/call-ext-method "getLinkPreviewData")
:params [link] :params [link]
:on-success #(re-frame/dispatch [::cache-link-preview-data link %]) :on-success #(re-frame/dispatch [::cache-link-preview-data link %])
:on-error #(log/error "Can't get preview data for " link)}]})) :on-error #(re-frame/dispatch [::cache-link-preview-data
link
{:error (str "Can't get preview data for " link)}])}]}))
(fx/defn cache-link-preview-data (fx/defn cache-link-preview-data
{:events [::cache-link-preview-data]} {:events [::cache-link-preview-data]}
[{{:keys [multiaccount]} :db :as cofx} site {:keys [error] :as data}] [{{:keys [multiaccount]} :db :as cofx} site data]
(when-not error
(multiaccounts.update/optimistic (multiaccounts.update/optimistic
cofx cofx
:link-previews-cache :link-previews-cache
(assoc (get multiaccount :link-previews-cache {}) site data)))) (assoc (get multiaccount :link-previews-cache {}) site data)))
(fx/defn should-suggest-link-preview (fx/defn should-suggest-link-preview
{:events [::should-suggest-link-preview]} {:events [::should-suggest-link-preview]}

View File

@ -59,13 +59,13 @@
(defview link-preview-loader [link outgoing] (defview link-preview-loader [link outgoing]
(letsubs [cache [:link-preview/cache]] (letsubs [cache [:link-preview/cache]]
(let [{:keys [site title thumbnailUrl] :as preview-data} (get cache link)] (let [{:keys [site title thumbnailUrl error] :as preview-data} (get cache link)]
(if (not preview-data) (if (not preview-data)
(do (do
(re-frame/dispatch (re-frame/dispatch
[::link-preview/load-link-preview-data link]) [::link-preview/load-link-preview-data link])
nil) nil)
(when-not error
[react/touchable-highlight [react/touchable-highlight
{:on-press #(when (and (security/safe-link? link)) {:on-press #(when (and (security/safe-link? link))
(re-frame/dispatch (re-frame/dispatch
@ -81,7 +81,7 @@
[quo/text {:size :small [quo/text {:size :small
:color :secondary :color :secondary
:style styles/link-preview-site} :style styles/link-preview-site}
site]]])))) site]]])))))
(defview link-preview-wrapper [links outgoing] (defview link-preview-wrapper [links outgoing]
(letsubs (letsubs