From 3d79e0750b417b835681a3331abdb46e8d99932e Mon Sep 17 00:00:00 2001 From: barisusakli Date: Thu, 17 Dec 2015 12:05:35 +0200 Subject: [PATCH] fix edit delete for rooms --- public/src/client/chats.js | 8 +++++--- public/src/modules/chat.js | 2 +- src/socket.io/modules.js | 6 ++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/public/src/client/chats.js b/public/src/client/chats.js index e853bffec1..021d548889 100644 --- a/public/src/client/chats.js +++ b/public/src/client/chats.js @@ -68,7 +68,7 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll', }) .on('click', '[data-action="delete"]', function() { var messageId = $(this).parents('[data-mid]').attr('data-mid'); - Chats.delete(messageId); + Chats.delete(messageId, ajaxify.data.roomId); }); $('.recent-chats').on('scroll', function() { @@ -126,7 +126,7 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll', }); }; - Chats.delete = function(messageId) { + Chats.delete = function(messageId, roomId) { translator.translate('[[modules:chat.delete_message_confirm]]', function(translated) { bootbox.confirm(translated, function(ok) { if (!ok) { @@ -134,7 +134,8 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll', } socket.emit('modules.chats.delete', { - messageId: messageId + messageId: messageId, + roomId: roomId }, function(err) { if (err) { return app.alertError(err.message); @@ -366,6 +367,7 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll', }); } else { socket.emit('modules.chats.edit', { + roomId: roomId, mid: mid, message: msg }, function(err) { diff --git a/public/src/modules/chat.js b/public/src/modules/chat.js index 57d5811de2..a3d4620f08 100644 --- a/public/src/modules/chat.js +++ b/public/src/modules/chat.js @@ -260,7 +260,7 @@ define('chat', ['components', 'taskbar', 'string', 'sounds', 'forum/chats', 'tra }) .on('click', '[data-action="delete"]', function() { var messageId = $(this).parents('[data-mid]').attr('data-mid'); - Chats.delete(messageId); + Chats.delete(messageId, data.roomId); }); Chats.addSinceHandler(chatModal.attr('roomId'), chatModal.find('.chat-content'), chatModal.find('[data-since]')); diff --git a/src/socket.io/modules.js b/src/socket.io/modules.js index 3f22f19500..3cd7ba3486 100644 --- a/src/socket.io/modules.js +++ b/src/socket.io/modules.js @@ -174,9 +174,11 @@ SocketModules.chats.delete = function(socket, data, callback) { } Messaging.canEdit(data.messageId, socket.uid, function(err, allowed) { - if (allowed) { - Messaging.deleteMessage(data.messageId, data.roomId, callback); + if (err || !allowed) { + return callback(err || new Error('[[error:cant-delete-chat-message]]')); } + + Messaging.deleteMessage(data.messageId, data.roomId, callback); }); };