Skip to content

Commit a1ce7da

Browse files
committed
session: Clear all PerAccountSessionState when leaving account
Really an instance of zulip#4446 that I forgot about in zulip#5606, oops. Related: zulip#4446
1 parent a50be3c commit a1ce7da

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

src/session/__tests__/sessionReducer-test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
DISMISS_SERVER_COMPAT_NOTICE,
1414
REGISTER_START,
1515
} from '../../actionConstants';
16-
import sessionReducer from '../sessionReducer';
16+
import sessionReducer, { initialPerAccountSessionState } from '../sessionReducer';
1717
import * as eg from '../../__tests__/lib/exampleData';
1818

1919
describe('sessionReducer', () => {
@@ -25,12 +25,12 @@ describe('sessionReducer', () => {
2525
loading: true,
2626
});
2727
const newState = sessionReducer(state, eg.action.account_switch);
28-
expect(newState).toEqual({ ...baseState, loading: false });
28+
expect(newState).toEqual({ ...baseState, ...initialPerAccountSessionState });
2929
});
3030

3131
test('LOGIN_SUCCESS', () => {
3232
const newState = sessionReducer(baseState, eg.action.login_success);
33-
expect(newState).toEqual(baseState);
33+
expect(newState).toEqual({ ...baseState, ...initialPerAccountSessionState });
3434
});
3535

3636
test('DEAD_QUEUE', () => {
@@ -47,7 +47,7 @@ describe('sessionReducer', () => {
4747
const newState = sessionReducer(state, deepFreeze({ type: LOGOUT }));
4848
expect(newState).toEqual({
4949
...baseState,
50-
loading: false,
50+
...initialPerAccountSessionState,
5151
});
5252
});
5353

src/session/sessionReducer.js

+20-5
Original file line numberDiff line numberDiff line change
@@ -117,22 +117,30 @@ export type SessionState = $ReadOnly<{|
117117
// PerAccountSessionState is inexact.)
118118
(s: SessionState): PerAccountSessionState => s; // eslint-disable-line no-unused-expressions
119119

120-
const initialState: SessionState = {
121-
eventQueueId: null,
122-
120+
const initialGlobalSessionState: $Exact<GlobalSessionState> = {
123121
// This will be `null` on startup, while we wait to hear `true` or `false`
124122
// from the native module over the RN bridge; so, have it start as `null`.
125123
isOnline: null,
126124

127125
isHydrated: false,
128-
loading: false,
129126
orientation: 'PORTRAIT',
130-
outboxSending: false,
131127
pushToken: null,
132128
debug: Object.freeze({}),
129+
};
130+
131+
/** PRIVATE; exported only for tests. */
132+
export const initialPerAccountSessionState: $Exact<PerAccountSessionState> = {
133+
eventQueueId: null,
134+
loading: false,
135+
outboxSending: false,
133136
hasDismissedServerCompatNotice: false,
134137
};
135138

139+
const initialState: SessionState = {
140+
...initialGlobalSessionState,
141+
...initialPerAccountSessionState,
142+
};
143+
136144
// eslint-disable-next-line default-param-last
137145
export default (state: SessionState = initialState, action: Action): SessionState => {
138146
switch (action.type) {
@@ -149,6 +157,9 @@ export default (state: SessionState = initialState, action: Action): SessionStat
149157
case LOGIN_SUCCESS:
150158
return {
151159
...state,
160+
loading: false,
161+
outboxSending: false,
162+
hasDismissedServerCompatNotice: false,
152163

153164
// We're about to request a new event queue; no use hanging on to
154165
// any old one we might have.
@@ -159,6 +170,8 @@ export default (state: SessionState = initialState, action: Action): SessionStat
159170
return {
160171
...state,
161172
loading: false,
173+
outboxSending: false,
174+
hasDismissedServerCompatNotice: false,
162175

163176
// Stop polling this event queue.
164177
eventQueueId: null,
@@ -168,6 +181,8 @@ export default (state: SessionState = initialState, action: Action): SessionStat
168181
return {
169182
...state,
170183
loading: false,
184+
outboxSending: false,
185+
hasDismissedServerCompatNotice: false,
171186

172187
// Stop polling this event queue. (We'll request a new one soon,
173188
// for the new account.)

0 commit comments

Comments
 (0)