mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-12 00:45:47 +01:00
ignore/watch categories recursively
This commit is contained in:
@@ -18,8 +18,8 @@
|
|||||||
"watching.description": "Show topics in unread",
|
"watching.description": "Show topics in unread",
|
||||||
"ignoring.description": "Do not show topics in unread",
|
"ignoring.description": "Do not show topics in unread",
|
||||||
|
|
||||||
"watch.message": "You are now watching updates from this category",
|
"watch.message": "You are now watching updates from this category and all subcategories",
|
||||||
"ignore.message": "You are now ignoring updates from this category",
|
"ignore.message": "You are now ignoring updates from this category and all subcategories",
|
||||||
|
|
||||||
"watched-categories": "Watched categories"
|
"watched-categories": "Watched categories"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
var db = require('../database');
|
var db = require('../database');
|
||||||
var categories = require('../categories');
|
var categories = require('../categories');
|
||||||
var privileges = require('../privileges');
|
var privileges = require('../privileges');
|
||||||
@@ -171,23 +171,52 @@ SocketCategories.getMoveCategories = function(socket, data, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SocketCategories.watch = function(socket, cid, callback) {
|
SocketCategories.watch = function(socket, cid, callback) {
|
||||||
user.watchCategory(socket.uid, cid, function(err) {
|
ignoreOrWatch(user.watchCategory, socket, cid, callback);
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
topics.pushUnreadCount(socket.uid, callback);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketCategories.ignore = function(socket, cid, callback) {
|
SocketCategories.ignore = function(socket, cid, callback) {
|
||||||
user.ignoreCategory(socket.uid, cid, function(err) {
|
ignoreOrWatch(user.ignoreCategory, socket, cid, callback);
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
topics.pushUnreadCount(socket.uid, callback);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function ignoreOrWatch(fn, socket, cid, callback) {
|
||||||
|
async.waterfall([
|
||||||
|
function(next) {
|
||||||
|
db.getSortedSetRange('categories:cid', 0, -1, next);
|
||||||
|
},
|
||||||
|
function(cids, next) {
|
||||||
|
categories.getCategoriesFields(cids, ['cid', 'parentCid'], next);
|
||||||
|
},
|
||||||
|
function(categoryData, next) {
|
||||||
|
categoryData.forEach(function(c) {
|
||||||
|
c.cid = parseInt(c.cid, 10);
|
||||||
|
c.parentCid = parseInt(c.parentCid, 10);
|
||||||
|
});
|
||||||
|
|
||||||
|
var cids = [parseInt(cid, 10)];
|
||||||
|
|
||||||
|
// filter to subcategories of cid
|
||||||
|
|
||||||
|
var any = true;
|
||||||
|
while (any) {
|
||||||
|
any = false;
|
||||||
|
categoryData.forEach(function(c) {
|
||||||
|
if (cids.indexOf(c.cid) === -1 && cids.indexOf(c.parentCid) !== -1) {
|
||||||
|
cids.push(c.cid);
|
||||||
|
any = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async.each(cids, function(cid, next) {
|
||||||
|
fn(socket.uid, cid, next);
|
||||||
|
}, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
topics.pushUnreadCount(socket.uid, next);
|
||||||
|
}
|
||||||
|
], callback);
|
||||||
|
}
|
||||||
|
|
||||||
SocketCategories.isModerator = function(socket, cid, callback) {
|
SocketCategories.isModerator = function(socket, cid, callback) {
|
||||||
user.isModerator(socket.uid, cid, callback);
|
user.isModerator(socket.uid, cid, callback);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user