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 }, {}); });