Skip to content
Open
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
42 changes: 11 additions & 31 deletions apps/meteor/app/api/server/v1/call-history.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CallHistory as CallHistoryService } from '@rocket.chat/core-services';
import type { CallHistoryItem, CallHistoryItemState, IMediaCall } from '@rocket.chat/core-typings';
import { CallHistory, MediaCalls } from '@rocket.chat/models';
import type { PaginatedRequest, PaginatedResult } from '@rocket.chat/rest-typings';
Expand All @@ -9,7 +10,6 @@ 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';
Expand Down Expand Up @@ -104,37 +104,17 @@ const callHistoryListEndpoints = API.v1.get(

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

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 searchTerm = typeof filter === 'string' && filter.trim();

const { cursor, totalCount } = CallHistory.findPaginated(query, {
sort: sort || { ts: -1 },
skip: offset,
limit: count,
});
const [items, total] = await Promise.all([cursor.toArray(), totalCount]);
const { items, total } = await CallHistoryService.search(
this.userId,
{
...(searchTerm && { searchTerm }),
...(direction && { direction }),
...(state && { inStates: ensureArray(state) }),
},
{ count, offset, sort },
);

return API.v1.success({
items,
Expand Down
50 changes: 21 additions & 29 deletions apps/meteor/client/views/mediaCallHistory/CallHistoryPage.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { CallHistoryItem, Serialized } from '@rocket.chat/core-typings';
import { Pagination } from '@rocket.chat/fuselage';
import { useDebouncedValue } from '@rocket.chat/fuselage-hooks';
import { useSort, usePagination, GenericTableLoadingRow } from '@rocket.chat/ui-client';
import { useEndpoint, useRouteParameter, useRouter } from '@rocket.chat/ui-contexts';
import { MediaCallHistoryTable, isCallHistoryUnknownContact, isCallHistoryTableInternalContact } from '@rocket.chat/ui-voip';
import type { CallHistoryTableInternalContact, CallHistoryUnknownContact, CallHistoryTableExternalContact } from '@rocket.chat/ui-voip';
import { MediaCallHistoryTable, isUnknownCallHistoryContact, isInternalCallHistoryContact } from '@rocket.chat/ui-voip';
import type { CallHistoryContact } from '@rocket.chat/ui-voip';
import { useQuery } from '@tanstack/react-query';
import { useCallback, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
Expand All @@ -14,6 +15,7 @@ import CallHistoryRowExternalUser from './CallHistoryRowExternalUser';
import CallHistoryRowInternalUser from './CallHistoryRowInternalUser';
import CallHistoryRowUnknownUser from './CallHistoryRowUnknownUser';
import MediaCallHistoryContextualbar from './MediaCallHistoryContextualbar';
import { getExternalContact } from './MediaCallHistoryExternal';
import GenericNoResults from '../../components/GenericNoResults';
import UserInfoWithData from '../room/contextualBar/UserInfo/UserInfoWithData';

Expand Down Expand Up @@ -43,6 +45,18 @@ const getStateFilter = <T extends string[]>(states: T): T | [...T, 'error'] | un
return states;
};

const getContact = (item: Serialized<CallHistoryItem>): CallHistoryContact => {
if (item.type !== 'media-call' || item.external) {
return getExternalContact(item);
}

if (!item.contactUsername || !item.contactName) {
return { unknown: true };
}

return { _id: item.contactId, username: item.contactUsername, name: item.contactName };
};

type DetailsTab = {
openTab: 'details';
rid: string;
Expand Down Expand Up @@ -130,33 +144,11 @@ const CallHistoryPage = () => {

const tableData = useMemo(() => {
return data?.items.map((item) => {
if (item.external) {
return {
_id: item._id,
contact: item.contactExtension
? ({ number: item.contactExtension } as CallHistoryTableExternalContact)
: ({ unknown: true } as CallHistoryUnknownContact),
type: item.direction,
status: item.state,
timestamp: item.ts,
duration: item.duration,
};
}
if (!item.contactUsername || !item.contactName) {
return {
_id: item._id,
contact: { unknown: true } as CallHistoryUnknownContact,
type: item.direction,
status: item.state,
timestamp: item.ts,
duration: item.duration,
};
}
return {
_id: item._id,
rid: item.rid,
contact: { _id: item.contactId, username: item.contactUsername, name: item.contactName } as CallHistoryTableInternalContact,
messageId: item.messageId,
...('rid' in item && { rid: item.rid }),
contact: getContact(item),
...('messageId' in item && { messageId: item.messageId }),
type: item.direction,
status: item.state,
timestamp: item.ts,
Expand Down Expand Up @@ -213,10 +205,10 @@ const CallHistoryPage = () => {
{tableData && tableData.length > 0 && (
<MediaCallHistoryTable sort={sortProps}>
{tableData.map((item) => {
if (isCallHistoryUnknownContact(item.contact)) {
if (isUnknownCallHistoryContact(item.contact)) {
return <CallHistoryRowUnknownUser key={item._id} {...item} contact={item.contact} onClick={() => onClickRow('', item._id)} />;
}
if (isCallHistoryTableInternalContact(item.contact)) {
if (isInternalCallHistoryContact(item.contact)) {
return (
<CallHistoryRowInternalUser
key={item._id}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { GenericMenu } from '@rocket.chat/ui-client';
import type { CallHistoryTableExternalContact, CallHistoryTableRowProps } from '@rocket.chat/ui-voip';
import type { ExternalCallHistoryContact, CallHistoryTableRowProps } from '@rocket.chat/ui-voip';
import { CallHistoryTableRow, usePeekMediaSessionState, useWidgetExternalControls } from '@rocket.chat/ui-voip';
import { useCallback, useMemo } from 'react';
import { useTranslation } from 'react-i18next';

type CallHistoryRowExternalUserProps = Omit<CallHistoryTableRowProps<CallHistoryTableExternalContact>, 'onClick' | 'menu'> & {
type CallHistoryRowExternalUserProps = Omit<CallHistoryTableRowProps<ExternalCallHistoryContact>, 'onClick' | 'menu'> & {
onClick: (historyId: string) => void;
};

Expand All @@ -22,6 +22,10 @@ const CallHistoryRowExternalUser = ({ _id, contact, type, status, duration, time
if (state === 'unavailable') {
return [];
}
if (!('number' in contact) || !contact.number) {
return [];
}

const disabled = state !== 'available';
return [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { Keys as IconName } from '@rocket.chat/icons';
import { GenericMenu } from '@rocket.chat/ui-client';
import { CallHistoryTableRow, usePeekMediaSessionState } from '@rocket.chat/ui-voip';
import type { CallHistoryTableRowProps, CallHistoryTableInternalContact, PeekMediaSessionStateReturn } from '@rocket.chat/ui-voip';
import type { CallHistoryTableRowProps, InternalCallHistoryContact, PeekMediaSessionStateReturn } from '@rocket.chat/ui-voip';
import type { TFunction } from 'i18next';
import { useCallback } from 'react';
import { useTranslation } from 'react-i18next';

import { useMediaCallInternalHistoryActions } from './useMediaCallInternalHistoryActions';

type CallHistoryRowInternalUserProps = Omit<CallHistoryTableRowProps<CallHistoryTableInternalContact>, 'onClick' | 'menu'> & {
type CallHistoryRowInternalUserProps = Omit<CallHistoryTableRowProps<InternalCallHistoryContact>, 'onClick' | 'menu'> & {
messageId?: string;
rid: string;
onClickUserInfo?: (userId: string, rid: string) => void;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { GenericMenu } from '@rocket.chat/ui-client';
import { CallHistoryTableRow } from '@rocket.chat/ui-voip';
import type { CallHistoryTableRowProps, CallHistoryUnknownContact } from '@rocket.chat/ui-voip';
import type { CallHistoryTableRowProps, UnknownCallHistoryContact } from '@rocket.chat/ui-voip';
import { useCallback } from 'react';
import { useTranslation } from 'react-i18next';

type CallHistoryRowUnknownUserProps = Omit<CallHistoryTableRowProps<CallHistoryUnknownContact>, 'onClick' | 'menu'> & {
type CallHistoryRowUnknownUserProps = Omit<CallHistoryTableRowProps<UnknownCallHistoryContact>, 'onClick' | 'menu'> & {
onClick: (historyId: string) => void;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,55 @@
import type { CallHistoryItem, IExternalMediaCallHistoryItem, IMediaCall, Serialized } from '@rocket.chat/core-typings';
import { CallHistoryContextualBar, useWidgetExternalControls, usePeekMediaSessionState } from '@rocket.chat/ui-voip';
import type { CallHistoryItem, IInternalMediaCallHistoryItem, IMediaCall, Serialized } from '@rocket.chat/core-typings';
import {
CallHistoryContextualBar,
useWidgetExternalControls,
usePeekMediaSessionState,
type ExternalCallHistoryContact,
type UnknownCallHistoryContact,
} from '@rocket.chat/ui-voip';
import { useMemo } from 'react';

type ExternalCallEndpointData = Serialized<{
item: IExternalMediaCallHistoryItem;
call: IMediaCall;
item: Exclude<CallHistoryItem, IInternalMediaCallHistoryItem>;
call?: IMediaCall;
}>;

type MediaCallHistoryExternalProps = {
data: ExternalCallEndpointData;
onClose: () => void;
};

const getContact = (item: ExternalCallEndpointData['item']) => {
return {
number: item.contactExtension,
};
export const getExternalContact = (item: ExternalCallEndpointData['item']): ExternalCallHistoryContact | UnknownCallHistoryContact => {
if (item.type === 'media-call') {
return {
number: item.contactExtension,
};
}

if (item.contactNumber) {
return {
number: item.contactNumber,
name: item.contactName,
};
}

if (item.contactName) {
return {
name: item.contactName,
};
}

return { unknown: true };
};

export const isExternalCallHistoryItem = (data: { item: Serialized<CallHistoryItem> }): data is ExternalCallEndpointData => {
return 'external' in data.item && data.item.external;
return data.item.type !== 'media-call' || data.item.external;
};

const MediaCallHistoryExternal = ({ data, onClose }: MediaCallHistoryExternalProps) => {
const contact = useMemo(() => getContact(data.item), [data]);
const contact = useMemo(() => getExternalContact(data.item), [data]);
const historyData = useMemo(() => {
return {
callId: data.call._id,
callId: data.item.callId,
direction: data.item.direction,
duration: data.item.duration,
startedAt: new Date(data.item.ts),
Expand All @@ -40,6 +63,9 @@ const MediaCallHistoryExternal = ({ data, onClose }: MediaCallHistoryExternalPro
if (state !== 'available') {
return {};
}
if (!('number' in contact) || !contact.number) {
return {};
}
return {
voiceCall: () => toggleWidget(contact),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { CallHistoryItem, IInternalMediaCallHistoryItem, IMediaCall, Serial
import { CallHistoryContextualBar } from '@rocket.chat/ui-voip';
import { useMemo } from 'react';

import { useMediaCallInternalHistoryActions } from './useMediaCallInternalHistoryActions';
import { type InternalCallHistoryContact, useMediaCallInternalHistoryActions } from './useMediaCallInternalHistoryActions';

type InternalCallEndpointData = Serialized<{
item: IInternalMediaCallHistoryItem;
Expand All @@ -18,10 +18,10 @@ type MediaCallHistoryInternalProps = {
};

export const isInternalCallHistoryItem = (data: { item: Serialized<CallHistoryItem> }): data is InternalCallEndpointData => {
return 'external' in data.item && !data.item.external;
return data.item.type === 'media-call' && !data.item.external;
};

const getContact = (item: InternalCallEndpointData['item'], call: InternalCallEndpointData['call']) => {
const getContact = (item: InternalCallEndpointData['item'], call: InternalCallEndpointData['call']): InternalCallHistoryContact => {
const { caller, callee } = call ?? {};
const contact = caller?.id === item.contactId ? caller : callee;
const { id, sipExtension, username, displayName, ...rest } = contact;
Expand Down
41 changes: 41 additions & 0 deletions apps/meteor/ee/server/settings/voip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,47 @@ export function addSettings(): Promise<void> {
invalidValue: 5060,
});
});

await this.section('VoIP_TeamCollab_ExternalCallHistory', async function () {
await this.add('VoIP_TeamCollab_ExternalCallHistory_Enabled', false, {
type: 'boolean',
public: true,
invalidValue: false,
i18nDescription: 'VoIP_TeamCollab_ExternalCallHistory_Enabled_Description',
});

const enableQuery = { _id: 'VoIP_TeamCollab_ExternalCallHistory_Enabled', value: true };

await this.add('VoIP_TeamCollab_ExternalCallHistory_Host', '', {
type: 'string',
public: false,
invalidValue: '',
enableQuery,
});

await this.add('VoIP_TeamCollab_ExternalCallHistory_User', '', {
type: 'string',
public: false,
invalidValue: '',
enableQuery,
});

await this.add('VoIP_TeamCollab_ExternalCallHistory_Password', '', {
type: 'password',
public: false,
secret: true,
invalidValue: '',
enableQuery,
});

await this.add('VoIP_TeamCollab_ExternalCallHistory_Timeout', 10000, {
type: 'int',
public: false,
invalidValue: 10000,
enableQuery,
i18nDescription: 'VoIP_TeamCollab_ExternalCallHistory_Timeout_Description',
});
});
},
);
});
Expand Down
1 change: 1 addition & 0 deletions apps/meteor/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default {
'<rootDir>/app/utils/lib/**.spec.ts',
'<rootDir>/server/lib/auditServerEvents/**.spec.ts',
'<rootDir>/server/services/import/**/*.spec.ts',
'<rootDir>/server/services/call-history/**/*.spec.ts',
'<rootDir>/server/settings/lib/**.spec.ts',
'<rootDir>/server/cron/**.spec.ts',
'<rootDir>/app/api/server/**.spec.ts',
Expand Down
3 changes: 3 additions & 0 deletions apps/meteor/server/services/call-history/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Logger } from '@rocket.chat/logger';

export const logger = new Logger('CallHistory');
23 changes: 23 additions & 0 deletions apps/meteor/server/services/call-history/mitel/definition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export type MitelConfig = {
host: string;
username: string;
password: string;
timeout?: number;
};

export type MitelCallItem = {
directoryNumber?: string;
name?: string;
callIdentity?: string;
dateTime: Date | null;
timeZone?: string;
duration: number;
typeOfCall?: 'incoming-answered' | 'incoming-missed' | 'outgoing';
transferredCall: boolean;
divertedCall: boolean;
firstDialledNumber?: string;
remoteNumber?: string;
directoryNumber2?: string;
name2?: string;
infoText2?: string;
};
Loading
Loading