diff --git a/src/status_im/common/signals/events.cljs b/src/status_im/common/signals/events.cljs index faab98945a..7bb94aa3b8 100644 --- a/src/status_im/common/signals/events.cljs +++ b/src/status_im/common/signals/events.cljs @@ -4,7 +4,6 @@ [legacy.status-im.visibility-status-updates.core :as visibility-status-updates] [oops.core :as oops] [status-im.common.pairing.events :as pairing] - [status-im.contexts.chat.messenger.messages.link-preview.events :as link-preview] [status-im.contexts.chat.messenger.messages.transport.events :as messages.transport] [status-im.contexts.communities.discover.events] [status-im.contexts.profile.push-notifications.local.events :as local-notifications] @@ -73,10 +72,7 @@ "community.found" (let [community (transforms/js->clj event-js)] - {:fx [[:dispatch - [:chat.ui/cache-link-preview-data (link-preview/community-link (:id community)) - community]] - [:dispatch [:discover-community/maybe-found-unknown-contract-community community]]]}) + {:fx [[:dispatch [:discover-community/maybe-found-unknown-contract-community community]]]}) "status.updates.timedout" (visibility-status-updates/handle-visibility-status-updates cofx (transforms/js->clj event-js)) diff --git a/src/status_im/contexts/chat/messenger/messages/link_preview/events.cljs b/src/status_im/contexts/chat/messenger/messages/link_preview/events.cljs deleted file mode 100644 index f75d4a7172..0000000000 --- a/src/status_im/contexts/chat/messenger/messages/link_preview/events.cljs +++ /dev/null @@ -1,48 +0,0 @@ -(ns status-im.contexts.chat.messenger.messages.link-preview.events - (:require [camel-snake-kebab.core :as csk] - [utils.collection] - [utils.re-frame :as rf])) - -(defn community-link - [id] - (str "https://status.app/c#" id)) - -(rf/reg-event-fx :chat.ui/cache-link-preview-data - (fn [{:keys [db]} [site data]] - (let [{:profile/keys [profile]} db - link-previews-cache (-> profile - (get :link-previews-cache {}) - (assoc site - (utils.collection/map-keys csk/->kebab-case-keyword - data)))] - {:db (assoc-in db [:profile/profile :link-previews-cache] link-previews-cache)}))) - -(rf/reg-event-fx :chat.ui/load-link-preview-data - (fn [{{:profile/keys [profile]} :db} [link]] - (let [{:keys [error] :as cache-data} (get-in profile [:link-previews-cache link])] - (when (or (not cache-data) error) - {:fx [[:json-rpc/call - [{:method "wakuext_getLinkPreviewData" - :params [link] - :on-success [:chat.ui/cache-link-preview-data link] - :on-error [:chat.ui/cache-link-preview-data link - {:error (str "Can't get preview data for " link)}]}]]]})))) - -(rf/reg-event-fx :chat.ui/should-suggest-link-preview - (fn [_ [enabled?]] - {:fx [[:dispatch - [:profile.settings/profile-update :link-preview-request-enabled (boolean enabled?)]]]})) - -(rf/reg-event-fx :chat.ui/enable-link-previews - (fn [{{:profile/keys [profile]} :db} [site enabled?]] - (let [enabled-sites (if enabled? - (conj (get profile :link-previews-enabled-sites #{}) site) - (disj (get profile :link-previews-enabled-sites #{}) site))] - {:fx [[:dispatch [:profile.settings/profile-update :link-previews-enabled-sites enabled-sites]]]}))) - -(rf/reg-event-fx :chat.ui/enable-all-link-previews - (fn [_ [link-previews-whitelist enabled?]] - (let [enabled-sites (if enabled? - (into #{} (map :title link-previews-whitelist)) - #{})] - {:fx [[:dispatch [:profile.settings/profile-update :link-previews-enabled-sites enabled-sites]]]}))) diff --git a/src/status_im/contexts/communities/events.cljs b/src/status_im/contexts/communities/events.cljs index ad7abf6221..78ff57f5bd 100644 --- a/src/status_im/contexts/communities/events.cljs +++ b/src/status_im/contexts/communities/events.cljs @@ -5,7 +5,6 @@ [oops.core :as oops] [schema.core :as schema] [status-im.constants :as constants] - [status-im.contexts.chat.messenger.messages.link-preview.events :as link-preview.events] status-im.contexts.communities.actions.accounts-selection.events status-im.contexts.communities.actions.addresses-for-permissions.events status-im.contexts.communities.actions.airdrop-addresses.events @@ -228,10 +227,7 @@ (when community-js {:db (update db :communities/fetching-communities dissoc community-id) :fx [[:dispatch [:communities/handle-community community-js]] - [:dispatch [:chat.ui/spectate-community community-id]] - [:dispatch - [:chat.ui/cache-link-preview-data (link-preview.events/community-link community-id) - (data-store.communities/<-rpc community-js)]]]})) + [:dispatch [:chat.ui/spectate-community community-id]]]})) (rf/reg-event-fx :chat.ui/community-fetched community-fetched) diff --git a/src/status_im/contexts/communities/events_test.cljs b/src/status_im/contexts/communities/events_test.cljs index 75a529f509..4edd637667 100644 --- a/src/status_im/contexts/communities/events_test.cljs +++ b/src/status_im/contexts/communities/events_test.cljs @@ -1,9 +1,8 @@ (ns status-im.contexts.communities.events-test - (:require [cljs.test :refer [deftest is testing]] - [legacy.status-im.data-store.communities :as data-store.communities] - matcher-combinators.test - [status-im.contexts.chat.messenger.messages.link-preview.events :as link-preview.events] - [status-im.contexts.communities.events :as events])) + (:require + [cljs.test :refer [deftest is testing]] + matcher-combinators.test + [status-im.contexts.communities.events :as events])) (def community-id "community-id") @@ -37,50 +36,40 @@ [:db :communities/fetching-communities community-id])))))) (deftest community-fetched-test - (with-redefs [link-preview.events/community-link (fn [id] (str "community-link+" id))] - (testing "given a community" - (let [cofx {:db {:communities/fetching-communities {community-id true}}} - arg [community-id {:id community-id}]] - (testing "remove community id from fetching indicator in db" - (is (match? - nil - (get-in (events/community-fetched cofx arg) - [:db :communities/fetching-communities community-id])))) - (testing "dispatch fxs" - (is (match? - {:fx [[:dispatch [:communities/handle-community {:id community-id}]] - [:dispatch [:chat.ui/spectate-community community-id]] - [:dispatch - [:chat.ui/cache-link-preview-data "community-link+community-id" - (data-store.communities/<-rpc #js {"id" community-id})]]]} - (events/community-fetched cofx arg)))))) - (testing "given a joined community" - (let [cofx {:db {:communities/fetching-communities {community-id true}}} - arg [community-id {:id community-id :joined true}]] - (testing "dispatch fxs, do not spectate community" - (is (match? - {:fx [[:dispatch [:communities/handle-community {:id community-id}]] - [:dispatch [:chat.ui/spectate-community community-id]] - [:dispatch - [:chat.ui/cache-link-preview-data "community-link+community-id" - (data-store.communities/<-rpc #js {"id" community-id})]]]} - (events/community-fetched cofx arg)))))) - (testing "given a token-gated community" - (let [cofx {:db {:communities/fetching-communities {community-id true}}} - arg [community-id {:id community-id :tokenPermissions [1]}]] - (testing "dispatch fxs, do not spectate community" - (is (match? - {:fx [[:dispatch [:communities/handle-community {:id community-id}]] - [:dispatch [:chat.ui/spectate-community community-id]] - [:dispatch - [:chat.ui/cache-link-preview-data "community-link+community-id" - (data-store.communities/<-rpc #js {"id" community-id})]]]} - (events/community-fetched cofx arg)))))) - (testing "given nil community" - (testing "do nothing" + (testing "given a community" + (let [cofx {:db {:communities/fetching-communities {community-id true}}} + arg [community-id {:id community-id}]] + (testing "remove community id from fetching indicator in db" (is (match? nil - (events/community-fetched {} [community-id nil]))))))) + (get-in (events/community-fetched cofx arg) + [:db :communities/fetching-communities community-id])))) + (testing "dispatch fxs" + (is (match? + {:fx [[:dispatch [:communities/handle-community {:id community-id}]] + [:dispatch [:chat.ui/spectate-community community-id]]]} + (events/community-fetched cofx arg)))))) + (testing "given a joined community" + (let [cofx {:db {:communities/fetching-communities {community-id true}}} + arg [community-id {:id community-id :joined true}]] + (testing "dispatch fxs, do not spectate community" + (is (match? + {:fx [[:dispatch [:communities/handle-community {:id community-id}]] + [:dispatch [:chat.ui/spectate-community community-id]]]} + (events/community-fetched cofx arg)))))) + (testing "given a token-gated community" + (let [cofx {:db {:communities/fetching-communities {community-id true}}} + arg [community-id {:id community-id :tokenPermissions [1]}]] + (testing "dispatch fxs, do not spectate community" + (is (match? + {:fx [[:dispatch [:communities/handle-community {:id community-id}]] + [:dispatch [:chat.ui/spectate-community community-id]]]} + (events/community-fetched cofx arg)))))) + (testing "given nil community" + (testing "do nothing" + (is (match? + nil + (events/community-fetched {} [community-id nil])))))) (deftest spectate-community-test (testing "given a joined community" diff --git a/src/status_im/events.cljs b/src/status_im/events.cljs index c9b3094f2f..6146852fca 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -20,7 +20,6 @@ status-im.contexts.chat.events [status-im.contexts.chat.home.add-new-contact.events] status-im.contexts.chat.messenger.composer.events - status-im.contexts.chat.messenger.messages.link-preview.events status-im.contexts.chat.messenger.photo-selector.events status-im.contexts.communities.events status-im.contexts.communities.overview.events