mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-28 09:36:16 +01:00
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
This commit is contained in:
@@ -18,9 +18,6 @@ module.exports = function (Messaging) {
|
|||||||
uids = [uids];
|
uids = [uids];
|
||||||
}
|
}
|
||||||
uids = uids.filter(uid => parseInt(uid, 10) > 0);
|
uids = uids.filter(uid => parseInt(uid, 10) > 0);
|
||||||
if (!uids.length) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
uids.forEach((uid) => {
|
uids.forEach((uid) => {
|
||||||
io.in(`uid_${uid}`).emit('event:unread.updateChatCount', data);
|
io.in(`uid_${uid}`).emit('event:unread.updateChatCount', data);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,20 +6,23 @@ const user = require('../user');
|
|||||||
const meta = require('../meta');
|
const meta = require('../meta');
|
||||||
const topics = require('../topics');
|
const topics = require('../topics');
|
||||||
const privileges = require('../privileges');
|
const privileges = require('../privileges');
|
||||||
|
const messaging = require('../messaging');
|
||||||
|
|
||||||
const SocketMeta = module.exports;
|
const SocketMeta = module.exports;
|
||||||
SocketMeta.rooms = {};
|
SocketMeta.rooms = {};
|
||||||
|
|
||||||
SocketMeta.reconnected = function (socket, data, callback) {
|
SocketMeta.reconnected = async function (socket) {
|
||||||
callback = callback || function () {};
|
if (socket.uid > 0) {
|
||||||
if (socket.uid) {
|
await Promise.all([
|
||||||
topics.pushUnreadCount(socket.uid);
|
topics.pushUnreadCount(socket.uid),
|
||||||
user.notifications.pushCount(socket.uid);
|
user.notifications.pushCount(socket.uid),
|
||||||
|
messaging.pushUnreadCount(socket.uid),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
callback(null, {
|
return {
|
||||||
'cache-buster': meta.config['cache-buster'],
|
'cache-buster': meta.config['cache-buster'],
|
||||||
hostname: os.hostname(),
|
hostname: os.hostname(),
|
||||||
});
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Rooms */
|
/* Rooms */
|
||||||
|
|||||||
@@ -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');
|
const socketMeta = require('../src/socket.io/meta');
|
||||||
socketMeta.reconnected({ uid: 1 }, {}, (err) => {
|
await socketMeta.reconnected({ uid: 1 }, {});
|
||||||
assert.ifError(err);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user