mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-24 01:10:31 +01:00
closes #3977
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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]]'));
|
||||
|
||||
Reference in New Issue
Block a user