2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-02-12 21:30:58 +00:00
|
|
|
import { createSelector } from 'reselect';
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { StateType } from '../reducer';
|
|
|
|
import type { NetworkStateType } from '../ducks/network';
|
2020-02-21 23:08:21 +00:00
|
|
|
import { isDone } from '../../util/registration';
|
2021-06-09 22:28:54 +00:00
|
|
|
import { SocketStatus } from '../../types/SocketStatus';
|
2020-02-12 21:30:58 +00:00
|
|
|
|
|
|
|
const getNetwork = (state: StateType): NetworkStateType => state.network;
|
|
|
|
|
|
|
|
export const hasNetworkDialog = createSelector(
|
|
|
|
getNetwork,
|
|
|
|
isDone,
|
|
|
|
(
|
2024-03-12 19:52:02 +00:00
|
|
|
{
|
|
|
|
isOnline,
|
|
|
|
isOutage,
|
|
|
|
socketStatus,
|
|
|
|
withinConnectingGracePeriod,
|
|
|
|
}: NetworkStateType,
|
2020-02-12 21:30:58 +00:00
|
|
|
isRegistrationDone: boolean
|
|
|
|
): boolean =>
|
2020-04-27 22:36:49 +00:00
|
|
|
isRegistrationDone &&
|
|
|
|
(!isOnline ||
|
2024-03-12 19:52:02 +00:00
|
|
|
isOutage ||
|
2021-06-09 22:28:54 +00:00
|
|
|
(socketStatus === SocketStatus.CONNECTING &&
|
|
|
|
!withinConnectingGracePeriod) ||
|
|
|
|
socketStatus === SocketStatus.CLOSED ||
|
|
|
|
socketStatus === SocketStatus.CLOSING)
|
2020-02-12 21:30:58 +00:00
|
|
|
);
|
2021-05-06 00:09:29 +00:00
|
|
|
|
|
|
|
export const isChallengePending = createSelector(
|
|
|
|
getNetwork,
|
|
|
|
({ challengeStatus }) => challengeStatus === 'pending'
|
|
|
|
);
|