v1.18.x
Barış Soner Uşaklı 6 years ago
parent 71163421aa
commit e55fb43703

@ -144,7 +144,7 @@
"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",
"chat-deleted-already": "This chat message has already been deleted.",
"chat-restored'already": "This chat message has already been restored.",
"chat-restored-already": "This chat message has already been restored.",
"already-voting-for-this-post": "You have already voted for this post.",
"reputation-system-disabled": "Reputation system is disabled.",

@ -36,7 +36,10 @@ module.exports = function (Messaging) {
return callback(err);
}
content = String(data.content);
content = String(data.content).trim();
if (!content) {
return callback(new Error('[[error:invalid-chat-message]]'));
}
var maximumChatMessageLength = (meta.config.maximumChatMessageLength || 1000);
if (content.length > maximumChatMessageLength) {

@ -19,7 +19,9 @@ module.exports = function (Messaging) {
if (raw === content) {
return callback();
}
if (!String(content).trim()) {
return callback(new Error('[[error:invalid-chat-message]]'));
}
Messaging.setMessageFields(mid, {
content: content,
edited: Date.now(),

@ -276,6 +276,13 @@ describe('Messaging Library', function () {
});
});
it('should fail to send chat if content is empty', function (done) {
socketModules.chats.send({ uid: fooUid }, { roomId: roomId, message: ' ' }, function (err) {
assert.equal(err.message, '[[error:invalid-chat-message]]');
done();
});
});
it('should send a message to a room', function (done) {
socketModules.chats.send({ uid: fooUid }, { roomId: roomId, message: 'first chat message' }, function (err, messageData) {
assert.ifError(err);
@ -554,6 +561,13 @@ describe('Messaging Library', function () {
});
});
it('should fail to edit message if new content is empty string', function (done) {
socketModules.chats.edit({ uid: fooUid }, { mid: 5, roomId: roomId, message: ' ' }, function (err) {
assert.equal(err.message, '[[error:invalid-chat-message]]');
done();
});
});
it('should fail to edit message if not own message', function (done) {
socketModules.chats.edit({ uid: herpUid }, { mid: 5, roomId: roomId, message: 'message edited' }, function (err) {
assert.equal(err.message, '[[error:cant-edit-chat-message]]');

Loading…
Cancel
Save