v1.18.x
Barış Soner Uşaklı 7 years ago
parent 89f5015d83
commit 99eb1d1785

@ -5,5 +5,7 @@
"disable-editing-help": "Administrators and global moderators are exempt from this restriction", "disable-editing-help": "Administrators and global moderators are exempt from this restriction",
"max-length": "Maximum length of chat messages", "max-length": "Maximum length of chat messages",
"max-room-size": "Maximum number of users in chat rooms", "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-edit-chat-message": "You are not allowed to edit this message",
"cant-remove-last-user": "You can't remove the last user", "cant-remove-last-user": "You can't remove the last user",
"cant-delete-chat-message": "You are not allowed to delete this message", "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.", "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.",

@ -44,10 +44,25 @@ module.exports = function (Messaging) {
}; };
Messaging.canEdit = function (messageId, uid, callback) { 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) { 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) { } else if (parseInt(meta.config.disableChatMessageEditing, 10) === 1) {
return callback(null, false); return callback(new Error('[[error:chat-message-editing-disabled]]'));
} }
async.waterfall([ async.waterfall([
@ -56,25 +71,36 @@ module.exports = function (Messaging) {
}, },
function (userData, next) { function (userData, next) {
if (parseInt(userData.banned, 10) === 1) { 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) { 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]]'));
} }
async.parallel({
Messaging.getMessageField(messageId, 'fromuid', next); isAdmin: function (next) {
user.isAdministrator(uid, next);
},
messageData: function (next) {
Messaging.getMessageFields(messageId, ['fromuid', 'timestamp'], next);
},
}, next);
}, },
function (fromUid, next) { function (results, next) {
if (parseInt(fromUid, 10) === parseInt(uid, 10)) { if (results.isAdmin) {
return callback(null, true); 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] + ']]'));
} }
user.isAdministrator(uid, next); if (parseInt(results.messageData.fromuid, 10) === parseInt(uid, 10)) {
}, return callback();
function (isAdmin, next) { }
next(null, isAdmin);
next(new Error('[[error:cant-' + type + '-chat-message]]'));
}, },
], callback); ], callback);
}; }
}; };

@ -246,10 +246,7 @@ SocketModules.chats.edit = function (socket, data, callback) {
function (next) { function (next) {
Messaging.canEdit(data.mid, socket.uid, next); Messaging.canEdit(data.mid, socket.uid, next);
}, },
function (allowed, next) { function (next) {
if (!allowed) {
return next(new Error('[[error:cant-edit-chat-message]]'));
}
Messaging.editMessage(socket.uid, data.mid, data.roomId, data.message, next); Messaging.editMessage(socket.uid, data.mid, data.roomId, data.message, next);
}, },
], callback); ], callback);
@ -262,13 +259,9 @@ SocketModules.chats.delete = function (socket, data, callback) {
async.waterfall([ async.waterfall([
function (next) { function (next) {
Messaging.canEdit(data.messageId, socket.uid, next); Messaging.canDelete(data.messageId, socket.uid, next);
}, },
function (allowed, next) { function (next) {
if (!allowed) {
return next(new Error('[[error:cant-delete-chat-message]]'));
}
Messaging.deleteMessage(data.messageId, data.roomId, next); Messaging.deleteMessage(data.messageId, data.roomId, next);
}, },
], callback); ], callback);

@ -23,6 +23,16 @@
<p class="help-block">[[admin/settings/chat:disable-editing-help]]</p> <p class="help-block">[[admin/settings/chat:disable-editing-help]]</p>
</div> </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"> <div class="form-group">
<label>[[admin/settings/chat:max-length]]</label> <label>[[admin/settings/chat:max-length]]</label>
<input type="text" class="form-control" value="1000" data-field="maximumChatMessageLength"> <input type="text" class="form-control" value="1000" data-field="maximumChatMessageLength">

Loading…
Cancel
Save