Calling selectors are now based on the root state
This commit is contained in:
parent
d1866a0e5d
commit
be99bbe87a
4 changed files with 47 additions and 19 deletions
|
@ -89,10 +89,12 @@ export interface ActiveCallStateType {
|
||||||
settingsDialogOpen: boolean;
|
settingsDialogOpen: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface CallsByConversationType {
|
||||||
|
[conversationId: string]: DirectCallStateType | GroupCallStateType;
|
||||||
|
}
|
||||||
|
|
||||||
export type CallingStateType = MediaDeviceSettings & {
|
export type CallingStateType = MediaDeviceSettings & {
|
||||||
callsByConversation: {
|
callsByConversation: CallsByConversationType;
|
||||||
[conversationId: string]: DirectCallStateType | GroupCallStateType;
|
|
||||||
};
|
|
||||||
activeCallState?: ActiveCallStateType;
|
activeCallState?: ActiveCallStateType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,17 +3,29 @@
|
||||||
|
|
||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
|
|
||||||
import { CallingStateType, DirectCallStateType } from '../ducks/calling';
|
import { StateType } from '../reducer';
|
||||||
|
import {
|
||||||
|
CallingStateType,
|
||||||
|
CallsByConversationType,
|
||||||
|
DirectCallStateType,
|
||||||
|
} from '../ducks/calling';
|
||||||
import { CallMode, CallState } from '../../types/Calling';
|
import { CallMode, CallState } from '../../types/Calling';
|
||||||
|
|
||||||
const getCallsByConversation = (state: CallingStateType) =>
|
const getCalling = (state: StateType): CallingStateType => state.calling;
|
||||||
state.callsByConversation;
|
|
||||||
|
const getCallsByConversation = createSelector(
|
||||||
|
getCalling,
|
||||||
|
(state: CallingStateType): CallsByConversationType =>
|
||||||
|
state.callsByConversation
|
||||||
|
);
|
||||||
|
|
||||||
// In theory, there could be multiple incoming calls. In practice, neither RingRTC nor the
|
// In theory, there could be multiple incoming calls. In practice, neither RingRTC nor the
|
||||||
// UI are ready to handle this.
|
// UI are ready to handle this.
|
||||||
export const getIncomingCall = createSelector(
|
export const getIncomingCall = createSelector(
|
||||||
getCallsByConversation,
|
getCallsByConversation,
|
||||||
(callsByConversation): undefined | DirectCallStateType => {
|
(
|
||||||
|
callsByConversation: CallsByConversationType
|
||||||
|
): undefined | DirectCallStateType => {
|
||||||
const result = Object.values(callsByConversation).find(
|
const result = Object.values(callsByConversation).find(
|
||||||
call =>
|
call =>
|
||||||
call.callMode === CallMode.Direct &&
|
call.callMode === CallMode.Direct &&
|
||||||
|
|
|
@ -124,7 +124,7 @@ const mapStateToActiveCallProp = (state: StateType) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const mapStateToIncomingCallProp = (state: StateType) => {
|
const mapStateToIncomingCallProp = (state: StateType) => {
|
||||||
const call = getIncomingCall(state.calling);
|
const call = getIncomingCall(state);
|
||||||
if (!call) {
|
if (!call) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,20 @@
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import { assert } from 'chai';
|
import { assert } from 'chai';
|
||||||
|
import { reducer as rootReducer } from '../../../state/reducer';
|
||||||
|
import { noopAction } from '../../../state/ducks/noop';
|
||||||
import { CallMode, CallState } from '../../../types/Calling';
|
import { CallMode, CallState } from '../../../types/Calling';
|
||||||
import { getIncomingCall } from '../../../state/selectors/calling';
|
import { getIncomingCall } from '../../../state/selectors/calling';
|
||||||
import { getEmptyState, CallingStateType } from '../../../state/ducks/calling';
|
import { getEmptyState, CallingStateType } from '../../../state/ducks/calling';
|
||||||
|
|
||||||
describe('state/selectors/calling', () => {
|
describe('state/selectors/calling', () => {
|
||||||
|
const getEmptyRootState = () => rootReducer(undefined, noopAction());
|
||||||
|
|
||||||
|
const getCallingState = (calling: CallingStateType) => ({
|
||||||
|
...getEmptyRootState(),
|
||||||
|
calling,
|
||||||
|
});
|
||||||
|
|
||||||
const stateWithDirectCall: CallingStateType = {
|
const stateWithDirectCall: CallingStateType = {
|
||||||
...getEmptyState(),
|
...getEmptyState(),
|
||||||
callsByConversation: {
|
callsByConversation: {
|
||||||
|
@ -49,23 +58,28 @@ describe('state/selectors/calling', () => {
|
||||||
|
|
||||||
describe('getIncomingCall', () => {
|
describe('getIncomingCall', () => {
|
||||||
it('returns undefined if there are no calls', () => {
|
it('returns undefined if there are no calls', () => {
|
||||||
assert.isUndefined(getIncomingCall(getEmptyState()));
|
assert.isUndefined(getIncomingCall(getEmptyRootState()));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns undefined if there is no incoming call', () => {
|
it('returns undefined if there is no incoming call', () => {
|
||||||
assert.isUndefined(getIncomingCall(stateWithDirectCall));
|
assert.isUndefined(getIncomingCall(getCallingState(stateWithDirectCall)));
|
||||||
assert.isUndefined(getIncomingCall(stateWithActiveDirectCall));
|
assert.isUndefined(
|
||||||
|
getIncomingCall(getCallingState(stateWithActiveDirectCall))
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns the incoming call', () => {
|
it('returns the incoming call', () => {
|
||||||
assert.deepEqual(getIncomingCall(stateWithIncomingDirectCall), {
|
assert.deepEqual(
|
||||||
callMode: CallMode.Direct,
|
getIncomingCall(getCallingState(stateWithIncomingDirectCall)),
|
||||||
conversationId: 'fake-direct-call-conversation-id',
|
{
|
||||||
callState: CallState.Ringing,
|
callMode: CallMode.Direct,
|
||||||
isIncoming: true,
|
conversationId: 'fake-direct-call-conversation-id',
|
||||||
isVideoCall: false,
|
callState: CallState.Ringing,
|
||||||
hasRemoteVideo: false,
|
isIncoming: true,
|
||||||
});
|
isVideoCall: false,
|
||||||
|
hasRemoteVideo: false,
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue