2023-08-09 00:53:06 +00:00
|
|
|
// Copyright 2023 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
2024-06-10 15:23:43 +00:00
|
|
|
import React, { memo, useCallback, useEffect, useMemo } from 'react';
|
2023-08-09 00:53:06 +00:00
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
import { useItemsActions } from '../ducks/items';
|
|
|
|
import {
|
|
|
|
getNavTabsCollapsed,
|
|
|
|
getPreferredLeftPaneWidth,
|
|
|
|
} from '../selectors/items';
|
|
|
|
import { getIntl, getRegionCode } from '../selectors/user';
|
2024-01-29 20:09:54 +00:00
|
|
|
import type { WidthBreakpoint } from '../../components/_util';
|
2023-08-09 00:53:06 +00:00
|
|
|
import { CallsTab } from '../../components/CallsTab';
|
|
|
|
import {
|
|
|
|
getAllConversations,
|
|
|
|
getConversationSelector,
|
|
|
|
} from '../selectors/conversations';
|
2024-03-18 23:31:42 +00:00
|
|
|
import { filterAndSortConversations } from '../../util/filterAndSortConversations';
|
2023-08-09 00:53:06 +00:00
|
|
|
import type {
|
|
|
|
CallHistoryFilter,
|
|
|
|
CallHistoryFilterOptions,
|
|
|
|
CallHistoryGroup,
|
|
|
|
CallHistoryPagination,
|
|
|
|
} from '../../types/CallDisposition';
|
|
|
|
import type { ConversationType } from '../ducks/conversations';
|
|
|
|
import { SmartConversationDetails } from './ConversationDetails';
|
2024-01-29 20:09:54 +00:00
|
|
|
import { SmartToastManager } from './ToastManager';
|
2023-08-09 00:53:06 +00:00
|
|
|
import { useCallingActions } from '../ducks/calling';
|
2024-05-17 22:02:07 +00:00
|
|
|
import {
|
|
|
|
getActiveCallState,
|
|
|
|
getAdhocCallSelector,
|
2024-05-17 23:22:51 +00:00
|
|
|
getAllCallLinks,
|
2024-05-17 22:02:07 +00:00
|
|
|
getCallSelector,
|
|
|
|
getCallLinkSelector,
|
|
|
|
} from '../selectors/calling';
|
2023-08-09 00:53:06 +00:00
|
|
|
import { useCallHistoryActions } from '../ducks/callHistory';
|
|
|
|
import { getCallHistoryEdition } from '../selectors/callHistory';
|
2023-08-14 23:28:47 +00:00
|
|
|
import { getHasPendingUpdate } from '../selectors/updates';
|
|
|
|
import { getHasAnyFailedStorySends } from '../selectors/stories';
|
2023-08-21 20:12:27 +00:00
|
|
|
import { getOtherTabsUnreadStats } from '../selectors/nav';
|
2024-05-22 16:24:27 +00:00
|
|
|
import { SmartCallLinkDetails } from './CallLinkDetails';
|
2024-05-17 23:22:51 +00:00
|
|
|
import type { CallLinkType } from '../../types/CallLink';
|
|
|
|
import { filterCallLinks } from '../../util/filterCallLinks';
|
2024-06-10 15:23:43 +00:00
|
|
|
import { useGlobalModalActions } from '../ducks/globalModals';
|
|
|
|
import { isCallLinksCreateEnabled } from '../../util/callLinks';
|
2024-05-17 23:22:51 +00:00
|
|
|
|
|
|
|
function getCallHistoryFilter({
|
|
|
|
allCallLinks,
|
|
|
|
allConversations,
|
|
|
|
regionCode,
|
|
|
|
options,
|
|
|
|
}: {
|
|
|
|
allConversations: Array<ConversationType>;
|
|
|
|
allCallLinks: Array<CallLinkType>;
|
|
|
|
regionCode: string | undefined;
|
|
|
|
options: CallHistoryFilterOptions;
|
|
|
|
}): CallHistoryFilter | null {
|
|
|
|
const { status } = options;
|
2023-08-09 00:53:06 +00:00
|
|
|
const query = options.query.normalize().trim();
|
|
|
|
|
2024-05-17 23:22:51 +00:00
|
|
|
if (query === '') {
|
|
|
|
return {
|
|
|
|
status,
|
|
|
|
callLinkRoomIds: null,
|
|
|
|
conversationIds: null,
|
|
|
|
};
|
|
|
|
}
|
2023-08-09 00:53:06 +00:00
|
|
|
|
2024-05-17 23:22:51 +00:00
|
|
|
let callLinkRoomIds = null;
|
|
|
|
let conversationIds = null;
|
2023-08-09 00:53:06 +00:00
|
|
|
|
2024-05-17 23:22:51 +00:00
|
|
|
const currentConversations = allConversations.filter(conversation => {
|
|
|
|
return conversation.removalStage == null;
|
|
|
|
});
|
2023-08-09 00:53:06 +00:00
|
|
|
|
2024-05-17 23:22:51 +00:00
|
|
|
const filteredConversations = filterAndSortConversations(
|
|
|
|
currentConversations,
|
|
|
|
query,
|
|
|
|
regionCode
|
|
|
|
);
|
|
|
|
|
|
|
|
if (filteredConversations.length > 0) {
|
|
|
|
conversationIds = filteredConversations.map(conversation => {
|
|
|
|
return conversation.id;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const filteredCallLinks = filterCallLinks(allCallLinks, query);
|
|
|
|
if (filteredCallLinks.length > 0) {
|
|
|
|
callLinkRoomIds = filteredCallLinks.map(callLink => {
|
|
|
|
return callLink.roomId;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the search query resulted in no matching call links or conversations, then
|
|
|
|
// no calls will match.
|
|
|
|
if (callLinkRoomIds == null && conversationIds == null) {
|
|
|
|
return null;
|
2023-08-09 00:53:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2024-05-17 23:22:51 +00:00
|
|
|
status,
|
|
|
|
callLinkRoomIds,
|
|
|
|
conversationIds,
|
2023-08-09 00:53:06 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-05-22 16:24:27 +00:00
|
|
|
function renderCallLinkDetails(
|
|
|
|
roomId: string,
|
|
|
|
callHistoryGroup: CallHistoryGroup
|
|
|
|
): JSX.Element {
|
|
|
|
return (
|
|
|
|
<SmartCallLinkDetails roomId={roomId} callHistoryGroup={callHistoryGroup} />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-08-09 00:53:06 +00:00
|
|
|
function renderConversationDetails(
|
|
|
|
conversationId: string,
|
|
|
|
callHistoryGroup: CallHistoryGroup | null
|
|
|
|
): JSX.Element {
|
|
|
|
return (
|
|
|
|
<SmartConversationDetails
|
|
|
|
conversationId={conversationId}
|
|
|
|
callHistoryGroup={callHistoryGroup}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-01-29 20:09:54 +00:00
|
|
|
function renderToastManager(props: {
|
|
|
|
containerWidthBreakpoint: WidthBreakpoint;
|
|
|
|
}): JSX.Element {
|
|
|
|
return <SmartToastManager disableMegaphone {...props} />;
|
|
|
|
}
|
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
export const SmartCallsTab = memo(function SmartCallsTab() {
|
2023-08-09 00:53:06 +00:00
|
|
|
const i18n = useSelector(getIntl);
|
|
|
|
const navTabsCollapsed = useSelector(getNavTabsCollapsed);
|
|
|
|
const preferredLeftPaneWidth = useSelector(getPreferredLeftPaneWidth);
|
|
|
|
const { savePreferredLeftPaneWidth, toggleNavTabsCollapse } =
|
|
|
|
useItemsActions();
|
|
|
|
|
2024-05-17 23:22:51 +00:00
|
|
|
const allCallLinks = useSelector(getAllCallLinks);
|
2023-08-09 00:53:06 +00:00
|
|
|
const allConversations = useSelector(getAllConversations);
|
|
|
|
const regionCode = useSelector(getRegionCode);
|
|
|
|
const getConversation = useSelector(getConversationSelector);
|
2024-05-17 22:02:07 +00:00
|
|
|
const getAdhocCall = useSelector(getAdhocCallSelector);
|
|
|
|
const getCall = useSelector(getCallSelector);
|
2024-04-01 19:19:35 +00:00
|
|
|
const getCallLink = useSelector(getCallLinkSelector);
|
2023-08-09 00:53:06 +00:00
|
|
|
|
|
|
|
const activeCall = useSelector(getActiveCallState);
|
|
|
|
const callHistoryEdition = useSelector(getCallHistoryEdition);
|
|
|
|
|
2023-08-14 23:28:47 +00:00
|
|
|
const hasPendingUpdate = useSelector(getHasPendingUpdate);
|
|
|
|
const hasFailedStorySends = useSelector(getHasAnyFailedStorySends);
|
2023-08-21 20:12:27 +00:00
|
|
|
const otherTabsUnreadStats = useSelector(getOtherTabsUnreadStats);
|
2023-08-14 23:28:47 +00:00
|
|
|
|
2024-06-10 15:23:43 +00:00
|
|
|
const canCreateCallLinks = useMemo(() => {
|
|
|
|
return isCallLinksCreateEnabled();
|
|
|
|
}, []);
|
|
|
|
|
2023-08-09 00:53:06 +00:00
|
|
|
const {
|
2024-06-10 15:23:43 +00:00
|
|
|
createCallLink,
|
2024-05-17 22:02:07 +00:00
|
|
|
hangUpActiveCall,
|
2023-08-09 00:53:06 +00:00
|
|
|
onOutgoingAudioCallInConversation,
|
|
|
|
onOutgoingVideoCallInConversation,
|
2024-05-17 22:02:07 +00:00
|
|
|
peekNotConnectedGroupCall,
|
2024-04-01 19:19:35 +00:00
|
|
|
startCallLinkLobbyByRoomId,
|
2024-05-17 22:02:07 +00:00
|
|
|
togglePip,
|
2023-08-09 00:53:06 +00:00
|
|
|
} = useCallingActions();
|
2023-08-22 21:01:36 +00:00
|
|
|
const {
|
|
|
|
clearAllCallHistory: clearCallHistory,
|
|
|
|
markCallHistoryRead,
|
|
|
|
markCallsTabViewed,
|
|
|
|
} = useCallHistoryActions();
|
2024-06-10 15:23:43 +00:00
|
|
|
const { toggleCallLinkEditModal } = useGlobalModalActions();
|
2023-08-09 00:53:06 +00:00
|
|
|
|
|
|
|
const getCallHistoryGroupsCount = useCallback(
|
|
|
|
async (options: CallHistoryFilterOptions) => {
|
2024-05-17 23:22:51 +00:00
|
|
|
const callHistoryFilter = getCallHistoryFilter({
|
|
|
|
allCallLinks,
|
2023-08-09 00:53:06 +00:00
|
|
|
allConversations,
|
|
|
|
regionCode,
|
2024-05-17 23:22:51 +00:00
|
|
|
options,
|
|
|
|
});
|
2023-08-09 00:53:06 +00:00
|
|
|
if (callHistoryFilter == null) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
const count = await window.Signal.Data.getCallHistoryGroupsCount(
|
|
|
|
callHistoryFilter
|
|
|
|
);
|
|
|
|
return count;
|
|
|
|
},
|
2024-05-17 23:22:51 +00:00
|
|
|
[allCallLinks, allConversations, regionCode]
|
2023-08-09 00:53:06 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const getCallHistoryGroups = useCallback(
|
|
|
|
async (
|
|
|
|
options: CallHistoryFilterOptions,
|
|
|
|
pagination: CallHistoryPagination
|
|
|
|
) => {
|
2024-05-17 23:22:51 +00:00
|
|
|
const callHistoryFilter = getCallHistoryFilter({
|
|
|
|
allCallLinks,
|
2023-08-09 00:53:06 +00:00
|
|
|
allConversations,
|
|
|
|
regionCode,
|
2024-05-17 23:22:51 +00:00
|
|
|
options,
|
|
|
|
});
|
2023-08-09 00:53:06 +00:00
|
|
|
if (callHistoryFilter == null) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
const results = await window.Signal.Data.getCallHistoryGroups(
|
|
|
|
callHistoryFilter,
|
|
|
|
pagination
|
|
|
|
);
|
|
|
|
return results;
|
|
|
|
},
|
2024-05-17 23:22:51 +00:00
|
|
|
[allCallLinks, allConversations, regionCode]
|
2023-08-09 00:53:06 +00:00
|
|
|
);
|
|
|
|
|
2024-06-10 15:23:43 +00:00
|
|
|
const handleCreateCallLink = useCallback(() => {
|
|
|
|
createCallLink(roomId => {
|
|
|
|
toggleCallLinkEditModal(roomId);
|
|
|
|
});
|
|
|
|
}, [createCallLink, toggleCallLinkEditModal]);
|
|
|
|
|
2023-08-22 21:01:36 +00:00
|
|
|
useEffect(() => {
|
|
|
|
markCallsTabViewed();
|
|
|
|
}, [markCallsTabViewed]);
|
|
|
|
|
2023-08-09 00:53:06 +00:00
|
|
|
return (
|
|
|
|
<CallsTab
|
|
|
|
activeCall={activeCall}
|
|
|
|
allConversations={allConversations}
|
2023-08-21 20:12:27 +00:00
|
|
|
otherTabsUnreadStats={otherTabsUnreadStats}
|
2023-08-09 00:53:06 +00:00
|
|
|
getConversation={getConversation}
|
|
|
|
getCallHistoryGroupsCount={getCallHistoryGroupsCount}
|
|
|
|
getCallHistoryGroups={getCallHistoryGroups}
|
2024-05-17 22:02:07 +00:00
|
|
|
getAdhocCall={getAdhocCall}
|
|
|
|
getCall={getCall}
|
2024-04-01 19:19:35 +00:00
|
|
|
getCallLink={getCallLink}
|
2023-11-27 22:07:13 +00:00
|
|
|
callHistoryEdition={callHistoryEdition}
|
2024-06-10 15:23:43 +00:00
|
|
|
canCreateCallLinks={canCreateCallLinks}
|
2024-05-17 22:02:07 +00:00
|
|
|
hangUpActiveCall={hangUpActiveCall}
|
2023-08-14 23:28:47 +00:00
|
|
|
hasFailedStorySends={hasFailedStorySends}
|
|
|
|
hasPendingUpdate={hasPendingUpdate}
|
2023-08-09 00:53:06 +00:00
|
|
|
i18n={i18n}
|
|
|
|
navTabsCollapsed={navTabsCollapsed}
|
|
|
|
onClearCallHistory={clearCallHistory}
|
2023-08-14 23:28:47 +00:00
|
|
|
onMarkCallHistoryRead={markCallHistoryRead}
|
2023-08-09 00:53:06 +00:00
|
|
|
onToggleNavTabsCollapse={toggleNavTabsCollapse}
|
2024-06-10 15:23:43 +00:00
|
|
|
onCreateCallLink={handleCreateCallLink}
|
2023-08-09 00:53:06 +00:00
|
|
|
onOutgoingAudioCallInConversation={onOutgoingAudioCallInConversation}
|
|
|
|
onOutgoingVideoCallInConversation={onOutgoingVideoCallInConversation}
|
2024-05-17 22:02:07 +00:00
|
|
|
peekNotConnectedGroupCall={peekNotConnectedGroupCall}
|
2023-08-09 00:53:06 +00:00
|
|
|
preferredLeftPaneWidth={preferredLeftPaneWidth}
|
2024-05-22 16:24:27 +00:00
|
|
|
renderCallLinkDetails={renderCallLinkDetails}
|
2023-08-09 00:53:06 +00:00
|
|
|
renderConversationDetails={renderConversationDetails}
|
2024-01-29 20:09:54 +00:00
|
|
|
renderToastManager={renderToastManager}
|
2023-08-09 00:53:06 +00:00
|
|
|
regionCode={regionCode}
|
|
|
|
savePreferredLeftPaneWidth={savePreferredLeftPaneWidth}
|
2024-04-01 19:19:35 +00:00
|
|
|
startCallLinkLobbyByRoomId={startCallLinkLobbyByRoomId}
|
2024-05-17 22:02:07 +00:00
|
|
|
togglePip={togglePip}
|
2023-08-09 00:53:06 +00:00
|
|
|
/>
|
|
|
|
);
|
2024-03-13 20:44:13 +00:00
|
|
|
});
|