From 71398364a7688f92bad3030b83b931452071feef Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 15 Jul 2021 16:29:17 -0500 Subject: [PATCH] Remove account_counters reducer --- .../__tests__/accounts_counters-test.js | 37 --- app/soapbox/reducers/accounts.js | 4 - app/soapbox/reducers/accounts_counters.js | 254 ------------------ app/soapbox/reducers/index.js | 2 - app/soapbox/selectors/index.js | 6 +- app/soapbox/utils/accounts.js | 2 +- 6 files changed, 3 insertions(+), 302 deletions(-) delete mode 100644 app/soapbox/reducers/__tests__/accounts_counters-test.js delete mode 100644 app/soapbox/reducers/accounts_counters.js diff --git a/app/soapbox/reducers/__tests__/accounts_counters-test.js b/app/soapbox/reducers/__tests__/accounts_counters-test.js deleted file mode 100644 index e708e9deb..000000000 --- a/app/soapbox/reducers/__tests__/accounts_counters-test.js +++ /dev/null @@ -1,37 +0,0 @@ -import reducer from '../accounts_counters'; -import { Map as ImmutableMap } from 'immutable'; -// import { ACCOUNT_FOLLOW_SUCCESS, ACCOUNT_UNFOLLOW_SUCCESS } from 'soapbox/actions/accounts'; -// import relationship from 'soapbox/__fixtures__/relationship.json'; -// import accounts_counter_initial from 'soapbox/__fixtures__/accounts_counter_initial.json'; -// import accounts_counter_unfollow from 'soapbox/__fixtures__/accounts_counter_unfollow.json'; -// import accounts_counter_follow from 'soapbox/__fixtures__/accounts_counter_follow.json'; - - -describe('accounts_counters reducer', () => { - it('should return the initial state', () => { - expect(reducer(undefined, {})).toEqual(ImmutableMap()); - }); - - // it('should handle ACCOUNT_FOLLOW_SUCCESS', () => { - // const state = ImmutableList([accounts_counter_initial]); - // const action = { - // type: ACCOUNT_FOLLOW_SUCCESS, - // relationship: relationship, - // alreadyFollowing: false, - // }; - // expect(reducer(state, action)).toEqual( - // ImmutableList([ accounts_counter_follow ])); - // }); - // - // it('should handle ACCOUNT_UNFOLLOW_SUCCESS', () => { - // const state = ImmutableList([accounts_counter_initial]); - // const action = { - // type: ACCOUNT_UNFOLLOW_SUCCESS, - // relationship: relationship, - // alreadyFollowing: true, - // }; - // expect(reducer(state, action)).toEqual( - // ImmutableList([accounts_counter_unfollow])); - // }); - -}); diff --git a/app/soapbox/reducers/accounts.js b/app/soapbox/reducers/accounts.js index 855a430f2..b5a441ed6 100644 --- a/app/soapbox/reducers/accounts.js +++ b/app/soapbox/reducers/accounts.js @@ -156,10 +156,6 @@ const normalizeAccount = account => { account.moved = account.moved.id; } - delete account.followers_count; - delete account.following_count; - delete account.statuses_count; - account = normalizePleroma(account); return fromJS(account); diff --git a/app/soapbox/reducers/accounts_counters.js b/app/soapbox/reducers/accounts_counters.js deleted file mode 100644 index 2159034ec..000000000 --- a/app/soapbox/reducers/accounts_counters.js +++ /dev/null @@ -1,254 +0,0 @@ -import { - ACCOUNT_FETCH_SUCCESS, - FOLLOWERS_FETCH_SUCCESS, - FOLLOWERS_EXPAND_SUCCESS, - FOLLOWING_FETCH_SUCCESS, - FOLLOWING_EXPAND_SUCCESS, - FOLLOW_REQUESTS_FETCH_SUCCESS, - FOLLOW_REQUESTS_EXPAND_SUCCESS, - ACCOUNT_FOLLOW_SUCCESS, - ACCOUNT_UNFOLLOW_SUCCESS, -} from 'soapbox/actions/accounts'; -import { - VERIFY_CREDENTIALS_SUCCESS, -} from 'soapbox/actions/auth'; -import { - ME_FETCH_SUCCESS, - ME_PATCH_SUCCESS, -} from 'soapbox/actions/me'; -import { - BLOCKS_FETCH_SUCCESS, - BLOCKS_EXPAND_SUCCESS, -} from 'soapbox/actions/blocks'; -import { - MUTES_FETCH_SUCCESS, - MUTES_EXPAND_SUCCESS, -} from 'soapbox/actions/mutes'; -import { - COMPOSE_SUGGESTIONS_READY, -} from 'soapbox/actions/compose'; -import { - REBLOG_SUCCESS, - UNREBLOG_SUCCESS, - FAVOURITE_SUCCESS, - UNFAVOURITE_SUCCESS, - REBLOGS_FETCH_SUCCESS, - FAVOURITES_FETCH_SUCCESS, - BOOKMARK_SUCCESS, - UNBOOKMARK_SUCCESS, -} from 'soapbox/actions/interactions'; -import { - TIMELINE_REFRESH_SUCCESS, - TIMELINE_EXPAND_SUCCESS, -} from 'soapbox/actions/timelines'; -import { - STATUS_FETCH_SUCCESS, - CONTEXT_FETCH_SUCCESS, -} from 'soapbox/actions/statuses'; -import { SEARCH_FETCH_SUCCESS } from 'soapbox/actions/search'; -import { - CONVERSATIONS_FETCH_SUCCESS, - CONVERSATIONS_UPDATE, -} from 'soapbox/actions/conversations'; -import { - NOTIFICATIONS_UPDATE, - NOTIFICATIONS_REFRESH_SUCCESS, - NOTIFICATIONS_EXPAND_SUCCESS, -} from 'soapbox/actions/notifications'; -import { - FAVOURITED_STATUSES_FETCH_SUCCESS, - FAVOURITED_STATUSES_EXPAND_SUCCESS, -} from 'soapbox/actions/favourites'; -import { - LIST_ACCOUNTS_FETCH_SUCCESS, - LIST_EDITOR_SUGGESTIONS_READY, -} from 'soapbox/actions/lists'; -import { - SUGGESTIONS_FETCH_SUCCESS, -} from 'soapbox/actions/suggestions'; -import { - CHATS_FETCH_SUCCESS, - CHAT_FETCH_SUCCESS, -} from 'soapbox/actions/chats'; -import { - EMOJI_REACTS_FETCH_SUCCESS, -} from 'soapbox/actions/emoji_reacts'; -import { - GROUP_REMOVED_ACCOUNTS_FETCH_SUCCESS, - GROUP_REMOVED_ACCOUNTS_EXPAND_SUCCESS, - GROUP_MEMBERS_FETCH_SUCCESS, - GROUP_MEMBERS_EXPAND_SUCCESS, -} from 'soapbox/actions/groups'; -import { - STREAMING_NOTIFICATION_UPDATE, - STREAMING_CHAT_UPDATE, - STREAMING_TIMELINE_UPDATE, -} from 'soapbox/actions/streaming'; -import { - STREAMING_FOLLOW_RELATIONSHIPS_UPDATE, -} from 'soapbox/actions/streaming'; -import { Map as ImmutableMap, fromJS } from 'immutable'; - -const importAccount = (state, account) => { - return state.set(account.id, fromJS({ - followers_count: account.followers_count, - following_count: account.following_count, - statuses_count: account.statuses_count, - })); -}; - -const importAccounts = (state, accounts) => { - return state.withMutations(state => { - accounts.forEach(account => importAccount(state, account)); - }); -}; - -const importStatus = (state, status) => { - return state.withMutations(state => { - importAccount(state, status.account); - - if (status.reblog && status.reblog.account) { - importAccount(state, status.reblog.account); - } - }); -}; - -const importStatuses = (state, statuses) => { - return state.withMutations(state => { - statuses.forEach(status => importStatus(state, status)); - }); -}; - -const importContext = (state, ancestors, descendants) => { - return state.withMutations(state => { - importStatuses(state, ancestors); - importStatuses(state, descendants); - }); -}; - -const importNotification = (state, notification) => ( - importAccount(state, notification.account) -); - -const importNotifications = (state, notifications) => { - return state.withMutations(state => { - notifications.forEach(notification => importNotification(state, notification)); - }); -}; - -const importConversation = (state, conversation) => ( - importAccounts(conversation.accounts) -); - -const importConversations = (state, conversations) => { - return state.withMutations(state => { - conversations.forEach(conversation => importConversation(state, conversation)); - }); -}; - -const importChat = (state, chat) => importAccount(state, chat.account); - -const importChats = (state, chats) => { - return state.withMutations(state => { - chats.forEach(chat => importChat(state, chat)); - }); -}; - -const importEmojiReact = (state, emojiReact) => ( - importAccounts(emojiReact.accounts) -); - -const importEmojiReacts = (state, emojiReacts) => { - return state.withMutations(state => { - emojiReacts.forEach(emojiReact => importEmojiReact(state, emojiReact)); - }); -}; - -const updateFollowCounters = (state, counterUpdates) => { - return state.withMutations(state => { - counterUpdates.forEach(counterUpdate => { - state.update(counterUpdate.id, ImmutableMap(), counters => counters.merge({ - followers_count: counterUpdate.follower_count, - following_count: counterUpdate.following_count, - })); - }); - }); -}; - -const initialState = ImmutableMap(); - -export default function accountsCounters(state = initialState, action) { - switch(action.type) { - case ACCOUNT_FETCH_SUCCESS: - case VERIFY_CREDENTIALS_SUCCESS: - return importAccount(state, action.account); - case ME_FETCH_SUCCESS: - case ME_PATCH_SUCCESS: - return importAccount(state, action.me); - case FOLLOWERS_FETCH_SUCCESS: - case FOLLOWERS_EXPAND_SUCCESS: - case FOLLOWING_FETCH_SUCCESS: - case FOLLOWING_EXPAND_SUCCESS: - case REBLOGS_FETCH_SUCCESS: - case FAVOURITES_FETCH_SUCCESS: - case COMPOSE_SUGGESTIONS_READY: - case FOLLOW_REQUESTS_FETCH_SUCCESS: - case FOLLOW_REQUESTS_EXPAND_SUCCESS: - case BLOCKS_FETCH_SUCCESS: - case BLOCKS_EXPAND_SUCCESS: - case MUTES_FETCH_SUCCESS: - case MUTES_EXPAND_SUCCESS: - case LIST_ACCOUNTS_FETCH_SUCCESS: - case LIST_EDITOR_SUGGESTIONS_READY: - case SUGGESTIONS_FETCH_SUCCESS: - case GROUP_REMOVED_ACCOUNTS_FETCH_SUCCESS: - case GROUP_REMOVED_ACCOUNTS_EXPAND_SUCCESS: - case GROUP_MEMBERS_FETCH_SUCCESS: - case GROUP_MEMBERS_EXPAND_SUCCESS: - return action.accounts ? importAccounts(state, action.accounts) : state; - case CONVERSATIONS_FETCH_SUCCESS: - return importConversations(state, action.conversations); - case CONVERSATIONS_UPDATE: - return importConversation(state, action.conversation); - case NOTIFICATIONS_REFRESH_SUCCESS: - case NOTIFICATIONS_EXPAND_SUCCESS: - return importNotifications(state, action.notifications); - case NOTIFICATIONS_UPDATE: - case STREAMING_NOTIFICATION_UPDATE: - return importNotification(state, action.notification); - case SEARCH_FETCH_SUCCESS: - return importAccounts(state, action.results.accounts); - case TIMELINE_REFRESH_SUCCESS: - case TIMELINE_EXPAND_SUCCESS: - case FAVOURITED_STATUSES_FETCH_SUCCESS: - case FAVOURITED_STATUSES_EXPAND_SUCCESS: - return importStatuses(state, action.statuses); - case CONTEXT_FETCH_SUCCESS: - return importContext(state, action.ancestors, action.descendants); - case REBLOG_SUCCESS: - case FAVOURITE_SUCCESS: - case UNREBLOG_SUCCESS: - case UNFAVOURITE_SUCCESS: - case STREAMING_TIMELINE_UPDATE: - case STATUS_FETCH_SUCCESS: - case BOOKMARK_SUCCESS: - case UNBOOKMARK_SUCCESS: - return importStatus(state, action.status); - case CHATS_FETCH_SUCCESS: - return importChats(state, action.chats); - case CHAT_FETCH_SUCCESS: - case STREAMING_CHAT_UPDATE: - return importChats(state, [action.chat]); - case EMOJI_REACTS_FETCH_SUCCESS: - return importEmojiReacts(state, action.emojiReacts); - case ACCOUNT_FOLLOW_SUCCESS: - return action.alreadyFollowing ? state : - state.updateIn([action.relationship.id, 'followers_count'], num => num + 1); - case ACCOUNT_UNFOLLOW_SUCCESS: - return state.updateIn([action.relationship.id, 'followers_count'], num => Math.max(0, num - 1)); - case STREAMING_FOLLOW_RELATIONSHIPS_UPDATE: - return updateFollowCounters(state, [action.follower, action.following]); - default: - return state; - } -}; diff --git a/app/soapbox/reducers/index.js b/app/soapbox/reducers/index.js index 751a04afb..b62007bf8 100644 --- a/app/soapbox/reducers/index.js +++ b/app/soapbox/reducers/index.js @@ -10,7 +10,6 @@ import modal from './modal'; import user_lists from './user_lists'; import domain_lists from './domain_lists'; import accounts from './accounts'; -import accounts_counters from './accounts_counters'; import statuses from './statuses'; import relationships from './relationships'; import settings from './settings'; @@ -65,7 +64,6 @@ const appReducer = combineReducers({ domain_lists, status_lists, accounts, - accounts_counters, statuses, relationships, settings, diff --git a/app/soapbox/selectors/index.js b/app/soapbox/selectors/index.js index 9b222921e..c4312dc01 100644 --- a/app/soapbox/selectors/index.js +++ b/app/soapbox/selectors/index.js @@ -2,7 +2,6 @@ import { createSelector } from 'reselect'; import { List as ImmutableList } from 'immutable'; const getAccountBase = (state, id) => state.getIn(['accounts', id], null); -const getAccountCounters = (state, id) => state.getIn(['accounts_counters', id], null); const getAccountRelationship = (state, id) => state.getIn(['relationships', id], null); const getAccountMoved = (state, id) => state.getIn(['accounts', state.getIn(['accounts', id, 'moved'])]); const getAccountAdminData = (state, id) => state.getIn(['admin', 'users', id]); @@ -14,17 +13,16 @@ const getAccountPatron = (state, id) => { export const makeGetAccount = () => { return createSelector([ getAccountBase, - getAccountCounters, getAccountRelationship, getAccountMoved, getAccountAdminData, getAccountPatron, - ], (base, counters, relationship, moved, admin, patron) => { + ], (base, relationship, moved, admin, patron) => { if (base === null) { return null; } - return base.merge(counters).withMutations(map => { + return base.withMutations(map => { map.set('relationship', relationship); map.set('moved', moved); map.set('patron', patron); diff --git a/app/soapbox/utils/accounts.js b/app/soapbox/utils/accounts.js index ce52a5562..64743377c 100644 --- a/app/soapbox/utils/accounts.js +++ b/app/soapbox/utils/accounts.js @@ -45,7 +45,7 @@ export const isModerator = account => ( export const getFollowDifference = (state, accountId, type) => { const listSize = state.getIn(['user_lists', type, accountId, 'items'], ImmutableList()).size; - const counter = state.getIn(['accounts_counters', accountId, `${type}_count`], 0); + const counter = state.getIn(['accounts', accountId, `${type}_count`], 0); return Math.max(counter - listSize, 0); };