Skip to content

Commit

Permalink
Add min right to mention users
Browse files Browse the repository at this point in the history
  • Loading branch information
7PH committed Jul 29, 2024
1 parent ef20b13 commit 1bd3d82
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
7 changes: 6 additions & 1 deletion app/server/plugins/core/room/MentionPlugin.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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
Expand Down Expand Up @@ -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', {
Expand Down
6 changes: 4 additions & 2 deletions app/server/skychat/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type Preferences = {
minRightForPublicMessages: number;
minRightForPrivateMessages: number;
minRightForMessageQuoting: number;
minRightForUserMention: number;
minRightForShortTermMessageHistory: number;
minRightForMessageHistory: number;
minRightForUserModeration: number | 'op';
Expand Down Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions app/template/preferences.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"minRightForPublicMessages": -1,
"minRightForPrivateMessages": -1,
"minRightForMessageQuoting": -1,
"minRightForUserMention": -1,
"minRightForUserModeration": "op",
"minRightForSetRight": "op",
"minRightForAudioRecording": -1,
Expand Down

0 comments on commit 1bd3d82

Please sign in to comment.