mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-02 05:40:43 +01:00
feat: #7743, groups/delete,ownership,posts,user
This commit is contained in:
@@ -1,65 +1,36 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
|
||||
var db = require('../database');
|
||||
var privileges = require('../privileges');
|
||||
var posts = require('../posts');
|
||||
const db = require('../database');
|
||||
const privileges = require('../privileges');
|
||||
const posts = require('../posts');
|
||||
|
||||
module.exports = function (Groups) {
|
||||
Groups.onNewPostMade = function (postData, callback) {
|
||||
Groups.onNewPostMade = async function (postData) {
|
||||
if (!parseInt(postData.uid, 10)) {
|
||||
return setImmediate(callback);
|
||||
return;
|
||||
}
|
||||
|
||||
var groupNames;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
Groups.getUserGroupMembership('groups:visible:createtime', [postData.uid], next);
|
||||
},
|
||||
function (_groupNames, next) {
|
||||
groupNames = _groupNames[0];
|
||||
let groupNames = await Groups.getUserGroupMembership('groups:visible:createtime', [postData.uid]);
|
||||
groupNames = groupNames[0];
|
||||
|
||||
const keys = groupNames.map(groupName => 'group:' + groupName + ':member:pids');
|
||||
db.sortedSetsAdd(keys, postData.timestamp, postData.pid, next);
|
||||
},
|
||||
function (next) {
|
||||
async.each(groupNames, function (groupName, next) {
|
||||
truncateMemberPosts(groupName, next);
|
||||
}, next);
|
||||
},
|
||||
], callback);
|
||||
const keys = groupNames.map(groupName => 'group:' + groupName + ':member:pids');
|
||||
await db.sortedSetsAdd(keys, postData.timestamp, postData.pid);
|
||||
await Promise.all(groupNames.map(name => truncateMemberPosts(name)));
|
||||
};
|
||||
|
||||
function truncateMemberPosts(groupName, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
db.getSortedSetRevRange('group:' + groupName + ':member:pids', 10, 10, next);
|
||||
},
|
||||
function (lastPid, next) {
|
||||
lastPid = lastPid[0];
|
||||
if (!parseInt(lastPid, 10)) {
|
||||
return callback();
|
||||
}
|
||||
db.sortedSetScore('group:' + groupName + ':member:pids', lastPid, next);
|
||||
},
|
||||
function (score, next) {
|
||||
db.sortedSetsRemoveRangeByScore(['group:' + groupName + ':member:pids'], '-inf', score, next);
|
||||
},
|
||||
], callback);
|
||||
async function truncateMemberPosts(groupName) {
|
||||
let lastPid = await db.getSortedSetRevRange('group:' + groupName + ':member:pids', 10, 10);
|
||||
lastPid = lastPid[0];
|
||||
if (!parseInt(lastPid, 10)) {
|
||||
return;
|
||||
}
|
||||
const score = await db.sortedSetScore('group:' + groupName + ':member:pids', lastPid);
|
||||
await db.sortedSetsRemoveRangeByScore(['group:' + groupName + ':member:pids'], '-inf', score);
|
||||
}
|
||||
|
||||
Groups.getLatestMemberPosts = function (groupName, max, uid, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
db.getSortedSetRevRange('group:' + groupName + ':member:pids', 0, max - 1, next);
|
||||
},
|
||||
function (pids, next) {
|
||||
privileges.posts.filter('topics:read', pids, uid, next);
|
||||
},
|
||||
function (pids, next) {
|
||||
posts.getPostSummaryByPids(pids, uid, { stripTags: false }, next);
|
||||
},
|
||||
], callback);
|
||||
Groups.getLatestMemberPosts = async function (groupName, max, uid) {
|
||||
let pids = await db.getSortedSetRevRange('group:' + groupName + ':member:pids', 0, max - 1);
|
||||
pids = await privileges.posts.filter('topics:read', pids, uid);
|
||||
return await posts.getPostSummaryByPids(pids, uid, { stripTags: false });
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user