Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(url-preview): Remove zombie code #21603

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/status_im/common/signals/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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))
Expand Down

This file was deleted.

6 changes: 1 addition & 5 deletions src/status_im/contexts/communities/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)]]]}))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line here can be quite expensive in large communities and, unfortunately, we were doing the full conversion using <-rpc twice, once here, and again inside the :communities/handle-community handler. Ouch!

[:dispatch [:chat.ui/spectate-community community-id]]]}))

(rf/reg-event-fx :chat.ui/community-fetched community-fetched)

Expand Down
83 changes: 36 additions & 47 deletions src/status_im/contexts/communities/events_test.cljs
Original file line number Diff line number Diff line change
@@ -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")

Expand Down Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion src/status_im/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down