Skip to content

Commit 730c370

Browse files
committed
model: Fix lots of reducers that weren't clearing data on LOGIN_SUCCESS
Most of these state subtrees hold per-account data we get from the server. In the current pre-#5005 design, where we only store server data for one account, these should already have been clearing out on LOGIN_SUCCESS, like we do with messages, narrows, etc. Two of the subtrees, `outbox` and `drafts`, hold client-side per-account data. Just as with server data, we've only been keeping these around for the active account, and like the other reducers touched in this commit, we've forgotten to handle LOGIN_SUCCESS for them. So, do that. Now, all the server-data subtrees and `outbox` and `drafts` all reset on ACCOUNT_SWITCH, LOGIN_SUCCESS, and LOGOUT. That's part of Greg's proposed fix for #4446. Next, we'll do the next part: > * 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-partly: #4446
1 parent 3677788 commit 730c370

File tree

10 files changed

+44
-6
lines changed

10 files changed

+44
-6
lines changed

src/alertWords/alertWordsReducer.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
/* @flow strict-local */
22
import type { AlertWordsState, PerAccountApplicableAction } from '../types';
3-
import { REGISTER_COMPLETE, EVENT_ALERT_WORDS, ACCOUNT_SWITCH, LOGOUT } from '../actionConstants';
3+
import {
4+
REGISTER_COMPLETE,
5+
EVENT_ALERT_WORDS,
6+
ACCOUNT_SWITCH,
7+
LOGOUT,
8+
LOGIN_SUCCESS,
9+
} from '../actionConstants';
410
import { NULL_ARRAY } from '../nullObjects';
511

612
const initialState = NULL_ARRAY;
@@ -12,6 +18,7 @@ export default (
1218
switch (action.type) {
1319
case LOGOUT:
1420
case ACCOUNT_SWITCH:
21+
case LOGIN_SUCCESS:
1522
return initialState;
1623

1724
case REGISTER_COMPLETE:

src/drafts/draftsReducer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* @flow strict-local */
22
import type { DraftsState, PerAccountApplicableAction } from '../types';
3-
import { DRAFT_UPDATE, LOGOUT, ACCOUNT_SWITCH } from '../actionConstants';
3+
import { DRAFT_UPDATE, LOGOUT, ACCOUNT_SWITCH, LOGIN_SUCCESS } from '../actionConstants';
44
import { NULL_OBJECT } from '../nullObjects';
55
import { keyFromNarrow } from '../utils/narrow';
66

@@ -29,6 +29,7 @@ export default (
2929
switch (action.type) {
3030
case LOGOUT:
3131
case ACCOUNT_SWITCH:
32+
case LOGIN_SUCCESS:
3233
return initialState;
3334

3435
case DRAFT_UPDATE:

src/mute/muteModel.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
/* @flow strict-local */
22

33
import type { MuteState, PerAccountApplicableAction, PerAccountState } from '../types';
4-
import { REGISTER_COMPLETE, LOGOUT, ACCOUNT_SWITCH, EVENT_MUTED_TOPICS } from '../actionConstants';
4+
import {
5+
REGISTER_COMPLETE,
6+
LOGOUT,
7+
ACCOUNT_SWITCH,
8+
EVENT_MUTED_TOPICS,
9+
LOGIN_SUCCESS,
10+
} from '../actionConstants';
511
import { getStreamsByName } from '../subscriptions/subscriptionSelectors';
612
import * as logging from '../utils/logging';
713
import DefaultMap from '../utils/DefaultMap';
@@ -49,6 +55,7 @@ export const reducer = (
4955
switch (action.type) {
5056
case LOGOUT:
5157
case ACCOUNT_SWITCH:
58+
case LOGIN_SUCCESS:
5259
return initialState;
5360

5461
case REGISTER_COMPLETE:

src/outbox/outboxReducer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
ACCOUNT_SWITCH,
99
DELETE_OUTBOX_MESSAGE,
1010
MESSAGE_SEND_COMPLETE,
11+
LOGIN_SUCCESS,
1112
} from '../actionConstants';
1213
import { NULL_ARRAY } from '../nullObjects';
1314
import { filterArray } from '../utils/immutability';
@@ -44,6 +45,7 @@ export default (
4445

4546
case ACCOUNT_SWITCH:
4647
case LOGOUT:
48+
case LOGIN_SUCCESS:
4749
return initialState;
4850

4951
default:

src/streams/streamsReducer.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import { EventTypes } from '../api/eventTypes';
33
import type { PerAccountApplicableAction, StreamsState, StreamUpdateEvent } from '../types';
44
import type { Stream, Subscription } from '../api/modelTypes';
55
import { ensureUnreachable } from '../types';
6-
import { LOGOUT, ACCOUNT_SWITCH, EVENT, REGISTER_COMPLETE } from '../actionConstants';
6+
import {
7+
LOGOUT,
8+
ACCOUNT_SWITCH,
9+
EVENT,
10+
REGISTER_COMPLETE,
11+
LOGIN_SUCCESS,
12+
} from '../actionConstants';
713
import { NULL_ARRAY } from '../nullObjects';
814
import { filterArray } from '../utils/immutability';
915

@@ -61,6 +67,7 @@ export default (
6167

6268
case LOGOUT:
6369
case ACCOUNT_SWITCH:
70+
case LOGIN_SUCCESS:
6471
return initialState;
6572

6673
case EVENT: {

src/topics/topicsReducer.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
/* @flow strict-local */
22
import type { TopicsState, PerAccountApplicableAction } from '../types';
3-
import { LOGOUT, ACCOUNT_SWITCH, INIT_TOPICS, EVENT_NEW_MESSAGE } from '../actionConstants';
3+
import {
4+
LOGOUT,
5+
ACCOUNT_SWITCH,
6+
INIT_TOPICS,
7+
EVENT_NEW_MESSAGE,
8+
LOGIN_SUCCESS,
9+
} from '../actionConstants';
410
import { NULL_OBJECT } from '../nullObjects';
511
import { replaceItemInArray } from '../utils/immutability';
612

@@ -43,6 +49,7 @@ export default (
4349
switch (action.type) {
4450
case LOGOUT:
4551
case ACCOUNT_SWITCH:
52+
case LOGIN_SUCCESS:
4653
return initialState;
4754

4855
case INIT_TOPICS:

src/unread/unreadHuddlesReducer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
EVENT_NEW_MESSAGE,
1111
EVENT_MESSAGE_DELETE,
1212
EVENT_UPDATE_MESSAGE_FLAGS,
13+
LOGIN_SUCCESS,
1314
} from '../actionConstants';
1415
import {
1516
pmUnreadsKeyFromMessage,
@@ -93,6 +94,7 @@ export default (
9394
switch (action.type) {
9495
case LOGOUT:
9596
case ACCOUNT_SWITCH:
97+
case LOGIN_SUCCESS:
9698
return initialState;
9799

98100
case REGISTER_COMPLETE:

src/unread/unreadMentionsReducer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
EVENT_NEW_MESSAGE,
1111
EVENT_MESSAGE_DELETE,
1212
EVENT_UPDATE_MESSAGE_FLAGS,
13+
LOGIN_SUCCESS,
1314
} from '../actionConstants';
1415
import { addItemsToArray, removeItemsFromArray } from '../utils/immutability';
1516
import { NULL_ARRAY } from '../nullObjects';
@@ -51,6 +52,7 @@ export default (
5152
switch (action.type) {
5253
case LOGOUT:
5354
case ACCOUNT_SWITCH:
55+
case LOGIN_SUCCESS:
5456
return initialState;
5557

5658
case REGISTER_COMPLETE:

src/unread/unreadModel.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
EVENT_NEW_MESSAGE,
2424
EVENT_UPDATE_MESSAGE,
2525
EVENT_UPDATE_MESSAGE_FLAGS,
26+
LOGIN_SUCCESS,
2627
LOGOUT,
2728
MESSAGE_FETCH_COMPLETE,
2829
REGISTER_COMPLETE,
@@ -226,7 +227,7 @@ function streamsReducer(
226227
switch (action.type) {
227228
case LOGOUT:
228229
case ACCOUNT_SWITCH:
229-
// TODO(#4446) also LOGIN_SUCCESS, presumably
230+
case LOGIN_SUCCESS:
230231
return initialStreamsState;
231232

232233
case REGISTER_COMPLETE: {

src/unread/unreadPmsReducer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
EVENT_NEW_MESSAGE,
1111
EVENT_MESSAGE_DELETE,
1212
EVENT_UPDATE_MESSAGE_FLAGS,
13+
LOGIN_SUCCESS,
1314
} from '../actionConstants';
1415
import { addItemsToPmArray, removeItemsDeeply } from './unreadHelpers';
1516
import { NULL_ARRAY } from '../nullObjects';
@@ -93,6 +94,7 @@ export default (
9394
switch (action.type) {
9495
case LOGOUT:
9596
case ACCOUNT_SWITCH:
97+
case LOGIN_SUCCESS:
9698
return initialState;
9799

98100
case REGISTER_COMPLETE:

0 commit comments

Comments
 (0)