Files
NodeBB/public/src/client/chats.js

468 lines
13 KiB
JavaScript
Raw Normal View History

'use strict';
2016-04-30 20:43:16 +03:00
define('forum/chats', [
'components',
'translator',
'mousetrap',
'forum/chats/recent',
2016-04-30 22:34:36 +03:00
'forum/chats/search',
2017-02-17 19:31:21 -07:00
'forum/chats/messages',
2017-08-30 11:31:15 -06:00
'benchpress',
], function (components, translator, mousetrap, recentChats, search, messages, Benchpress) {
var Chats = {
2017-02-17 19:31:21 -07:00
initialised: false,
};
var newMessage = false;
Chats.init = function () {
2015-09-18 14:30:18 -04:00
var env = utils.findBootstrapEnvironment();
if (!Chats.initialised) {
Chats.addSocketListeners();
Chats.addGlobalEventListeners();
}
2017-08-11 11:55:46 -04:00
recentChats.init();
Chats.addEventListeners();
2016-01-12 16:43:17 +02:00
Chats.createAutoComplete($('[component="chat/input"]'));
Chats.resizeMainWindow();
if (env === 'md' || env === 'lg') {
Chats.addHotkeys();
}
$(document).ready(function () {
$(window).trigger('action:chat.loaded', $('.chats-full'));
});
2015-02-01 20:29:57 -05:00
Chats.initialised = true;
messages.scrollToBottom($('.expanded-chat ul.chat-content'));
2016-02-25 18:11:45 +02:00
2016-04-30 20:43:16 +03:00
search.init();
2015-12-14 13:39:53 -05:00
2015-12-16 10:09:00 +02:00
if (ajaxify.data.hasOwnProperty('roomId')) {
2015-12-14 13:39:53 -05:00
components.get('chat/input').focus();
}
};
Chats.addEventListeners = function () {
2015-12-16 10:09:00 +02:00
Chats.addSendHandlers(ajaxify.data.roomId, $('.chat-input'), $('.expanded-chat button[data-action="send"]'));
2018-01-06 12:03:52 -05:00
Chats.addPopoutHandler();
Chats.addActionHandlers(components.get('chat/messages'), ajaxify.data.roomId);
Chats.addMemberHandler(ajaxify.data.roomId, components.get('chat/controls').find('[data-action="members"]'));
Chats.addRenameHandler(ajaxify.data.roomId, components.get('chat/controls').find('[data-action="rename"]'));
Chats.addLeaveHandler(ajaxify.data.roomId, components.get('chat/controls').find('[data-action="leave"]'));
2018-01-06 12:03:52 -05:00
Chats.addScrollHandler(ajaxify.data.roomId, ajaxify.data.uid, $('.chat-content'));
Chats.addCharactersLeftHandler($('[component="chat/main-wrapper"]'));
};
2018-01-06 12:03:52 -05:00
Chats.addPopoutHandler = function () {
$('[data-action="pop-out"]').on('click', function () {
2015-12-16 10:09:00 +02:00
var text = components.get('chat/input').val();
var roomId = ajaxify.data.roomId;
if (app.previousUrl && app.previousUrl.match(/chats/)) {
ajaxify.go('user/' + ajaxify.data.userslug + '/chats', function () {
2016-10-02 15:17:22 +03:00
app.openChat(roomId, ajaxify.data.uid);
}, true);
} else {
window.history.go(-1);
2016-10-02 15:17:22 +03:00
app.openChat(roomId, ajaxify.data.uid);
}
2015-08-24 11:34:09 -04:00
$(window).one('action:chat.loaded', function () {
2015-08-24 11:34:09 -04:00
components.get('chat/input').val(text);
});
});
2016-09-20 16:58:50 +03:00
};
Chats.addScrollHandler = function (roomId, uid, el) {
2016-09-20 16:58:50 +03:00
var loading = false;
el.off('scroll').on('scroll', function () {
2016-09-20 16:58:50 +03:00
if (loading) {
return;
}
var top = (el[0].scrollHeight - el.height()) * 0.1;
if (el.scrollTop() >= top) {
return;
}
loading = true;
2017-12-15 10:21:33 -05:00
var start = parseInt(el.children('[data-mid]').length, 10);
socket.emit('modules.chats.getMessages', {
roomId: roomId,
uid: uid,
start: start,
}, function (err, data) {
2016-09-20 16:58:50 +03:00
if (err) {
return app.alertError(err.message);
}
2016-10-03 20:35:36 +03:00
if (!data) {
return;
}
messages.parseMessage(data, function (html) {
2016-09-20 16:58:50 +03:00
var currentScrollTop = el.scrollTop();
var previousHeight = el[0].scrollHeight;
html = $(html);
el.prepend(html);
html.find('.timeago').timeago();
html.find('img:not(.not-responsive)').addClass('img-responsive');
el.scrollTop((el[0].scrollHeight - previousHeight) + currentScrollTop);
loading = false;
});
});
});
2015-09-18 14:30:18 -04:00
};
2017-11-03 16:32:33 -04:00
Chats.addCharactersLeftHandler = function (parent) {
var element = parent.find('[component="chat/input"]');
2018-04-03 15:45:32 -04:00
element.on('change keyup paste', function () {
messages.updateRemainingLength(parent);
2017-04-17 18:59:46 -04:00
});
};
Chats.addActionHandlers = function (element, roomId) {
element.on('click', '[data-action]', function () {
2016-04-30 22:34:36 +03:00
var messageId = $(this).parents('[data-mid]').attr('data-mid');
var action = this.getAttribute('data-action');
switch (action) {
case 'edit':
var inputEl = $('[data-roomid="' + roomId + '"] [component="chat/input"]');
messages.prepEdit(inputEl, messageId, roomId);
break;
case 'delete':
messages.delete(messageId, roomId);
break;
case 'restore':
messages.restore(messageId, roomId);
break;
}
2016-04-30 22:34:36 +03:00
});
};
Chats.addHotkeys = function () {
mousetrap.bind('ctrl+up', function () {
var activeContact = $('.chats-list .bg-info');
2017-02-17 20:20:42 -07:00
var prev = activeContact.prev();
if (prev.length) {
Chats.switchChat(prev.attr('data-roomid'));
}
});
mousetrap.bind('ctrl+down', function () {
var activeContact = $('.chats-list .bg-info');
2017-02-17 20:20:42 -07:00
var next = activeContact.next();
if (next.length) {
Chats.switchChat(next.attr('data-roomid'));
}
});
mousetrap.bind('up', function (e) {
Squashed commit of the following: Closes #2668 commit 3d4f494ed3257bceda8f6f82057cab83f0f252b3 Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 12:06:42 2015 -0500 theme minvers for #2668 commit b608ce61854f8195143685bb9753b80d32b26e95 Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 12:01:03 2015 -0500 Allowing chat modal to edit and delete messages re: #2668 commit 0104db90a4070582f3938b6929dae35f985bac35 Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 11:51:23 2015 -0500 Fixed issue where newSet calculations were off ... sometimes. Also, rendering of edited messages now parses a template partial, instead of just replacing the content. commit 5cb6ca600425ca9320c599b32306e93dcc5aa4ce Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 11:07:12 2015 -0500 If edited content matches existing content... ... then edit is aborted. commit 6e7495247b1895589c716db29f919a934087b924 Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 11:05:08 2015 -0500 some linting and fixed issue where new msgs when deleted would crash server commit db4a9e40d6dff44569c2437378121db8fdf75cf8 Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 17:25:56 2015 -0500 Message deletion for #2668, and fixed bug Fixed bug where chat modal would spawn even though user was sitting on the /chats page. commit a5aa2498ab4a8bba02a6daa43a9dbed7b3e37976 Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 14:55:23 2015 -0500 wiring up the edit button, #2668 commit 5f2afdcf6f2b9eae6b5873ca100149e65e3d385d Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 14:20:39 2015 -0500 added indicator to show if and when a message had been edited commit e8301132d525c1b9fd46c98cdb282ac7ea7a0d7f Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 14:06:39 2015 -0500 Allowing editing of chat messages commit bfd991be1cb1769599f7d5d2b1638e313c3c2dcb Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 10:33:49 2015 -0500 Added messageId to messages object return commit 0306ee6657b3288dd4547c66869d7d4ece0b31ad Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 08:20:17 2015 -0500 WIP #2668
2015-12-11 12:07:02 -05:00
if (e.target === components.get('chat/input').get(0)) {
// Retrieve message id from messages list
var message = components.get('chat/messages').find('.chat-message[data-self="1"]').last();
var lastMid = message.attr('data-mid');
var inputEl = components.get('chat/input');
2016-04-30 22:34:36 +03:00
messages.prepEdit(inputEl, lastMid, ajaxify.data.roomId);
Squashed commit of the following: Closes #2668 commit 3d4f494ed3257bceda8f6f82057cab83f0f252b3 Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 12:06:42 2015 -0500 theme minvers for #2668 commit b608ce61854f8195143685bb9753b80d32b26e95 Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 12:01:03 2015 -0500 Allowing chat modal to edit and delete messages re: #2668 commit 0104db90a4070582f3938b6929dae35f985bac35 Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 11:51:23 2015 -0500 Fixed issue where newSet calculations were off ... sometimes. Also, rendering of edited messages now parses a template partial, instead of just replacing the content. commit 5cb6ca600425ca9320c599b32306e93dcc5aa4ce Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 11:07:12 2015 -0500 If edited content matches existing content... ... then edit is aborted. commit 6e7495247b1895589c716db29f919a934087b924 Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 11:05:08 2015 -0500 some linting and fixed issue where new msgs when deleted would crash server commit db4a9e40d6dff44569c2437378121db8fdf75cf8 Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 17:25:56 2015 -0500 Message deletion for #2668, and fixed bug Fixed bug where chat modal would spawn even though user was sitting on the /chats page. commit a5aa2498ab4a8bba02a6daa43a9dbed7b3e37976 Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 14:55:23 2015 -0500 wiring up the edit button, #2668 commit 5f2afdcf6f2b9eae6b5873ca100149e65e3d385d Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 14:20:39 2015 -0500 added indicator to show if and when a message had been edited commit e8301132d525c1b9fd46c98cdb282ac7ea7a0d7f Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 14:06:39 2015 -0500 Allowing editing of chat messages commit bfd991be1cb1769599f7d5d2b1638e313c3c2dcb Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 10:33:49 2015 -0500 Added messageId to messages object return commit 0306ee6657b3288dd4547c66869d7d4ece0b31ad Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 08:20:17 2015 -0500 WIP #2668
2015-12-11 12:07:02 -05:00
}
});
};
2018-01-06 12:03:52 -05:00
Chats.addMemberHandler = function (roomId, buttonEl) {
var modal;
buttonEl.on('click', function () {
Benchpress.parse('partials/modals/manage_room', {}, function (html) {
translator.translate(html, function (html) {
modal = bootbox.dialog({
title: '[[modules:chat.manage-room]]',
message: html,
});
modal.attr('component', 'chat/manage-modal');
Chats.refreshParticipantsList(roomId, modal);
var searchInput = modal.find('input');
var errorEl = modal.find('.text-danger');
require(['autocomplete', 'translator'], function (autocomplete, translator) {
autocomplete.user(searchInput, function (event, selected) {
errorEl.text('');
socket.emit('modules.chats.addUserToRoom', {
roomId: roomId,
username: selected.item.user.name,
}, function (err) {
if (err) {
translator.translate(err.message, function (translated) {
errorEl.text(translated);
});
}
Chats.refreshParticipantsList(roomId, modal);
searchInput.val('');
2018-01-06 12:03:52 -05:00
});
});
});
});
});
});
};
Chats.addLeaveHandler = function (roomId, buttonEl) {
buttonEl.on('click', function () {
bootbox.confirm({
size: 'small',
title: '[[modules:chat.leave]]',
message: '<p>[[modules:chat.leave-prompt]]</p><p class="help-block">[[modules:chat.leave-help]]</p>',
callback: function (ok) {
if (ok) {
socket.emit('modules.chats.leave', roomId, function (err) {
if (err) {
app.alertError(err.message);
}
// Return user to chats page. If modal, close modal.
var modal = buttonEl.parents('.chat-modal');
if (modal.length) {
require(['chat'], function (chatLib) {
chatLib.close(modal);
});
} else {
ajaxify.go('chats');
}
});
}
},
});
});
};
Chats.refreshParticipantsList = function (roomId, modal) {
socket.emit('modules.chats.getUsersInRoom', { roomId: roomId }, function (err, users) {
var listEl = modal.find('.list-group');
if (err) {
return translator.translate('[[error:invalid-data]]', function (translated) {
listEl.find('li').text(translated);
});
}
Benchpress.parse('partials/modals/manage_room_users', {
users: users,
}, function (html) {
listEl.html(html);
});
});
};
2017-12-21 16:51:16 -05:00
Chats.addRenameHandler = function (roomId, buttonEl, roomName) {
var modal;
buttonEl.on('click', function () {
Benchpress.parse('partials/modals/rename_room', {
name: roomName || ajaxify.data.roomName,
}, function (html) {
translator.translate(html, function (html) {
modal = bootbox.dialog({
title: '[[modules:chat.rename-room]]',
message: html,
buttons: {
save: {
label: '[[global:save]]',
className: 'btn-primary',
callback: submit,
},
},
});
});
});
});
2015-12-23 11:27:34 +02:00
2017-12-21 16:51:16 -05:00
function submit() {
socket.emit('modules.chats.renameRoom', {
roomId: roomId,
2017-12-21 16:51:16 -05:00
newName: modal.find('#roomName').val(),
}, function (err) {
2015-12-23 11:27:34 +02:00
if (err) {
return app.alertError(err.message);
}
});
2017-12-21 16:51:16 -05:00
}
2015-12-23 11:27:34 +02:00
};
Chats.addSendHandlers = function (roomId, inputEl, sendEl) {
inputEl.off('keypress').on('keypress', function (e) {
2015-09-18 12:22:16 -04:00
if (e.which === 13 && !e.shiftKey) {
2016-04-30 22:34:36 +03:00
messages.sendMessage(roomId, inputEl);
2015-09-18 12:22:16 -04:00
return false;
}
});
sendEl.off('click').on('click', function () {
2016-04-30 22:34:36 +03:00
messages.sendMessage(roomId, inputEl);
2015-09-18 12:22:16 -04:00
inputEl.focus();
return false;
});
};
Chats.createAutoComplete = function (element) {
2016-01-12 16:37:34 +02:00
var data = {
element: element,
strategies: [],
options: {
zIndex: 20000,
listPosition: function (position) {
2016-01-12 16:37:34 +02:00
this.$el.css(this._applyPlacement(position));
this.$el.css('position', 'absolute');
return this;
2017-02-17 19:31:21 -07:00
},
},
2016-01-12 16:37:34 +02:00
};
$(window).trigger('chat:autocomplete:init', data);
if (data.strategies.length) {
data.element.textcomplete(data.strategies, data.options);
}
};
Chats.leave = function (el) {
2016-01-08 12:34:09 +02:00
var roomId = el.attr('data-roomid');
socket.emit('modules.chats.leave', roomId, function (err) {
2016-01-08 12:34:09 +02:00
if (err) {
return app.alertError(err.message);
}
2017-03-07 19:51:52 +03:00
if (parseInt(roomId, 10) === parseInt(ajaxify.data.roomId, 10)) {
ajaxify.go('user/' + ajaxify.data.userslug + '/chats');
2016-01-08 12:34:09 +02:00
} else {
el.remove();
}
2017-03-07 19:51:52 +03:00
require(['chat'], function (chat) {
var modal = chat.getModal(roomId);
if (modal.length) {
chat.close(modal);
}
});
2016-01-08 12:34:09 +02:00
});
};
Chats.switchChat = function (roomid) {
var url = 'user/' + ajaxify.data.userslug + '/chats/' + roomid;
if (self.fetch) {
fetch(config.relative_path + '/api/' + url, { credentials: 'include' })
.then(function (response) {
if (response.ok) {
2017-08-11 11:55:46 -04:00
response.json().then(function (payload) {
app.parseAndTranslate('partials/chats/message-window', payload, function (html) {
components.get('chat/main-wrapper').html(html);
2017-12-21 11:19:16 -05:00
html.find('.timeago').timeago();
Chats.resizeMainWindow();
ajaxify.data = payload;
Chats.setActive();
Chats.addEventListeners();
$(window).trigger('action:chat.loaded', $('.chats-full'));
messages.scrollToBottom($('.expanded-chat ul.chat-content'));
if (history.pushState) {
history.pushState({
url: 'user/' + payload.userslug + '/chats/' + payload.roomId,
}, null, window.location.protocol + '//' + window.location.host + config.relative_path + '/user/' + payload.userslug + '/chats/' + payload.roomId);
}
});
});
} else {
2017-08-11 11:55:46 -04:00
console.warn('[search] Received ' + response.status);
}
})
.catch(function (error) {
console.warn('[search] ' + error.message);
});
} else {
ajaxify.go(url);
}
2015-09-25 10:49:44 -04:00
};
Chats.addGlobalEventListeners = function () {
$(window).on('resize', Chats.resizeMainWindow);
$(window).on('mousemove keypress click', function () {
2015-12-16 10:09:00 +02:00
if (newMessage && ajaxify.data.roomId) {
socket.emit('modules.chats.markRead', ajaxify.data.roomId);
newMessage = false;
}
});
};
Chats.addSocketListeners = function () {
socket.on('event:chats.receive', function (data) {
2015-12-16 15:09:14 +02:00
if (parseInt(data.roomId, 10) === parseInt(ajaxify.data.roomId, 10)) {
newMessage = data.self === 0;
data.message.self = data.self;
2015-09-18 14:30:18 -04:00
2016-04-30 22:34:36 +03:00
messages.appendChatMessage($('.expanded-chat .chat-content'), data.message);
} else if (ajaxify.data.template.chats) {
2017-02-18 14:32:35 -07:00
var roomEl = $('[data-roomid=' + data.roomId + ']');
if (roomEl.length > 0) {
roomEl.addClass('unread');
} else {
var recentEl = components.get('chat/recent');
2017-08-30 11:31:15 -06:00
Benchpress.parse('partials/chats/recent_room', {
rooms: {
roomId: data.roomId,
lastUser: data.message.fromUser,
usernames: data.message.fromUser.username,
unread: true,
},
2017-02-18 14:32:35 -07:00
}, function (html) {
translator.translate(html, function (translated) {
recentEl.prepend(translated);
2016-04-15 17:44:16 +00:00
});
2017-02-18 14:32:35 -07:00
});
2016-04-15 17:44:16 +00:00
}
}
});
socket.on('event:user_status_change', function (data) {
app.updateUserStatus($('.chats-list [data-uid="' + data.uid + '"] [component="user/status"]'), data.status);
});
Squashed commit of the following: Closes #2668 commit 3d4f494ed3257bceda8f6f82057cab83f0f252b3 Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 12:06:42 2015 -0500 theme minvers for #2668 commit b608ce61854f8195143685bb9753b80d32b26e95 Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 12:01:03 2015 -0500 Allowing chat modal to edit and delete messages re: #2668 commit 0104db90a4070582f3938b6929dae35f985bac35 Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 11:51:23 2015 -0500 Fixed issue where newSet calculations were off ... sometimes. Also, rendering of edited messages now parses a template partial, instead of just replacing the content. commit 5cb6ca600425ca9320c599b32306e93dcc5aa4ce Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 11:07:12 2015 -0500 If edited content matches existing content... ... then edit is aborted. commit 6e7495247b1895589c716db29f919a934087b924 Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 11:05:08 2015 -0500 some linting and fixed issue where new msgs when deleted would crash server commit db4a9e40d6dff44569c2437378121db8fdf75cf8 Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 17:25:56 2015 -0500 Message deletion for #2668, and fixed bug Fixed bug where chat modal would spawn even though user was sitting on the /chats page. commit a5aa2498ab4a8bba02a6daa43a9dbed7b3e37976 Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 14:55:23 2015 -0500 wiring up the edit button, #2668 commit 5f2afdcf6f2b9eae6b5873ca100149e65e3d385d Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 14:20:39 2015 -0500 added indicator to show if and when a message had been edited commit e8301132d525c1b9fd46c98cdb282ac7ea7a0d7f Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 14:06:39 2015 -0500 Allowing editing of chat messages commit bfd991be1cb1769599f7d5d2b1638e313c3c2dcb Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 10:33:49 2015 -0500 Added messageId to messages object return commit 0306ee6657b3288dd4547c66869d7d4ece0b31ad Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 08:20:17 2015 -0500 WIP #2668
2015-12-11 12:07:02 -05:00
2016-04-30 22:34:36 +03:00
messages.onChatMessageEdit();
2016-02-01 21:22:36 +02:00
socket.on('event:chats.roomRename', function (data) {
var roomEl = components.get('chat/recent/room', data.roomId);
var titleEl = roomEl.find('[component="chat/title"]');
ajaxify.data.roomName = data.newName;
titleEl.text(data.newName);
2016-02-01 21:22:36 +02:00
});
};
Squashed commit of the following: Closes #2668 commit 3d4f494ed3257bceda8f6f82057cab83f0f252b3 Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 12:06:42 2015 -0500 theme minvers for #2668 commit b608ce61854f8195143685bb9753b80d32b26e95 Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 12:01:03 2015 -0500 Allowing chat modal to edit and delete messages re: #2668 commit 0104db90a4070582f3938b6929dae35f985bac35 Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 11:51:23 2015 -0500 Fixed issue where newSet calculations were off ... sometimes. Also, rendering of edited messages now parses a template partial, instead of just replacing the content. commit 5cb6ca600425ca9320c599b32306e93dcc5aa4ce Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 11:07:12 2015 -0500 If edited content matches existing content... ... then edit is aborted. commit 6e7495247b1895589c716db29f919a934087b924 Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 11:05:08 2015 -0500 some linting and fixed issue where new msgs when deleted would crash server commit db4a9e40d6dff44569c2437378121db8fdf75cf8 Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 17:25:56 2015 -0500 Message deletion for #2668, and fixed bug Fixed bug where chat modal would spawn even though user was sitting on the /chats page. commit a5aa2498ab4a8bba02a6daa43a9dbed7b3e37976 Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 14:55:23 2015 -0500 wiring up the edit button, #2668 commit 5f2afdcf6f2b9eae6b5873ca100149e65e3d385d Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 14:20:39 2015 -0500 added indicator to show if and when a message had been edited commit e8301132d525c1b9fd46c98cdb282ac7ea7a0d7f Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 14:06:39 2015 -0500 Allowing editing of chat messages commit bfd991be1cb1769599f7d5d2b1638e313c3c2dcb Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 10:33:49 2015 -0500 Added messageId to messages object return commit 0306ee6657b3288dd4547c66869d7d4ece0b31ad Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 08:20:17 2015 -0500 WIP #2668
2015-12-11 12:07:02 -05:00
Chats.resizeMainWindow = function () {
var viewportHeight = $(window).height();
var fromTop = components.get('chat/main-wrapper').offset().top || components.get('chat/nav-wrapper').offset().top;
2018-01-18 11:41:28 -05:00
$('.chats-full').height(viewportHeight - fromTop - 1);
Chats.setActive();
};
Chats.setActive = function () {
2015-12-16 10:09:00 +02:00
if (ajaxify.data.roomId) {
socket.emit('modules.chats.markRead', ajaxify.data.roomId);
$('[data-roomid="' + ajaxify.data.roomId + '"]').toggleClass('unread', false);
2018-03-23 10:04:30 -04:00
$('.expanded-chat [component="chat/input"]').focus();
}
$('.chats-list li').removeClass('bg-info');
$('.chats-list li[data-roomid="' + ajaxify.data.roomId + '"]').addClass('bg-info');
components.get('chat/nav-wrapper').attr('data-loaded', ajaxify.data.roomId ? '1' : '0');
};
return Chats;
});