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

68 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-08-09 00:53:06 +00:00
// Copyright 2023 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { createSelector } from 'reselect';
import type { CallHistoryState } from '../ducks/callHistory';
import type { StateType } from '../reducer';
2024-06-26 00:58:38 +00:00
import {
AdhocCallStatus,
CallType,
type CallHistoryDetails,
} from '../../types/CallDisposition';
2023-08-09 00:53:06 +00:00
import { getOwn } from '../../util/getOwn';
const getCallHistory = (state: StateType): CallHistoryState =>
state.callHistory;
export const getCallHistoryEdition = createSelector(
getCallHistory,
callHistory => {
return callHistory.edition;
}
);
export type CallHistorySelectorType = (
callId: string
) => CallHistoryDetails | void;
export const getCallHistorySelector = createSelector(
getCallHistory,
(callHistory): CallHistorySelectorType => {
return callId => {
return getOwn(callHistory.callHistoryByCallId, callId);
};
}
);
export const getCallHistoryUnreadCount = createSelector(
getCallHistory,
callHistory => {
return callHistory.unreadCount;
}
);
2024-06-26 00:58:38 +00:00
export const getCallHistoryLatestCall = createSelector(
getCallHistory,
callHistory => {
let latestCall = null;
for (const callId of Object.keys(callHistory.callHistoryByCallId)) {
const call = callHistory.callHistoryByCallId[callId];
// Skip unused call links
if (
call.type === CallType.Adhoc &&
call.status === AdhocCallStatus.Pending
) {
continue;
}
if (latestCall == null || call.timestamp > latestCall.timestamp) {
latestCall = call;
}
}
return latestCall;
}
);