various group chat fixes #3980

fix multiple modals using the same tagsinput
fix online user getting chat notification
fix owner not being able to remove users in the chat modal
v1.18.x
barisusakli 9 years ago
parent 80fd0b20bd
commit dff3d7f20e

@ -254,16 +254,17 @@ app.cacheBuster = null;
if (chat.modalExists(roomId)) {
loadAndCenter(chat.getModal(roomId));
} else {
socket.emit('modules.chats.getUsersInRoom', {roomId: roomId}, function(err, users) {
socket.emit('modules.chats.loadRoom', {roomId: roomId}, function(err, roomData) {
if (err) {
return app.alertError(err.message);
}
users = users.filter(function(user) {
roomData.users = roomData.users.filter(function(user) {
return user && parseInt(user.uid, 10) !== parseInt(app.user.uid, 10);
});
chat.createModal({
roomId: roomId,
users: users
users: roomData.users,
owner: roomData.owner
}, loadAndCenter);
});
}

@ -18,7 +18,7 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll',
}
Chats.addEventListeners();
Chats.createTagsInput(ajaxify.data.roomId, ajaxify.data.users);
Chats.createTagsInput($('[component="chat/messages"] .users-tag-input'), ajaxify.data);
if (env === 'md' || env === 'lg') {
Chats.resizeMainWindow();
@ -185,16 +185,14 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll',
});
};
Chats.createTagsInput = function(roomId, users) {
var tagEl = $('.users-tag-input');
Chats.createTagsInput = function(tagEl, data) {
tagEl.tagsinput({
confirmKeys: [13, 44],
trimValue: true
});
if (users && users.length) {
users.forEach(function(user) {
if (data.users && data.users.length) {
data.users.forEach(function(user) {
tagEl.tagsinput('add', user.username);
});
}
@ -203,7 +201,7 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll',
if (event.item === app.user.username) {
return;
}
socket.emit('modules.chats.addUserToRoom', {roomId: roomId, username: event.item}, function(err) {
socket.emit('modules.chats.addUserToRoom', {roomId: data.roomId, username: event.item}, function(err) {
if (err && err.message === '[[error:no-user]]') {
tagEl.tagsinput('remove', event.item);
}
@ -211,11 +209,11 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll',
});
tagEl.on('beforeItemRemove', function(event) {
event.cancel = !ajaxify.data.owner;
event.cancel = !data.owner;
});
tagEl.on('itemRemoved', function(event) {
socket.emit('modules.chats.removeUserFromRoom', {roomId: roomId, username: event.item});
socket.emit('modules.chats.removeUserFromRoom', {roomId: data.roomId, username: event.item});
});
var input = $('.users-tag-container').find('.bootstrap-tagsinput input');

@ -29,14 +29,14 @@ define('chat', ['components', 'taskbar', 'string', 'sounds', 'forum/chats', 'tra
Chats.appendChatMessage(modal.find('.chat-content'), data.message);
if (modal.is(":visible")) {
if (modal.is(':visible')) {
taskbar.updateActive(modal.attr('UUID'));
Chats.scrollToBottom(modal.find('.chat-content'));
} else {
module.toggleNew(modal.attr('UUID'), true, true);
}
if (!isSelf && (!modal.is(":visible") || !app.isFocused)) {
if (!isSelf && (!modal.is(':visible') || !app.isFocused)) {
app.alternatingTitle('[[modules:chat.user_has_messaged_you, ' + username + ']]');
sounds.play('chat-incoming');
@ -46,15 +46,25 @@ define('chat', ['components', 'taskbar', 'string', 'sounds', 'forum/chats', 'tra
});
}
} else {
module.createModal({
roomId: data.roomId,
silent: true
}, function(modal) {
module.toggleNew(modal.attr('UUID'), true, true);
if (!isSelf) {
app.alternatingTitle('[[modules:chat.user_has_messaged_you, ' + username + ']]');
sounds.play('chat-incoming');
socket.emit('modules.chats.loadRoom', {roomId: data.roomId}, function(err, roomData) {
if (err) {
return app.alertError(err.message);
}
roomData.users = roomData.users.filter(function(user) {
return user && parseInt(user.uid, 10) !== parseInt(app.user.uid, 10);
});
module.createModal({
roomId: data.roomId,
users: roomData.users,
owner: roomData.owner,
silent: true
}, function(modal) {
module.toggleNew(modal.attr('UUID'), true, true);
if (!isSelf) {
app.alternatingTitle('[[modules:chat.user_has_messaged_you, ' + username + ']]');
sounds.play('chat-incoming');
}
});
});
}
});
@ -267,7 +277,7 @@ define('chat', ['components', 'taskbar', 'string', 'sounds', 'forum/chats', 'tra
Chats.addSendHandlers(chatModal.attr('roomId'), chatModal.find('#chat-message-input'), chatModal.find('#chat-message-send-btn'));
Chats.createTagsInput(data.roomId, data.users);
Chats.createTagsInput(chatModal.find('.users-tag-input'), data);
Chats.loadChatSince(chatModal.attr('roomId'), chatModal.find('.chat-content'), 'recent');

@ -59,7 +59,7 @@ module.exports = function(Messaging) {
}
uids = uids.filter(function(uid, index) {
return isOnline[index] && parseInt(fromuid, 10) !== parseInt(uid, 10);
return !isOnline[index] && parseInt(fromuid, 10) !== parseInt(uid, 10);
});
if (!uids.length) {

@ -101,20 +101,27 @@ SocketModules.chats.send = function(socket, data, callback) {
});
};
SocketModules.chats.getUsersInRoom = function(socket, data, callback) {
SocketModules.chats.loadRoom = function(socket, data, callback) {
if (!data || !data.roomId) {
return callback(new Error('[[error:invalid-data]]'));
}
var isOwner = false;
async.waterfall([
function (next) {
Messaging.isUserInRoom(socket.uid, data.roomId, next);
async.parallel({
inRoom: async.apply(Messaging.isUserInRoom, socket.uid, data.roomId),
isOwner: async.apply(Messaging.isRoomOwner, socket.uid, data.roomId)
}, next);
},
function (inRoom, next) {
if (!inRoom) {
function (results, next) {
if (!results.inRoom) {
return next(new Error('[[error:not-allowerd]]'));
}
isOwner = results.isOwner;
Messaging.getUsersInRoom(data.roomId, 0, -1, next);
},
function (users, next) {
next(null, {users: users, owner: isOwner});
}
], callback);
};

Loading…
Cancel
Save