From aaab1fe6041146ae19db6641c8a7b799dca7b946 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Wed, 8 Dec 2021 19:33:28 +0100 Subject: [PATCH] Fix some cases where the chat immediatly close Peertube events are not fired in the good order. This is a dirty fix: saving the current window location when initializing the chat, and comparing the saved url when navigation-end is triggered. --- CHANGELOG.md | 6 ++++++ client/common-client-plugin.ts | 9 +++++++++ client/videowatch-client-plugin.ts | 1 + 3 files changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dbadeb81..fc91b0a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## v5.0.2 + +### Fixes + +* Fix some cases where the chat immediatly close (Peertube events are not fired in the good order). + ## v5.0.1 ### Breaking changes diff --git a/client/common-client-plugin.ts b/client/common-client-plugin.ts index e5c40d82..6bee6279 100644 --- a/client/common-client-plugin.ts +++ b/client/common-client-plugin.ts @@ -5,6 +5,15 @@ async function register ({ peertubeHelpers, registerHook, registerVideoField }: handler: () => { const container = document.querySelector('#peertube-plugin-livechat-container') if (container) { + const url = container.getAttribute('peertube-plugin-livechat-current-url') + if (url && url === window.location.href) { + console.warn( + '[peertube-plugin-livechat navigation-end] ' + + 'It seems that action:router.navigation-end was called after action:video-watch.video.loaded. ' + + 'No removing the chat from the DOM.' + ) + return + } container.remove() } } diff --git a/client/videowatch-client-plugin.ts b/client/videowatch-client-plugin.ts index ef888934..db017173 100644 --- a/client/videowatch-client-plugin.ts +++ b/client/videowatch-client-plugin.ts @@ -289,6 +289,7 @@ function register ({ registerHook, peertubeHelpers }: RegisterOptions): void { container = document.createElement('div') container.setAttribute('id', 'peertube-plugin-livechat-container') container.setAttribute('peertube-plugin-livechat-state', 'initializing') + container.setAttribute('peertube-plugin-livechat-current-url', window.location.href) placeholder.append(container) peertubeHelpers.getSettings().then((s: any) => {