Skip to content

Node.js based forum software built for the modern web

closes #3977

barisusakli18013c5518c9
diff --git a/public/src/client/chats.js b/public/src/client/chats.js
index 72dbbe0921..305588d019 100644
--- a/public/src/client/chats.js
+++ b/public/src/client/chats.js
@@ -35,6 +35,11 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll',
};
Chats.addEventListeners = function() {
+ $('[component="chat/recent"]').on('click', '[component="chat/leave"]', function() {
+ Chats.leave($(this).parents('[data-roomid]'));
+ return false;
+ });
+
$('[component="chat/recent"]').on('click', '[component="chat/recent/room"]', function() {
Chats.switchChat($(this).attr('data-roomid'));
});
@@ -268,6 +273,20 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll',
});
};
+ Chats.leave = function(el) {
+ var roomId = el.attr('data-roomid');
+ socket.emit('modules.chats.leave', roomId, function(err) {
+ if (err) {
+ return app.alertError(err.message);
+ }
+ if (parseInt(roomId, 10) === ajaxify.data.roomId) {
+ ajaxify.go('chats');
+ } else {
+ el.remove();
+ }
+ });
+ };
+
Chats.switchChat = function(roomid) {
ajaxify.go('chats/' + roomid);
};
diff --git a/src/messaging/rooms.js b/src/messaging/rooms.js
index 7c590176a7..784c6cb2c0 100644
--- a/src/messaging/rooms.js
+++ b/src/messaging/rooms.js
@@ -101,12 +101,19 @@ module.exports = function(Messaging) {
},
function (results, next) {
if (!results.isOwner) {
- return next(new Error('[[error:cant-remove-users-to-chat-room]]'));
+ return next(new Error('[[error:cant-remove-users-from-chat-room]]'));
}
if (results.userCount === 2) {
return next(new Error('[[error:cant-remove-last-user]]'));
}
+ Messaging.leaveRoom(uids, roomId, next);
+ }
+ ], callback);
+ };
+ Messaging.leaveRoom = function(uids, roomId, callback) {
+ async.waterfall([
+ function (next) {
db.sortedSetRemove('chat:room:' + roomId + ':uids', uids, next);
},
function (next) {
diff --git a/src/socket.io/modules.js b/src/socket.io/modules.js
index 1e4dda83c7..3d12f66ad0 100644
--- a/src/socket.io/modules.js
+++ b/src/socket.io/modules.js
@@ -180,6 +180,15 @@ SocketModules.chats.removeUserFromRoom = function(socket, data, callback) {
], callback);
};
+SocketModules.chats.leave = function(socket, roomid, callback) {
+ if (!socket.uid || !roomid) {
+ return callback(new Error('[[error:invalid-data]]'));
+ }
+
+ Messaging.leaveRoom([socket.uid], roomid, callback);
+};
+
+
SocketModules.chats.edit = function(socket, data, callback) {
if (!data || !data.roomId) {
return callback(new Error('[[error:invalid-data]]'));