mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
closes #6163
This commit is contained in:
@@ -5,5 +5,7 @@
|
||||
"disable-editing-help": "Administrators and global moderators are exempt from this restriction",
|
||||
"max-length": "Maximum length of chat messages",
|
||||
"max-room-size": "Maximum number of users in chat rooms",
|
||||
"delay": "Time between chat messages in milliseconds"
|
||||
"delay": "Time between chat messages in milliseconds",
|
||||
"restrictions.seconds-edit-after": "Number of seconds before users are allowed to edit chat messages after posting. (0 disabled)",
|
||||
"restrictions.seconds-delete-after": "Number of seconds before users are allowed to delete chat messages after posting. (0 disabled)"
|
||||
}
|
||||
@@ -137,6 +137,8 @@
|
||||
"cant-edit-chat-message": "You are not allowed to edit this message",
|
||||
"cant-remove-last-user": "You can't remove the last user",
|
||||
"cant-delete-chat-message": "You are not allowed to delete this message",
|
||||
"chat-edit-duration-expired": "You are only allowed to edit chat messages for %1 second(s) after posting",
|
||||
"chat-delete-duration-expired": "You are only allowed to delete chat messages for %1 second(s) after posting",
|
||||
|
||||
"already-voting-for-this-post": "You have already voted for this post.",
|
||||
"reputation-system-disabled": "Reputation system is disabled.",
|
||||
|
||||
@@ -44,10 +44,25 @@ module.exports = function (Messaging) {
|
||||
};
|
||||
|
||||
Messaging.canEdit = function (messageId, uid, callback) {
|
||||
canEditDelete(messageId, uid, 'edit', callback);
|
||||
};
|
||||
|
||||
Messaging.canDelete = function (messageId, uid, callback) {
|
||||
canEditDelete(messageId, uid, 'delete', callback);
|
||||
};
|
||||
|
||||
function canEditDelete(messageId, uid, type, callback) {
|
||||
var durationConfig = '';
|
||||
if (type === 'edit') {
|
||||
durationConfig = 'chatEditDuration';
|
||||
} else if (type === 'delete') {
|
||||
durationConfig = 'chatDeleteDuration';
|
||||
}
|
||||
|
||||
if (parseInt(meta.config.disableChat, 10) === 1) {
|
||||
return callback(null, false);
|
||||
return callback(new Error('[[error:chat-disabled]]'));
|
||||
} else if (parseInt(meta.config.disableChatMessageEditing, 10) === 1) {
|
||||
return callback(null, false);
|
||||
return callback(new Error('[[error:chat-message-editing-disabled]]'));
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
@@ -56,25 +71,36 @@ module.exports = function (Messaging) {
|
||||
},
|
||||
function (userData, next) {
|
||||
if (parseInt(userData.banned, 10) === 1) {
|
||||
return callback(null, false);
|
||||
return callback(new Error('[[error:user-banned]]'));
|
||||
}
|
||||
|
||||
if (parseInt(meta.config.requireEmailConfirmation, 10) === 1 && parseInt(userData['email:confirmed'], 10) !== 1) {
|
||||
return callback(null, false);
|
||||
return callback(new Error('[[error:email-not-confirmed]]'));
|
||||
}
|
||||
|
||||
Messaging.getMessageField(messageId, 'fromuid', next);
|
||||
},
|
||||
function (fromUid, next) {
|
||||
if (parseInt(fromUid, 10) === parseInt(uid, 10)) {
|
||||
return callback(null, true);
|
||||
}
|
||||
|
||||
async.parallel({
|
||||
isAdmin: function (next) {
|
||||
user.isAdministrator(uid, next);
|
||||
},
|
||||
function (isAdmin, next) {
|
||||
next(null, isAdmin);
|
||||
messageData: function (next) {
|
||||
Messaging.getMessageFields(messageId, ['fromuid', 'timestamp'], next);
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
if (results.isAdmin) {
|
||||
return callback();
|
||||
}
|
||||
var chatConfigDuration = parseInt(meta.config[durationConfig], 10);
|
||||
if (chatConfigDuration && Date.now() - parseInt(results.messageData.timestamp, 10) > chatConfigDuration * 1000) {
|
||||
return callback(new Error('[[error:chat-' + type + '-duration-expired, ' + meta.config[durationConfig] + ']]'));
|
||||
}
|
||||
|
||||
if (parseInt(results.messageData.fromuid, 10) === parseInt(uid, 10)) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
next(new Error('[[error:cant-' + type + '-chat-message]]'));
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -246,10 +246,7 @@ SocketModules.chats.edit = function (socket, data, callback) {
|
||||
function (next) {
|
||||
Messaging.canEdit(data.mid, socket.uid, next);
|
||||
},
|
||||
function (allowed, next) {
|
||||
if (!allowed) {
|
||||
return next(new Error('[[error:cant-edit-chat-message]]'));
|
||||
}
|
||||
function (next) {
|
||||
Messaging.editMessage(socket.uid, data.mid, data.roomId, data.message, next);
|
||||
},
|
||||
], callback);
|
||||
@@ -262,13 +259,9 @@ SocketModules.chats.delete = function (socket, data, callback) {
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
Messaging.canEdit(data.messageId, socket.uid, next);
|
||||
Messaging.canDelete(data.messageId, socket.uid, next);
|
||||
},
|
||||
function (allowed, next) {
|
||||
if (!allowed) {
|
||||
return next(new Error('[[error:cant-delete-chat-message]]'));
|
||||
}
|
||||
|
||||
function (next) {
|
||||
Messaging.deleteMessage(data.messageId, data.roomId, next);
|
||||
},
|
||||
], callback);
|
||||
|
||||
@@ -23,6 +23,16 @@
|
||||
<p class="help-block">[[admin/settings/chat:disable-editing-help]]</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>[[admin/settings/chat:restrictions.seconds-edit-after]]</label>
|
||||
<input type="text" class="form-control" value="0" data-field="chatEditDuration">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>[[admin/settings/chat:restrictions.seconds-delete-after]]</label>
|
||||
<input type="text" class="form-control" value="0" data-field="chatDeleteDuration">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>[[admin/settings/chat:max-length]]</label>
|
||||
<input type="text" class="form-control" value="1000" data-field="maximumChatMessageLength">
|
||||
|
||||
Reference in New Issue
Block a user