From 1bd3d82fdd99c678baba453042be89aac6c00c7b Mon Sep 17 00:00:00 2001 From: 7PH Date: Tue, 30 Jul 2024 00:38:48 +0200 Subject: [PATCH] Add min right to mention users --- README.md | 1 + app/server/plugins/core/room/MentionPlugin.ts | 7 ++++++- app/server/skychat/Config.ts | 6 ++++-- app/template/preferences.json.template | 1 + 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d60e6a65..e3e3a7ba 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ The `config/preferences.json` file specifies application preferences. The availa | minRightForPublicMessages | number | -1 | Min. right to send public messages | | minRightForPrivateMessages | number | -1 | Min. right to send private messages | | minRightForMessageQuoting | number | -1 | Min. right to quote messages | +| minRightForUserMention | number | -1 | Min. right to mention users | | minRightForShortTermMessageHistory | number | -1 | Min. right to access short term room message history | | minRightForMessageHistory | number | -1 | Min. right to access full room message history | | minRightForUserModeration | number | 'op' | Min. right to ban, kick and access user ips | diff --git a/app/server/plugins/core/room/MentionPlugin.ts b/app/server/plugins/core/room/MentionPlugin.ts index 06f1ec02..4332e713 100644 --- a/app/server/plugins/core/room/MentionPlugin.ts +++ b/app/server/plugins/core/room/MentionPlugin.ts @@ -1,3 +1,4 @@ +import { Config } from '../../../skychat/Config.js'; import { Connection } from '../../../skychat/Connection.js'; import { Message } from '../../../skychat/Message.js'; import { Session } from '../../../skychat/Session.js'; @@ -13,6 +14,10 @@ export class MentionPlugin extends RoomPlugin { // Intercept quotes in messages public async onBeforeMessageBroadcastHook(message: Message, connection: Connection) { + if (connection.session.user.right < Config.PREFERENCES.minRightForUserMention) { + return message; + } + const mentions = message.content.match(/@[a-zA-Z0-9-_]+/g); // Note quote detected @@ -42,7 +47,7 @@ export class MentionPlugin extends RoomPlugin { continue; } // Skip if in a room where the mentioned user is not allowed - if (!connection.room || !connection.room.accepts(session)) { + if (!connection.room?.accepts(session)) { continue; } session.send('mention', { diff --git a/app/server/skychat/Config.ts b/app/server/skychat/Config.ts index 541fa0c9..d436f21b 100644 --- a/app/server/skychat/Config.ts +++ b/app/server/skychat/Config.ts @@ -5,6 +5,7 @@ export type Preferences = { minRightForPublicMessages: number; minRightForPrivateMessages: number; minRightForMessageQuoting: number; + minRightForUserMention: number; minRightForShortTermMessageHistory: number; minRightForMessageHistory: number; minRightForUserModeration: number | 'op'; @@ -96,10 +97,11 @@ export class Config { // Load preferences.json Config.PREFERENCES = JSON.parse(fs.readFileSync('config/preferences.json').toString()); const keys: string[] = [ - 'minRightForPrivateMessages', - 'minRightForMessageQuoting', 'minRightForShortTermMessageHistory', 'minRightForMessageHistory', + 'minRightForPrivateMessages', + 'minRightForMessageQuoting', + 'minRightForUserMention', 'minRightForUserModeration', 'minRightForSetRight', 'minRightForAudioRecording', diff --git a/app/template/preferences.json.template b/app/template/preferences.json.template index 362f111c..42897974 100644 --- a/app/template/preferences.json.template +++ b/app/template/preferences.json.template @@ -4,6 +4,7 @@ "minRightForPublicMessages": -1, "minRightForPrivateMessages": -1, "minRightForMessageQuoting": -1, + "minRightForUserMention": -1, "minRightForUserModeration": "op", "minRightForSetRight": "op", "minRightForAudioRecording": -1,