2014-03-13 17:15:07 -04:00
|
|
|
"use strict";
|
2015-12-15 17:50:30 +02:00
|
|
|
/* globals app, define, socket, templates, utils, ajaxify */
|
2014-03-12 01:40:31 -04:00
|
|
|
|
2015-04-17 13:44:47 -04:00
|
|
|
define('chat', ['components', 'taskbar', 'string', 'sounds', 'forum/chats', 'translator'], function(components, taskbar, S, sounds, Chats, translator) {
|
2013-08-26 13:18:20 -04:00
|
|
|
|
2013-06-18 11:26:57 -04:00
|
|
|
var module = {};
|
2014-07-19 10:33:27 -04:00
|
|
|
var newMessage = false;
|
2013-06-18 11:26:57 -04:00
|
|
|
|
2014-01-13 10:06:00 -05:00
|
|
|
module.prepareDOM = function() {
|
2015-08-26 15:58:53 -04:00
|
|
|
var chatsToggleEl = components.get('chat/dropdown'),
|
2015-08-26 16:32:32 -04:00
|
|
|
chatsListEl = components.get('chat/list');
|
2014-01-13 13:50:33 -05:00
|
|
|
|
2014-01-13 10:06:00 -05:00
|
|
|
chatsToggleEl.on('click', function() {
|
2014-03-12 01:40:31 -04:00
|
|
|
if (chatsToggleEl.parent().hasClass('open')) {
|
2014-01-13 10:06:00 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-18 14:30:18 -04:00
|
|
|
module.loadChatsDropdown(chatsListEl);
|
2014-01-13 10:06:00 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
socket.on('event:chats.receive', function(data) {
|
2014-04-14 18:04:12 -04:00
|
|
|
var username = data.message.fromUser.username;
|
2015-12-16 15:09:14 +02:00
|
|
|
var isSelf = data.self === 1;
|
2014-09-02 16:01:45 -04:00
|
|
|
data.message.self = data.self;
|
2015-12-16 15:09:14 +02:00
|
|
|
|
2014-09-02 15:50:02 -04:00
|
|
|
newMessage = data.self === 0;
|
2015-12-16 15:09:14 +02:00
|
|
|
if (module.modalExists(data.roomId)) {
|
|
|
|
|
var modal = module.getModal(data.roomId);
|
2015-09-18 14:30:18 -04:00
|
|
|
|
|
|
|
|
Chats.appendChatMessage(modal.find('.chat-content'), data.message);
|
2014-01-13 13:50:33 -05:00
|
|
|
|
2015-12-21 10:14:44 +02:00
|
|
|
if (modal.is(':visible')) {
|
2014-01-13 13:50:33 -05:00
|
|
|
taskbar.updateActive(modal.attr('UUID'));
|
2015-07-29 12:58:06 -04:00
|
|
|
Chats.scrollToBottom(modal.find('.chat-content'));
|
2014-01-13 10:06:00 -05:00
|
|
|
} else {
|
2015-07-28 10:24:46 -04:00
|
|
|
module.toggleNew(modal.attr('UUID'), true, true);
|
2014-01-13 10:06:00 -05:00
|
|
|
}
|
2014-01-13 13:50:33 -05:00
|
|
|
|
2015-12-21 10:14:44 +02:00
|
|
|
if (!isSelf && (!modal.is(':visible') || !app.isFocused)) {
|
2014-05-09 17:57:39 -04:00
|
|
|
app.alternatingTitle('[[modules:chat.user_has_messaged_you, ' + username + ']]');
|
2014-07-07 19:47:03 -04:00
|
|
|
sounds.play('chat-incoming');
|
2015-04-27 12:41:16 -04:00
|
|
|
|
|
|
|
|
taskbar.push('chat', modal.attr('UUID'), {
|
|
|
|
|
title: username,
|
|
|
|
|
touid: data.message.fromUser.uid
|
|
|
|
|
});
|
2014-01-13 13:50:33 -05:00
|
|
|
}
|
|
|
|
|
} else {
|
2015-12-21 10:14:44 +02:00
|
|
|
socket.emit('modules.chats.loadRoom', {roomId: data.roomId}, function(err, roomData) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return app.alertError(err.message);
|
2014-05-09 17:46:10 -04:00
|
|
|
}
|
2015-12-21 10:14:44 +02:00
|
|
|
roomData.users = roomData.users.filter(function(user) {
|
|
|
|
|
return user && parseInt(user.uid, 10) !== parseInt(app.user.uid, 10);
|
|
|
|
|
});
|
2015-12-23 11:27:34 +02:00
|
|
|
roomData.silent = true;
|
|
|
|
|
module.createModal(roomData, function(modal) {
|
2016-01-16 11:01:06 +02:00
|
|
|
module.toggleNew(modal.attr('UUID'), !isSelf, true);
|
2015-12-21 10:14:44 +02:00
|
|
|
if (!isSelf) {
|
|
|
|
|
app.alternatingTitle('[[modules:chat.user_has_messaged_you, ' + username + ']]');
|
|
|
|
|
sounds.play('chat-incoming');
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-01-13 13:50:33 -05:00
|
|
|
});
|
|
|
|
|
}
|
2014-01-13 10:06:00 -05:00
|
|
|
});
|
2014-04-15 12:48:28 -04:00
|
|
|
|
|
|
|
|
socket.on('event:chats.userStartTyping', function(withUid) {
|
|
|
|
|
var modal = module.getModal(withUid);
|
2015-07-29 12:58:06 -04:00
|
|
|
var chatContent = modal.find('.chat-content');
|
2014-05-09 17:57:39 -04:00
|
|
|
if (!chatContent.length) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-05-02 16:02:22 -04:00
|
|
|
var atBottom = chatContent[0].scrollHeight - chatContent.scrollTop() === chatContent.innerHeight();
|
|
|
|
|
|
2014-07-07 19:47:03 -04:00
|
|
|
modal.find('.user-typing').removeClass('hide');
|
2014-05-02 16:02:22 -04:00
|
|
|
if (atBottom) {
|
2014-07-07 13:09:09 -04:00
|
|
|
Chats.scrollToBottom(chatContent);
|
2014-05-02 16:02:22 -04:00
|
|
|
}
|
2014-04-15 12:48:28 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
socket.on('event:chats.userStopTyping', function(withUid) {
|
|
|
|
|
var modal = module.getModal(withUid);
|
|
|
|
|
modal.find('.user-typing').addClass('hide');
|
|
|
|
|
});
|
2014-09-02 05:04:39 -04:00
|
|
|
|
2014-09-06 22:08:55 -04:00
|
|
|
socket.on('event:user_status_change', function(data) {
|
2014-11-04 16:49:02 -05:00
|
|
|
var modal = module.getModal(data.uid);
|
2015-04-07 13:45:46 -04:00
|
|
|
app.updateUserStatus(modal.find('[component="user/status"]'), data.status);
|
2014-09-02 05:04:39 -04:00
|
|
|
});
|
2015-12-23 11:27:34 +02:00
|
|
|
|
|
|
|
|
socket.on('event:chats.roomRename', function(data) {
|
|
|
|
|
module.getModal(data.roomId).find('[component="chat/room/name"]').val(data.newName);
|
|
|
|
|
});
|
2016-02-01 21:22:36 +02:00
|
|
|
|
|
|
|
|
Chats.onChatEdit();
|
2014-03-12 01:40:31 -04:00
|
|
|
};
|
2014-01-13 10:06:00 -05:00
|
|
|
|
2015-09-18 14:30:18 -04:00
|
|
|
module.loadChatsDropdown = function(chatsListEl) {
|
2015-12-15 17:50:30 +02:00
|
|
|
socket.emit('modules.chats.getRecentChats', {after: 0}, function(err, data) {
|
2015-08-26 16:32:32 -04:00
|
|
|
if (err) {
|
|
|
|
|
return app.alertError(err.message);
|
|
|
|
|
}
|
2015-12-15 17:50:30 +02:00
|
|
|
|
|
|
|
|
var rooms = data.rooms;
|
2015-08-26 16:32:32 -04:00
|
|
|
|
|
|
|
|
chatsListEl.empty();
|
|
|
|
|
|
2015-12-15 17:50:30 +02:00
|
|
|
if (!rooms.length) {
|
2015-08-26 16:32:32 -04:00
|
|
|
translator.translate('[[modules:chat.no_active]]', function(str) {
|
|
|
|
|
$('<li />')
|
|
|
|
|
.addClass('no_active')
|
|
|
|
|
.html('<a href="#">' + str + '</a>')
|
|
|
|
|
.appendTo(chatsListEl);
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-15 17:50:30 +02:00
|
|
|
rooms.forEach(function(roomObj) {
|
|
|
|
|
function createUserImage(userObj) {
|
|
|
|
|
return '<a data-ajaxify="false">' +
|
2015-09-27 17:50:16 -04:00
|
|
|
(userObj.picture ?
|
|
|
|
|
'<img src="' + userObj.picture + '" title="' + userObj.username +'" />' :
|
|
|
|
|
'<div class="user-icon" style="background-color: ' + userObj['icon:bgColor'] + '">' + userObj['icon:text'] + '</div>') +
|
2015-08-26 16:32:32 -04:00
|
|
|
'<i class="fa fa-circle status ' + userObj.status + '"></i> ' +
|
2015-12-17 11:47:32 +02:00
|
|
|
roomObj.usernames + '</a>';
|
2015-12-15 17:50:30 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-29 15:33:16 +02:00
|
|
|
var dropdownEl = $('<li class="' + (roomObj.unread ? 'unread' : '') + '"/>')
|
2015-12-15 17:50:30 +02:00
|
|
|
.attr('data-roomId', roomObj.roomId)
|
2015-08-26 16:32:32 -04:00
|
|
|
.appendTo(chatsListEl);
|
|
|
|
|
|
2015-12-17 11:47:32 +02:00
|
|
|
if (roomObj.lastUser) {
|
|
|
|
|
dropdownEl.append(createUserImage(roomObj.lastUser));
|
2015-12-29 15:33:16 +02:00
|
|
|
} else {
|
|
|
|
|
translator.translate('[[modules:chat.no-users-in-room]]', function(str) {
|
|
|
|
|
dropdownEl.append(str);
|
|
|
|
|
});
|
2015-12-17 11:47:32 +02:00
|
|
|
}
|
2015-09-14 13:19:21 -04:00
|
|
|
|
|
|
|
|
dropdownEl.click(function() {
|
|
|
|
|
if (!ajaxify.currentPage.match(/^chats\//)) {
|
2015-12-16 10:09:00 +02:00
|
|
|
app.openChat(roomObj.roomId);
|
2015-09-14 13:19:21 -04:00
|
|
|
} else {
|
2015-12-16 10:09:00 +02:00
|
|
|
ajaxify.go('chats/' + roomObj.roomId);
|
2015-09-14 13:19:21 -04:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-08-26 16:32:32 -04:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2013-06-18 11:26:57 -04:00
|
|
|
module.bringModalToTop = function(chatModal) {
|
|
|
|
|
var topZ = 0;
|
2014-11-07 18:38:03 -05:00
|
|
|
|
|
|
|
|
taskbar.updateActive(chatModal.attr('UUID'));
|
|
|
|
|
|
2014-10-02 20:21:43 -04:00
|
|
|
if ($('.chat-modal').length === 1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-01-06 17:37:42 -05:00
|
|
|
$('.chat-modal').each(function() {
|
|
|
|
|
var thisZ = parseInt($(this).css('zIndex'), 10);
|
|
|
|
|
if (thisZ > topZ) {
|
|
|
|
|
topZ = thisZ;
|
|
|
|
|
}
|
2013-06-18 11:26:57 -04:00
|
|
|
});
|
2014-10-02 20:21:43 -04:00
|
|
|
|
2013-08-26 13:18:20 -04:00
|
|
|
chatModal.css('zIndex', topZ + 1);
|
2014-02-26 21:55:29 -05:00
|
|
|
};
|
2013-06-18 11:26:57 -04:00
|
|
|
|
2015-12-16 10:09:00 +02:00
|
|
|
module.getModal = function(roomId) {
|
|
|
|
|
return $('#chat-modal-' + roomId);
|
2014-02-26 21:55:29 -05:00
|
|
|
};
|
2013-08-27 15:55:44 -04:00
|
|
|
|
2015-12-16 10:09:00 +02:00
|
|
|
module.modalExists = function(roomId) {
|
|
|
|
|
return $('#chat-modal-' + roomId).length !== 0;
|
2014-02-26 21:55:29 -05:00
|
|
|
};
|
2013-10-11 13:06:21 -04:00
|
|
|
|
2014-01-31 15:13:52 -05:00
|
|
|
function checkStatus(chatModal) {
|
2014-09-06 22:08:55 -04:00
|
|
|
socket.emit('user.checkStatus', chatModal.attr('touid'), function(err, status) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return app.alertError(err.message);
|
|
|
|
|
}
|
2013-10-11 13:06:21 -04:00
|
|
|
|
2015-04-07 13:45:46 -04:00
|
|
|
app.updateUserStatus(chatModal.find('[component="user/status"]'), status);
|
2014-09-02 05:04:39 -04:00
|
|
|
});
|
2013-08-28 22:08:46 -04:00
|
|
|
}
|
2013-10-11 13:06:21 -04:00
|
|
|
|
2015-07-24 14:25:23 -04:00
|
|
|
module.createModal = function(data, callback) {
|
2015-12-23 11:27:34 +02:00
|
|
|
templates.parse('chat', data, function(chatTpl) {
|
2014-03-29 17:13:33 -04:00
|
|
|
translator.translate(chatTpl, function (chatTpl) {
|
2014-01-05 22:09:13 -05:00
|
|
|
|
|
|
|
|
var chatModal = $(chatTpl),
|
2014-11-07 18:38:03 -05:00
|
|
|
uuid = utils.generateUUID(),
|
|
|
|
|
dragged = false;
|
2014-01-05 22:09:13 -05:00
|
|
|
|
2015-12-16 10:09:00 +02:00
|
|
|
chatModal.attr('id', 'chat-modal-' + data.roomId);
|
|
|
|
|
chatModal.attr('roomId', data.roomId);
|
2014-07-19 10:33:27 -04:00
|
|
|
chatModal.attr('intervalId', 0);
|
2014-01-05 22:09:13 -05:00
|
|
|
chatModal.attr('UUID', uuid);
|
2014-10-02 20:21:43 -04:00
|
|
|
chatModal.css('position', 'fixed');
|
|
|
|
|
chatModal.css('zIndex', 100);
|
2014-01-05 22:09:13 -05:00
|
|
|
chatModal.appendTo($('body'));
|
2014-11-04 16:49:02 -05:00
|
|
|
module.center(chatModal);
|
2014-01-05 22:09:13 -05:00
|
|
|
|
2015-06-08 16:58:53 -04:00
|
|
|
app.loadJQueryUI(function() {
|
|
|
|
|
chatModal.find('.modal-content').resizable({
|
|
|
|
|
minHeight: 250,
|
|
|
|
|
minWidth: 400
|
|
|
|
|
});
|
2014-05-02 18:07:12 -04:00
|
|
|
|
2015-06-08 16:58:53 -04:00
|
|
|
chatModal.find('.modal-content').on('resize', function(event, ui) {
|
|
|
|
|
if (ui.originalSize.height === ui.size.height) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-05-02 18:07:12 -04:00
|
|
|
|
2015-07-29 12:58:06 -04:00
|
|
|
chatModal.find('.chat-content').css('height', module.calculateChatListHeight(chatModal));
|
2015-06-08 16:58:53 -04:00
|
|
|
});
|
2015-09-10 17:13:36 -04:00
|
|
|
|
2015-06-08 16:58:53 -04:00
|
|
|
chatModal.draggable({
|
|
|
|
|
start:function() {
|
|
|
|
|
module.bringModalToTop(chatModal);
|
|
|
|
|
},
|
|
|
|
|
stop:function() {
|
|
|
|
|
chatModal.find('#chat-message-input').focus();
|
|
|
|
|
},
|
|
|
|
|
distance: 10,
|
|
|
|
|
handle: '.modal-header'
|
|
|
|
|
});
|
2014-05-02 18:07:12 -04:00
|
|
|
});
|
|
|
|
|
|
2014-04-15 12:48:28 -04:00
|
|
|
chatModal.find('#chat-close-btn').on('click', function() {
|
|
|
|
|
module.close(chatModal);
|
2014-01-05 22:09:13 -05:00
|
|
|
});
|
|
|
|
|
|
2014-09-25 10:30:17 -04:00
|
|
|
function gotoChats() {
|
2015-04-17 13:44:47 -04:00
|
|
|
var text = components.get('chat/input').val();
|
|
|
|
|
$(window).one('action:ajaxify.end', function() {
|
|
|
|
|
components.get('chat/input').val(text);
|
|
|
|
|
});
|
2015-09-10 17:13:36 -04:00
|
|
|
|
2015-12-16 13:35:24 +02:00
|
|
|
ajaxify.go('chats/' + chatModal.attr('roomId'));
|
2014-07-09 11:03:32 -04:00
|
|
|
module.close(chatModal);
|
2014-09-25 10:30:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
chatModal.find('.modal-header').on('dblclick', gotoChats);
|
|
|
|
|
chatModal.find('button[data-action="maximize"]').on('click', gotoChats);
|
2014-07-09 11:03:32 -04:00
|
|
|
|
2015-12-15 17:50:30 +02:00
|
|
|
chatModal.on('click', function() {
|
2014-01-05 22:09:13 -05:00
|
|
|
module.bringModalToTop(chatModal);
|
2014-11-07 18:38:03 -05:00
|
|
|
|
2015-12-17 11:56:28 +02:00
|
|
|
if (dragged) {
|
2014-11-07 18:38:03 -05:00
|
|
|
dragged = false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
chatModal.on('mousemove', function(e) {
|
|
|
|
|
if (e.which === 1) {
|
|
|
|
|
dragged = true;
|
|
|
|
|
}
|
2014-01-05 22:09:13 -05:00
|
|
|
});
|
|
|
|
|
|
2014-07-19 10:33:27 -04:00
|
|
|
chatModal.on('mousemove keypress click', function() {
|
|
|
|
|
if (newMessage) {
|
2015-12-16 10:09:00 +02:00
|
|
|
socket.emit('modules.chats.markRead', data.roomId);
|
2014-07-19 10:33:27 -04:00
|
|
|
newMessage = false;
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-07-09 11:03:32 -04:00
|
|
|
|
2015-12-11 12:07:02 -05:00
|
|
|
chatModal.find('[component="chat/messages"]')
|
|
|
|
|
.on('click', '[data-action="edit"]', function() {
|
|
|
|
|
var messageId = $(this).parents('[data-mid]').attr('data-mid');
|
|
|
|
|
var inputEl = chatModal.find('[component="chat/input"]');
|
2015-12-17 11:22:15 +02:00
|
|
|
Chats.prepEdit(inputEl, messageId, data.roomId);
|
2015-12-11 12:07:02 -05:00
|
|
|
})
|
|
|
|
|
.on('click', '[data-action="delete"]', function() {
|
|
|
|
|
var messageId = $(this).parents('[data-mid]').attr('data-mid');
|
2015-12-17 12:05:35 +02:00
|
|
|
Chats.delete(messageId, data.roomId);
|
2015-12-11 12:07:02 -05:00
|
|
|
});
|
|
|
|
|
|
2015-12-16 10:09:00 +02:00
|
|
|
Chats.addSinceHandler(chatModal.attr('roomId'), chatModal.find('.chat-content'), chatModal.find('[data-since]'));
|
2015-12-23 11:27:34 +02:00
|
|
|
Chats.addRenameHandler(chatModal.attr('roomId'), chatModal.find('[component="chat/room/name"]'));
|
2014-09-17 16:29:03 -04:00
|
|
|
|
2015-12-16 10:09:00 +02:00
|
|
|
Chats.addSendHandlers(chatModal.attr('roomId'), chatModal.find('#chat-message-input'), chatModal.find('#chat-message-send-btn'));
|
2014-01-05 22:09:13 -05:00
|
|
|
|
2015-12-21 10:14:44 +02:00
|
|
|
Chats.createTagsInput(chatModal.find('.users-tag-input'), data);
|
2016-01-12 16:37:34 +02:00
|
|
|
Chats.createAutoComplete(chatModal.find('[component="chat/input"]'));
|
2015-12-16 13:35:24 +02:00
|
|
|
|
2015-12-16 10:09:00 +02:00
|
|
|
Chats.loadChatSince(chatModal.attr('roomId'), chatModal.find('.chat-content'), 'recent');
|
2015-09-18 14:30:18 -04:00
|
|
|
|
|
|
|
|
checkStatus(chatModal);
|
2014-01-05 22:09:13 -05:00
|
|
|
|
|
|
|
|
taskbar.push('chat', chatModal.attr('UUID'), {
|
2015-12-17 11:56:28 +02:00
|
|
|
title: data.users.length ? data.users[0].username : '',
|
2015-12-16 10:09:00 +02:00
|
|
|
roomId: data.roomId,
|
2014-06-13 13:57:38 -04:00
|
|
|
icon: 'fa-comment',
|
2014-01-05 22:09:13 -05:00
|
|
|
state: ''
|
|
|
|
|
});
|
|
|
|
|
|
2014-07-01 15:05:07 -04:00
|
|
|
$(window).trigger('action:chat.loaded', chatModal);
|
|
|
|
|
|
2015-07-24 14:25:23 -04:00
|
|
|
if (typeof callback === 'function') {
|
|
|
|
|
callback(chatModal);
|
|
|
|
|
}
|
2014-01-05 22:09:13 -05:00
|
|
|
});
|
2013-08-28 22:08:46 -04:00
|
|
|
});
|
2014-02-26 21:55:29 -05:00
|
|
|
};
|
2013-06-18 11:26:57 -04:00
|
|
|
|
2014-12-21 00:08:01 -05:00
|
|
|
module.focusInput = function(chatModal) {
|
|
|
|
|
chatModal.find('#chat-message-input').focus();
|
|
|
|
|
};
|
|
|
|
|
|
2015-07-24 14:25:23 -04:00
|
|
|
module.close = function(chatModal, silent) {
|
2014-07-19 10:33:27 -04:00
|
|
|
clearInterval(chatModal.attr('intervalId'));
|
|
|
|
|
chatModal.attr('intervalId', 0);
|
2014-04-15 12:48:28 -04:00
|
|
|
chatModal.remove();
|
|
|
|
|
chatModal.data('modal', null);
|
|
|
|
|
taskbar.discard('chat', chatModal.attr('UUID'));
|
2015-12-16 10:09:00 +02:00
|
|
|
Chats.notifyTyping(chatModal.attr('roomId'), false);
|
2015-02-26 11:03:15 -05:00
|
|
|
|
|
|
|
|
if (chatModal.attr('data-mobile')) {
|
|
|
|
|
module.disableMobileBehaviour(chatModal);
|
|
|
|
|
}
|
2014-04-15 12:48:28 -04:00
|
|
|
};
|
|
|
|
|
|
2013-11-04 12:37:06 -05:00
|
|
|
module.center = function(chatModal) {
|
2014-11-04 16:49:02 -05:00
|
|
|
var hideAfter = false;
|
|
|
|
|
if (chatModal.hasClass('hide')) {
|
|
|
|
|
chatModal.removeClass('hide');
|
|
|
|
|
hideAfter = true;
|
|
|
|
|
}
|
|
|
|
|
chatModal.css('left', Math.max(0, (($(window).width() - $(chatModal).outerWidth()) / 2) + $(window).scrollLeft()) + 'px');
|
|
|
|
|
chatModal.css('top', Math.max(0, $(window).height() / 2 - $(chatModal).outerHeight() / 2) + 'px');
|
2014-12-21 00:08:01 -05:00
|
|
|
|
2014-11-04 16:49:02 -05:00
|
|
|
if (hideAfter) {
|
|
|
|
|
chatModal.addClass('hide');
|
|
|
|
|
}
|
2013-10-11 13:06:21 -04:00
|
|
|
return chatModal;
|
2014-02-26 21:55:29 -05:00
|
|
|
};
|
2013-10-11 13:06:21 -04:00
|
|
|
|
2013-06-18 12:11:48 -04:00
|
|
|
module.load = function(uuid) {
|
2015-12-16 10:09:00 +02:00
|
|
|
var chatModal = $('div[UUID="' + uuid + '"]');
|
2014-01-05 22:09:13 -05:00
|
|
|
chatModal.removeClass('hide');
|
2014-09-02 05:04:39 -04:00
|
|
|
checkStatus(chatModal);
|
2013-12-05 17:35:44 -05:00
|
|
|
taskbar.updateActive(uuid);
|
2015-07-29 12:58:06 -04:00
|
|
|
Chats.scrollToBottom(chatModal.find('.chat-content'));
|
2014-01-30 14:04:20 -05:00
|
|
|
module.bringModalToTop(chatModal);
|
2014-12-21 00:08:01 -05:00
|
|
|
module.focusInput(chatModal);
|
2015-12-16 10:09:00 +02:00
|
|
|
socket.emit('modules.chats.markRead', chatModal.attr('roomId'));
|
2015-02-26 11:03:15 -05:00
|
|
|
|
|
|
|
|
var env = utils.findBootstrapEnvironment();
|
2016-01-16 14:49:32 -08:00
|
|
|
if (env === 'xs') {
|
2015-02-26 11:03:15 -05:00
|
|
|
module.enableMobileBehaviour(chatModal);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.enableMobileBehaviour = function(modalEl) {
|
|
|
|
|
app.toggleNavbar(false);
|
|
|
|
|
modalEl.attr('data-mobile', '1');
|
2015-07-29 12:58:06 -04:00
|
|
|
var messagesEl = modalEl.find('.chat-content');
|
2015-02-26 11:03:15 -05:00
|
|
|
messagesEl.css('height', module.calculateChatListHeight(modalEl));
|
|
|
|
|
|
|
|
|
|
$(window).on('resize', function() {
|
|
|
|
|
messagesEl.css('height', module.calculateChatListHeight(modalEl));
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.disableMobileBehaviour = function(modalEl) {
|
|
|
|
|
app.toggleNavbar(true);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.calculateChatListHeight = function(modalEl) {
|
|
|
|
|
var totalHeight = modalEl.find('.modal-content').outerHeight() - modalEl.find('.modal-header').outerHeight(),
|
|
|
|
|
padding = parseInt(modalEl.find('.modal-body').css('padding-top'), 10) + parseInt(modalEl.find('.modal-body').css('padding-bottom'), 10),
|
2015-07-29 12:58:06 -04:00
|
|
|
contentMargin = parseInt(modalEl.find('.chat-content').css('margin-top'), 10) + parseInt(modalEl.find('.chat-content').css('margin-bottom'), 10),
|
2015-02-26 11:03:15 -05:00
|
|
|
sinceHeight = modalEl.find('.since-bar').outerHeight(true),
|
|
|
|
|
inputGroupHeight = modalEl.find('.input-group').outerHeight();
|
|
|
|
|
|
|
|
|
|
return totalHeight - padding - contentMargin - sinceHeight - inputGroupHeight;
|
2014-02-26 21:55:29 -05:00
|
|
|
};
|
2013-06-18 12:11:48 -04:00
|
|
|
|
|
|
|
|
module.minimize = function(uuid) {
|
2014-04-15 12:48:28 -04:00
|
|
|
var chatModal = $('div[UUID="' + uuid + '"]');
|
2014-01-05 22:09:13 -05:00
|
|
|
chatModal.addClass('hide');
|
2013-06-18 12:11:48 -04:00
|
|
|
taskbar.minimize('chat', uuid);
|
2014-07-19 10:33:27 -04:00
|
|
|
clearInterval(chatModal.attr('intervalId'));
|
|
|
|
|
chatModal.attr('intervalId', 0);
|
2015-12-16 10:09:00 +02:00
|
|
|
Chats.notifyTyping(chatModal.attr('roomId'), false);
|
2014-02-26 21:55:29 -05:00
|
|
|
};
|
2013-06-18 12:11:48 -04:00
|
|
|
|
2015-07-24 14:25:23 -04:00
|
|
|
module.toggleNew = taskbar.toggleNew;
|
2013-06-18 11:26:57 -04:00
|
|
|
|
2015-07-24 14:25:23 -04:00
|
|
|
|
2013-06-18 11:26:57 -04:00
|
|
|
return module;
|
2014-04-10 20:31:57 +01:00
|
|
|
});
|