diff --git a/install/data/defaults.json b/install/data/defaults.json index 397d1704e7..fefa23b8ea 100644 --- a/install/data/defaults.json +++ b/install/data/defaults.json @@ -81,6 +81,7 @@ "upvotesPerUserPerDay": 6, "downvotesPerDay": 10, "downvotesPerUserPerDay": 3, + "min:rep:chat": 0, "min:rep:downvote": 0, "min:rep:upvote": 0, "min:rep:flag": 0, diff --git a/public/language/en-GB/admin/settings/reputation.json b/public/language/en-GB/admin/settings/reputation.json index 4140161eb8..ae502f1edd 100644 --- a/public/language/en-GB/admin/settings/reputation.json +++ b/public/language/en-GB/admin/settings/reputation.json @@ -10,6 +10,7 @@ "min-rep-downvote": "Minimum reputation to downvote posts", "downvotes-per-day": "Downvotes per day (set to 0 for unlimited downvotes)", "downvotes-per-user-per-day": "Downvotes per user per day (set to 0 for unlimited downvotes)", + "min-rep-chat": "Minimum reputation to send chat messages", "min-rep-flag": "Minimum reputation to flag posts", "min-rep-website": "Minimum reputation to add \"Website\" to user profile", "min-rep-aboutme": "Minimum reputation to add \"About me\" to user profile", diff --git a/public/language/en-GB/error.json b/public/language/en-GB/error.json index e641d741a0..957049d43b 100644 --- a/public/language/en-GB/error.json +++ b/public/language/en-GB/error.json @@ -184,6 +184,7 @@ "already-voting-for-this-post": "You have already voted for this post.", "reputation-system-disabled": "Reputation system is disabled.", "downvoting-disabled": "Downvoting is disabled", + "not-enough-reputation-to-chat": "You need %1 reputation to chat", "not-enough-reputation-to-upvote": "You need %1 reputation to upvote", "not-enough-reputation-to-downvote": "You need %1 reputation to downvote", "not-enough-reputation-to-flag": "You need %1 reputation to flag this post", diff --git a/src/messaging/index.js b/src/messaging/index.js index 0526cab7ae..6ad192ef7f 100644 --- a/src/messaging/index.js +++ b/src/messaging/index.js @@ -199,6 +199,7 @@ Messaging.canMessageUser = async (uid, toUid) => { const [exists, canChat] = await Promise.all([ user.exists(toUid), privileges.global.can('chat', uid), + checkReputation(uid), ]); if (!exists) { @@ -232,12 +233,16 @@ Messaging.canMessageRoom = async (uid, roomId) => { throw new Error('[[error:chat-disabled]]'); } - const inRoom = await Messaging.isUserInRoom(uid, roomId); + const [inRoom, canChat] = await Promise.all([ + Messaging.isUserInRoom(uid, roomId), + privileges.global.can('chat', uid), + checkReputation(uid), + ]); + if (!inRoom) { throw new Error('[[error:not-in-room]]'); } - const canChat = await privileges.global.can('chat', uid); if (!canChat) { throw new Error('[[error:no-privileges]]'); } @@ -248,6 +253,15 @@ Messaging.canMessageRoom = async (uid, roomId) => { }); }; +async function checkReputation(uid) { + if (meta.config['min:rep:chat'] > 0) { + const reputation = await user.getUserField(uid, 'reputation'); + if (meta.config['min:rep:chat'] > reputation) { + throw new Error(`[[error:not-enough-reputation-to-chat, ${meta.config['min:rep:chat']}]]`); + } + } +} + Messaging.hasPrivateChat = async (uid, withUid) => { if (parseInt(uid, 10) === parseInt(withUid, 10)) { return 0; diff --git a/src/views/admin/settings/reputation.tpl b/src/views/admin/settings/reputation.tpl index 0d06b7cc3a..e82843d8f3 100644 --- a/src/views/admin/settings/reputation.tpl +++ b/src/views/admin/settings/reputation.tpl @@ -31,6 +31,10 @@
[[admin/settings/reputation:thresholds]]
+
+ + +