From 8da3b2a487b332d3c7711b12a9c8746df3671290 Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Wed, 2 Jan 2019 13:16:56 -0500 Subject: [PATCH] fix: #7142 due to no refresh on login socket listeners were added more than once, so remove them before adding the listeners --- public/src/client/header/chat.js | 27 +++++++++++++++-------- public/src/client/header/notifications.js | 18 ++++++++++----- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/public/src/client/header/chat.js b/public/src/client/header/chat.js index ccd7aa0098..fbea548f03 100644 --- a/public/src/client/header/chat.js +++ b/public/src/client/header/chat.js @@ -18,19 +18,28 @@ define('forum/header/chat', ['components'], function (components) { requireAndCall('loadChatsDropdown', chatsListEl); } - socket.on('event:chats.receive', function (data) { - requireAndCall('onChatMessageReceived', data); - }); + socket.removeListener('event:chats.receive', onChatMessageReceived); + socket.on('event:chats.receive', onChatMessageReceived); - socket.on('event:user_status_change', function (data) { - requireAndCall('onUserStatusChange', data); - }); + socket.removeListener('event:user_status_change', onUserStatusChange); + socket.on('event:user_status_change', onUserStatusChange); - socket.on('event:chats.roomRename', function (data) { - requireAndCall('onRoomRename', data); - }); + socket.removeListener('event:chats.roomRename', onRoomRename); + socket.on('event:chats.roomRename', onRoomRename); }; + function onChatMessageReceived(data) { + requireAndCall('onChatMessageReceived', data); + } + + function onUserStatusChange(data) { + requireAndCall('onUserStatusChange', data); + } + + function onRoomRename(data) { + requireAndCall('onRoomRename', data); + } + function requireAndCall(method, param) { require(['chat'], function (chat) { chat[method](param); diff --git a/public/src/client/header/notifications.js b/public/src/client/header/notifications.js index ff532f52c7..b30535f0fd 100644 --- a/public/src/client/header/notifications.js +++ b/public/src/client/header/notifications.js @@ -21,15 +21,21 @@ define('forum/header/notifications', ['components'], function (components) { requireAndCall('loadNotifications', notifList); } - socket.on('event:new_notification', function (data) { - requireAndCall('onNewNotification', data); - }); + socket.removeListener('event:new_notification', onNewNotification); + socket.on('event:new_notification', onNewNotification); - socket.on('event:notifications.updateCount', function (data) { - requireAndCall('updateNotifCount', data); - }); + socket.removeListener('event:notifications.updateCount', onUpdateCount); + socket.on('event:notifications.updateCount', onUpdateCount); }; + function onNewNotification(data) { + requireAndCall('onNewNotification', data); + } + + function onUpdateCount(data) { + requireAndCall('updateNotifCount', data); + } + function requireAndCall(method, param) { require(['notifications'], function (notifications) { notifications[method](param);