2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
2020-11-06 17:36:37 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { createSelector } from 'reselect';
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { StateType } from '../reducer';
|
|
|
|
import type {
|
2020-12-02 18:11:54 +00:00
|
|
|
CallingStateType,
|
|
|
|
CallsByConversationType,
|
|
|
|
DirectCallStateType,
|
2021-06-17 17:15:10 +00:00
|
|
|
GroupCallStateType,
|
2020-12-02 18:11:54 +00:00
|
|
|
} from '../ducks/calling';
|
2023-07-18 23:57:38 +00:00
|
|
|
import { getIncomingCall as getIncomingCallHelper } from '../ducks/callingHelpers';
|
2022-07-08 20:46:25 +00:00
|
|
|
import { getUserACI } from './user';
|
2020-12-07 20:43:19 +00:00
|
|
|
import { getOwn } from '../../util/getOwn';
|
2023-08-10 16:43:33 +00:00
|
|
|
import type { AciString } from '../../types/ServiceId';
|
2020-11-06 17:36:37 +00:00
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
export type CallStateType = DirectCallStateType | GroupCallStateType;
|
|
|
|
|
2020-12-02 18:11:54 +00:00
|
|
|
const getCalling = (state: StateType): CallingStateType => state.calling;
|
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
export const getActiveCallState = createSelector(
|
2021-01-29 22:58:28 +00:00
|
|
|
getCalling,
|
2021-06-17 17:15:10 +00:00
|
|
|
(state: CallingStateType) => state.activeCallState
|
2021-01-29 22:58:28 +00:00
|
|
|
);
|
|
|
|
|
2020-12-07 20:43:19 +00:00
|
|
|
export const getCallsByConversation = createSelector(
|
2020-12-02 18:11:54 +00:00
|
|
|
getCalling,
|
|
|
|
(state: CallingStateType): CallsByConversationType =>
|
|
|
|
state.callsByConversation
|
|
|
|
);
|
2020-11-06 17:36:37 +00:00
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
export type CallSelectorType = (
|
|
|
|
conversationId: string
|
|
|
|
) => CallStateType | undefined;
|
2020-12-07 20:43:19 +00:00
|
|
|
export const getCallSelector = createSelector(
|
|
|
|
getCallsByConversation,
|
2021-11-11 22:43:05 +00:00
|
|
|
(callsByConversation: CallsByConversationType): CallSelectorType =>
|
|
|
|
(conversationId: string) =>
|
|
|
|
getOwn(callsByConversation, conversationId)
|
2021-06-17 17:15:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
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)
|
2020-12-07 20:43:19 +00:00
|
|
|
);
|
|
|
|
|
2022-08-05 01:07:46 +00:00
|
|
|
export const isInFullScreenCall = createSelector(
|
|
|
|
getCalling,
|
|
|
|
(state: CallingStateType): boolean =>
|
|
|
|
Boolean(state.activeCallState && !state.activeCallState.pip)
|
|
|
|
);
|
|
|
|
|
2020-11-06 17:36:37 +00:00
|
|
|
export const getIncomingCall = createSelector(
|
|
|
|
getCallsByConversation,
|
2022-07-08 20:46:25 +00:00
|
|
|
getUserACI,
|
2020-12-02 18:11:54 +00:00
|
|
|
(
|
2021-08-20 16:06:15 +00:00
|
|
|
callsByConversation: CallsByConversationType,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci: AciString | undefined
|
2022-02-23 18:48:40 +00:00
|
|
|
): undefined | DirectCallStateType | GroupCallStateType => {
|
2023-08-10 16:43:33 +00:00
|
|
|
if (!ourAci) {
|
2022-02-23 18:48:40 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
return getIncomingCallHelper(callsByConversation, ourAci);
|
2022-02-23 18:48:40 +00:00
|
|
|
}
|
2020-11-06 17:36:37 +00:00
|
|
|
);
|
2022-05-25 18:03:27 +00:00
|
|
|
|
2022-11-17 02:52:04 +00:00
|
|
|
export const areAnyCallsActiveOrRinging = createSelector(
|
|
|
|
getActiveCall,
|
|
|
|
getIncomingCall,
|
|
|
|
(activeCall, incomingCall): boolean => Boolean(activeCall || incomingCall)
|
|
|
|
);
|