Co-authored-by: Camille Moussu <cmoussu@linagora.com>
This commit is contained in:
@@ -110,7 +110,7 @@ describe("refreshCalendarWithSyncToken", () => {
|
||||
expect(result.type).toBe("calendars/refreshWithSyncToken/fulfilled");
|
||||
expect(result.payload).toMatchObject({
|
||||
calId: mockCalendar.id,
|
||||
deletedEvents: ["deleted-event"],
|
||||
deletedEvents: ["/calendars/user1/cal1/deleted-event.ics"],
|
||||
createdOrUpdatedEvents: [],
|
||||
syncToken: "new-sync-token-456",
|
||||
});
|
||||
@@ -236,8 +236,8 @@ describe("refreshCalendarWithSyncToken", () => {
|
||||
if (result.type === "calendars/refreshWithSyncToken/fulfilled") {
|
||||
const payload = result.payload as SyncTokenUpdates;
|
||||
expect(payload?.deletedEvents).toEqual([
|
||||
"deleted-event",
|
||||
"updated-event",
|
||||
"/calendars/user1/cal1/deleted-event.ics",
|
||||
"/calendars/user1/cal1/updated-event.ics",
|
||||
]);
|
||||
expect(payload?.createdOrUpdatedEvents).toHaveLength(1);
|
||||
expect(payload?.createdOrUpdatedEvents[0].uid).toBe("updated-event");
|
||||
|
||||
@@ -334,12 +334,13 @@ const CalendarSlice = createSlice({
|
||||
|
||||
if (syncStatus === "SUCCESS") {
|
||||
const deletedSet = new Set(deletedEvents); // working with a Set for deletion avoids O(nxm) complexity
|
||||
Object.keys(target.events)
|
||||
.filter((eventKey) => {
|
||||
const baseUid = extractEventBaseUuid(eventKey);
|
||||
return deletedSet.has(eventKey) || deletedSet.has(baseUid);
|
||||
Object.values(target.events)
|
||||
.filter((event) => {
|
||||
return deletedSet.has(event.URL);
|
||||
})
|
||||
.forEach((eventKey) => delete target.events[eventKey]);
|
||||
.forEach((event) => {
|
||||
delete target.events[event.uid];
|
||||
});
|
||||
|
||||
for (const event of createdOrUpdatedEvents) {
|
||||
target.events[event.uid] = event;
|
||||
|
||||
@@ -14,13 +14,11 @@ export function processSyncUpdates(
|
||||
for (const update of updates) {
|
||||
const href = update?._links?.self?.href;
|
||||
if (!href) continue;
|
||||
const fileName = extractFileNameFromHref(href);
|
||||
|
||||
if (update.status === 404) {
|
||||
toDelete.push(fileName);
|
||||
toDelete.push(href);
|
||||
} else if (update.status === 200) {
|
||||
toExpand.push(href);
|
||||
toDelete.push(fileName); // we delete the old version of the event to replace it by the new when it's updated
|
||||
toDelete.push(href); // we delete the old version of the event to replace it by the new when it's updated
|
||||
} else if (update.status === 410) {
|
||||
throw new Error("SYNC_TOKEN_INVALID");
|
||||
}
|
||||
@@ -28,8 +26,3 @@ export function processSyncUpdates(
|
||||
|
||||
return { toDelete, toExpand };
|
||||
}
|
||||
|
||||
function extractFileNameFromHref(href: string): string {
|
||||
const fileNameMatch = href.match(/\/([^/]+)\.ics$/); // CalDAV href are like /calendars/userID/CalendarID/EventId.ics
|
||||
return fileNameMatch ? fileNameMatch[1] : href;
|
||||
}
|
||||
|
||||
@@ -380,7 +380,7 @@ export default function EventPreviewModal({
|
||||
setOpenDuplicateModal(true);
|
||||
}}
|
||||
/>
|
||||
{isOrganizer && (
|
||||
{isOwn && (
|
||||
<MenuItem
|
||||
onClick={async () => {
|
||||
if (isRecurring) {
|
||||
|
||||
Reference in New Issue
Block a user