fix: #10631, fix user digest setting display acp

isekai-main
Barış Soner Uşaklı 3 years ago
parent c7aefe9cdf
commit 0084b563f3

@ -79,6 +79,7 @@ module.exports = function (User) {
'users:online', 'users:online',
'digest:day:uids', 'digest:day:uids',
'digest:week:uids', 'digest:week:uids',
'digest:biweek:uids',
'digest:month:uids', 'digest:month:uids',
], uid); ], uid);
} }

@ -43,33 +43,15 @@ Digest.execute = async function (payload) {
}; };
Digest.getUsersInterval = async (uids) => { Digest.getUsersInterval = async (uids) => {
// Checks whether user specifies digest setting, or null/false for system default setting // Checks whether user specifies digest setting, or false for system default setting
let single = false; let single = false;
if (!Array.isArray(uids) && !isNaN(parseInt(uids, 10))) { if (!Array.isArray(uids) && !isNaN(parseInt(uids, 10))) {
uids = [uids]; uids = [uids];
single = true; single = true;
} }
const settings = await Promise.all([ const settings = await db.getObjects(uids.map(uid => `user:${uid}:settings`));
db.isSortedSetMembers('digest:day:uids', uids), const interval = uids.map((uid, index) => (settings[index] && settings[index].dailyDigestFreq) || false);
db.isSortedSetMembers('digest:week:uids', uids),
db.isSortedSetMembers('digest:biweek:uids', uids),
db.isSortedSetMembers('digest:month:uids', uids),
]);
const interval = uids.map((uid, index) => {
if (settings[0][index]) {
return 'day';
} else if (settings[1][index]) {
return 'week';
} else if (settings[2][index]) {
return 'biweek';
} else if (settings[3][index]) {
return 'month';
}
return false;
});
return single ? interval[0] : interval; return single ? interval[0] : interval;
}; };
@ -163,15 +145,16 @@ Digest.send = async function (data) {
Digest.getDeliveryTimes = async (start, stop) => { Digest.getDeliveryTimes = async (start, stop) => {
const count = await db.sortedSetCard('users:joindate'); const count = await db.sortedSetCard('users:joindate');
const uids = await user.getUidsFromSet('users:joindate', start, stop); const uids = await user.getUidsFromSet('users:joindate', start, stop);
if (!uids) { if (!uids.length) {
return []; return [];
} }
// Grab the last time a digest was successfully delivered to these uids const [scores, settings] = await Promise.all([
const scores = await db.sortedSetScores('digest:delivery', uids); // Grab the last time a digest was successfully delivered to these uids
db.sortedSetScores('digest:delivery', uids),
// Get users' digest settings // Get users' digest settings
const settings = await Digest.getUsersInterval(uids); Digest.getUsersInterval(uids),
]);
// Populate user data // Populate user data
let userData = await user.getUsersFields(uids, ['username', 'picture']); let userData = await user.getUsersFields(uids, ['username', 'picture']);

Loading…
Cancel
Save