From 01a052d3806e5a6c405459d4027701e856a9842d Mon Sep 17 00:00:00 2001 From: John Livingston Date: Mon, 11 Apr 2022 18:12:12 +0200 Subject: [PATCH] Fix #97 #54: Settings to hide the chat for anonymous users --- CHANGELOG.md | 10 +++++++++ client/videowatch-client-plugin.ts | 8 +++++++ documentation/common.md | 8 +++++++ server/lib/prosody/config.ts | 7 +++++- server/lib/prosody/config/content.ts | 32 +++++++++++++++++----------- server/lib/settings.ts | 8 +++++++ 6 files changed, 59 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb66a913..8ca5c81e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## 5.7.0 + +### New features + +* You can disable the chat for anonymous users (users that are not connected to your Peertube instance). + * Note: this is a first version of this feature, released to quickly help some Peertube admins that are facing spam attacks. + * The chat will not be visible at all for anonymous users. + * In a future release, the chat will be replaced by a message saying «please log in to [...]». + * If you are not using the «Prosody controlled by Peertube» mode, this settings is not a real security feature. An attacker could easily find the chat uri and join it. + ## 5.6.0 ### Important notes diff --git a/client/videowatch-client-plugin.ts b/client/videowatch-client-plugin.ts index f40ea323..fc7dfb81 100644 --- a/client/videowatch-client-plugin.ts +++ b/client/videowatch-client-plugin.ts @@ -13,6 +13,10 @@ interface VideoWatchLoadedHookOptions { playlist?: any } +function isAnonymousUser (registerOptions: RegisterClientOptions): boolean { + return !registerOptions.peertubeHelpers.isLoggedIn() +} + function guessIsMine (registerOptions: RegisterClientOptions, video: Video): boolean { // Note: this is not safe, but it is not a problem: // this function is used for non critical functions @@ -239,6 +243,10 @@ function register (registerOptions: RegisterClientOptions): void { settings = s logger.log('Checking if this video should have a chat...') + if (settings['chat-no-anonymous'] === true && isAnonymousUser(registerOptions)) { + logger.log('No chat for anonymous users') + return + } if (!videoHasWebchat(s, video)) { logger.log('This video has no webchat') return diff --git a/documentation/common.md b/documentation/common.md index d887ac45..a286a0cb 100644 --- a/documentation/common.md +++ b/documentation/common.md @@ -39,6 +39,14 @@ You can choose some UUIDs for which the chat will be available. If you don't want te enable the feature for all videos, you can use this field to list videos UUIDs. You can add comments: everything rights to the # character will be stripped off, as for empty lines. +### Hide the chat for anonymous users + +If checked, anonymous Peertube users won't see the chat. + +Note: for now this feature simply hide the chat. +In a future release, the chat will be replaced by a message saying «please log in to [...]». +See [v5.7.0 Release Notes](https://github.com/JohnXLivingston/peertube-plugin-livechat/blob/main/CHANGELOG.md#570) for more information. + ### Webchat iframe style attribute You can add some custom styles that will be added to the iframe. diff --git a/server/lib/prosody/config.ts b/server/lib/prosody/config.ts index 4b532fd1..582172ac 100644 --- a/server/lib/prosody/config.ts +++ b/server/lib/prosody/config.ts @@ -91,7 +91,8 @@ async function getProsodyConfig (options: RegisterServerOptions): Promise() @@ -100,6 +101,7 @@ async function getProsodyConfig (options: RegisterServerOptions): Promise