mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
refactor: move async call to parallel
This commit is contained in:
@@ -76,20 +76,22 @@ module.exports = function (Messaging) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
async function sendNotification(fromUid, roomId, isPublic, messageObj) {
|
async function sendNotification(fromUid, roomId, messageObj) {
|
||||||
fromUid = parseInt(fromUid, 10);
|
fromUid = parseInt(fromUid, 10);
|
||||||
|
|
||||||
const [settings, roomData] = await Promise.all([
|
const [settings, roomData, realtimeUids] = await Promise.all([
|
||||||
db.getObject(`chat:room:${roomId}:notification:settings`),
|
db.getObject(`chat:room:${roomId}:notification:settings`),
|
||||||
Messaging.getRoomData(roomId),
|
Messaging.getRoomData(roomId),
|
||||||
|
io.getUidsInRoom(`chat_room_${roomId}`),
|
||||||
]);
|
]);
|
||||||
const roomDefault = roomData.notificationSetting;
|
const roomDefault = roomData.notificationSetting;
|
||||||
let uidsToNotify = [];
|
const uidsToNotify = [];
|
||||||
const { ALLMESSAGES } = Messaging.notificationSettings;
|
const { ALLMESSAGES } = Messaging.notificationSettings;
|
||||||
await batch.processSortedSet(`chat:room:${roomId}:uids:online`, async (uids) => {
|
await batch.processSortedSet(`chat:room:${roomId}:uids:online`, async (uids) => {
|
||||||
uids = uids.filter(
|
uids = uids.filter(
|
||||||
uid => (parseInt((settings && settings[uid]) || roomDefault, 10) === ALLMESSAGES) &&
|
uid => (parseInt((settings && settings[uid]) || roomDefault, 10) === ALLMESSAGES) &&
|
||||||
fromUid !== parseInt(uid, 10)
|
fromUid !== parseInt(uid, 10) &&
|
||||||
|
!realtimeUids.includes(parseInt(uid, 10))
|
||||||
);
|
);
|
||||||
const hasRead = await Messaging.hasRead(uids, roomId);
|
const hasRead = await Messaging.hasRead(uids, roomId);
|
||||||
uidsToNotify.push(...uids.filter((uid, index) => !hasRead[index]));
|
uidsToNotify.push(...uids.filter((uid, index) => !hasRead[index]));
|
||||||
@@ -99,10 +101,6 @@ module.exports = function (Messaging) {
|
|||||||
interval: 100,
|
interval: 100,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Suppress notifications for users who are literally present in the room
|
|
||||||
const realtimeUids = await io.getUidsInRoom(`chat_room_${isPublic ? 'public_' : ''}${roomId}`);
|
|
||||||
uidsToNotify = uidsToNotify.filter(uid => !realtimeUids.includes(parseInt(uid, 10)));
|
|
||||||
|
|
||||||
if (uidsToNotify.length) {
|
if (uidsToNotify.length) {
|
||||||
const { displayname } = messageObj.fromUser;
|
const { displayname } = messageObj.fromUser;
|
||||||
const isGroupChat = await Messaging.isGroupChat(roomId);
|
const isGroupChat = await Messaging.isGroupChat(roomId);
|
||||||
|
|||||||
Reference in New Issue
Block a user