diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 2b8cab95d8d..e758e3b0cb2 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -96,6 +96,7 @@ const Wysiwyg = Widget.extend({ this.tooltipTimeouts = []; Wysiwyg.activeWysiwygs.add(this); this._oNotEditableObservers = new Map(); + this._joinPeerToPeer = this._joinPeerToPeer.bind(this); }, /** * @@ -138,6 +139,8 @@ const Wysiwyg = Widget.extend({ this.getSession()['notification_type'] ) { editorCollaborationOptions = this.setupCollaboration(options.collaborationChannel); + // Wait until editor is focused to join the peer to peer network. + this.$editable[0].addEventListener('focus', this._joinPeerToPeer); } const getYoutubeVideoElement = async (url) => { @@ -236,12 +239,6 @@ const Wysiwyg = Widget.extend({ this.$root = this.$root || $wrapwrap; } - if (this._peerToPeerLoading) { - // Now that the editor is loaded, wait for the peerToPeer to be - // ready to join. - this._peerToPeerLoading.then(() => this.ptp.notifyAllClients('ptp_join')); - } - this.$editable.on('click', '[data-oe-field][data-oe-sanitize-prevent-edition]', () => { Dialog.alert(this, _t("Someone with escalated rights previously modified this area, you are therefore not able to modify it yourself.")); }); @@ -2515,6 +2512,9 @@ const Wysiwyg = Widget.extend({ dialog.open({shouldFocusButtons:true}); this.resetEditor(dbRecord.body); + // We were in a peer to peer session before the conflict, join + // it again immediately. + this._joinPeerToPeer(); } this.preSavePromiseResolve(); resetPreSavePromise(); @@ -2531,6 +2531,12 @@ const Wysiwyg = Widget.extend({ this.ptp && this.ptp.stop(); this._collaborationStopBus && this._collaborationStopBus(); }, + _joinPeerToPeer: function () { + this.$editable[0].removeEventListener('focus', this._joinPeerToPeer); + if (this._peerToPeerLoading) { + this._peerToPeerLoading.then(() => this.ptp.notifyAllClients('ptp_join')); + } + }, resetEditor: function (value, options) { if (options) { this.options = this._getEditorOptions(options); @@ -2550,7 +2556,8 @@ const Wysiwyg = Widget.extend({ this.odooEditor.collaborationSetClientId(this._currentClientId); this.setValue(value); this.odooEditor.historyReset(); - this.ptp.notifyAllClients('ptp_join'); + // Wait until editor is focused to join the peer to peer network. + this.$editable[0].addEventListener('focus', this._joinPeerToPeer); }, /** * Set contenteditable=false for all `.o_not_editable` found within node if