Search call links in calls tab
This commit is contained in:
parent
fc9c5488c5
commit
dea641bae4
9 changed files with 384 additions and 112 deletions
|
@ -28,6 +28,7 @@ import { useCallingActions } from '../ducks/calling';
|
|||
import {
|
||||
getActiveCallState,
|
||||
getAdhocCallSelector,
|
||||
getAllCallLinks,
|
||||
getCallSelector,
|
||||
getCallLinkSelector,
|
||||
} from '../selectors/calling';
|
||||
|
@ -36,41 +37,67 @@ import { getCallHistoryEdition } from '../selectors/callHistory';
|
|||
import { getHasPendingUpdate } from '../selectors/updates';
|
||||
import { getHasAnyFailedStorySends } from '../selectors/stories';
|
||||
import { getOtherTabsUnreadStats } from '../selectors/nav';
|
||||
import type { CallLinkType } from '../../types/CallLink';
|
||||
import { filterCallLinks } from '../../util/filterCallLinks';
|
||||
|
||||
function getCallHistoryFilter(
|
||||
allConversations: Array<ConversationType>,
|
||||
regionCode: string | undefined,
|
||||
options: CallHistoryFilterOptions
|
||||
): CallHistoryFilter | null {
|
||||
function getCallHistoryFilter({
|
||||
allCallLinks,
|
||||
allConversations,
|
||||
regionCode,
|
||||
options,
|
||||
}: {
|
||||
allConversations: Array<ConversationType>;
|
||||
allCallLinks: Array<CallLinkType>;
|
||||
regionCode: string | undefined;
|
||||
options: CallHistoryFilterOptions;
|
||||
}): CallHistoryFilter | null {
|
||||
const { status } = options;
|
||||
const query = options.query.normalize().trim();
|
||||
|
||||
if (query !== '') {
|
||||
const currentConversations = allConversations.filter(conversation => {
|
||||
return conversation.removalStage == null;
|
||||
});
|
||||
|
||||
const filteredConversations = filterAndSortConversations(
|
||||
currentConversations,
|
||||
query,
|
||||
regionCode
|
||||
);
|
||||
|
||||
// If there are no matching conversations, then no calls will match.
|
||||
if (filteredConversations.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (query === '') {
|
||||
return {
|
||||
status: options.status,
|
||||
conversationIds: filteredConversations.map(conversation => {
|
||||
return conversation.id;
|
||||
}),
|
||||
status,
|
||||
callLinkRoomIds: null,
|
||||
conversationIds: null,
|
||||
};
|
||||
}
|
||||
|
||||
let callLinkRoomIds = null;
|
||||
let conversationIds = null;
|
||||
|
||||
const currentConversations = allConversations.filter(conversation => {
|
||||
return conversation.removalStage == null;
|
||||
});
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
return {
|
||||
status: options.status,
|
||||
conversationIds: null,
|
||||
status,
|
||||
callLinkRoomIds,
|
||||
conversationIds,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -99,6 +126,7 @@ export const SmartCallsTab = memo(function SmartCallsTab() {
|
|||
const { savePreferredLeftPaneWidth, toggleNavTabsCollapse } =
|
||||
useItemsActions();
|
||||
|
||||
const allCallLinks = useSelector(getAllCallLinks);
|
||||
const allConversations = useSelector(getAllConversations);
|
||||
const regionCode = useSelector(getRegionCode);
|
||||
const getConversation = useSelector(getConversationSelector);
|
||||
|
@ -129,11 +157,12 @@ export const SmartCallsTab = memo(function SmartCallsTab() {
|
|||
|
||||
const getCallHistoryGroupsCount = useCallback(
|
||||
async (options: CallHistoryFilterOptions) => {
|
||||
const callHistoryFilter = getCallHistoryFilter(
|
||||
const callHistoryFilter = getCallHistoryFilter({
|
||||
allCallLinks,
|
||||
allConversations,
|
||||
regionCode,
|
||||
options
|
||||
);
|
||||
options,
|
||||
});
|
||||
if (callHistoryFilter == null) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -142,7 +171,7 @@ export const SmartCallsTab = memo(function SmartCallsTab() {
|
|||
);
|
||||
return count;
|
||||
},
|
||||
[allConversations, regionCode]
|
||||
[allCallLinks, allConversations, regionCode]
|
||||
);
|
||||
|
||||
const getCallHistoryGroups = useCallback(
|
||||
|
@ -150,11 +179,12 @@ export const SmartCallsTab = memo(function SmartCallsTab() {
|
|||
options: CallHistoryFilterOptions,
|
||||
pagination: CallHistoryPagination
|
||||
) => {
|
||||
const callHistoryFilter = getCallHistoryFilter(
|
||||
const callHistoryFilter = getCallHistoryFilter({
|
||||
allCallLinks,
|
||||
allConversations,
|
||||
regionCode,
|
||||
options
|
||||
);
|
||||
options,
|
||||
});
|
||||
if (callHistoryFilter == null) {
|
||||
return [];
|
||||
}
|
||||
|
@ -164,7 +194,7 @@ export const SmartCallsTab = memo(function SmartCallsTab() {
|
|||
);
|
||||
return results;
|
||||
},
|
||||
[allConversations, regionCode]
|
||||
[allCallLinks, allConversations, regionCode]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue