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