mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-14 02:27:49 +01:00
refactor: remove chats.initialized, all events handlers are removed before being added
This commit is contained in:
@@ -26,7 +26,6 @@ define('forum/chats', [
|
|||||||
api, uploadHelpers
|
api, uploadHelpers
|
||||||
) {
|
) {
|
||||||
const Chats = {
|
const Chats = {
|
||||||
initialised: false,
|
|
||||||
activeAutocomplete: {},
|
activeAutocomplete: {},
|
||||||
newMessage: false,
|
newMessage: false,
|
||||||
};
|
};
|
||||||
@@ -55,10 +54,9 @@ define('forum/chats', [
|
|||||||
socket.emit('modules.chats.enterPublic', ajaxify.data.publicRooms.map(r => r.roomId));
|
socket.emit('modules.chats.enterPublic', ajaxify.data.publicRooms.map(r => r.roomId));
|
||||||
const env = utils.findBootstrapEnvironment();
|
const env = utils.findBootstrapEnvironment();
|
||||||
chatNavWrapper = $('[component="chat/nav-wrapper"]');
|
chatNavWrapper = $('[component="chat/nav-wrapper"]');
|
||||||
if (!Chats.initialised) {
|
|
||||||
Chats.addSocketListeners();
|
Chats.addSocketListeners();
|
||||||
Chats.addGlobalEventListeners();
|
Chats.addGlobalEventListeners();
|
||||||
}
|
|
||||||
|
|
||||||
recentChats.init();
|
recentChats.init();
|
||||||
|
|
||||||
@@ -69,7 +67,6 @@ define('forum/chats', [
|
|||||||
Chats.addHotkeys();
|
Chats.addHotkeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
Chats.initialised = true;
|
|
||||||
const chatContentEl = $('[component="chat/message/content"]');
|
const chatContentEl = $('[component="chat/message/content"]');
|
||||||
messages.wrapImagesInLinks(chatContentEl);
|
messages.wrapImagesInLinks(chatContentEl);
|
||||||
if (ajaxify.data.scrollToIndex) {
|
if (ajaxify.data.scrollToIndex) {
|
||||||
@@ -676,14 +673,18 @@ define('forum/chats', [
|
|||||||
};
|
};
|
||||||
|
|
||||||
Chats.addGlobalEventListeners = function () {
|
Chats.addGlobalEventListeners = function () {
|
||||||
$(window).on('mousemove keypress click', function () {
|
$(window).off('mousemove keypress click', onUserInteraction)
|
||||||
if (Chats.newMessage && ajaxify.data.roomId) {
|
.on('mousemove keypress click', onUserInteraction);
|
||||||
api.del(`/chats/${ajaxify.data.roomId}/state`, {});
|
|
||||||
Chats.newMessage = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function onUserInteraction() {
|
||||||
|
if (Chats.newMessage && ajaxify.data.roomId) {
|
||||||
|
// mark current room read on user interaction
|
||||||
|
api.del(`/chats/${ajaxify.data.roomId}/state`, {});
|
||||||
|
Chats.newMessage = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Chats.addSocketListeners = function () {
|
Chats.addSocketListeners = function () {
|
||||||
events.init();
|
events.init();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user