signal-desktop/ts/state/selectors/calling.ts

68 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-08-20 16:06:15 +00:00
// Copyright 2020-2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { createSelector } from 'reselect';
import { StateType } from '../reducer';
import {
CallingStateType,
CallsByConversationType,
DirectCallStateType,
GroupCallStateType,
getIncomingCall as getIncomingCallHelper,
} from '../ducks/calling';
2021-08-20 16:06:15 +00:00
import { getUserUuid } from './user';
import { getOwn } from '../../util/getOwn';
export type CallStateType = DirectCallStateType | GroupCallStateType;
const getCalling = (state: StateType): CallingStateType => state.calling;
export const getActiveCallState = createSelector(
2021-01-29 22:58:28 +00:00
getCalling,
(state: CallingStateType) => state.activeCallState
2021-01-29 22:58:28 +00:00
);
export const getCallsByConversation = createSelector(
getCalling,
(state: CallingStateType): CallsByConversationType =>
state.callsByConversation
);
export type CallSelectorType = (
conversationId: string
) => CallStateType | undefined;
export const getCallSelector = createSelector(
getCallsByConversation,
(callsByConversation: CallsByConversationType): CallSelectorType => (
conversationId: string
) => getOwn(callsByConversation, conversationId)
);
export const getActiveCall = createSelector(
getActiveCallState,
getCallSelector,
(activeCallState, callSelector): undefined | CallStateType => {
if (activeCallState && activeCallState.conversationId) {
return callSelector(activeCallState.conversationId);
}
return undefined;
}
);
export const isInCall = createSelector(
getActiveCall,
(call: CallStateType | undefined): boolean => Boolean(call)
);
export const getIncomingCall = createSelector(
getCallsByConversation,
2021-08-20 16:06:15 +00:00
getUserUuid,
(
2021-08-20 16:06:15 +00:00
callsByConversation: CallsByConversationType,
ourUuid: string
): undefined | DirectCallStateType | GroupCallStateType =>
getIncomingCallHelper(callsByConversation, ourUuid)
);