|
|
@ -8,6 +8,7 @@ const batch = require('../batch');
|
|
|
|
const meta = require('../meta');
|
|
|
|
const meta = require('../meta');
|
|
|
|
const user = require('./index');
|
|
|
|
const user = require('./index');
|
|
|
|
const topics = require('../topics');
|
|
|
|
const topics = require('../topics');
|
|
|
|
|
|
|
|
const messaging = require('../messaging');
|
|
|
|
const plugins = require('../plugins');
|
|
|
|
const plugins = require('../plugins');
|
|
|
|
const emailer = require('../emailer');
|
|
|
|
const emailer = require('../emailer');
|
|
|
|
const utils = require('../utils');
|
|
|
|
const utils = require('../utils');
|
|
|
@ -94,13 +95,16 @@ Digest.send = async function (data) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await Promise.all(userData.map(async (userObj) => {
|
|
|
|
await Promise.all(userData.map(async (userObj) => {
|
|
|
|
const [notifications, topics] = await Promise.all([
|
|
|
|
const [publicRooms, notifications, topics] = await Promise.all([
|
|
|
|
|
|
|
|
getUnreadPublicRooms(userObj.uid),
|
|
|
|
user.notifications.getUnreadInterval(userObj.uid, data.interval),
|
|
|
|
user.notifications.getUnreadInterval(userObj.uid, data.interval),
|
|
|
|
getTermTopics(data.interval, userObj.uid),
|
|
|
|
getTermTopics(data.interval, userObj.uid),
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
const unreadNotifs = notifications.filter(Boolean);
|
|
|
|
const unreadNotifs = notifications.filter(Boolean);
|
|
|
|
// If there are no notifications and no new topics, don't bother sending a digest
|
|
|
|
// If there are no notifications and no new topics and no unread chats, don't bother sending a digest
|
|
|
|
if (!unreadNotifs.length && !topics.top.length && !topics.popular.length && !topics.recent.length) {
|
|
|
|
if (!unreadNotifs.length &&
|
|
|
|
|
|
|
|
!topics.top.length && !topics.popular.length && !topics.recent.length &&
|
|
|
|
|
|
|
|
!publicRooms.length) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -120,6 +124,7 @@ Digest.send = async function (data) {
|
|
|
|
username: userObj.username,
|
|
|
|
username: userObj.username,
|
|
|
|
userslug: userObj.userslug,
|
|
|
|
userslug: userObj.userslug,
|
|
|
|
notifications: unreadNotifs,
|
|
|
|
notifications: unreadNotifs,
|
|
|
|
|
|
|
|
publicRooms: publicRooms,
|
|
|
|
recent: topics.recent,
|
|
|
|
recent: topics.recent,
|
|
|
|
topTopics: topics.top,
|
|
|
|
topTopics: topics.top,
|
|
|
|
popularTopics: topics.popular,
|
|
|
|
popularTopics: topics.popular,
|
|
|
@ -212,3 +217,8 @@ async function getTermTopics(term, uid) {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return { top, popular, recent };
|
|
|
|
return { top, popular, recent };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function getUnreadPublicRooms(uid) {
|
|
|
|
|
|
|
|
const publicRooms = await messaging.getPublicRooms(uid, uid);
|
|
|
|
|
|
|
|
return publicRooms.filter(r => r && r.unread);
|
|
|
|
|
|
|
|
}
|
|
|
|