From b6218dbd5cb568c13262b719e12755abaf856070 Mon Sep 17 00:00:00 2001
From: Chris Bobbe <cbobbe@zulip.com>
Date: Thu, 8 Dec 2022 17:23:51 -0800
Subject: [PATCH] model: Factor out new RESET_ACCOUNT_DATA action

As Greg proposed in #4446, so the pattern of consistently clearing
data on all ways of leaving an account gets maintained naturally:

(except we chose the name RESET_ACCOUNT_DATA instead of
CLEAR_ACCOUNT_DATA)

> * I think it'd be a useful refactor to consolidate one action type
>   like `CLEAR_ACCOUNT_DATA`.
>   * The action creators for these three (in `accountActions.js`) can
>     dispatch that first, then also a `LOGOUT` etc.
>   * Almost all the reducers would respond only to the
>     `CLEAR_ACCOUNT_DATA`.
>   * There are a couple of exceptions, like `accountReducers` and
>     `sessionReducers`, that actually want to treat the three cases
>     differently. Those would be the only ones to continue responding
>     to `LOGOUT` etc.; and they'd stand out better as a result.
>   * Then there are further changes we might make to those, but
>     that'll be easier to see after that.

Fixes: #4446
---
 src/__tests__/lib/exampleData.js                 |  3 +++
 src/account/accountActions.js                    | 16 ++++++++++++++++
 src/account/logoutActions.js                     | 13 +++++++++++--
 src/actionConstants.js                           |  2 ++
 src/actionTypes.js                               |  7 +++++++
 src/alertWords/alertWordsReducer.js              | 12 ++----------
 src/caughtup/caughtUpReducer.js                  |  8 ++------
 src/chat/__tests__/flagsReducer-test.js          |  6 +++---
 src/chat/fetchingReducer.js                      |  8 ++------
 src/chat/flagsReducer.js                         |  8 ++------
 src/chat/narrowsReducer.js                       |  8 ++------
 src/drafts/draftsReducer.js                      |  6 ++----
 src/message/messagesReducer.js                   |  8 ++------
 src/mute/__tests__/muteModel-test.js             |  4 ++--
 src/mute/__tests__/mutedUsersReducer-test.js     |  4 ++--
 src/mute/muteModel.js                            | 12 ++----------
 src/mute/mutedUsersReducer.js                    | 12 ++----------
 src/outbox/outboxReducer.js                      |  8 ++------
 src/pm-conversations/pmConversationsModel.js     |  8 ++------
 src/presence/__tests__/presenceReducer-test.js   |  6 ++----
 src/presence/presenceReducer.js                  |  8 ++------
 src/realm/__tests__/realmReducer-test.js         | 10 ++--------
 src/realm/realmReducer.js                        |  8 ++------
 src/streams/__tests__/streamsReducer-test.js     |  4 ++--
 src/streams/streamsReducer.js                    | 12 ++----------
 .../__tests__/subscriptionsReducer-test.js       | 11 +++--------
 src/subscriptions/subscriptionsReducer.js        |  8 ++------
 src/topics/__tests__/topicsReducer-test.js       |  4 ++--
 src/topics/topicsReducer.js                      | 12 ++----------
 src/typing/typingReducer.js                      |  8 ++------
 .../__tests__/unreadHuddlesReducer-test.js       |  7 +++----
 .../__tests__/unreadMentionsReducer-test.js      | 11 +++--------
 src/unread/__tests__/unreadModel-test.js         |  7 +++----
 src/unread/__tests__/unreadPmsReducer-test.js    | 15 +++++++--------
 src/unread/unreadHuddlesReducer.js               |  8 ++------
 src/unread/unreadMentionsReducer.js              |  8 ++------
 src/unread/unreadModel.js                        |  8 ++------
 src/unread/unreadPmsReducer.js                   |  8 ++------
 .../__tests__/userGroupsReducer-test.js          |  4 ++--
 src/user-groups/userGroupsReducer.js             |  8 ++------
 .../__tests__/userStatusesModel-test.js          |  4 ++--
 src/user-statuses/userStatusesModel.js           |  8 ++------
 src/users/__tests__/usersReducer-test.js         | 11 +++--------
 src/users/usersReducer.js                        |  8 ++------
 44 files changed, 128 insertions(+), 231 deletions(-)

diff --git a/src/__tests__/lib/exampleData.js b/src/__tests__/lib/exampleData.js
index 62f59facec0..c2808f95708 100644
--- a/src/__tests__/lib/exampleData.js
+++ b/src/__tests__/lib/exampleData.js
@@ -25,6 +25,7 @@ import { CreateWebPublicStreamPolicy, EmailAddressVisibility } from '../../api/p
 import type {
   AccountSwitchAction,
   LoginSuccessAction,
+  ResetAccountDataAction,
   RegisterCompleteAction,
   MessageFetchStartAction,
   MessageFetchCompleteAction,
@@ -44,6 +45,7 @@ import { ZulipVersion } from '../../utils/zulipVersion';
 import {
   ACCOUNT_SWITCH,
   LOGIN_SUCCESS,
+  RESET_ACCOUNT_DATA,
   REGISTER_COMPLETE,
   EVENT_NEW_MESSAGE,
   MESSAGE_FETCH_START,
@@ -705,6 +707,7 @@ export const action = Object.freeze({
     email: selfAccount.email,
     apiKey: selfAccount.apiKey,
   }): LoginSuccessAction),
+  reset_account_data: (deepFreeze({ type: RESET_ACCOUNT_DATA }): ResetAccountDataAction),
 
   /**
    * A minimal well-typed REGISTER_COMPLETE action from a recent server.
diff --git a/src/account/accountActions.js b/src/account/accountActions.js
index 7abe8d4dc8e..b1f37fda9a0 100644
--- a/src/account/accountActions.js
+++ b/src/account/accountActions.js
@@ -11,6 +11,7 @@ import { registerAndStartPolling } from '../events/eventActions';
 import { resetToMainTabs } from '../nav/navActions';
 import { sendOutbox } from '../outbox/outboxActions';
 import { initNotifications } from '../notification/notifTokens';
+import { resetAccountData } from './logoutActions';
 
 export const dismissServerPushSetupNotice = (): PerAccountAction => ({
   type: DISMISS_SERVER_PUSH_SETUP_NOTICE,
@@ -30,6 +31,13 @@ export const accountSwitch =
   (index: number): GlobalThunkAction<Promise<void>> =>
   async (dispatch, getState, { activeAccountDispatch }) => {
     NavigationService.dispatch(resetToMainTabs());
+
+    // Clear out the space we use for the active account's server data, to
+    // make way for a new active account.
+    // TODO(#5006): When each account has its own space to hold server data,
+    //   we won't have to do this.
+    activeAccountDispatch(resetAccountData());
+
     dispatch(accountSwitchPlain(index));
 
     // Now dispatch some actions on the new, post-switch active account.
@@ -60,6 +68,14 @@ export const loginSuccess =
   (realm: URL, email: string, apiKey: string): GlobalThunkAction<Promise<void>> =>
   async (dispatch, getState, { activeAccountDispatch }) => {
     NavigationService.dispatch(resetToMainTabs());
+
+    // In case there's already an active account, clear out the space we use
+    // for the active account's server data, to make way for a new active
+    // account.
+    // TODO(#5006): When each account has its own space to hold server data,
+    //   we won't have to do this.
+    activeAccountDispatch(resetAccountData());
+
     dispatch(loginSuccessPlain(realm, email, apiKey));
 
     // Now dispatch some actions on the new, post-login active account.
diff --git a/src/account/logoutActions.js b/src/account/logoutActions.js
index 4cda9106b10..1bdb8725cdc 100644
--- a/src/account/logoutActions.js
+++ b/src/account/logoutActions.js
@@ -1,9 +1,17 @@
 /* @flow strict-local */
 import * as NavigationService from '../nav/NavigationService';
-import type { AllAccountsAction, ThunkAction } from '../types';
-import { LOGOUT } from '../actionConstants';
+import type { PerAccountAction, AllAccountsAction, ThunkAction } from '../types';
+import { LOGOUT, RESET_ACCOUNT_DATA } from '../actionConstants';
 import { resetToAccountPicker } from '../nav/navActions';
 
+/**
+ * Reset per-account server data and some client-side data (drafts/outbox).
+ */
+// In this file just to prevent import cycles.
+export const resetAccountData = (): PerAccountAction => ({
+  type: RESET_ACCOUNT_DATA,
+});
+
 const logoutPlain = (): AllAccountsAction => ({
   type: LOGOUT,
 });
@@ -14,5 +22,6 @@ const logoutPlain = (): AllAccountsAction => ({
 // In its own file just to prevent import cycles.
 export const logout = (): ThunkAction<Promise<void>> => async (dispatch, getState) => {
   NavigationService.dispatch(resetToAccountPicker());
+  dispatch(resetAccountData());
   dispatch(logoutPlain());
 };
diff --git a/src/actionConstants.js b/src/actionConstants.js
index b8c40af709f..381e9d1e0a7 100644
--- a/src/actionConstants.js
+++ b/src/actionConstants.js
@@ -15,6 +15,8 @@ export const REGISTER_START: 'REGISTER_START' = 'REGISTER_START';
 export const REGISTER_ABORT: 'REGISTER_ABORT' = 'REGISTER_ABORT';
 export const REGISTER_COMPLETE: 'REGISTER_COMPLETE' = 'REGISTER_COMPLETE';
 
+export const RESET_ACCOUNT_DATA: 'RESET_ACCOUNT_DATA' = 'RESET_ACCOUNT_DATA';
+
 export const REFRESH_SERVER_EMOJI_DATA: 'REFRESH_SERVER_EMOJI_DATA' = 'REFRESH_SERVER_EMOJI_DATA';
 
 export const DISMISS_SERVER_PUSH_SETUP_NOTICE: 'DISMISS_SERVER_PUSH_SETUP_NOTICE' =
diff --git a/src/actionTypes.js b/src/actionTypes.js
index dd055956795..a67d339557c 100644
--- a/src/actionTypes.js
+++ b/src/actionTypes.js
@@ -10,6 +10,7 @@ import {
   ACCOUNT_REMOVE,
   LOGIN_SUCCESS,
   LOGOUT,
+  RESET_ACCOUNT_DATA,
   DISMISS_SERVER_PUSH_SETUP_NOTICE,
   GOT_PUSH_TOKEN,
   UNACK_PUSH_TOKEN,
@@ -170,6 +171,10 @@ type LogoutAction = $ReadOnly<{|
   type: typeof LOGOUT,
 |}>;
 
+export type ResetAccountDataAction = $ReadOnly<{|
+  type: typeof RESET_ACCOUNT_DATA,
+|}>;
+
 type DismissServerPushSetupNoticeAction = $ReadOnly<{|
   type: typeof DISMISS_SERVER_PUSH_SETUP_NOTICE,
   date: Date,
@@ -646,6 +651,7 @@ export type PerAccountAction =
   // The grouping here is completely arbitrary; don't worry about it.
   | EventAction
   | LoadingAction
+  | ResetAccountDataAction
   | RefreshServerEmojiDataAction
   | MessageAction
   | OutboxAction
@@ -739,6 +745,7 @@ export type DispatchableWithoutAccountAction =
 /** True just if the action is a PerAccountApplicableAction. */
 export function isPerAccountApplicableAction(action: Action): boolean {
   switch (action.type) {
+    case RESET_ACCOUNT_DATA:
     case EVENT:
     case EVENT_ALERT_WORDS:
     case EVENT_MESSAGE_DELETE:
diff --git a/src/alertWords/alertWordsReducer.js b/src/alertWords/alertWordsReducer.js
index 9a466081e86..4fbd6430f80 100644
--- a/src/alertWords/alertWordsReducer.js
+++ b/src/alertWords/alertWordsReducer.js
@@ -1,12 +1,6 @@
 /* @flow strict-local */
 import type { AlertWordsState, PerAccountApplicableAction } from '../types';
-import {
-  REGISTER_COMPLETE,
-  EVENT_ALERT_WORDS,
-  ACCOUNT_SWITCH,
-  LOGOUT,
-  LOGIN_SUCCESS,
-} from '../actionConstants';
+import { REGISTER_COMPLETE, EVENT_ALERT_WORDS, RESET_ACCOUNT_DATA } from '../actionConstants';
 import { NULL_ARRAY } from '../nullObjects';
 
 const initialState = NULL_ARRAY;
@@ -16,9 +10,7 @@ export default (
   action: PerAccountApplicableAction,
 ): AlertWordsState => {
   switch (action.type) {
-    case LOGOUT:
-    case ACCOUNT_SWITCH:
-    case LOGIN_SUCCESS:
+    case RESET_ACCOUNT_DATA:
       return initialState;
 
     case REGISTER_COMPLETE:
diff --git a/src/caughtup/caughtUpReducer.js b/src/caughtup/caughtUpReducer.js
index a7a4c4ba97c..8c1c0590f17 100644
--- a/src/caughtup/caughtUpReducer.js
+++ b/src/caughtup/caughtUpReducer.js
@@ -2,14 +2,12 @@
 import type { CaughtUpState, PerAccountApplicableAction } from '../types';
 import {
   REGISTER_COMPLETE,
-  LOGOUT,
-  LOGIN_SUCCESS,
-  ACCOUNT_SWITCH,
   MESSAGE_FETCH_START,
   MESSAGE_FETCH_ERROR,
   MESSAGE_FETCH_COMPLETE,
   EVENT_UPDATE_MESSAGE,
   EVENT_UPDATE_MESSAGE_FLAGS,
+  RESET_ACCOUNT_DATA,
 } from '../actionConstants';
 import { NULL_OBJECT } from '../nullObjects';
 import { DEFAULT_CAUGHTUP } from './caughtUpSelectors';
@@ -35,9 +33,7 @@ export default (
 ): CaughtUpState => {
   switch (action.type) {
     case REGISTER_COMPLETE:
-    case LOGOUT:
-    case LOGIN_SUCCESS:
-    case ACCOUNT_SWITCH:
+    case RESET_ACCOUNT_DATA:
       return initialState;
 
     case MESSAGE_FETCH_START: {
diff --git a/src/chat/__tests__/flagsReducer-test.js b/src/chat/__tests__/flagsReducer-test.js
index ed5408ed0a3..2165e9a223f 100644
--- a/src/chat/__tests__/flagsReducer-test.js
+++ b/src/chat/__tests__/flagsReducer-test.js
@@ -4,7 +4,7 @@ import deepFreeze from 'deep-freeze';
 
 import * as eg from '../../__tests__/lib/exampleData';
 import flagsReducer from '../flagsReducer';
-import { EVENT_UPDATE_MESSAGE_FLAGS, ACCOUNT_SWITCH } from '../../actionConstants';
+import { EVENT_UPDATE_MESSAGE_FLAGS } from '../../actionConstants';
 
 describe('flagsReducer', () => {
   describe('MESSAGE_FETCH_COMPLETE', () => {
@@ -270,7 +270,7 @@ describe('flagsReducer', () => {
     });
   });
 
-  describe('ACCOUNT_SWITCH', () => {
+  describe('RESET_ACCOUNT_DATA', () => {
     test('resets to initial state', () => {
       const message = eg.streamMessage();
 
@@ -284,7 +284,7 @@ describe('flagsReducer', () => {
         historical: { [message.id]: true },
       });
 
-      expect(flagsReducer(prevState, deepFreeze({ type: ACCOUNT_SWITCH, index: 2 }))).toEqual(
+      expect(flagsReducer(prevState, eg.action.reset_account_data)).toEqual(
         eg.baseReduxState.flags,
       );
     });
diff --git a/src/chat/fetchingReducer.js b/src/chat/fetchingReducer.js
index 47e0a384853..37b9a170929 100644
--- a/src/chat/fetchingReducer.js
+++ b/src/chat/fetchingReducer.js
@@ -1,12 +1,10 @@
 /* @flow strict-local */
 import type { FetchingState, PerAccountApplicableAction } from '../types';
 import {
-  LOGOUT,
-  LOGIN_SUCCESS,
-  ACCOUNT_SWITCH,
   MESSAGE_FETCH_START,
   MESSAGE_FETCH_ERROR,
   MESSAGE_FETCH_COMPLETE,
+  RESET_ACCOUNT_DATA,
 } from '../actionConstants';
 import { NULL_OBJECT } from '../nullObjects';
 import { DEFAULT_FETCHING } from './fetchingSelectors';
@@ -68,9 +66,7 @@ export default (
   action: PerAccountApplicableAction,
 ): FetchingState => {
   switch (action.type) {
-    case LOGOUT:
-    case LOGIN_SUCCESS:
-    case ACCOUNT_SWITCH:
+    case RESET_ACCOUNT_DATA:
       return initialState;
 
     case MESSAGE_FETCH_START:
diff --git a/src/chat/flagsReducer.js b/src/chat/flagsReducer.js
index 00e6a7cd30f..4765368c68c 100644
--- a/src/chat/flagsReducer.js
+++ b/src/chat/flagsReducer.js
@@ -8,9 +8,7 @@ import {
   MESSAGE_FETCH_COMPLETE,
   EVENT_NEW_MESSAGE,
   EVENT_UPDATE_MESSAGE_FLAGS,
-  LOGOUT,
-  LOGIN_SUCCESS,
-  ACCOUNT_SWITCH,
+  RESET_ACCOUNT_DATA,
 } from '../actionConstants';
 import { deeperMerge } from '../utils/misc';
 import type { UserMessageFlag } from '../api/modelTypes';
@@ -134,9 +132,7 @@ export default (
 ): FlagsState => {
   switch (action.type) {
     case REGISTER_COMPLETE:
-    case LOGOUT:
-    case LOGIN_SUCCESS:
-    case ACCOUNT_SWITCH:
+    case RESET_ACCOUNT_DATA:
       return initialState;
 
     case MESSAGE_FETCH_COMPLETE:
diff --git a/src/chat/narrowsReducer.js b/src/chat/narrowsReducer.js
index e1ff72775c2..65d2c9a39e4 100644
--- a/src/chat/narrowsReducer.js
+++ b/src/chat/narrowsReducer.js
@@ -7,9 +7,6 @@ import type { NarrowsState, PerAccountApplicableAction } from '../types';
 import { ensureUnreachable } from '../types';
 import {
   REGISTER_COMPLETE,
-  LOGOUT,
-  LOGIN_SUCCESS,
-  ACCOUNT_SWITCH,
   MESSAGE_FETCH_START,
   MESSAGE_FETCH_ERROR,
   MESSAGE_FETCH_COMPLETE,
@@ -17,6 +14,7 @@ import {
   EVENT_MESSAGE_DELETE,
   EVENT_UPDATE_MESSAGE_FLAGS,
   EVENT_UPDATE_MESSAGE,
+  RESET_ACCOUNT_DATA,
 } from '../actionConstants';
 import { LAST_MESSAGE_ANCHOR, FIRST_UNREAD_ANCHOR } from '../anchor';
 import {
@@ -197,9 +195,7 @@ export default (
 ): NarrowsState => {
   switch (action.type) {
     case REGISTER_COMPLETE:
-    case LOGOUT:
-    case LOGIN_SUCCESS:
-    case ACCOUNT_SWITCH:
+    case RESET_ACCOUNT_DATA:
       return initialState;
 
     case MESSAGE_FETCH_START: {
diff --git a/src/drafts/draftsReducer.js b/src/drafts/draftsReducer.js
index e26a6946915..9c3b0b58b15 100644
--- a/src/drafts/draftsReducer.js
+++ b/src/drafts/draftsReducer.js
@@ -1,6 +1,6 @@
 /* @flow strict-local */
 import type { DraftsState, PerAccountApplicableAction } from '../types';
-import { DRAFT_UPDATE, LOGOUT, ACCOUNT_SWITCH, LOGIN_SUCCESS } from '../actionConstants';
+import { DRAFT_UPDATE, RESET_ACCOUNT_DATA } from '../actionConstants';
 import { NULL_OBJECT } from '../nullObjects';
 import { keyFromNarrow } from '../utils/narrow';
 
@@ -27,9 +27,7 @@ export default (
   action: PerAccountApplicableAction,
 ): DraftsState => {
   switch (action.type) {
-    case LOGOUT:
-    case ACCOUNT_SWITCH:
-    case LOGIN_SUCCESS:
+    case RESET_ACCOUNT_DATA:
       return initialState;
 
     case DRAFT_UPDATE:
diff --git a/src/message/messagesReducer.js b/src/message/messagesReducer.js
index a79d2ccb7c8..919a1c8dcad 100644
--- a/src/message/messagesReducer.js
+++ b/src/message/messagesReducer.js
@@ -12,9 +12,6 @@ import type {
 } from '../types';
 import {
   REGISTER_COMPLETE,
-  LOGOUT,
-  LOGIN_SUCCESS,
-  ACCOUNT_SWITCH,
   MESSAGE_FETCH_COMPLETE,
   EVENT_NEW_MESSAGE,
   EVENT_SUBMESSAGE,
@@ -22,6 +19,7 @@ import {
   EVENT_REACTION_ADD,
   EVENT_REACTION_REMOVE,
   EVENT_UPDATE_MESSAGE,
+  RESET_ACCOUNT_DATA,
 } from '../actionConstants';
 import { getNarrowsForMessage } from '../utils/narrow';
 import * as logging from '../utils/logging';
@@ -142,9 +140,7 @@ export default (
 ): MessagesState => {
   switch (action.type) {
     case REGISTER_COMPLETE:
-    case LOGOUT:
-    case LOGIN_SUCCESS:
-    case ACCOUNT_SWITCH:
+    case RESET_ACCOUNT_DATA:
       return initialState;
 
     case MESSAGE_FETCH_COMPLETE:
diff --git a/src/mute/__tests__/muteModel-test.js b/src/mute/__tests__/muteModel-test.js
index 196e41a37b6..61f3648ef78 100644
--- a/src/mute/__tests__/muteModel-test.js
+++ b/src/mute/__tests__/muteModel-test.js
@@ -38,10 +38,10 @@ describe('reducer', () => {
     });
   });
 
-  describe('ACCOUNT_SWITCH', () => {
+  describe('RESET_ACCOUNT_DATA', () => {
     test('resets state to initial state', () => {
       const state = makeMuteState([[eg.stream, 'some_topic']]);
-      expect(reducer(state, eg.action.account_switch, eg.plusReduxState)).toEqual(initialState);
+      expect(reducer(state, eg.action.reset_account_data, eg.plusReduxState)).toEqual(initialState);
     });
   });
 
diff --git a/src/mute/__tests__/mutedUsersReducer-test.js b/src/mute/__tests__/mutedUsersReducer-test.js
index 24c65f13aeb..ff947c4b140 100644
--- a/src/mute/__tests__/mutedUsersReducer-test.js
+++ b/src/mute/__tests__/mutedUsersReducer-test.js
@@ -24,9 +24,9 @@ describe('mutedUsersReducer', () => {
     });
   });
 
-  describe('ACCOUNT_SWITCH', () => {
+  describe('RESET_ACCOUNT_DATA', () => {
     test('resets state to initial state', () => {
-      expect(mutedUsersReducer(baseState, eg.action.account_switch)).toEqual(Immutable.Map());
+      expect(mutedUsersReducer(baseState, eg.action.reset_account_data)).toEqual(Immutable.Map());
     });
   });
 
diff --git a/src/mute/muteModel.js b/src/mute/muteModel.js
index 18e9635116b..ee38e7c5471 100644
--- a/src/mute/muteModel.js
+++ b/src/mute/muteModel.js
@@ -1,13 +1,7 @@
 /* @flow strict-local */
 
 import type { MuteState, PerAccountApplicableAction, PerAccountState } from '../types';
-import {
-  REGISTER_COMPLETE,
-  LOGOUT,
-  ACCOUNT_SWITCH,
-  EVENT_MUTED_TOPICS,
-  LOGIN_SUCCESS,
-} from '../actionConstants';
+import { REGISTER_COMPLETE, EVENT_MUTED_TOPICS, RESET_ACCOUNT_DATA } from '../actionConstants';
 import { getStreamsByName } from '../subscriptions/subscriptionSelectors';
 import * as logging from '../utils/logging';
 import DefaultMap from '../utils/DefaultMap';
@@ -53,9 +47,7 @@ export const reducer = (
   globalState: PerAccountState,
 ): MuteState => {
   switch (action.type) {
-    case LOGOUT:
-    case ACCOUNT_SWITCH:
-    case LOGIN_SUCCESS:
+    case RESET_ACCOUNT_DATA:
       return initialState;
 
     case REGISTER_COMPLETE:
diff --git a/src/mute/mutedUsersReducer.js b/src/mute/mutedUsersReducer.js
index 00777a80334..032aad03b9c 100644
--- a/src/mute/mutedUsersReducer.js
+++ b/src/mute/mutedUsersReducer.js
@@ -2,13 +2,7 @@
 import Immutable from 'immutable';
 
 import type { MutedUsersState, PerAccountApplicableAction, UserId } from '../types';
-import {
-  REGISTER_COMPLETE,
-  LOGIN_SUCCESS,
-  LOGOUT,
-  ACCOUNT_SWITCH,
-  EVENT_MUTED_USERS,
-} from '../actionConstants';
+import { REGISTER_COMPLETE, EVENT_MUTED_USERS, RESET_ACCOUNT_DATA } from '../actionConstants';
 import type { MutedUser } from '../api/apiTypes';
 
 const initialState: MutedUsersState = Immutable.Map();
@@ -22,9 +16,7 @@ export default (
   action: PerAccountApplicableAction,
 ): MutedUsersState => {
   switch (action.type) {
-    case LOGOUT:
-    case ACCOUNT_SWITCH:
-    case LOGIN_SUCCESS:
+    case RESET_ACCOUNT_DATA:
       return initialState;
 
     case REGISTER_COMPLETE:
diff --git a/src/outbox/outboxReducer.js b/src/outbox/outboxReducer.js
index eca174dd611..99181f8487c 100644
--- a/src/outbox/outboxReducer.js
+++ b/src/outbox/outboxReducer.js
@@ -4,11 +4,9 @@ import {
   REGISTER_COMPLETE,
   MESSAGE_SEND_START,
   EVENT_NEW_MESSAGE,
-  LOGOUT,
-  ACCOUNT_SWITCH,
   DELETE_OUTBOX_MESSAGE,
   MESSAGE_SEND_COMPLETE,
-  LOGIN_SUCCESS,
+  RESET_ACCOUNT_DATA,
 } from '../actionConstants';
 import { NULL_ARRAY } from '../nullObjects';
 import { filterArray } from '../utils/immutability';
@@ -43,9 +41,7 @@ export default (
     case EVENT_NEW_MESSAGE:
       return filterArray(state, item => item && item.timestamp !== +action.local_message_id);
 
-    case ACCOUNT_SWITCH:
-    case LOGOUT:
-    case LOGIN_SUCCESS:
+    case RESET_ACCOUNT_DATA:
       return initialState;
 
     default:
diff --git a/src/pm-conversations/pmConversationsModel.js b/src/pm-conversations/pmConversationsModel.js
index 81e24916be7..d85a8c8206f 100644
--- a/src/pm-conversations/pmConversationsModel.js
+++ b/src/pm-conversations/pmConversationsModel.js
@@ -2,12 +2,10 @@
 import Immutable from 'immutable';
 import invariant from 'invariant';
 import {
-  ACCOUNT_SWITCH,
   EVENT_NEW_MESSAGE,
-  LOGIN_SUCCESS,
-  LOGOUT,
   MESSAGE_FETCH_COMPLETE,
   REGISTER_COMPLETE,
+  RESET_ACCOUNT_DATA,
 } from '../actionConstants';
 import { makeUserId } from '../api/idTypes';
 
@@ -184,9 +182,7 @@ export function reducer(
   action: PerAccountApplicableAction,
 ): PmConversationsState {
   switch (action.type) {
-    case LOGOUT:
-    case LOGIN_SUCCESS:
-    case ACCOUNT_SWITCH:
+    case RESET_ACCOUNT_DATA:
       return initialState;
 
     case REGISTER_COMPLETE: {
diff --git a/src/presence/__tests__/presenceReducer-test.js b/src/presence/__tests__/presenceReducer-test.js
index 98080a3457e..4796bc5cfd9 100644
--- a/src/presence/__tests__/presenceReducer-test.js
+++ b/src/presence/__tests__/presenceReducer-test.js
@@ -172,7 +172,7 @@ describe('presenceReducer', () => {
     });
   });
 
-  describe('ACCOUNT_SWITCH', () => {
+  describe('RESET_ACCOUNT_DATA', () => {
     test('resets state to initial state', () => {
       const prevState = deepFreeze({
         'email@example.com': {
@@ -181,11 +181,9 @@ describe('presenceReducer', () => {
         },
       });
 
-      const action = eg.action.account_switch;
-
       const expectedState = {};
 
-      const actualState = presenceReducer(prevState, action);
+      const actualState = presenceReducer(prevState, eg.action.reset_account_data);
 
       expect(actualState).toEqual(expectedState);
     });
diff --git a/src/presence/presenceReducer.js b/src/presence/presenceReducer.js
index 6b76883b25f..d42a5ff273b 100644
--- a/src/presence/presenceReducer.js
+++ b/src/presence/presenceReducer.js
@@ -1,12 +1,10 @@
 /* @flow strict-local */
 import type { PresenceState, PerAccountApplicableAction } from '../types';
 import {
-  LOGOUT,
-  LOGIN_SUCCESS,
-  ACCOUNT_SWITCH,
   EVENT_PRESENCE,
   PRESENCE_RESPONSE,
   REGISTER_COMPLETE,
+  RESET_ACCOUNT_DATA,
 } from '../actionConstants';
 import { NULL_OBJECT } from '../nullObjects';
 import { getAggregatedPresence } from '../utils/presence';
@@ -19,9 +17,7 @@ export default (
   action: PerAccountApplicableAction,
 ): PresenceState => {
   switch (action.type) {
-    case LOGOUT:
-    case LOGIN_SUCCESS:
-    case ACCOUNT_SWITCH:
+    case RESET_ACCOUNT_DATA:
       return initialState;
 
     case REGISTER_COMPLETE:
diff --git a/src/realm/__tests__/realmReducer-test.js b/src/realm/__tests__/realmReducer-test.js
index 43899193aef..b829d5a81b8 100644
--- a/src/realm/__tests__/realmReducer-test.js
+++ b/src/realm/__tests__/realmReducer-test.js
@@ -4,7 +4,6 @@ import deepFreeze from 'deep-freeze';
 import type { RealmState } from '../../types';
 import realmReducer from '../realmReducer';
 import {
-  ACCOUNT_SWITCH,
   EVENT_REALM_EMOJI_UPDATE,
   EVENT_UPDATE_DISPLAY_SETTINGS,
   EVENT_REALM_FILTERS,
@@ -103,18 +102,13 @@ describe('realmReducer', () => {
     });
   });
 
-  describe('ACCOUNT_SWITCH', () => {
+  describe('RESET_ACCOUNT_DATA', () => {
     test('resets state', () => {
       const initialState = eg.plusReduxState.realm;
 
-      const action = deepFreeze({
-        type: ACCOUNT_SWITCH,
-        index: 1,
-      });
-
       const expectedState = eg.baseReduxState.realm;
 
-      const actualState = realmReducer(initialState, action);
+      const actualState = realmReducer(initialState, eg.action.reset_account_data);
 
       expect(actualState).toEqual(expectedState);
     });
diff --git a/src/realm/realmReducer.js b/src/realm/realmReducer.js
index b02721dd591..4d5479810af 100644
--- a/src/realm/realmReducer.js
+++ b/src/realm/realmReducer.js
@@ -14,13 +14,11 @@ import { EventTypes } from '../api/eventTypes';
 import {
   REGISTER_COMPLETE,
   EVENT_REALM_EMOJI_UPDATE,
-  LOGOUT,
-  LOGIN_SUCCESS,
-  ACCOUNT_SWITCH,
   EVENT,
   EVENT_UPDATE_DISPLAY_SETTINGS,
   EVENT_REALM_FILTERS,
   REFRESH_SERVER_EMOJI_DATA,
+  RESET_ACCOUNT_DATA,
 } from '../actionConstants';
 import { objectFromEntries } from '../jsBackport';
 import { objectEntries } from '../flowPonyfill';
@@ -110,9 +108,7 @@ export default (
   action: PerAccountApplicableAction,
 ): RealmState => {
   switch (action.type) {
-    case LOGOUT:
-    case LOGIN_SUCCESS:
-    case ACCOUNT_SWITCH:
+    case RESET_ACCOUNT_DATA:
       return initialState;
 
     case REGISTER_COMPLETE: {
diff --git a/src/streams/__tests__/streamsReducer-test.js b/src/streams/__tests__/streamsReducer-test.js
index d931dfa9683..eadfd78ed63 100644
--- a/src/streams/__tests__/streamsReducer-test.js
+++ b/src/streams/__tests__/streamsReducer-test.js
@@ -11,10 +11,10 @@ const mkAction = <E: $Diff<StreamEvent, {| id: mixed, type: mixed |}>>(event: E)
   deepFreeze({ type: EVENT, event: { id: 0, type: EventTypes.stream, ...event } });
 
 describe('streamsReducer', () => {
-  describe('ACCOUNT_SWITCH', () => {
+  describe('RESET_ACCOUNT_DATA', () => {
     test('resets state to initial state', () => {
       expect(
-        streamsReducer([eg.makeStream({ name: 'some_stream' })], eg.action.account_switch),
+        streamsReducer([eg.makeStream({ name: 'some_stream' })], eg.action.reset_account_data),
       ).toEqual([]);
     });
   });
diff --git a/src/streams/streamsReducer.js b/src/streams/streamsReducer.js
index 60601305b39..9f3debe586c 100644
--- a/src/streams/streamsReducer.js
+++ b/src/streams/streamsReducer.js
@@ -3,13 +3,7 @@ import { EventTypes } from '../api/eventTypes';
 import type { PerAccountApplicableAction, StreamsState, StreamUpdateEvent } from '../types';
 import type { Stream, Subscription } from '../api/modelTypes';
 import { ensureUnreachable } from '../types';
-import {
-  LOGOUT,
-  ACCOUNT_SWITCH,
-  EVENT,
-  REGISTER_COMPLETE,
-  LOGIN_SUCCESS,
-} from '../actionConstants';
+import { EVENT, REGISTER_COMPLETE, RESET_ACCOUNT_DATA } from '../actionConstants';
 import { NULL_ARRAY } from '../nullObjects';
 import { filterArray } from '../utils/immutability';
 
@@ -65,9 +59,7 @@ export default (
     case REGISTER_COMPLETE:
       return action.data.streams || initialState;
 
-    case LOGOUT:
-    case ACCOUNT_SWITCH:
-    case LOGIN_SUCCESS:
+    case RESET_ACCOUNT_DATA:
       return initialState;
 
     case EVENT: {
diff --git a/src/subscriptions/__tests__/subscriptionsReducer-test.js b/src/subscriptions/__tests__/subscriptionsReducer-test.js
index 7be94f6ccfe..690191aee5a 100644
--- a/src/subscriptions/__tests__/subscriptionsReducer-test.js
+++ b/src/subscriptions/__tests__/subscriptionsReducer-test.js
@@ -3,7 +3,7 @@
 import deepFreeze from 'deep-freeze';
 
 import { EventTypes } from '../../api/eventTypes';
-import { EVENT_SUBSCRIPTION, ACCOUNT_SWITCH, EVENT } from '../../actionConstants';
+import { EVENT_SUBSCRIPTION, EVENT } from '../../actionConstants';
 import subscriptionsReducer from '../subscriptionsReducer';
 import * as eg from '../../__tests__/lib/exampleData';
 
@@ -200,18 +200,13 @@ describe('subscriptionsReducer', () => {
     });
   });
 
-  describe('ACCOUNT_SWITCH', () => {
+  describe('RESET_ACCOUNT_DATA', () => {
     test('resets state to initial state', () => {
       const initialState = deepFreeze([sub1]);
 
-      const action = deepFreeze({
-        type: ACCOUNT_SWITCH,
-        index: 2,
-      });
-
       const expectedState = [];
 
-      const actualState = subscriptionsReducer(initialState, action);
+      const actualState = subscriptionsReducer(initialState, eg.action.reset_account_data);
 
       expect(actualState).toEqual(expectedState);
     });
diff --git a/src/subscriptions/subscriptionsReducer.js b/src/subscriptions/subscriptionsReducer.js
index 8f3f9a3c09e..fe59c19851c 100644
--- a/src/subscriptions/subscriptionsReducer.js
+++ b/src/subscriptions/subscriptionsReducer.js
@@ -4,12 +4,10 @@ import type { SubscriptionsState, PerAccountApplicableAction } from '../types';
 import { ensureUnreachable } from '../types';
 import { updateStreamProperties } from '../streams/streamsReducer';
 import {
-  LOGOUT,
-  LOGIN_SUCCESS,
-  ACCOUNT_SWITCH,
   EVENT_SUBSCRIPTION,
   REGISTER_COMPLETE,
   EVENT,
+  RESET_ACCOUNT_DATA,
 } from '../actionConstants';
 import { NULL_ARRAY } from '../nullObjects';
 import { filterArray } from '../utils/immutability';
@@ -21,9 +19,7 @@ export default (
   action: PerAccountApplicableAction,
 ): SubscriptionsState => {
   switch (action.type) {
-    case LOGOUT:
-    case LOGIN_SUCCESS:
-    case ACCOUNT_SWITCH:
+    case RESET_ACCOUNT_DATA:
       return initialState;
 
     case REGISTER_COMPLETE:
diff --git a/src/topics/__tests__/topicsReducer-test.js b/src/topics/__tests__/topicsReducer-test.js
index d4618cc0a64..73f870d0e9e 100644
--- a/src/topics/__tests__/topicsReducer-test.js
+++ b/src/topics/__tests__/topicsReducer-test.js
@@ -8,10 +8,10 @@ import { INIT_TOPICS } from '../../actionConstants';
 import { NULL_OBJECT } from '../../nullObjects';
 
 describe('topicsReducer', () => {
-  describe('ACCOUNT_SWITCH', () => {
+  describe('RESET_ACCOUNT_DATA', () => {
     test('resets state to initial state', () => {
       const prevState = deepFreeze({ [eg.stream.stream_id]: [{ max_id: 1, name: 'some topic' }] });
-      expect(topicsReducer(prevState, eg.action.account_switch)).toEqual(NULL_OBJECT);
+      expect(topicsReducer(prevState, eg.action.reset_account_data)).toEqual(NULL_OBJECT);
     });
   });
 
diff --git a/src/topics/topicsReducer.js b/src/topics/topicsReducer.js
index 17e08665198..23d1e58209f 100644
--- a/src/topics/topicsReducer.js
+++ b/src/topics/topicsReducer.js
@@ -1,12 +1,6 @@
 /* @flow strict-local */
 import type { TopicsState, PerAccountApplicableAction } from '../types';
-import {
-  LOGOUT,
-  ACCOUNT_SWITCH,
-  INIT_TOPICS,
-  EVENT_NEW_MESSAGE,
-  LOGIN_SUCCESS,
-} from '../actionConstants';
+import { INIT_TOPICS, EVENT_NEW_MESSAGE, RESET_ACCOUNT_DATA } from '../actionConstants';
 import { NULL_OBJECT } from '../nullObjects';
 import { replaceItemInArray } from '../utils/immutability';
 
@@ -47,9 +41,7 @@ export default (
   action: PerAccountApplicableAction,
 ): TopicsState => {
   switch (action.type) {
-    case LOGOUT:
-    case ACCOUNT_SWITCH:
-    case LOGIN_SUCCESS:
+    case RESET_ACCOUNT_DATA:
       return initialState;
 
     case INIT_TOPICS:
diff --git a/src/typing/typingReducer.js b/src/typing/typingReducer.js
index 45d5a8ec138..6dda6f6208b 100644
--- a/src/typing/typingReducer.js
+++ b/src/typing/typingReducer.js
@@ -5,9 +5,7 @@ import {
   EVENT_TYPING_STOP,
   CLEAR_TYPING,
   DEAD_QUEUE,
-  LOGOUT,
-  LOGIN_SUCCESS,
-  ACCOUNT_SWITCH,
+  RESET_ACCOUNT_DATA,
 } from '../actionConstants';
 import { pmTypingKeyFromRecipients } from '../utils/recipient';
 import { NULL_OBJECT } from '../nullObjects';
@@ -98,9 +96,7 @@ export default (
       return clearTyping(state, action);
 
     case DEAD_QUEUE:
-    case LOGOUT:
-    case LOGIN_SUCCESS:
-    case ACCOUNT_SWITCH:
+    case RESET_ACCOUNT_DATA:
       return initialState;
 
     default:
diff --git a/src/unread/__tests__/unreadHuddlesReducer-test.js b/src/unread/__tests__/unreadHuddlesReducer-test.js
index 854ebf46db2..4a4d71de82f 100644
--- a/src/unread/__tests__/unreadHuddlesReducer-test.js
+++ b/src/unread/__tests__/unreadHuddlesReducer-test.js
@@ -2,13 +2,13 @@
 import deepFreeze from 'deep-freeze';
 
 import unreadHuddlesReducer from '../unreadHuddlesReducer';
-import { ACCOUNT_SWITCH, EVENT_UPDATE_MESSAGE_FLAGS } from '../../actionConstants';
+import { RESET_ACCOUNT_DATA, EVENT_UPDATE_MESSAGE_FLAGS } from '../../actionConstants';
 import { NULL_ARRAY } from '../../nullObjects';
 import * as eg from '../../__tests__/lib/exampleData';
 import { makeUserId } from '../../api/idTypes';
 
 describe('unreadHuddlesReducer', () => {
-  describe('ACCOUNT_SWITCH', () => {
+  describe('RESET_ACCOUNT_DATA', () => {
     test('resets state to initial state', () => {
       const initialState = deepFreeze([
         {
@@ -18,8 +18,7 @@ describe('unreadHuddlesReducer', () => {
       ]);
 
       const action = deepFreeze({
-        type: ACCOUNT_SWITCH,
-        index: 1,
+        type: RESET_ACCOUNT_DATA,
       });
 
       const expectedState = [];
diff --git a/src/unread/__tests__/unreadMentionsReducer-test.js b/src/unread/__tests__/unreadMentionsReducer-test.js
index 3e250e21a45..1fb8126b79a 100644
--- a/src/unread/__tests__/unreadMentionsReducer-test.js
+++ b/src/unread/__tests__/unreadMentionsReducer-test.js
@@ -3,23 +3,18 @@ import deepFreeze from 'deep-freeze';
 import Immutable from 'immutable';
 
 import unreadMentionsReducer from '../unreadMentionsReducer';
-import { ACCOUNT_SWITCH, EVENT_UPDATE_MESSAGE_FLAGS } from '../../actionConstants';
+import { EVENT_UPDATE_MESSAGE_FLAGS } from '../../actionConstants';
 import { NULL_ARRAY } from '../../nullObjects';
 import * as eg from '../../__tests__/lib/exampleData';
 
 describe('unreadMentionsReducer', () => {
-  describe('ACCOUNT_SWITCH', () => {
+  describe('RESET_ACCOUNT_DATA', () => {
     test('resets state to initial state', () => {
       const initialState = deepFreeze([1, 2, 3]);
 
-      const action = deepFreeze({
-        type: ACCOUNT_SWITCH,
-        index: 0,
-      });
-
       const expectedState = [];
 
-      const actualState = unreadMentionsReducer(initialState, action);
+      const actualState = unreadMentionsReducer(initialState, eg.action.reset_account_data);
 
       expect(actualState).toEqual(expectedState);
     });
diff --git a/src/unread/__tests__/unreadModel-test.js b/src/unread/__tests__/unreadModel-test.js
index 8f99889fbcb..4210b74c746 100644
--- a/src/unread/__tests__/unreadModel-test.js
+++ b/src/unread/__tests__/unreadModel-test.js
@@ -1,7 +1,7 @@
 /* @flow strict-local */
 import Immutable from 'immutable';
 
-import { ACCOUNT_SWITCH, EVENT_UPDATE_MESSAGE_FLAGS } from '../../actionConstants';
+import { EVENT_UPDATE_MESSAGE_FLAGS } from '../../actionConstants';
 import { reducer, setUnion } from '../unreadModel';
 import { type UnreadState } from '../unreadModelTypes';
 import * as eg from '../../__tests__/lib/exampleData';
@@ -37,13 +37,12 @@ describe('stream substate', () => {
   const summary = (state: UnreadState) =>
     state.streams.map(perStream => perStream.map(perTopic => perTopic.toArray()));
 
-  describe('ACCOUNT_SWITCH', () => {
+  describe('RESET_ACCOUNT_DATA', () => {
     test('resets state to initial state', () => {
       const state = makeUnreadState(eg.plusReduxState, [eg.streamMessage()]);
       expect(state).not.toEqual(initialState);
 
-      const action = { type: ACCOUNT_SWITCH, index: 1 };
-      expect(reducer(state, action, eg.plusReduxState)).toEqual(initialState);
+      expect(reducer(state, eg.action.reset_account_data, eg.plusReduxState)).toEqual(initialState);
     });
   });
 
diff --git a/src/unread/__tests__/unreadPmsReducer-test.js b/src/unread/__tests__/unreadPmsReducer-test.js
index 8e62270b940..e6274560a00 100644
--- a/src/unread/__tests__/unreadPmsReducer-test.js
+++ b/src/unread/__tests__/unreadPmsReducer-test.js
@@ -2,13 +2,13 @@
 import deepFreeze from 'deep-freeze';
 
 import unreadPmsReducer from '../unreadPmsReducer';
-import { ACCOUNT_SWITCH, EVENT_UPDATE_MESSAGE_FLAGS } from '../../actionConstants';
+import { EVENT_UPDATE_MESSAGE_FLAGS } from '../../actionConstants';
 import { NULL_ARRAY } from '../../nullObjects';
 import * as eg from '../../__tests__/lib/exampleData';
 import { makeUserId } from '../../api/idTypes';
 
 describe('unreadPmsReducer', () => {
-  describe('ACCOUNT_SWITCH', () => {
+  describe('RESET_ACCOUNT_DATA', () => {
     test('resets state to initial state', () => {
       const initialState = deepFreeze([
         {
@@ -17,14 +17,13 @@ describe('unreadPmsReducer', () => {
         },
       ]);
 
-      const action = deepFreeze({
-        type: ACCOUNT_SWITCH,
-        index: 1,
-      });
-
       const expectedState = [];
 
-      const actualState = unreadPmsReducer(initialState, action, eg.plusReduxState);
+      const actualState = unreadPmsReducer(
+        initialState,
+        eg.action.reset_account_data,
+        eg.plusReduxState,
+      );
 
       expect(actualState).toEqual(expectedState);
     });
diff --git a/src/unread/unreadHuddlesReducer.js b/src/unread/unreadHuddlesReducer.js
index 0b1eedf6129..b78eb9f40ea 100644
--- a/src/unread/unreadHuddlesReducer.js
+++ b/src/unread/unreadHuddlesReducer.js
@@ -5,12 +5,10 @@ import type { PerAccountApplicableAction } from '../types';
 import type { UnreadHuddlesState } from './unreadModelTypes';
 import {
   REGISTER_COMPLETE,
-  LOGOUT,
-  ACCOUNT_SWITCH,
   EVENT_NEW_MESSAGE,
   EVENT_MESSAGE_DELETE,
   EVENT_UPDATE_MESSAGE_FLAGS,
-  LOGIN_SUCCESS,
+  RESET_ACCOUNT_DATA,
 } from '../actionConstants';
 import {
   pmUnreadsKeyFromMessage,
@@ -92,9 +90,7 @@ export default (
   globalState: PerAccountState,
 ): UnreadHuddlesState => {
   switch (action.type) {
-    case LOGOUT:
-    case ACCOUNT_SWITCH:
-    case LOGIN_SUCCESS:
+    case RESET_ACCOUNT_DATA:
       return initialState;
 
     case REGISTER_COMPLETE:
diff --git a/src/unread/unreadMentionsReducer.js b/src/unread/unreadMentionsReducer.js
index 05b1b437b95..4220d33d49d 100644
--- a/src/unread/unreadMentionsReducer.js
+++ b/src/unread/unreadMentionsReducer.js
@@ -5,12 +5,10 @@ import type { PerAccountApplicableAction } from '../types';
 import type { UnreadMentionsState } from './unreadModelTypes';
 import {
   REGISTER_COMPLETE,
-  LOGOUT,
-  ACCOUNT_SWITCH,
   EVENT_NEW_MESSAGE,
   EVENT_MESSAGE_DELETE,
   EVENT_UPDATE_MESSAGE_FLAGS,
-  LOGIN_SUCCESS,
+  RESET_ACCOUNT_DATA,
 } from '../actionConstants';
 import { addItemsToArray, removeItemsFromArray } from '../utils/immutability';
 import { NULL_ARRAY } from '../nullObjects';
@@ -50,9 +48,7 @@ export default (
   action: PerAccountApplicableAction,
 ): UnreadMentionsState => {
   switch (action.type) {
-    case LOGOUT:
-    case ACCOUNT_SWITCH:
-    case LOGIN_SUCCESS:
+    case RESET_ACCOUNT_DATA:
       return initialState;
 
     case REGISTER_COMPLETE:
diff --git a/src/unread/unreadModel.js b/src/unread/unreadModel.js
index c2c2ef246b3..87ce9155c7a 100644
--- a/src/unread/unreadModel.js
+++ b/src/unread/unreadModel.js
@@ -18,15 +18,13 @@ import unreadPmsReducer from './unreadPmsReducer';
 import unreadHuddlesReducer from './unreadHuddlesReducer';
 import unreadMentionsReducer from './unreadMentionsReducer';
 import {
-  ACCOUNT_SWITCH,
   EVENT_MESSAGE_DELETE,
   EVENT_NEW_MESSAGE,
   EVENT_UPDATE_MESSAGE,
   EVENT_UPDATE_MESSAGE_FLAGS,
-  LOGIN_SUCCESS,
-  LOGOUT,
   MESSAGE_FETCH_COMPLETE,
   REGISTER_COMPLETE,
+  RESET_ACCOUNT_DATA,
 } from '../actionConstants';
 import DefaultMap from '../utils/DefaultMap';
 import * as logging from '../utils/logging';
@@ -225,9 +223,7 @@ function streamsReducer(
   globalState: PerAccountState,
 ): UnreadStreamsState {
   switch (action.type) {
-    case LOGOUT:
-    case ACCOUNT_SWITCH:
-    case LOGIN_SUCCESS:
+    case RESET_ACCOUNT_DATA:
       return initialStreamsState;
 
     case REGISTER_COMPLETE: {
diff --git a/src/unread/unreadPmsReducer.js b/src/unread/unreadPmsReducer.js
index ab84f333afc..1c1ac6e8865 100644
--- a/src/unread/unreadPmsReducer.js
+++ b/src/unread/unreadPmsReducer.js
@@ -5,12 +5,10 @@ import type { PerAccountApplicableAction, PerAccountState } from '../types';
 import type { UnreadPmsState } from './unreadModelTypes';
 import {
   REGISTER_COMPLETE,
-  LOGOUT,
-  ACCOUNT_SWITCH,
   EVENT_NEW_MESSAGE,
   EVENT_MESSAGE_DELETE,
   EVENT_UPDATE_MESSAGE_FLAGS,
-  LOGIN_SUCCESS,
+  RESET_ACCOUNT_DATA,
 } from '../actionConstants';
 import { addItemsToPmArray, removeItemsDeeply } from './unreadHelpers';
 import { NULL_ARRAY } from '../nullObjects';
@@ -92,9 +90,7 @@ export default (
   globalState: PerAccountState,
 ): UnreadPmsState => {
   switch (action.type) {
-    case LOGOUT:
-    case ACCOUNT_SWITCH:
-    case LOGIN_SUCCESS:
+    case RESET_ACCOUNT_DATA:
       return initialState;
 
     case REGISTER_COMPLETE:
diff --git a/src/user-groups/__tests__/userGroupsReducer-test.js b/src/user-groups/__tests__/userGroupsReducer-test.js
index 44fa9e81f04..99453063aa0 100644
--- a/src/user-groups/__tests__/userGroupsReducer-test.js
+++ b/src/user-groups/__tests__/userGroupsReducer-test.js
@@ -44,10 +44,10 @@ describe('userGroupsReducer', () => {
     });
   });
 
-  describe('ACCOUNT_SWITCH', () => {
+  describe('RESET_ACCOUNT_DATA', () => {
     test('resets state to initial state', () => {
       const prevState = deepFreeze([eg.makeUserGroup()]);
-      expect(userGroupsReducer(prevState, eg.action.account_switch)).toEqual([]);
+      expect(userGroupsReducer(prevState, eg.action.reset_account_data)).toEqual([]);
     });
   });
 
diff --git a/src/user-groups/userGroupsReducer.js b/src/user-groups/userGroupsReducer.js
index a405bc1adba..3f7d1dc2d8b 100644
--- a/src/user-groups/userGroupsReducer.js
+++ b/src/user-groups/userGroupsReducer.js
@@ -1,15 +1,13 @@
 /* @flow strict-local */
 import type { UserGroupsState, PerAccountApplicableAction } from '../types';
 import {
-  LOGOUT,
-  LOGIN_SUCCESS,
-  ACCOUNT_SWITCH,
   REGISTER_COMPLETE,
   EVENT_USER_GROUP_ADD,
   EVENT_USER_GROUP_REMOVE,
   EVENT_USER_GROUP_UPDATE,
   EVENT_USER_GROUP_ADD_MEMBERS,
   EVENT_USER_GROUP_REMOVE_MEMBERS,
+  RESET_ACCOUNT_DATA,
 } from '../actionConstants';
 import { NULL_ARRAY } from '../nullObjects';
 
@@ -50,9 +48,7 @@ export default (
   action: PerAccountApplicableAction,
 ): UserGroupsState => {
   switch (action.type) {
-    case LOGOUT:
-    case LOGIN_SUCCESS:
-    case ACCOUNT_SWITCH:
+    case RESET_ACCOUNT_DATA:
       return initialState;
 
     case REGISTER_COMPLETE:
diff --git a/src/user-statuses/__tests__/userStatusesModel-test.js b/src/user-statuses/__tests__/userStatusesModel-test.js
index 5b030015bf1..f44b109476b 100644
--- a/src/user-statuses/__tests__/userStatusesModel-test.js
+++ b/src/user-statuses/__tests__/userStatusesModel-test.js
@@ -29,9 +29,9 @@ describe('reducer', () => {
     reaction_type: '',
   };
 
-  describe('ACCOUNT_SWITCH', () => {
+  describe('RESET_ACCOUNT_DATA', () => {
     test('resets state to initial state', () => {
-      expect(reducer(testUserStatusesState, eg.action.account_switch)).toEqual(Immutable.Map());
+      expect(reducer(testUserStatusesState, eg.action.reset_account_data)).toEqual(Immutable.Map());
     });
   });
 
diff --git a/src/user-statuses/userStatusesModel.js b/src/user-statuses/userStatusesModel.js
index b3ecf9261ef..7be0906088e 100644
--- a/src/user-statuses/userStatusesModel.js
+++ b/src/user-statuses/userStatusesModel.js
@@ -7,12 +7,10 @@ import { objectEntries } from '../flowPonyfill';
 import type { PerAccountState, PerAccountApplicableAction, UserId } from '../types';
 import type { UserStatusesState } from './userStatusesCore';
 import {
-  LOGOUT,
-  LOGIN_SUCCESS,
-  ACCOUNT_SWITCH,
   REGISTER_COMPLETE,
   EVENT_USER_REMOVE,
   EVENT_USER_STATUS_UPDATE,
+  RESET_ACCOUNT_DATA,
 } from '../actionConstants';
 import { kUserStatusZero } from './userStatusesCore';
 
@@ -65,9 +63,7 @@ export const reducer = (
   action: PerAccountApplicableAction,
 ): UserStatusesState => {
   switch (action.type) {
-    case LOGOUT:
-    case LOGIN_SUCCESS:
-    case ACCOUNT_SWITCH:
+    case RESET_ACCOUNT_DATA:
       return initialState;
 
     case REGISTER_COMPLETE: {
diff --git a/src/users/__tests__/usersReducer-test.js b/src/users/__tests__/usersReducer-test.js
index fc4f71469e1..609962df8c1 100644
--- a/src/users/__tests__/usersReducer-test.js
+++ b/src/users/__tests__/usersReducer-test.js
@@ -3,7 +3,7 @@ import deepFreeze from 'deep-freeze';
 
 import * as eg from '../../__tests__/lib/exampleData';
 import { UploadedAvatarURL } from '../../utils/avatar';
-import { EVENT_USER_ADD, ACCOUNT_SWITCH, EVENT } from '../../actionConstants';
+import { EVENT_USER_ADD, EVENT } from '../../actionConstants';
 import { EventTypes, type RealmUserUpdateEvent } from '../../api/eventTypes';
 import type { User } from '../../types';
 import { RoleValues } from '../../api/permissionsTypes';
@@ -145,20 +145,15 @@ describe('usersReducer', () => {
     });
   });
 
-  describe('ACCOUNT_SWITCH', () => {
+  describe('RESET_ACCOUNT_DATA', () => {
     const user1 = eg.makeUser();
 
     test('resets state to initial state', () => {
       const prevState = deepFreeze([user1]);
 
-      const action = deepFreeze({
-        type: ACCOUNT_SWITCH,
-        index: 2,
-      });
-
       const expectedState = [];
 
-      const actualState = usersReducer(prevState, action);
+      const actualState = usersReducer(prevState, eg.action.reset_account_data);
 
       expect(actualState).toEqual(expectedState);
     });
diff --git a/src/users/usersReducer.js b/src/users/usersReducer.js
index 2b96b9a986e..04137b664c6 100644
--- a/src/users/usersReducer.js
+++ b/src/users/usersReducer.js
@@ -1,13 +1,11 @@
 /* @flow strict-local */
 import type { User, UsersState, PerAccountApplicableAction } from '../types';
 import {
-  LOGOUT,
-  LOGIN_SUCCESS,
-  ACCOUNT_SWITCH,
   REGISTER_COMPLETE,
   EVENT_USER_ADD,
   EVENT_USER_REMOVE,
   EVENT,
+  RESET_ACCOUNT_DATA,
 } from '../actionConstants';
 import { EventTypes } from '../api/eventTypes';
 import { NULL_ARRAY } from '../nullObjects';
@@ -19,9 +17,7 @@ export default (
   action: PerAccountApplicableAction,
 ): UsersState => {
   switch (action.type) {
-    case LOGOUT:
-    case LOGIN_SUCCESS:
-    case ACCOUNT_SWITCH:
+    case RESET_ACCOUNT_DATA:
       return initialState;
 
     case REGISTER_COMPLETE: