Skip to content

Commit

Permalink
fix: Use Close_Session post message to properly end the Collabora edi…
Browse files Browse the repository at this point in the history
…ting before opening locally

Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Apr 15, 2024
1 parent 871897c commit c9022bf
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
1 change: 1 addition & 0 deletions lib/Controller/WopiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public function checkFileInfo($fileId, $access_token) {
'EnableInsertRemoteImage' => !$isPublic,
'EnableShare' => $file->isShareable() && !$isVersion && !$isPublic,
'HideUserList' => '',
'EnableOwnerTermination' => $wopi->getCanwrite() && !$isPublic,
'DisablePrint' => $wopi->getHideDownload(),
'DisableExport' => $wopi->getHideDownload(),
'DisableCopy' => $wopi->getHideDownload(),
Expand Down
30 changes: 14 additions & 16 deletions src/mixins/openLocal.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,6 @@ export default {
startOpenLocalProcess() {
this.showOpenLocalConfirmation()
},
async unlockAndOpenLocally() {
if (this.openingLocally) {
let shouldContinue = true
try {
await this.unlockFile()
} catch (e) {
shouldContinue = e.response.status === 400
}

if (shouldContinue) {
this.openLocally()
}
}
},

showOpenLocalConfirmation() {
window.OC.dialogs.confirmDestructive(
Expand All @@ -66,8 +52,20 @@ export default {
return
}
this.openingLocally = true
this.sendPostMessage('Get_Views')
})
this.postMessage.registerPostMessageHandler(this.handleCloseSesssion)
this.sendPostMessage('Action_Save', {
DontTerminateEdit: false,
DontSaveIfUnmodified: false,
Notify: false,
})
this.sendPostMessage('Close_Session')
},
)
},

handleCloseSesssion() {
this.postMessage.unregisterPostMessageHandler(this.handleCloseSesssion)
this.openLocally()
},

showOpenLocalFinished() {
Expand Down
20 changes: 15 additions & 5 deletions src/view/Office.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import { NcButton, NcEmptyContent, NcLoadingIcon } from '@nextcloud/vue'
import AlertOctagonOutline from 'vue-material-design-icons/AlertOctagonOutline.vue'
import { loadState } from '@nextcloud/initial-state'
import { showInfo } from '@nextcloud/dialogs'
import ZoteroHint from '../components/Modal/ZoteroHint.vue'
import { basename, dirname } from 'path'
Expand Down Expand Up @@ -173,7 +174,6 @@ export default {
error: null,
errorType: null,
loadingMsg: null,
views: [],
showLinkPicker: false,
showZotero: false,
Expand Down Expand Up @@ -368,10 +368,8 @@ export default {
case 'UI_Close':
this.close()
break
case 'Get_Views_Resp':
case 'Views_List':
this.views = args
this.unlockAndOpenLocally()
case 'Session_Closed':
this.handleSessionClosed(args)
break
case 'UI_SaveAs':
this.saveAs(args.format)
Expand Down Expand Up @@ -443,6 +441,18 @@ export default {
}
},
handleSessionClosed({ Reason }) {
if (Reason !== 'OwnerTermination') {
return
}
if (this.openingLocally) {
return
}
showInfo(t('richdocuments', 'The collaborative editing was terminated by another user'))
this.close()
},
},
}
</script>
Expand Down

0 comments on commit c9022bf

Please sign in to comment.