Skip to content

The open alternative to Salesforce, designed for AI.

Open the calendar event from the Call Recordings widget (#28398)

nitin33d50953fca9
diff --git a/packages/twenty-apps/public/call-recorder/src/front-components/components/CallRecordingRow.tsx b/packages/twenty-apps/public/call-recorder/src/front-components/components/CallRecordingRow.tsx
index 3f8d7a592ad..165982b8e88 100644
--- a/packages/twenty-apps/public/call-recorder/src/front-components/components/CallRecordingRow.tsx
+++ b/packages/twenty-apps/public/call-recorder/src/front-components/components/CallRecordingRow.tsx
@@ -1,5 +1,5 @@
import styled from '@emotion/styled';
-import { isUndefined } from '@sniptt/guards';
+import { isNonEmptyString, isUndefined } from '@sniptt/guards';
import { getPublicAssetUrl } from 'twenty-sdk/utils';
import { Avatar, Chip, ChipVariant } from 'twenty-ui/data-display';
import { IconCalendar } from 'twenty-ui/icon';
@@ -24,6 +24,7 @@ const StyledRightContent = styled.span`
type CallRecordingRowProps = {
callRecordingId: string;
+ calendarEventId: string | undefined;
title: string;
formattedDate: string | undefined;
formattedDuration: string | undefined;
@@ -32,36 +33,51 @@ type CallRecordingRowProps = {
export const CallRecordingRow = ({
callRecordingId,
+ calendarEventId,
title,
formattedDate,
formattedDuration,
statusTag,
}: CallRecordingRowProps) => {
+ const isClickable = isNonEmptyString(calendarEventId);
+
const handleClick = () => {
+ if (!isClickable) {
+ return;
+ }
+
void openRecord({
- objectNameSingular: 'callRecording',
- recordId: callRecordingId,
+ objectNameSingular: 'calendarEvent',
+ recordId: calendarEventId,
});
};
+ const chip = (
+ <Chip
+ label={title}
+ clickable={isClickable}
+ variant={isClickable ? ChipVariant.Highlighted : ChipVariant.Transparent}
+ leftComponent={
+ <Avatar
+ avatarUrl={getPublicAssetUrl('logo.svg')}
+ placeholder={title}
+ placeholderColorSeed={callRecordingId}
+ type="rounded"
+ size="sm"
+ />
+ }
+ />
+ );
+
return (
<StyledCallRecordingRowLayout>
- <StyledChipButton type="button" onClick={handleClick}>
- <Chip
- label={title}
- clickable
- variant={ChipVariant.Highlighted}
- leftComponent={
- <Avatar
- avatarUrl={getPublicAssetUrl('logo.svg')}
- placeholder={title}
- placeholderColorSeed={callRecordingId}
- type="rounded"
- size="sm"
- />
- }
- />
- </StyledChipButton>
+ {isClickable ? (
+ <StyledChipButton type="button" onClick={handleClick}>
+ {chip}
+ </StyledChipButton>
+ ) : (
+ chip
+ )}
<StyledRightContent>
<CallRecordingRowStatus
statusTag={statusTag}
diff --git a/packages/twenty-apps/public/call-recorder/src/front-components/components/CallRecordingsWidget.tsx b/packages/twenty-apps/public/call-recorder/src/front-components/components/CallRecordingsWidget.tsx
index 7db371cd7c7..ccdbe4796fc 100644
--- a/packages/twenty-apps/public/call-recorder/src/front-components/components/CallRecordingsWidget.tsx
+++ b/packages/twenty-apps/public/call-recorder/src/front-components/components/CallRecordingsWidget.tsx
@@ -68,6 +68,11 @@ const CallRecordingList = ({
<CallRecordingRow
key={callRecording.id}
callRecordingId={callRecording.id}
+ calendarEventId={
+ callRecording.calendarEvent?.isShared
+ ? callRecording.calendarEvent.id
+ : undefined
+ }
title={resolveCallRecordingDisplayTitle(callRecording)}
formattedDate={formatCallRecordingDate({
dateTime: getCallRecordingDisplayDate(callRecording),
diff --git a/packages/twenty-apps/public/call-recorder/src/front-components/constants/not-shared-calendar-event-title.constant.ts b/packages/twenty-apps/public/call-recorder/src/front-components/constants/not-shared-calendar-event-title.constant.ts
new file mode 100644
index 00000000000..db94acc5538
--- /dev/null
+++ b/packages/twenty-apps/public/call-recorder/src/front-components/constants/not-shared-calendar-event-title.constant.ts
@@ -0,0 +1 @@
+export const NOT_SHARED_CALENDAR_EVENT_TITLE = 'Not shared';
diff --git a/packages/twenty-apps/public/call-recorder/src/front-components/types/call-recording-node.type.ts b/packages/twenty-apps/public/call-recorder/src/front-components/types/call-recording-node.type.ts
index e0d35deea6a..941ac85a5e1 100644
--- a/packages/twenty-apps/public/call-recorder/src/front-components/types/call-recording-node.type.ts
+++ b/packages/twenty-apps/public/call-recorder/src/front-components/types/call-recording-node.type.ts
@@ -10,5 +10,6 @@ export type CallRecordingNode = {
id: string;
title?: string | null;
startsAt?: string | null;
+ isShared?: boolean;
} | null;
};
diff --git a/packages/twenty-apps/public/call-recorder/src/front-components/utils/__tests__/fetch-call-recordings-for-record.test.ts b/packages/twenty-apps/public/call-recorder/src/front-components/utils/__tests__/fetch-call-recordings-for-record.test.ts
index 3a5dae402f3..fa322f312ee 100644
--- a/packages/twenty-apps/public/call-recorder/src/front-components/utils/__tests__/fetch-call-recordings-for-record.test.ts
+++ b/packages/twenty-apps/public/call-recorder/src/front-components/utils/__tests__/fetch-call-recordings-for-record.test.ts
@@ -3,9 +3,13 @@ import { describe, expect, it, type Mock, vi } from 'vitest';
import { CALL_RECORDINGS_WIDGET_MAX_CALENDAR_EVENT_TARGET_PAGES } from 'src/front-components/constants/call-recordings-widget-max-calendar-event-target-pages.constant';
import { fetchCallRecordingsForRecord } from 'src/front-components/utils/fetch-call-recordings-for-record.util';
+import { RESTRICTED_FIELD_PLACEHOLDER } from 'src/logic-functions/constants/restricted-field-placeholder';
import { TWENTY_PAGE_SIZE } from 'src/logic-functions/constants/twenty-page-size';
type QueryRequest = {
+ calendarEvents?: {
+ __args: { filter: { id: { in: string[] } } };
+ };
calendarEventTargets?: { __args: { orderBy: unknown } };
callRecordings?: {
__args: {
@@ -43,9 +47,11 @@ const buildCalendarEventTargetConnection = (
type CallRecordingFixture = {
id: string;
+ status?: string;
+ calendarEventId?: string;
startedAt?: string | null;
createdAt?: string;
- calendarEvent?: { id: string; startsAt: string } | null;
+ calendarEvent?: { id: string; title?: string; startsAt: string } | null;
};
const buildCallRecordingConnection = (
@@ -61,14 +67,30 @@ const buildCallRecordingConnection = (
},
});
+const buildCalendarEventConnection = (
+ calendarEvents: Array<{ id: string; title: string | null }>,
+) => ({
+ calendarEvents: {
+ pageInfo: { hasNextPage: false, endCursor: null },
+ edges: calendarEvents.map((calendarEvent) => ({ node: calendarEvent })),
+ },
+});
+
const isCalendarEventTargetQuery = (request: QueryRequest) =>
'calendarEventTargets' in request;
-const getCallRecordingQueries = (query: Mock) =>
+const getQueries = <TQueryName extends keyof QueryRequest>({
+ query,
+ queryName,
+}: {
+ query: Mock<(request: QueryRequest) => unknown>;
+ queryName: TQueryName;
+}) =>
query.mock.calls
- .map(([request]) => request as QueryRequest)
- .flatMap((request) =>
- isUndefined(request.callRecordings) ? [] : [request.callRecordings],
+ .map(([request]) => request[queryName])
+ .filter(
+ (namedQuery): namedQuery is NonNullable<QueryRequest[TQueryName]> =>
+ !isUndefined(namedQuery),
);
const fetchForPerson = (query: Mock, maxCount = 20) =>
@@ -129,7 +151,10 @@ describe('fetchCallRecordingsForRecord', () => {
{ calendarEvent: { startsAt: 'DescNullsLast' } },
]);
- const [callRecordingQuery] = getCallRecordingQueries(query);
+ const [callRecordingQuery] = getQueries({
+ query,
+ queryName: 'callRecordings',
+ });
expect(callRecordingQuery.__args.filter).toEqual({
calendarEventId: { in: ['calendar-event-1', 'calendar-event-2'] },
@@ -171,6 +196,11 @@ describe('fetchCallRecordingsForRecord', () => {
},
},
]),
+ )
+ .mockResolvedValueOnce(
+ buildCalendarEventConnection([
+ { id: 'calendar-event-1', title: 'Planning' },
+ ]),
);
const callRecordings = await fetchForPerson(query, 3);
@@ -181,7 +211,10 @@ describe('fetchCallRecordingsForRecord', () => {
`started-${TWENTY_PAGE_SIZE - 2}`,
]);
- const callRecordingQueries = getCallRecordingQueries(query);
+ const callRecordingQueries = getQueries({
+ query,
+ queryName: 'callRecordings',
+ });
expect(callRecordingQueries).toHaveLength(2);
expect(callRecordingQueries[1].__args.after).toBe('next-recording-cursor');
@@ -220,10 +253,57 @@ describe('fetchCallRecordingsForRecord', () => {
'next-target-cursor',
);
expect(
- getCallRecordingQueries(query)[1].__args.filter.calendarEventId,
+ getQueries({ query, queryName: 'callRecordings' })[1].__args.filter
+ .calendarEventId,
).toEqual({ in: ['past-meeting'] });
});
+ it('keeps reading meetings until enough distinct meetings have recordings', async () => {
+ const query = vi
+ .fn()
+ .mockResolvedValueOnce(
+ buildCalendarEventTargetConnection(['newest-meeting'], true),
+ )
+ .mockResolvedValueOnce(
+ buildCallRecordingConnection([
+ {
+ id: 'retry',
+ status: 'COMPLETED',
+ calendarEventId: 'newest-meeting',
+ startedAt: '2026-01-02T11:00:00.000Z',
+ createdAt: '2026-01-02T11:00:00.000Z',
+ },
+ {
+ id: 'first',
+ status: 'COMPLETED',
+ calendarEventId: 'newest-meeting',
+ startedAt: '2026-01-02T10:00:00.000Z',
+ createdAt: '2026-01-02T10:00:00.000Z',
+ },
+ ]),
+ )
+ .mockResolvedValueOnce(
+ buildCalendarEventTargetConnection(['older-meeting'], true),
+ )
+ .mockResolvedValueOnce(
+ buildCallRecordingConnection([
+ {
+ id: 'older',
+ status: 'COMPLETED',
+ calendarEventId: 'older-meeting',
+ startedAt: '2026-01-01T10:00:00.000Z',
+ },
+ ]),
+ );
+
+ const callRecordings = await fetchForPerson(query, 2);
+
+ expect(callRecordings.map((callRecording) => callRecording.id)).toEqual([
+ 'first',
+ 'older',
+ ]);
+ });
+
it('stops reading meetings once the target page cap is reached', async () => {
let targetPageIndex = 0;
const query = vi.fn((request: QueryRequest) => {
@@ -251,6 +331,72 @@ describe('fetchCallRecordingsForRecord', () => {
);
});
+ it('checks once which meetings of the listed recordings are shared', async () => {
+ const query = vi
+ .fn()
+ .mockResolvedValueOnce(
+ buildCalendarEventTargetConnection([
+ 'shared-meeting',
+ 'restricted-meeting',
+ 'hidden-meeting',
+ ]),
+ )
+ .mockResolvedValueOnce(
+ buildCallRecordingConnection([
+ {
+ id: 'shared-recording',
+ calendarEventId: 'shared-meeting',
+ startedAt: '2026-03-01T10:00:00.000Z',
+ calendarEvent: {
+ id: 'shared-meeting',
+ title: 'Roadmap review',
+ startsAt: '2026-03-01T10:00:00.000Z',
+ },
+ },
+ {
+ id: 'restricted-recording',
+ calendarEventId: 'restricted-meeting',
+ startedAt: '2026-02-01T10:00:00.000Z',
+ calendarEvent: {
+ id: 'restricted-meeting',
+ title: 'Confidential offer',
+ startsAt: '2026-02-01T10:00:00.000Z',
+ },
+ },
+ {
+ id: 'hidden-recording',
+ calendarEventId: 'hidden-meeting',
+ startedAt: '2026-01-01T10:00:00.000Z',
+ calendarEvent: {
+ id: 'hidden-meeting',
+ title: 'Board meeting',
+ startsAt: '2026-01-01T10:00:00.000Z',
+ },
+ },
+ ]),
+ )
+ .mockResolvedValueOnce(
+ buildCalendarEventConnection([
+ { id: 'shared-meeting', title: 'Roadmap review' },
+ { id: 'restricted-meeting', title: RESTRICTED_FIELD_PLACEHOLDER },
+ ]),
+ );
+
+ const callRecordings = await fetchForPerson(query);
+
+ expect(
+ callRecordings.map((callRecording) => [
+ callRecording.id,
+ callRecording.calendarEvent?.isShared,
+ ]),
+ ).toEqual([
+ ['shared-recording', true],
+ ['restricted-recording', false],
+ ['hidden-recording', false],
+ ]);
+ expect(getQueries({ query, queryName: 'calendarEvents' })).toHaveLength(1);
+ });
+
it('skips the meeting join when meetings could not be used to order targets', async () => {
const query = vi
.fn()
@@ -274,7 +420,10 @@ describe('fetchCallRecordingsForRecord', () => {
{ createdAt: 'DescNullsLast' },
]);
- const callRecordingQueries = getCallRecordingQueries(query);
+ const callRecordingQueries = getQueries({
+ query,
+ queryName: 'callRecordings',
+ });
expect(callRecordingQueries).toHaveLength(1);
expect(callRecordingQueries[0].edges.node.calendarEvent).toBeUndefined();
diff --git a/packages/twenty-apps/public/call-recorder/src/front-components/utils/__tests__/get-most-recent-call-recordings.test.ts b/packages/twenty-apps/public/call-recorder/src/front-components/utils/__tests__/get-most-recent-call-recordings.test.ts
index 4b109dcab0d..537d31c4c6a 100644
--- a/packages/twenty-apps/public/call-recorder/src/front-components/utils/__tests__/get-most-recent-call-recordings.test.ts
+++ b/packages/twenty-apps/public/call-recorder/src/front-components/utils/__tests__/get-most-recent-call-recordings.test.ts
@@ -78,4 +78,80 @@ describe('getMostRecentCallRecordings', () => {
'b',
]);
});
+
+ it('lists each meeting once, through the recording its page shows', () => {
+ const callRecordings = getMostRecentCallRecordings({
+ callRecordings: [
+ {
+ id: 'retry-recording',
+ status: 'RECORDING',
+ calendarEventId: 'meeting',
+ startedAt: '2026-01-02T11:00:00.000Z',
+ createdAt: '2026-01-02T10:30:00.000Z',
+ },
+ {
+ id: 'first-completed',
+ status: 'COMPLETED',
+ calendarEventId: 'meeting',
+ startedAt: '2026-01-02T10:00:00.000Z',
+ createdAt: '2026-01-02T09:59:00.000Z',
+ },
+ {
+ id: 'other-meeting',
+ status: 'COMPLETED',
+ calendarEventId: 'other',
+ startedAt: '2026-01-01T10:00:00.000Z',
+ },
+ { id: 'no-meeting-a', startedAt: '2025-12-02T10:00:00.000Z' },
+ { id: 'no-meeting-b', startedAt: '2025-12-01T10:00:00.000Z' },
+ ],
+ maxCount: 10,
+ });
+
+ expect(callRecordings.map((callRecording) => callRecording.id)).toEqual([
+ 'first-completed',
+ 'other-meeting',
+ 'no-meeting-a',
+ 'no-meeting-b',
+ ]);
+ });
+
+ it('caps by distinct meetings rather than by recordings', () => {
+ const callRecordings = getMostRecentCallRecordings({
+ callRecordings: [
+ {
+ id: 'newest-a',
+ status: 'COMPLETED',
+ calendarEventId: 'newest',
+ startedAt: '2026-01-03T10:00:00.000Z',
+ createdAt: '2026-01-03T10:00:00.000Z',
+ },
+ {
+ id: 'newest-b',
+ status: 'COMPLETED',
+ calendarEventId: 'newest',
+ startedAt: '2026-01-03T11:00:00.000Z',
+ createdAt: '2026-01-03T11:00:00.000Z',
+ },
+ {
+ id: 'middle',
+ status: 'COMPLETED',
+ calendarEventId: 'middle',
+ startedAt: '2026-01-02T10:00:00.000Z',
+ },
+ {
+ id: 'oldest',
+ status: 'COMPLETED',
+ calendarEventId: 'oldest',
+ startedAt: '2026-01-01T10:00:00.000Z',
+ },
+ ],
+ maxCount: 2,
+ });
+
+ expect(callRecordings.map((callRecording) => callRecording.id)).toEqual([
+ 'newest-a',
+ 'middle',
+ ]);
+ });
});
diff --git a/packages/twenty-apps/public/call-recorder/src/front-components/utils/__tests__/get-representative-call-recording.test.ts b/packages/twenty-apps/public/call-recorder/src/front-components/utils/__tests__/get-representative-call-recording.test.ts
new file mode 100644
index 00000000000..af558973433
--- /dev/null
+++ b/packages/twenty-apps/public/call-recorder/src/front-components/utils/__tests__/get-representative-call-recording.test.ts
@@ -0,0 +1,53 @@
+import { describe, expect, it } from 'vitest';
+
+import { getRepresentativeCallRecording } from 'src/front-components/utils/get-representative-call-recording.util';
+
+describe('getRepresentativeCallRecording', () => {
+ it('picks the oldest completed recording', () => {
+ expect(
+ getRepresentativeCallRecording([
+ {
+ id: 'newer-completed',
+ status: 'COMPLETED',
+ createdAt: '2026-01-03T10:00:00.000Z',
+ },
+ {
+ id: 'oldest-recording',
+ status: 'RECORDING',
+ createdAt: '2026-01-01T10:00:00.000Z',
+ },
+ {
+ id: 'older-completed',
+ status: 'COMPLETED',
+ createdAt: '2026-01-02T10:00:00.000Z',
+ },
+ ])?.id,
+ ).toBe('older-completed');
+ });
+
+ it('picks the oldest recording still in progress when none completed', () => {
+ expect(
+ getRepresentativeCallRecording([
+ {
+ id: 'failed',
+ status: 'FAILED',
+ createdAt: '2026-01-01T10:00:00.000Z',
+ },
+ {
+ id: 'newer-processing',
+ status: 'PROCESSING',
+ createdAt: '2026-01-03T10:00:00.000Z',
+ },
+ {
+ id: 'older-recording',
+ status: 'RECORDING',
+ createdAt: '2026-01-02T10:00:00.000Z',
+ },
+ ])?.id,
+ ).toBe('older-recording');
+ });
+
+ it('returns nothing for no recordings', () => {
+ expect(getRepresentativeCallRecording([])).toBeUndefined();
+ });
+});
diff --git a/packages/twenty-apps/public/call-recorder/src/front-components/utils/__tests__/resolve-call-recording-display-title.test.ts b/packages/twenty-apps/public/call-recorder/src/front-components/utils/__tests__/resolve-call-recording-display-title.test.ts
index 6b8f85074be..e1a682d32fc 100644
--- a/packages/twenty-apps/public/call-recorder/src/front-components/utils/__tests__/resolve-call-recording-display-title.test.ts
+++ b/packages/twenty-apps/public/call-recorder/src/front-components/utils/__tests__/resolve-call-recording-display-title.test.ts
@@ -31,6 +31,19 @@ describe('resolveCallRecordingDisplayTitle', () => {
).toBe('Untitled call');
});
+ it('hides both titles when the meeting is not shared', () => {
+ expect(
+ resolveCallRecordingDisplayTitle({
+ title: 'Confidential offer',
+ calendarEvent: {
+ id: 'event',
+ title: RESTRICTED_FIELD_PLACEHOLDER,
+ isShared: false,
+ },
+ }),
+ ).toBe('Not shared');
+ });
+
it('uses a short fallback without any title', () => {
expect(
resolveCallRecordingDisplayTitle({ title: null, calendarEvent: null }),
diff --git a/packages/twenty-apps/public/call-recorder/src/front-components/utils/fetch-call-recordings-for-record.util.ts b/packages/twenty-apps/public/call-recorder/src/front-components/utils/fetch-call-recordings-for-record.util.ts
index 67640c762db..6144e4653c2 100644
--- a/packages/twenty-apps/public/call-recorder/src/front-components/utils/fetch-call-recordings-for-record.util.ts
+++ b/packages/twenty-apps/public/call-recorder/src/front-components/utils/fetch-call-recordings-for-record.util.ts
@@ -1,5 +1,6 @@
import { isNonEmptyString, isString, isUndefined } from '@sniptt/guards';
import { type CoreApiClient } from 'twenty-client-sdk/core';
+import { isDefined } from 'twenty-sdk/utils';
import { CALL_RECORDINGS_WIDGET_MAX_CALENDAR_EVENT_TARGET_PAGES } from 'src/front-components/constants/call-recordings-widget-max-calendar-event-target-pages.constant';
import { CALL_RECORDINGS_WIDGET_MAX_CALL_RECORDINGS_PER_BATCH } from 'src/front-components/constants/call-recordings-widget-max-call-recordings-per-batch.constant';
@@ -8,6 +9,7 @@ import { type CalendarEventTargetFieldName } from 'src/front-components/types/ca
import { type CallRecordingNode } from 'src/front-components/types/call-recording-node.type';
import { getMostRecentCallRecordings } from 'src/front-components/utils/get-most-recent-call-recordings.util';
import { isPermissionDeniedError } from 'src/front-components/utils/is-permission-denied-error.util';
+import { RESTRICTED_FIELD_PLACEHOLDER } from 'src/logic-functions/constants/restricted-field-placeholder';
import { TWENTY_PAGE_SIZE } from 'src/logic-functions/constants/twenty-page-size';
import {
fetchAllNodes,
@@ -21,6 +23,11 @@ type CalendarEventTargetNode = {
calendarEventId?: string | null;
};
+type CalendarEventTitleNode = {
+ id: string;
+ title?: string | null;
+};
+
type CalendarEventTargetOrderBy = Array<Record<string, unknown>>;
const BY_MEETING_DATE_ORDER_BY: CalendarEventTargetOrderBy = [
@@ -138,6 +145,87 @@ const fetchListedCallRecordingsForCalendarEventIds = async ({
);
};
+// Unlike the nested relation, top-level calendarEvents apply the visibility restrictions.
+const fetchVisibleCalendarEventTitles = async ({
+ client,
+ calendarEventIds,
+}: {
+ client: QueryClient;
+ calendarEventIds: string[];
+}): Promise<CalendarEventTitleNode[]> =>
+ fetchAllNodes<CalendarEventTitleNode>(async (afterCursor) => {
+ const queryResult = await client.query({
+ calendarEvents: {
+ __args: {
+ filter: { id: { in: calendarEventIds } },
+ first: TWENTY_PAGE_SIZE,
+ ...(isUndefined(afterCursor) ? {} : { after: afterCursor }),
+ },
+ pageInfo: {
+ hasNextPage: true,
+ endCursor: true,
+ },
+ edges: {
+ node: {
+ id: true,
+ title: true,
+ },
+ },
+ },
+ });
+
+ return queryResult.calendarEvents as
+ | ConnectionPage<CalendarEventTitleNode>
+ | undefined;
+ });
+
+const markSharedCalendarEvents = async ({
+ client,
+ callRecordings,
+}: {
+ client: QueryClient;
+ callRecordings: CallRecordingNode[];
+}): Promise<CallRecordingNode[]> => {
+ const calendarEventIds = [
+ ...new Set(
+ callRecordings
+ .map((callRecording) => callRecording.calendarEvent?.id)
+ .filter(isNonEmptyString),
+ ),
+ ];
+
+ if (calendarEventIds.length === 0) {
+ return callRecordings;
+ }
+
+ const visibleCalendarEventTitleById = new Map(
+ (await fetchVisibleCalendarEventTitles({ client, calendarEventIds })).map(
+ (calendarEvent) => [calendarEvent.id, calendarEvent.title],
+ ),
+ );
+
+ return callRecordings.map((callRecording) => {
+ if (!isDefined(callRecording.calendarEvent)) {
+ return callRecording;
+ }
+
+ const visibleTitle = visibleCalendarEventTitleById.get(
+ callRecording.calendarEvent.id,
+ );
+
+ return {
+ ...callRecording,
+ calendarEvent: {
+ ...callRecording.calendarEvent,
+ title: visibleTitle,
+ isShared:
+ visibleCalendarEventTitleById.has(callRecording.calendarEvent.id) &&
+ visibleTitle !== RESTRICTED_FIELD_PLACEHOLDER,
+ },
+ };
+ });
+};
+
// A record's newest meetings are often upcoming ones without a recording yet.
export const fetchCallRecordingsForRecord = async ({
client,
@@ -176,7 +264,9 @@ export const fetchCallRecordingsForRecord = async ({
// Target creation order is not meeting order, so the fallback reads every page.
const hasEnoughCallRecordings = () =>
- orderBy === BY_MEETING_DATE_ORDER_BY && callRecordings.length >= maxCount;
+ orderBy === BY_MEETING_DATE_ORDER_BY &&
+ getMostRecentCallRecordings({ callRecordings, maxCount }).length >=
+ maxCount;
while (
hasNextPage &&
@@ -235,5 +325,15 @@ export const fetchCallRecordingsForRecord = async ({
afterCursor = isString(endCursor) ? endCursor : undefined;
}
- return getMostRecentCallRecordings({ callRecordings, maxCount });
+ const mostRecentCallRecordings = getMostRecentCallRecordings({
+ callRecordings,
+ maxCount,
+ });
+
+ return isCalendarEventLoaded
+ ? markSharedCalendarEvents({
+ client,
+ callRecordings: mostRecentCallRecordings,
+ })
+ : mostRecentCallRecordings;
};
diff --git a/packages/twenty-apps/public/call-recorder/src/front-components/utils/get-most-recent-call-recordings.util.ts b/packages/twenty-apps/public/call-recorder/src/front-components/utils/get-most-recent-call-recordings.util.ts
index bc90d8562dc..9bfbffca191 100644
--- a/packages/twenty-apps/public/call-recorder/src/front-components/utils/get-most-recent-call-recordings.util.ts
+++ b/packages/twenty-apps/public/call-recorder/src/front-components/utils/get-most-recent-call-recordings.util.ts
@@ -1,7 +1,8 @@
-import { isUndefined } from '@sniptt/guards';
+import { isNonEmptyString, isUndefined } from '@sniptt/guards';
import { type CallRecordingNode } from 'src/front-components/types/call-recording-node.type';
import { getCallRecordingDisplayDate } from 'src/front-components/utils/get-call-recording-display-date.util';
+import { getRepresentativeCallRecording } from 'src/front-components/utils/get-representative-call-recording.util';
import { getTimestamp } from 'src/front-components/utils/get-timestamp.util';
const compareCallRecordingsByDisplayDate = (
@@ -25,6 +26,11 @@ const compareCallRecordingsByDisplayDate = (
);
};
+const getCalendarEventKey = (callRecording: CallRecordingNode): string =>
+ isNonEmptyString(callRecording.calendarEventId)
+ ? callRecording.calendarEventId
+ : callRecording.id;
+
export const getMostRecentCallRecordings = ({
callRecordings,
maxCount,
@@ -35,8 +41,23 @@ export const getMostRecentCallRecordings = ({
const callRecordingsById = new Map(
callRecordings.map((callRecording) => [callRecording.id, callRecording]),
);
+ const callRecordingsByCalendarEventKey = new Map<
+ string,
+ CallRecordingNode[]
+ >();
+
+ for (const callRecording of callRecordingsById.values()) {
+ const calendarEventKey = getCalendarEventKey(callRecording);
+
+ callRecordingsByCalendarEventKey.set(calendarEventKey, [
+ ...(callRecordingsByCalendarEventKey.get(calendarEventKey) ?? []),
+ callRecording,
+ ]);
+ }
- return [...callRecordingsById.values()]
+ return [...callRecordingsByCalendarEventKey.values()]
+ .map(getRepresentativeCallRecording)
+ .filter((callRecording) => !isUndefined(callRecording))
.sort(compareCallRecordingsByDisplayDate)
.slice(0, maxCount);
};
diff --git a/packages/twenty-apps/public/call-recorder/src/front-components/utils/get-representative-call-recording.util.ts b/packages/twenty-apps/public/call-recorder/src/front-components/utils/get-representative-call-recording.util.ts
new file mode 100644
index 00000000000..a3af697454c
--- /dev/null
+++ b/packages/twenty-apps/public/call-recorder/src/front-components/utils/get-representative-call-recording.util.ts
@@ -0,0 +1,47 @@
+import { isUndefined } from '@sniptt/guards';
+
+import { type CallRecordingNode } from 'src/front-components/types/call-recording-node.type';
+import { getTimestamp } from 'src/front-components/utils/get-timestamp.util';
+import { isCallRecordingInProgress } from 'src/front-components/utils/is-call-recording-in-progress.util';
+import { CallRecordingStatus } from 'src/logic-functions/constants/call-recording-status';
+
+const compareCallRecordingsByCreation = ({
+ firstCallRecording,
+ secondCallRecording,
+}: {
+ firstCallRecording: Pick<CallRecordingNode, 'id' | 'createdAt'>;
+ secondCallRecording: Pick<CallRecordingNode, 'id' | 'createdAt'>;
+}): number => {
+ const firstTimestamp = getTimestamp(firstCallRecording.createdAt);
+ const secondTimestamp = getTimestamp(secondCallRecording.createdAt);
+
+ if (isUndefined(firstTimestamp) !== isUndefined(secondTimestamp)) {
+ return isUndefined(firstTimestamp) ? 1 : -1;
+ }
+
+ return (
+ (firstTimestamp ?? 0) - (secondTimestamp ?? 0) ||
+ firstCallRecording.id.localeCompare(secondCallRecording.id)
+ );
+};
+
+// Same rule as the server pick behind the calendar event's tabs, applied to listed statuses only.
+export const getRepresentativeCallRecording = (
+ callRecordings: CallRecordingNode[],
+): CallRecordingNode | undefined => {
+ const callRecordingsByCreation = [...callRecordings].sort(
+ (firstCallRecording, secondCallRecording) =>
+ compareCallRecordingsByCreation({
+ firstCallRecording,
+ secondCallRecording,
+ }),
+ );
+
+ return (
+ callRecordingsByCreation.find(
+ (callRecording) => callRecording.status === CallRecordingStatus.COMPLETED,
+ ) ??
+ callRecordingsByCreation.find(isCallRecordingInProgress) ??
+ callRecordingsByCreation[0]
+ );
+};
diff --git a/packages/twenty-apps/public/call-recorder/src/front-components/utils/resolve-call-recording-display-title.util.ts b/packages/twenty-apps/public/call-recorder/src/front-components/utils/resolve-call-recording-display-title.util.ts
index f7e468431d4..475a8d33425 100644
--- a/packages/twenty-apps/public/call-recorder/src/front-components/utils/resolve-call-recording-display-title.util.ts
+++ b/packages/twenty-apps/public/call-recorder/src/front-components/utils/resolve-call-recording-display-title.util.ts
@@ -1,12 +1,23 @@
+import { NOT_SHARED_CALENDAR_EVENT_TITLE } from 'src/front-components/constants/not-shared-calendar-event-title.constant';
import { UNTITLED_CALL_RECORDING_TITLE } from 'src/front-components/constants/untitled-call-recording-title.constant';
import { type CallRecordingNode } from 'src/front-components/types/call-recording-node.type';
import { getFirstNonEmptyString } from 'src/front-components/utils/get-first-non-empty-string.util';
import { stripRestrictedFieldValue } from 'src/logic-functions/data/strip-restricted-field-value.util';
+// The recording title is copied from its meeting, so it is hidden with it.
export const resolveCallRecordingDisplayTitle = (
callRecording: Pick<CallRecordingNode, 'title' | 'calendarEvent'>,
-): string =>
- getFirstNonEmptyString([
- stripRestrictedFieldValue(callRecording.title ?? undefined),
- stripRestrictedFieldValue(callRecording.calendarEvent?.title ?? undefined),
- ]) ?? UNTITLED_CALL_RECORDING_TITLE;
+): string => {
+ if (callRecording.calendarEvent?.isShared === false) {
+ return NOT_SHARED_CALENDAR_EVENT_TITLE;
+ }
+
+ return (
+ getFirstNonEmptyString([
+ stripRestrictedFieldValue(callRecording.title ?? undefined),
+ stripRestrictedFieldValue(
+ callRecording.calendarEvent?.title ?? undefined,
+ ),
+ ]) ?? UNTITLED_CALL_RECORDING_TITLE
+ );
+};