This commit is contained in:
Barış Soner Uşaklı
2019-07-22 18:36:29 -04:00
parent 0d047f4eb9
commit 0b498acdcf
3 changed files with 25 additions and 4 deletions

View File

@@ -103,12 +103,25 @@ UserNotifications.getNotifications = async function (nids, uid) {
return result && result.notifications;
};
UserNotifications.getDailyUnread = async function (uid) {
const yesterday = Date.now() - (1000 * 60 * 60 * 24); // Approximate, can be more or less depending on time changes, makes no difference really.
const nids = await db.getSortedSetRevRangeByScore('uid:' + uid + ':notifications:unread', 0, 20, '+inf', yesterday);
UserNotifications.getUnreadInterval = async function (uid, interval) {
const dayInMs = 1000 * 60 * 60 * 24;
const times = {
day: dayInMs,
week: 7 * dayInMs,
month: 30 * dayInMs,
};
if (!times[interval]) {
return [];
}
const min = Date.now() - times[interval];
const nids = await db.getSortedSetRevRangeByScore('uid:' + uid + ':notifications:unread', 0, 20, '+inf', min);
return await UserNotifications.getNotifications(nids, uid);
};
UserNotifications.getDailyUnread = async function (uid) {
return await UserNotifications.getUnreadInterval(uid, 'day');
};
UserNotifications.getUnreadCount = async function (uid) {
if (parseInt(uid, 10) <= 0) {
return 0;