fix: keep a file's Modified time on move, Undo and restore in the demo

This commit is contained in:
Linus Rath
2026-10-28 10:19:46 +01:00
parent 10420b8d96
commit 55fb5acef5
2 changed files with 26 additions and 2 deletions
+22
View File
@@ -0,0 +1,22 @@
import { describe, expect, it } from 'vitest';
import { DemoJMAPClient } from '@/lib/demo/demo-client';
// A move, its Undo and a restore from the trash are all parentId updates;
// none of them may make a file look edited.
describe('DemoJMAPClient files', () => {
it('keeps a file\'s Modified time when it is moved or renamed', async () => {
const client = new DemoJMAPClient();
const folder = await client.createFileDirectory('Target', null);
const nodes = await client.listAllFileNodes();
const original = nodes.find((n) => n.blobId != null && n.modified)!;
const before = original.modified;
await client.updateFileNodes({ [original.id]: { parentId: folder.id } });
await client.updateFileNode(original.id, { name: 'renamed.txt' });
const after = (await client.getFileNodes([original.id]))[0];
expect(after.parentId).toBe(folder.id);
expect(after.name).toBe('renamed.txt');
expect(after.modified).toBe(before);
});
});
+4 -2
View File
@@ -1409,8 +1409,10 @@ export class DemoJMAPClient implements IJMAPClient {
}
async updateFileNode(id: string, updates: Partial<Pick<FileNode, 'name' | 'parentId'>>): Promise<void> {
// A rename or move leaves `modified` alone, as on Stalwart: it dates the
// content, and a move or its Undo shouldn't make a file look edited.
const node = this.data.fileNodes.find(n => n.id === id);
if (node) Object.assign(node, updates, { modified: new Date().toISOString() });
if (node) Object.assign(node, updates);
}
async updateFileNodes(updates: Record<string, Partial<Pick<FileNode, 'name' | 'parentId'>>>): Promise<{ updated: string[]; notUpdated: Record<string, string> }> {
@@ -1418,7 +1420,7 @@ export class DemoJMAPClient implements IJMAPClient {
for (const [id, patch] of Object.entries(updates)) {
const node = this.data.fileNodes.find(n => n.id === id);
if (node) {
Object.assign(node, patch, { modified: new Date().toISOString() });
Object.assign(node, patch);
updated.push(id);
}
}