Skip to content

Commit

Permalink
session [nfc]: Split getGlobalSession vs getSession
Browse files Browse the repository at this point in the history
  • Loading branch information
gnprice committed Oct 4, 2021
1 parent f469002 commit 3883530
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/common/OfflineNotice.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as logging from '../utils/logging';
import { createStyleSheet, HALF_COLOR } from '../styles';
import { useHasStayedTrueForMs } from '../reactUtils';
import { useSelector } from '../react-redux';
import { getSession } from '../selectors';
import { getGlobalSession } from '../selectors';
import Label from './Label';

const styles = createStyleSheet({
Expand Down Expand Up @@ -37,7 +37,7 @@ type Props = $ReadOnly<{||}>;
* Shows nothing if the Internet is reachable.
*/
export default function OfflineNotice(props: Props): Node {
const isOnline = useSelector(state => getSession(state).isOnline);
const isOnline = useSelector(state => getGlobalSession(state).isOnline);

const shouldShowUncertaintyNotice = useHasStayedTrueForMs(
// See note in `SessionState` for what this means.
Expand Down
4 changes: 2 additions & 2 deletions src/common/ZulipStatusBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Color from 'color';
import type { ThemeName } from '../types';
import { useSelector } from '../react-redux';
import { foregroundColorFromBackground } from '../utils/color';
import { getSession, getGlobalSettings } from '../selectors';
import { getGlobalSession, getGlobalSettings } from '../selectors';

type BarStyle = $PropertyType<React$ElementConfig<typeof StatusBar>, 'barStyle'>;

Expand Down Expand Up @@ -46,7 +46,7 @@ type Props = $ReadOnly<{|
export default function ZulipStatusBar(props: Props): Node {
const { hidden = false } = props;
const theme = useSelector(state => getGlobalSettings(state).theme);
const orientation = useSelector(state => getSession(state).orientation);
const orientation = useSelector(state => getGlobalSession(state).orientation);
const backgroundColor = props.backgroundColor;
const statusBarColor = getStatusBarColor(backgroundColor, theme);
return (
Expand Down
5 changes: 3 additions & 2 deletions src/directSelectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ import type {
User,
UserStatusState,
} from './types';
import type { SessionState } from './session/sessionReducer';
import type { PerAccountSessionState, GlobalSessionState } from './session/sessionReducer';

export const getAccounts = (state: GlobalState): AccountsState => state.accounts;

export const getSession = (state: GlobalState): SessionState => state.session;
export const getSession = (state: PerAccountState): PerAccountSessionState => state.session;
export const getGlobalSession = (state: GlobalState): GlobalSessionState => state.session;

export const getIsOnline = (state: GlobalState): boolean | null => state.session.isOnline;
export const getDebug = (state: GlobalState): Debug => state.session.debug;
Expand Down
4 changes: 2 additions & 2 deletions src/lightbox/Lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as NavigationService from '../nav/NavigationService';
import type { Message } from '../types';
import { useSelector } from '../react-redux';
import type { ShowActionSheetWithOptions } from '../message/messageActionSheet';
import { getAuth, getSession } from '../selectors';
import { getAuth, getGlobalSession } from '../selectors';
import { getResource } from '../utils/url';
import LightboxHeader from './LightboxHeader';
import LightboxFooter from './LightboxFooter';
Expand Down Expand Up @@ -69,7 +69,7 @@ export default function Lightbox(props: Props): Node {

// Since we're using `Dimensions.get` (below), we'll want a rerender
// when the orientation changes. No need to store the value.
useSelector(state => getSession(state).orientation);
useSelector(state => getGlobalSession(state).orientation);

const { width: windowWidth, height: windowHeight } = Dimensions.get('window');

Expand Down
6 changes: 3 additions & 3 deletions src/notification/notificationActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '.';
import type { Notification } from './types';
import { getAuth } from '../selectors';
import { getSession, getAccounts } from '../directSelectors';
import { getGlobalSession, getAccounts } from '../directSelectors';
import { GOT_PUSH_TOKEN, ACK_PUSH_TOKEN, UNACK_PUSH_TOKEN } from '../actionConstants';
import { identityOfAccount, authOfAccount } from '../account/accountMisc';
import { getAllUsersByEmail, getOwnUserId } from '../users/userSelectors';
Expand Down Expand Up @@ -79,7 +79,7 @@ const sendPushToken = async (dispatch: Dispatch, account: Account | void, pushTo

/** Tell all logged-in accounts' servers about our device token, as needed. */
export const sendAllPushToken = (): ThunkAction<Promise<void>> => async (dispatch, getState) => {
const { pushToken } = getSession(getState());
const { pushToken } = getGlobalSession(getState());
if (pushToken === null) {
return;
}
Expand All @@ -89,7 +89,7 @@ export const sendAllPushToken = (): ThunkAction<Promise<void>> => async (dispatc

/** Tell this account's server about our device token, if needed. */
export const initNotifications = (): ThunkAction<Promise<void>> => async (dispatch, getState) => {
const { pushToken } = getSession(getState());
const { pushToken } = getGlobalSession(getState());
if (pushToken === null) {
// Probably, we just don't have the token yet. When we learn it,
// the listener will update this and all other logged-in servers.
Expand Down

0 comments on commit 3883530

Please sign in to comment.