|
|
@ -1,38 +1,30 @@
|
|
|
|
'use strict';
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
define('chat', [
|
|
|
|
define('chat', [
|
|
|
|
'components',
|
|
|
|
'components',
|
|
|
|
'taskbar',
|
|
|
|
'taskbar',
|
|
|
|
'string',
|
|
|
|
], function (components, taskbar) {
|
|
|
|
'sounds',
|
|
|
|
|
|
|
|
'forum/chats',
|
|
|
|
|
|
|
|
'forum/chats/messages',
|
|
|
|
|
|
|
|
'translator',
|
|
|
|
|
|
|
|
'scrollStop',
|
|
|
|
|
|
|
|
'benchpress',
|
|
|
|
|
|
|
|
], function (components, taskbar, S, sounds, Chats, ChatsMessages, translator, scrollStop, Benchpress) {
|
|
|
|
|
|
|
|
var module = {};
|
|
|
|
var module = {};
|
|
|
|
var newMessage = false;
|
|
|
|
var newMessage = false;
|
|
|
|
|
|
|
|
|
|
|
|
module.prepareDOM = function () {
|
|
|
|
module.loadChatsDropdown = function (chatsListEl) {
|
|
|
|
var chatsToggleEl = components.get('chat/dropdown');
|
|
|
|
socket.emit('modules.chats.getRecentChats', {
|
|
|
|
var chatsListEl = components.get('chat/list');
|
|
|
|
uid: app.user.uid,
|
|
|
|
var chatsDropdownWrapper = chatsToggleEl.parents('.dropdown');
|
|
|
|
after: 0,
|
|
|
|
|
|
|
|
}, function (err, data) {
|
|
|
|
chatsToggleEl.on('click', function () {
|
|
|
|
if (err) {
|
|
|
|
if (chatsToggleEl.parent().hasClass('open')) {
|
|
|
|
return app.alertError(err.message);
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.loadChatsDropdown(chatsListEl);
|
|
|
|
var rooms = data.rooms.filter(function (room) {
|
|
|
|
|
|
|
|
return room.teaser;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (chatsDropdownWrapper.hasClass('open')) {
|
|
|
|
app.parseAndTranslate('partials/chats/dropdown', { rooms: rooms }, function (html) {
|
|
|
|
module.loadChatsDropdown(chatsListEl);
|
|
|
|
chatsListEl.find('*').not('.navigation-link').remove();
|
|
|
|
}
|
|
|
|
chatsListEl.prepend(html);
|
|
|
|
|
|
|
|
app.createUserTooltips(chatsListEl, 'right');
|
|
|
|
chatsListEl.on('click', '[data-roomid]', function (ev) {
|
|
|
|
chatsListEl.off('click').on('click', '[data-roomid]', function (ev) {
|
|
|
|
if ($(ev.target).parents('.user-link').length) {
|
|
|
|
if ($(ev.target).parents('.user-link').length) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -44,21 +36,26 @@ define('chat', [
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$('[component="chats/mark-all-read"]').on('click', function () {
|
|
|
|
$('[component="chats/mark-all-read"]').off('click').on('click', function () {
|
|
|
|
socket.emit('modules.chats.markAllRead', function (err) {
|
|
|
|
socket.emit('modules.chats.markAllRead', function (err) {
|
|
|
|
if (err) {
|
|
|
|
if (err) {
|
|
|
|
return app.alertError(err);
|
|
|
|
return app.alertError(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
socket.on('event:chats.receive', function (data) {
|
|
|
|
|
|
|
|
|
|
|
|
module.onChatMessageReceived = function (data) {
|
|
|
|
var username = data.message.fromUser.username;
|
|
|
|
var username = data.message.fromUser.username;
|
|
|
|
var isSelf = data.self === 1;
|
|
|
|
var isSelf = data.self === 1;
|
|
|
|
data.message.self = data.self;
|
|
|
|
data.message.self = data.self;
|
|
|
|
|
|
|
|
|
|
|
|
newMessage = data.self === 0;
|
|
|
|
newMessage = data.self === 0;
|
|
|
|
if (module.modalExists(data.roomId)) {
|
|
|
|
if (module.modalExists(data.roomId)) {
|
|
|
|
|
|
|
|
require(['forum/chats/messages'], function (ChatsMessages) {
|
|
|
|
var modal = module.getModal(data.roomId);
|
|
|
|
var modal = module.getModal(data.roomId);
|
|
|
|
|
|
|
|
|
|
|
|
ChatsMessages.appendChatMessage(modal.find('.chat-content'), data.message);
|
|
|
|
ChatsMessages.appendChatMessage(modal.find('.chat-content'), data.message);
|
|
|
@ -71,15 +68,14 @@ define('chat', [
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!isSelf && (!modal.is(':visible') || !app.isFocused)) {
|
|
|
|
if (!isSelf && (!modal.is(':visible') || !app.isFocused)) {
|
|
|
|
app.alternatingTitle('[[modules:chat.user_has_messaged_you, ' + username + ']]');
|
|
|
|
updateTitleAndPlaySound(data.message.mid, username);
|
|
|
|
sounds.play('chat-incoming', 'chat.incoming:' + data.message.mid);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
taskbar.push('chat', modal.attr('data-uuid'), {
|
|
|
|
taskbar.push('chat', modal.attr('data-uuid'), {
|
|
|
|
title: '[[modules:chat.chatting_with]] ' + (data.roomName || username),
|
|
|
|
title: '[[modules:chat.chatting_with]] ' + (data.roomName || username),
|
|
|
|
touid: data.message.fromUser.uid,
|
|
|
|
touid: data.message.fromUser.uid,
|
|
|
|
roomId: data.roomId,
|
|
|
|
roomId: data.roomId,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
} else if (!ajaxify.data.template.chats) {
|
|
|
|
} else if (!ajaxify.data.template.chats) {
|
|
|
|
socket.emit('modules.chats.loadRoom', {
|
|
|
|
socket.emit('modules.chats.loadRoom', {
|
|
|
|
roomId: data.roomId,
|
|
|
|
roomId: data.roomId,
|
|
|
@ -96,52 +92,30 @@ define('chat', [
|
|
|
|
module.createModal(roomData, function (modal) {
|
|
|
|
module.createModal(roomData, function (modal) {
|
|
|
|
module.toggleNew(modal.attr('data-uuid'), !isSelf, true);
|
|
|
|
module.toggleNew(modal.attr('data-uuid'), !isSelf, true);
|
|
|
|
if (!isSelf) {
|
|
|
|
if (!isSelf) {
|
|
|
|
app.alternatingTitle('[[modules:chat.user_has_messaged_you, ' + username + ']]');
|
|
|
|
updateTitleAndPlaySound(data.message.mid, username);
|
|
|
|
sounds.play('chat-incoming', 'chat.incoming:' + data.message.mid);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function updateTitleAndPlaySound(mid, username) {
|
|
|
|
|
|
|
|
app.alternatingTitle('[[modules:chat.user_has_messaged_you, ' + username + ']]');
|
|
|
|
|
|
|
|
require(['sounds'], function (sounds) {
|
|
|
|
|
|
|
|
sounds.play('chat-incoming', 'chat.incoming:' + mid);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
socket.on('event:user_status_change', function (data) {
|
|
|
|
module.onUserStatusChange = function (data) {
|
|
|
|
var modal = module.getModal(data.uid);
|
|
|
|
var modal = module.getModal(data.uid);
|
|
|
|
app.updateUserStatus(modal.find('[component="user/status"]'), data.status);
|
|
|
|
app.updateUserStatus(modal.find('[component="user/status"]'), data.status);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
socket.on('event:chats.roomRename', function (data) {
|
|
|
|
module.onRoomRename = function (data) {
|
|
|
|
var newTitle = $('<div/>').html(data.newName).text();
|
|
|
|
var newTitle = $('<div/>').html(data.newName).text();
|
|
|
|
var modal = module.getModal(data.roomId);
|
|
|
|
var modal = module.getModal(data.roomId);
|
|
|
|
modal.find('[component="chat/room/name"]').text(newTitle);
|
|
|
|
modal.find('[component="chat/room/name"]').text(newTitle);
|
|
|
|
taskbar.updateTitle('chat', modal.attr('data-uuid'), newTitle);
|
|
|
|
taskbar.updateTitle('chat', modal.attr('data-uuid'), newTitle);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ChatsMessages.onChatMessageEdit();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.loadChatsDropdown = function (chatsListEl) {
|
|
|
|
|
|
|
|
socket.emit('modules.chats.getRecentChats', {
|
|
|
|
|
|
|
|
uid: app.user.uid,
|
|
|
|
|
|
|
|
after: 0,
|
|
|
|
|
|
|
|
}, function (err, data) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
|
|
|
return app.alertError(err.message);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var rooms = data.rooms.filter(function (room) {
|
|
|
|
|
|
|
|
return room.teaser;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Benchpress.parse('partials/chats/dropdown', {
|
|
|
|
|
|
|
|
rooms: rooms,
|
|
|
|
|
|
|
|
}, function (html) {
|
|
|
|
|
|
|
|
translator.translate(html, function (translated) {
|
|
|
|
|
|
|
|
chatsListEl.find('*').not('.navigation-link').remove();
|
|
|
|
|
|
|
|
chatsListEl.prepend(translated);
|
|
|
|
|
|
|
|
app.createUserTooltips(chatsListEl, 'right');
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
module.getModal = function (roomId) {
|
|
|
|
module.getModal = function (roomId) {
|
|
|
@ -153,6 +127,7 @@ define('chat', [
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
module.createModal = function (data, callback) {
|
|
|
|
module.createModal = function (data, callback) {
|
|
|
|
|
|
|
|
require(['scrollStop', 'forum/chats', 'forum/chats/messages'], function (scrollStop, Chats, ChatsMessages) {
|
|
|
|
app.parseAndTranslate('chat', data, function (chatModal) {
|
|
|
|
app.parseAndTranslate('chat', data, function (chatModal) {
|
|
|
|
var uuid = utils.generateUUID();
|
|
|
|
var uuid = utils.generateUUID();
|
|
|
|
var dragged = false;
|
|
|
|
var dragged = false;
|
|
|
@ -249,6 +224,7 @@ define('chat', [
|
|
|
|
|
|
|
|
|
|
|
|
Chats.addCharactersLeftHandler(chatModal);
|
|
|
|
Chats.addCharactersLeftHandler(chatModal);
|
|
|
|
Chats.addIPHandler(chatModal);
|
|
|
|
Chats.addIPHandler(chatModal);
|
|
|
|
|
|
|
|
ChatsMessages.onChatMessageEdit();
|
|
|
|
|
|
|
|
|
|
|
|
taskbar.push('chat', chatModal.attr('data-uuid'), {
|
|
|
|
taskbar.push('chat', chatModal.attr('data-uuid'), {
|
|
|
|
title: '[[modules:chat.chatting_with]] ' + (data.roomName || (data.users.length ? data.users[0].username : '')),
|
|
|
|
title: '[[modules:chat.chatting_with]] ' + (data.roomName || (data.users.length ? data.users[0].username : '')),
|
|
|
@ -263,6 +239,7 @@ define('chat', [
|
|
|
|
callback(chatModal);
|
|
|
|
callback(chatModal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
module.focusInput = function (chatModal) {
|
|
|
|
module.focusInput = function (chatModal) {
|
|
|
@ -297,6 +274,7 @@ define('chat', [
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
module.load = function (uuid) {
|
|
|
|
module.load = function (uuid) {
|
|
|
|
|
|
|
|
require(['forum/chats/messages'], function (ChatsMessages) {
|
|
|
|
var chatModal = $('.chat-modal[data-uuid="' + uuid + '"]');
|
|
|
|
var chatModal = $('.chat-modal[data-uuid="' + uuid + '"]');
|
|
|
|
chatModal.removeClass('hide');
|
|
|
|
chatModal.removeClass('hide');
|
|
|
|
taskbar.updateActive(uuid);
|
|
|
|
taskbar.updateActive(uuid);
|
|
|
@ -308,6 +286,7 @@ define('chat', [
|
|
|
|
if (env === 'xs' || env === 'sm') {
|
|
|
|
if (env === 'xs' || env === 'sm') {
|
|
|
|
module.enableMobileBehaviour(chatModal);
|
|
|
|
module.enableMobileBehaviour(chatModal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
module.enableMobileBehaviour = function (modalEl) {
|
|
|
|
module.enableMobileBehaviour = function (modalEl) {
|
|
|
@ -340,6 +319,5 @@ define('chat', [
|
|
|
|
|
|
|
|
|
|
|
|
module.toggleNew = taskbar.toggleNew;
|
|
|
|
module.toggleNew = taskbar.toggleNew;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return module;
|
|
|
|
return module;
|
|
|
|
});
|
|
|
|
});
|
|
|
|