26f0a416a1
- Remove feature flag - Remove legacy methods in file-upload and file-service - Migrate AI Chat to new file management --------- Co-authored-by: Charles Bochet <charles@twenty.com>
34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
import { type Attachment } from '@/activities/files/types/Attachment';
|
|
import { filterAttachmentsWithFile } from '@/activities/files/utils/filterAttachmentsWithFile';
|
|
import { compareUrls } from '@/activities/utils/compareUrls';
|
|
import {
|
|
type AttachmentInfo,
|
|
getActivityAttachmentPathsAndName,
|
|
} from '@/activities/utils/getActivityAttachmentPathsAndName';
|
|
import { getAttachmentUrl } from '@/activities/utils/getAttachmentUrl';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
|
|
export const getActivityAttachmentIdsAndNameToUpdate = (
|
|
newActivityBody: string,
|
|
oldActivityAttachments: Attachment[] = [],
|
|
) => {
|
|
const activityAttachmentsNameAndPaths =
|
|
getActivityAttachmentPathsAndName(newActivityBody);
|
|
if (activityAttachmentsNameAndPaths.length === 0) return [];
|
|
|
|
const attachmentsWithFile = filterAttachmentsWithFile(oldActivityAttachments);
|
|
|
|
return activityAttachmentsNameAndPaths.reduce(
|
|
(acc: Partial<Attachment>[], activity: AttachmentInfo) => {
|
|
const foundActivity = attachmentsWithFile.find((attachment) =>
|
|
compareUrls(getAttachmentUrl({ attachment }), activity.path),
|
|
);
|
|
if (isDefined(foundActivity) && foundActivity.name !== activity.name) {
|
|
acc.push({ id: foundActivity.id, name: activity.name });
|
|
}
|
|
return acc;
|
|
},
|
|
[],
|
|
);
|
|
};
|