Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions apps/meteor/app/api/server/v1/call-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import {
validateUnauthorizedErrorResponse,
validateForbiddenErrorResponse,
} from '@rocket.chat/rest-typings';
import { escapeRegExp } from '@rocket.chat/string-helpers';

import { ensureArray } from '../../../../lib/utils/arrayUtils';
import type { ExtractRoutesFromAPI } from '../ApiClass';
import { API } from '../api';
import { getPaginationItems } from '../helpers/getPaginationItems';

type CallHistoryList = PaginatedRequest<{
filter?: string;
direction?: CallHistoryItem['direction'];
state?: CallHistoryItemState[] | CallHistoryItemState;
}>;
Expand All @@ -31,6 +33,9 @@ const CallHistoryListSchema = {
sort: {
type: 'string',
},
filter: {
type: 'string',
},
direction: {
type: 'string',
enum: ['inbound', 'outbound'],
Expand Down Expand Up @@ -106,14 +111,31 @@ const callHistoryListEndpoints = API.v1.get(
const { offset, count } = await getPaginationItems(this.queryParams as Record<string, string | number | null | undefined>);
const { sort } = await this.parseJsonQuery();

const { direction, state } = this.queryParams;
const { direction, state, filter } = this.queryParams;

const stateFilter = state && ensureArray(state);
const filterText = typeof filter === 'string' && filter.trim();

const stateFilter = state && ensureArray(state);
const query = {
uid: this.userId,
...(direction && { direction }),
...(stateFilter?.length && { state: { $in: stateFilter } }),
...(filterText && {
$or: [
{
external: false,
contactName: { $regex: escapeRegExp(filterText), $options: 'i' },
},
{
external: false,
contactUsername: { $regex: escapeRegExp(filterText), $options: 'i' },
},
{
external: true,
contactExtension: { $regex: escapeRegExp(filterText), $options: 'i' },
},
],
}),
};

const { cursor, totalCount } = CallHistory.findPaginated(query, {
Expand Down
39 changes: 38 additions & 1 deletion apps/meteor/server/startup/callHistoryTestData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export async function addCallHistoryTestData(uid: string, extraUid: string): Pro
const callId3 = 'rocketchat.external.call.test.outbound';
const callId4 = 'rocketchat.external.call.test.inbound';

const extraCallId1 = 'rocketchat.extra.call.test.1';
const extraCallId2 = 'rocketchat.extra.call.test.2';

await CallHistory.deleteMany({ uid });
await MediaCalls.deleteMany({ _id: { $in: [callId1, callId2, callId3, callId4] } });

Expand All @@ -22,6 +25,8 @@ export async function addCallHistoryTestData(uid: string, extraUid: string): Pro
uid,
contactId: extraUid,
direction: 'outbound',
contactName: 'Pineapple', // random words used for searching
contactUsername: 'fruit-001',
},
{
_id: 'rocketchat.internal.history.test.inbound',
Expand All @@ -35,6 +40,38 @@ export async function addCallHistoryTestData(uid: string, extraUid: string): Pro
uid,
contactId: extraUid,
direction: 'inbound',
contactName: 'Apple',
contactUsername: 'fruit-002',
},
{
_id: 'rocketchat.internal.history.test.outbound.2',
ts: new Date(),
callId: extraCallId1,
state: 'transferred',
type: 'media-call',
duration: 10,
endedAt: new Date(),
external: false,
uid,
contactId: extraUid,
direction: 'outbound',
contactName: 'Grapefruit 002',
contactUsername: 'username-001',
},
{
_id: 'rocketchat.internal.history.test.inbound.2',
ts: new Date(),
callId: extraCallId2,
state: 'transferred',
type: 'media-call',
duration: 10,
endedAt: new Date(),
external: false,
uid,
contactId: extraUid,
direction: 'inbound',
contactName: 'Pasta 1',
contactUsername: 'meal',
},
{
_id: 'rocketchat.external.history.test.outbound',
Expand All @@ -60,7 +97,7 @@ export async function addCallHistoryTestData(uid: string, extraUid: string): Pro
external: true,
uid,
direction: 'inbound',
contactExtension: '1001',
contactExtension: '1002',
},
]);

Expand Down
Loading
Loading