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',
'digest:day:uids',
'digest:week:uids',
'digest:biweek:uids',
'digest:month:uids',
], uid);
}

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

Loading…
Cancel
Save