feat: closes #10501, minimum reputation to chat

isekai-main
Barış Soner Uşaklı 3 years ago
parent 07678fb5a4
commit b28f9f776a

@ -81,6 +81,7 @@
"upvotesPerUserPerDay": 6, "upvotesPerUserPerDay": 6,
"downvotesPerDay": 10, "downvotesPerDay": 10,
"downvotesPerUserPerDay": 3, "downvotesPerUserPerDay": 3,
"min:rep:chat": 0,
"min:rep:downvote": 0, "min:rep:downvote": 0,
"min:rep:upvote": 0, "min:rep:upvote": 0,
"min:rep:flag": 0, "min:rep:flag": 0,

@ -10,6 +10,7 @@
"min-rep-downvote": "Minimum reputation to downvote posts", "min-rep-downvote": "Minimum reputation to downvote posts",
"downvotes-per-day": "Downvotes per day (set to 0 for unlimited downvotes)", "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)", "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-flag": "Minimum reputation to flag posts",
"min-rep-website": "Minimum reputation to add \"Website\" to user profile", "min-rep-website": "Minimum reputation to add \"Website\" to user profile",
"min-rep-aboutme": "Minimum reputation to add \"About me\" to user profile", "min-rep-aboutme": "Minimum reputation to add \"About me\" to user profile",

@ -184,6 +184,7 @@
"already-voting-for-this-post": "You have already voted for this post.", "already-voting-for-this-post": "You have already voted for this post.",
"reputation-system-disabled": "Reputation system is disabled.", "reputation-system-disabled": "Reputation system is disabled.",
"downvoting-disabled": "Downvoting 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-upvote": "You need %1 reputation to upvote",
"not-enough-reputation-to-downvote": "You need %1 reputation to downvote", "not-enough-reputation-to-downvote": "You need %1 reputation to downvote",
"not-enough-reputation-to-flag": "You need %1 reputation to flag this post", "not-enough-reputation-to-flag": "You need %1 reputation to flag this post",

@ -199,6 +199,7 @@ Messaging.canMessageUser = async (uid, toUid) => {
const [exists, canChat] = await Promise.all([ const [exists, canChat] = await Promise.all([
user.exists(toUid), user.exists(toUid),
privileges.global.can('chat', uid), privileges.global.can('chat', uid),
checkReputation(uid),
]); ]);
if (!exists) { if (!exists) {
@ -232,12 +233,16 @@ Messaging.canMessageRoom = async (uid, roomId) => {
throw new Error('[[error:chat-disabled]]'); 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) { if (!inRoom) {
throw new Error('[[error:not-in-room]]'); throw new Error('[[error:not-in-room]]');
} }
const canChat = await privileges.global.can('chat', uid);
if (!canChat) { if (!canChat) {
throw new Error('[[error:no-privileges]]'); 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) => { Messaging.hasPrivateChat = async (uid, withUid) => {
if (parseInt(uid, 10) === parseInt(withUid, 10)) { if (parseInt(uid, 10) === parseInt(withUid, 10)) {
return 0; return 0;

@ -31,6 +31,10 @@
<div class="col-sm-2 col-xs-12 settings-header">[[admin/settings/reputation:thresholds]]</div> <div class="col-sm-2 col-xs-12 settings-header">[[admin/settings/reputation:thresholds]]</div>
<div class="col-sm-10 col-xs-12"> <div class="col-sm-10 col-xs-12">
<form> <form>
<div class="form-group">
<label for="min:rep:chat">[[admin/settings/reputation:min-rep-chat]]</label>
<input type="text" class="form-control" placeholder="0" data-field="min:rep:chat" id="min:rep:chat">
</div>
<div class="form-group"> <div class="form-group">
<label for="min:rep:upvote">[[admin/settings/reputation:min-rep-upvote]]</label> <label for="min:rep:upvote">[[admin/settings/reputation:min-rep-upvote]]</label>
<input type="text" class="form-control" placeholder="0" data-field="min:rep:upvote" id="min:rep:upvote"> <input type="text" class="form-control" placeholder="0" data-field="min:rep:upvote" id="min:rep:upvote">

Loading…
Cancel
Save