This commit is contained in:
Baris Usakli
2019-01-04 13:27:31 -05:00
parent 0263b4daec
commit 7809ba2800
5 changed files with 124 additions and 38 deletions

View File

@@ -1,11 +1,14 @@
'use strict';
var async = require('async');
const _ = require('lodash');
var db = require('../database');
var user = require('../user');
var meta = require('../meta');
var groups = require('../groups');
var topics = require('../topics');
var categories = require('../categories');
var notifications = require('../notifications');
var privileges = require('../privileges');
var plugins = require('../plugins');
@@ -18,7 +21,7 @@ module.exports = function (Posts) {
user.getUserFields(uid, ['uid', 'reputation', 'postcount'], next);
},
function (userData, next) {
var shouldQueue = meta.config.postQueue && (!userData.uid || userData.reputation < 0 || userData.postcount <= 0);
const shouldQueue = meta.config.postQueue && (!userData.uid || userData.reputation < 0 || userData.postcount <= 0);
plugins.fireHook('filter:post.shouldQueue', {
shouldQueue: shouldQueue,
uid: uid,
@@ -31,6 +34,44 @@ module.exports = function (Posts) {
], callback);
};
function removeQueueNotification(id, callback) {
async.waterfall([
function (next) {
notifications.rescind('post-queue-' + id, next);
},
function (next) {
getParsedObject(id, next);
},
function (data, next) {
if (!data) {
return callback();
}
getCid(data.type, data, next);
},
function (cid, next) {
getNotificationUids(cid, next);
},
function (uids, next) {
uids.forEach(uid => user.notifications.pushCount(uid));
next();
},
], callback);
}
function getNotificationUids(cid, callback) {
async.waterfall([
function (next) {
async.parallel([
async.apply(groups.getMembersOfGroups, ['administrators', 'Global Moderators']),
async.apply(categories.getModeratorUids, [cid]),
], next);
},
function (results, next) {
next(null, _.union(results));
},
], callback);
}
Posts.addToQueue = function (data, callback) {
var type = data.title ? 'topic' : 'reply';
var id = type + '-' + Date.now();
@@ -64,14 +105,21 @@ module.exports = function (Posts) {
path: '/post-queue',
}, next);
},
cid: function (next) {
getCid(type, data, next);
uids: function (next) {
async.waterfall([
function (next) {
getCid(type, data, next);
},
function (cid, next) {
getNotificationUids(cid, next);
},
], next);
},
}, next);
},
function (results, next) {
if (results.notification) {
notifications.pushGroups(results.notification, ['administrators', 'Global Moderators', 'cid:' + results.cid + ':privileges:moderate'], next);
notifications.push(results.uids, next);
} else {
next();
}
@@ -127,15 +175,15 @@ module.exports = function (Posts) {
Posts.removeFromQueue = function (id, callback) {
async.waterfall([
function (next) {
removeQueueNotification(id, next);
},
function (next) {
db.sortedSetRemove('post:queue', id, next);
},
function (next) {
db.delete('post:queue:' + id, next);
},
function (next) {
notifications.rescind('post-queue-' + id, next);
},
], callback);
};