Skip to content

Commit 2c7135b

Browse files
committed
fix(files_versions): update version only after save with current mtime
- files_version matches the item's mtime with the node's to consider whether an item is the current one. This often does not match with Date.now() as it does not match real file's mtime - fetches the current mtime from the server upon save. This can be avoided, when Collabora also sends the mtime along the Doc_ModifiedStatus message - Action_Save and UI_Save actions would trigger updates before the actual save action, meta data cannot be correct at this time - There are still edge cases: 1. The current version is not always detected correctly, leading to "broken" preview image and download link. The image stays until a refresh, the link will work once it turns into a regular version. It is already a lot better. 2. Sometimes the version generation can take longer (saw it happening once after 2min), in those case the preview and download link do not work. Out of scope here. Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de> Assisted-by: Claude:claude-sonnet-5
1 parent 170f8aa commit 2c7135b

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

src/view/FilesAppIntegration.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export default {
116116
const newFileModel = oldFile.clone()
117117
newFileModel.set('id', node.fileid)
118118
newFileModel.set('name', newName)
119-
newFileModel.set('mtime', Date.now())
119+
newFileModel.set('mtime', node.mtime?.getTime())
120120
this.getFileList()
121121
.add(newFileModel.toJSON())
122122
}
@@ -487,6 +487,13 @@ export default {
487487
}
488488
},
489489

490+
async refreshFileInfo() {
491+
const node = await this.getFileNode(true)
492+
if (node) {
493+
emit('files:node:updated', node)
494+
}
495+
},
496+
490497
async updateFileInfo(name, mtime) {
491498
const node = await this.getFileNode()
492499

src/view/Office.vue

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ export default {
406406
close() {
407407
FilesAppIntegration.close()
408408
if (this.modified) {
409-
FilesAppIntegration.updateFileInfo(undefined, Date.now())
409+
FilesAppIntegration.refreshFileInfo()
410410
}
411411
disableScrollLock()
412412
this.restoreFavicon()
@@ -526,7 +526,7 @@ export default {
526526
this.switchToSavedAsFile(newFileName)
527527
} else {
528528
// When saving the current file, update its modification time
529-
FilesAppIntegration.updateFileInfo(undefined, Date.now())
529+
FilesAppIntegration.refreshFileInfo()
530530
}
531531
}
532532
break
@@ -580,19 +580,11 @@ export default {
580580
case 'Action_GetLinkPreview':
581581
this.resolveLink(args.url)
582582
break
583-
case 'Action_Save':
584-
if (this.modified) {
585-
FilesAppIntegration.updateFileInfo(undefined, Date.now())
586-
}
587-
break
588-
case 'UI_Save':
589-
FilesAppIntegration.updateFileInfo(undefined, Date.now())
590-
break
591583
case 'Clicked_Button':
592584
this.buttonClicked(args)
593585
break
594586
case 'Doc_ModifiedStatus':
595-
if (args.Modified !== this.modified && !this.openingLocally) {
587+
if (this.modified && !args.Modified && !this.openingLocally) {
596588
FilesAppIntegration.updateFileInfo(undefined, Date.now())
597589
}
598590
this.modified = args.Modified

0 commit comments

Comments
 (0)