2022-02-23 18:48:40 +00:00
|
|
|
// Copyright 2020-2022 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 {
|
2022-05-25 18:03:27 +00:00
|
|
|
ActiveCallStateType,
|
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';
|
2021-10-26 19:15:33 +00:00
|
|
|
import { getIncomingCall as getIncomingCallHelper } from '../ducks/calling';
|
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';
|
2022-05-25 18:03:27 +00:00
|
|
|
import { CallViewMode } from '../../types/Calling';
|
2021-10-26 22:59:08 +00:00
|
|
|
import type { UUIDStringType } from '../../types/UUID';
|
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,
|
2022-02-23 18:48:40 +00:00
|
|
|
ourUuid: UUIDStringType | undefined
|
|
|
|
): undefined | DirectCallStateType | GroupCallStateType => {
|
|
|
|
if (!ourUuid) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return getIncomingCallHelper(callsByConversation, ourUuid);
|
|
|
|
}
|
2020-11-06 17:36:37 +00:00
|
|
|
);
|
2022-05-25 18:03:27 +00:00
|
|
|
|
|
|
|
export const isInSpeakerView = (
|
|
|
|
call: Pick<ActiveCallStateType, 'viewMode'> | undefined
|
|
|
|
): boolean => {
|
|
|
|
return Boolean(
|
|
|
|
call?.viewMode === CallViewMode.Presentation ||
|
|
|
|
call?.viewMode === CallViewMode.Speaker
|
|
|
|
);
|
|
|
|
};
|