From 1e6c6f4e4408f4fd438661b65475cf00cd49f98a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Sun, 9 Mar 2025 12:03:09 -0400 Subject: [PATCH] fix: #13094, update unread chats on reconnect unread topics and notifications were updated on reconnections, added chats as well convert function to async added awaits --- src/messaging/unread.js | 3 --- src/socket.io/meta.js | 17 ++++++++++------- test/socket.io.js | 7 ++----- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/messaging/unread.js b/src/messaging/unread.js index 1a63d81139..8ca893a638 100644 --- a/src/messaging/unread.js +++ b/src/messaging/unread.js @@ -18,9 +18,6 @@ module.exports = function (Messaging) { uids = [uids]; } uids = uids.filter(uid => parseInt(uid, 10) > 0); - if (!uids.length) { - return; - } uids.forEach((uid) => { io.in(`uid_${uid}`).emit('event:unread.updateChatCount', data); }); diff --git a/src/socket.io/meta.js b/src/socket.io/meta.js index 0e59e93849..f2181344e8 100644 --- a/src/socket.io/meta.js +++ b/src/socket.io/meta.js @@ -6,20 +6,23 @@ const user = require('../user'); const meta = require('../meta'); const topics = require('../topics'); const privileges = require('../privileges'); +const messaging = require('../messaging'); const SocketMeta = module.exports; SocketMeta.rooms = {}; -SocketMeta.reconnected = function (socket, data, callback) { - callback = callback || function () {}; - if (socket.uid) { - topics.pushUnreadCount(socket.uid); - user.notifications.pushCount(socket.uid); +SocketMeta.reconnected = async function (socket) { + if (socket.uid > 0) { + await Promise.all([ + topics.pushUnreadCount(socket.uid), + user.notifications.pushCount(socket.uid), + messaging.pushUnreadCount(socket.uid), + ]); } - callback(null, { + return { 'cache-buster': meta.config['cache-buster'], hostname: os.hostname(), - }); + }; }; /* Rooms */ diff --git a/test/socket.io.js b/test/socket.io.js index 8fd2895809..0e725ad3be 100644 --- a/test/socket.io.js +++ b/test/socket.io.js @@ -269,12 +269,9 @@ describe('socket.io', () => { }); }); - it('should push unread notifications on reconnect', (done) => { + it('should push unread notifications/chats on reconnect', async () => { const socketMeta = require('../src/socket.io/meta'); - socketMeta.reconnected({ uid: 1 }, {}, (err) => { - assert.ifError(err); - done(); - }); + await socketMeta.reconnected({ uid: 1 }, {}); });