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

redux: Discard messages/narrows on REALM_INIT, not DEAD_QUEUE. #3822

Merged
merged 3 commits into from
Feb 19, 2020
Merged
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
4 changes: 2 additions & 2 deletions src/caughtup/caughtUpReducer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* @flow strict-local */
import type { CaughtUp, CaughtUpState, Action } from '../types';
import {
DEAD_QUEUE,
REALM_INIT,
LOGOUT,
LOGIN_SUCCESS,
ACCOUNT_SWITCH,
@@ -56,7 +56,7 @@ const legacyInferCaughtUp = (prevCaughtUp: CaughtUp | void, action) => {

export default (state: CaughtUpState = initialState, action: Action): CaughtUpState => {
switch (action.type) {
case DEAD_QUEUE:
case REALM_INIT:
case LOGOUT:
case LOGIN_SUCCESS:
case ACCOUNT_SWITCH:
7 changes: 5 additions & 2 deletions src/chat/Chat.js
Original file line number Diff line number Diff line change
@@ -11,10 +11,12 @@ import ComposeBox from '../compose/ComposeBox';
import UnreadNotice from './UnreadNotice';
import styles from '../styles';
import { canSendToNarrow } from '../utils/narrow';
import { getLoading } from '../directSelectors';
import { getFetchingForNarrow } from './fetchingSelectors';
import { getShownMessagesForNarrow } from './narrowsSelectors';

type SelectorProps = {|
loading: boolean,
fetching: Fetching,
haveNoMessages: boolean,
|};
@@ -37,9 +39,9 @@ const componentStyles = StyleSheet.create({

class Chat extends PureComponent<Props> {
render() {
const { fetching, haveNoMessages, narrow } = this.props;
const { fetching, loading, haveNoMessages, narrow } = this.props;

const isFetching = fetching.older || fetching.newer;
const isFetching = fetching.older || fetching.newer || loading;
const showMessagePlaceholders = haveNoMessages && isFetching;
const sayNoMessages = haveNoMessages && !isFetching;
const showComposeBox = canSendToNarrow(narrow) && !showMessagePlaceholders;
@@ -59,6 +61,7 @@ class Chat extends PureComponent<Props> {
}

export default connect<SelectorProps, _, _>((state, props) => ({
loading: getLoading(state),
fetching: getFetchingForNarrow(state, props.narrow),
haveNoMessages: getShownMessagesForNarrow(state, props.narrow).length === 0,
}))(Chat);
2 changes: 0 additions & 2 deletions src/chat/fetchingReducer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* @flow strict-local */
import type { FetchingState, Action } from '../types';
import {
DEAD_QUEUE,
LOGOUT,
LOGIN_SUCCESS,
ACCOUNT_SWITCH,
@@ -42,7 +41,6 @@ const messageFetchComplete = (state, action) => {

export default (state: FetchingState = initialState, action: Action): FetchingState => {
switch (action.type) {
case DEAD_QUEUE:
case LOGOUT:
case LOGIN_SUCCESS:
case DO_NARROW:
6 changes: 4 additions & 2 deletions src/chat/flagsReducer.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* @flow strict-local */
import type { Action, FlagsState, Message } from '../types';
import {
DEAD_QUEUE,
REALM_INIT,
MESSAGE_FETCH_COMPLETE,
EVENT_NEW_MESSAGE,
EVENT_UPDATE_MESSAGE_FLAGS,
LOGOUT,
LOGIN_SUCCESS,
ACCOUNT_SWITCH,
} from '../actionConstants';
import { deeperMerge } from '../utils/misc';
@@ -98,8 +99,9 @@ const eventUpdateMessageFlags = (state, action) => {

export default (state: FlagsState = initialState, action: Action): FlagsState => {
switch (action.type) {
case DEAD_QUEUE:
case REALM_INIT:
case LOGOUT:
case LOGIN_SUCCESS:
case ACCOUNT_SWITCH:
return initialState;

4 changes: 2 additions & 2 deletions src/chat/narrowsReducer.js
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import union from 'lodash.union';
import type { NarrowsState, Action } from '../types';
import { ensureUnreachable } from '../types';
import {
DEAD_QUEUE,
REALM_INIT,
LOGOUT,
LOGIN_SUCCESS,
ACCOUNT_SWITCH,
@@ -95,7 +95,7 @@ const eventUpdateMessageFlags = (state, action) => {

export default (state: NarrowsState = initialState, action: Action): NarrowsState => {
switch (action.type) {
case DEAD_QUEUE:
case REALM_INIT:
case LOGOUT:
case LOGIN_SUCCESS:
case ACCOUNT_SWITCH:
4 changes: 2 additions & 2 deletions src/message/messagesReducer.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ import omit from 'lodash.omit';

import type { MessagesState, Action } from '../types';
import {
DEAD_QUEUE,
REALM_INIT,
LOGOUT,
LOGIN_SUCCESS,
ACCOUNT_SWITCH,
@@ -139,7 +139,7 @@ const eventUpdateMessage = (state, action) => {

export default (state: MessagesState = initialState, action: Action): MessagesState => {
switch (action.type) {
case DEAD_QUEUE:
case REALM_INIT:
case LOGOUT:
case LOGIN_SUCCESS:
case ACCOUNT_SWITCH: