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

503 lines
14 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',
'composer/autocomplete',
'hooks',
'bootbox',
2021-12-06 14:31:35 -05:00
'alerts',
'chat',
2021-12-15 10:59:58 -05:00
'api',
], function (
components, translator, mousetrap,
recentChats, search, messages,
2021-12-15 10:59:58 -05:00
autocomplete, hooks, bootbox, alerts, chatModule,
api
) {
const Chats = {
2017-02-17 19:31:21 -07:00
initialised: false,
};
let newMessage = false;
Chats.init = function () {
const env = utils.findBootstrapEnvironment();
if (!Chats.initialised) {
Chats.addSocketListeners();
Chats.addGlobalEventListeners();
}
2017-08-11 11:55:46 -04:00
recentChats.init();
Chats.addEventListeners();
Chats.setActive();
if (env === 'md' || env === 'lg') {
Chats.addHotkeys();
}
$(document).ready(function () {
hooks.fire('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.addScrollBottomHandler($('.chat-content'));
2018-01-06 12:03:52 -05:00
Chats.addCharactersLeftHandler($('[component="chat/main-wrapper"]'));
2018-05-31 15:05:12 -04:00
Chats.addIPHandler($('[component="chat/main-wrapper"]'));
Chats.createAutoComplete($('[component="chat/input"]'));
$('[data-action="close"]').on('click', function () {
Chats.switchChat();
});
2018-05-31 15:05:12 -04:00
};
Chats.addIPHandler = function (container) {
container.on('click', '.chat-ip-button', function () {
const ipEl = $(this).parent();
const mid = ipEl.parents('[data-mid]').attr('data-mid');
2018-05-31 15:05:12 -04:00
socket.emit('modules.chats.getIP', mid, function (err, ip) {
if (err) {
2021-12-06 14:31:35 -05:00
return alerts.error(err);
2018-05-31 15:05:12 -04:00
}
ipEl.html(ip);
});
});
2018-01-06 12:03:52 -05:00
};
2018-01-06 12:03:52 -05:00
Chats.addPopoutHandler = function () {
$('[data-action="pop-out"]').on('click', function () {
const text = components.get('chat/input').val();
const roomId = ajaxify.data.roomId;
if (app.previousUrl && app.previousUrl.match(/chats/)) {
ajaxify.go('user/' + ajaxify.data.userslug + '/chats', function () {
chatModule.openChat(roomId, ajaxify.data.uid);
}, true);
} else {
window.history.go(-1);
chatModule.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) {
let loading = false;
el.off('scroll').on('scroll', function () {
messages.toggleScrollUpAlert(el);
2016-09-20 16:58:50 +03:00
if (loading) {
return;
}
const top = (el[0].scrollHeight - el.height()) * 0.1;
2016-09-20 16:58:50 +03:00
if (el.scrollTop() >= top) {
return;
}
loading = true;
const 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) {
2021-12-06 14:31:35 -05:00
return alerts.error(err);
2016-09-20 16:58:50 +03:00
}
2016-10-03 20:35:36 +03:00
if (!data) {
2018-09-26 22:05:01 -04:00
loading = false;
2016-10-03 20:35:36 +03:00
return;
}
data = data.filter(function (chatMsg) {
return !$('[component="chat/message"][data-mid="' + chatMsg.messageId + '"]').length;
});
if (!data.length) {
2018-09-26 22:05:01 -04:00
loading = false;
return;
}
messages.parseMessage(data, function (html) {
const currentScrollTop = el.scrollTop();
const previousHeight = el[0].scrollHeight;
2016-09-20 16:58:50 +03:00
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
};
Chats.addScrollBottomHandler = function (chatContent) {
chatContent.parent()
.find('[component="chat/messages/scroll-up-alert"]')
.off('click').on('click', function () {
messages.scrollToBottom(chatContent);
});
};
2017-11-03 16:32:33 -04:00
Chats.addCharactersLeftHandler = function (parent) {
const 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 () {
const messageId = $(this).parents('[data-mid]').attr('data-mid');
const action = this.getAttribute('data-action');
switch (action) {
case 'edit': {
const inputEl = $('[data-roomid="' + roomId + '"] [component="chat/input"]');
2020-06-03 11:25:25 -04:00
messages.prepEdit(inputEl, messageId, roomId);
break;
}
2020-06-03 11:25:25 -04:00
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 () {
const activeContact = $('.chats-list .bg-info');
const prev = activeContact.prev();
if (prev.length) {
Chats.switchChat(prev.attr('data-roomid'));
}
});
mousetrap.bind('ctrl+down', function () {
const activeContact = $('.chats-list .bg-info');
const 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
const message = components.get('chat/messages').find('.chat-message[data-self="1"]').last();
if (!message.length) {
return;
}
const lastMid = message.attr('data-mid');
const inputEl = components.get('chat/input');
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.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) {
let modal;
2018-01-06 12:03:52 -05:00
buttonEl.on('click', function () {
app.parseAndTranslate('partials/modals/manage_room', {}, function (html) {
modal = bootbox.dialog({
title: '[[modules:chat.manage-room]]',
message: html,
});
2018-01-06 12:03:52 -05:00
modal.attr('component', 'chat/manage-modal');
Chats.refreshParticipantsList(roomId, modal);
Chats.addKickHandler(roomId, modal);
const searchInput = modal.find('input');
const errorEl = modal.find('.text-danger');
require(['autocomplete', 'translator'], function (autocomplete, translator) {
autocomplete.user(searchInput, function (event, selected) {
errorEl.text('');
2021-12-21 11:05:27 -05:00
api.post(`/chats/${roomId}/users`, {
uids: [selected.item.user.uid],
}).then((body) => {
Chats.refreshParticipantsList(roomId, modal, body);
searchInput.val('');
2021-12-21 11:05:27 -05:00
}).catch((err) => {
translator.translate(err.message, function (translated) {
errorEl.text(translated);
});
2018-01-06 12:03:52 -05:00
});
});
});
});
});
};
2018-04-30 12:35:17 -04:00
Chats.addKickHandler = function (roomId, modal) {
modal.on('click', '[data-action="kick"]', function () {
const uid = parseInt(this.getAttribute('data-uid'), 10);
2018-04-30 12:35:17 -04:00
api.delete(`/chats/${roomId}/users/${uid}`, {}).then((body) => {
Chats.refreshParticipantsList(roomId, modal, body);
}).catch(alerts.error);
2018-04-30 12:35:17 -04: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) {
2021-12-22 10:20:24 -05:00
api.delete(`/chats/${roomId}/users/${app.user.uid}`, {}).then(() => {
// Return user to chats page. If modal, close modal.
const modal = buttonEl.parents('.chat-modal');
if (modal.length) {
chatModule.close(modal);
} else {
ajaxify.go('chats');
}
2021-12-22 10:20:24 -05:00
}).catch(alerts.error);
}
},
});
});
};
2021-12-21 11:05:27 -05:00
Chats.refreshParticipantsList = async (roomId, modal, data) => {
const listEl = modal.find('.list-group');
2021-12-21 11:05:27 -05:00
if (!data) {
try {
data = await api.get(`/chats/${roomId}/users`, {});
} catch (err) {
translator.translate('[[error:invalid-data]]', function (translated) {
listEl.find('li').text(translated);
});
}
}
app.parseAndTranslate('partials/modals/manage_room_users', data, function (html) {
listEl.html(html);
});
};
2017-12-21 16:51:16 -05:00
Chats.addRenameHandler = function (roomId, buttonEl, roomName) {
let modal;
2017-12-21 16:51:16 -05:00
buttonEl.on('click', function () {
app.parseAndTranslate('partials/modals/rename_room', {
2017-12-21 16:51:16 -05:00
name: roomName || ajaxify.data.roomName,
}, function (html) {
modal = bootbox.dialog({
title: '[[modules:chat.rename-room]]',
message: html,
buttons: {
save: {
label: '[[global:save]]',
className: 'btn-primary',
callback: submit,
2017-12-21 16:51:16 -05:00
},
},
2017-12-21 16:51:16 -05:00
});
});
});
2015-12-23 11:27:34 +02:00
2017-12-21 16:51:16 -05:00
function submit() {
2021-12-15 10:59:58 -05:00
api.put(`/chats/${roomId}`, {
name: modal.find('#roomName').val(),
}).catch(alerts.error);
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) {
2019-02-13 10:54:12 -05:00
if (!element.length) {
return;
}
const data = {
2016-01-12 16:37:34 +02:00
element: element,
strategies: [],
options: {
style: {
'z-index': 20000,
flex: 0,
top: 'inherit',
2017-02-17 19:31:21 -07:00
},
placement: 'top',
2017-02-17 19:31:21 -07:00
},
2016-01-12 16:37:34 +02:00
};
hooks.fire('chat:autocomplete:init', data);
2016-01-12 16:37:34 +02:00
if (data.strategies.length) {
autocomplete.setup(data);
2016-01-12 16:37:34 +02:00
}
};
Chats.leave = function (el) {
const roomId = el.attr('data-roomid');
2021-12-22 10:20:24 -05:00
api.delete(`/chats/${roomId}/users/${app.user.uid}`, {}).then(() => {
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();
}
const modal = chatModule.getModal(roomId);
if (modal.length) {
chatModule.close(modal);
}
2021-12-22 10:20:24 -05:00
}).catch(alerts.error);
2016-01-08 12:34:09 +02:00
};
Chats.switchChat = function (roomid) {
// Allow empty arg for return to chat list/close chat
if (!roomid) {
roomid = '';
}
const url = 'user/' + ajaxify.data.userslug + '/chats/' + roomid + window.location.search;
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();
ajaxify.data = payload;
Chats.setActive();
Chats.addEventListeners();
hooks.fire('action:chat.loaded', $('.chats-full'));
messages.scrollToBottom($('.expanded-chat ul.chat-content'));
if (history.pushState) {
history.pushState({
2019-10-16 17:42:02 -04:00
url: url,
}, null, window.location.protocol + '//' + window.location.host + config.relative_path + '/' + url);
}
});
});
} 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('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) {
const roomEl = $('[data-roomid=' + data.roomId + ']');
2017-02-18 14:32:35 -07:00
if (roomEl.length > 0) {
roomEl.addClass('unread');
} else {
const recentEl = components.get('chat/recent');
app.parseAndTranslate('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) {
recentEl.prepend(html);
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
messages.addSocketListeners();
2016-02-01 21:22:36 +02:00
socket.on('event:chats.roomRename', function (data) {
const roomEl = components.get('chat/recent/room', data.roomId);
const 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.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;
});