Guidance on creating a topic approval by category plugin



  • Hey, all. I'm trying to get into plugin development to customize my nodeBB site but I'm finding the documentation a little lacking and my search attempts haven't been too fruitful, so my apologies if I'm asking silly/repeated questions.

    So, my end goal is that I'd like one specific topic category to require approval on all topic creations to ensure quality in that category (in my case, how-to instructions/guides). So, basically I'd like to utilize the post queue but instead of by new member, by category instead.

    First off, how could I best store this data? I'll probably make a basic ACP page to read and allow selection of categories admins would desire requiring approval in. But then, what calls would I need to make to store this data in the DB? Should it be attached to the category data? Is there a more appropriate place to put it?

    Second I assume I'll be using the filter:post.shouldQueue hook? How would I ultimately figure out if they're posting in a category requiring approval/access the data from the first question?

    Thanks in advance!


  • GNU/Linux Admin

    Well, that filter looks to be right (at least, by name). On the receiving end, once you've registered a hook listener to that hook, the method you register will be called with a single data object and a callback.

    That data object contains shouldQueue, a Boolean (change this if you want the post to be queued), uid, the uid creating the post, and data, a catch-all that contains the post data, likely.

    Check for the cid in there, and if not present, the tid is probably going to be there. You can then call getTopicField(theTid, 'cid', function (err, cid) { ... }); to get the cid.

    Determine whether the cid is the one you want to queue replies, and adjust shouldQueue boolean as appropriate 👍

    Then call the callback with the same arguments: callback(null, data);



  • Awesome, thanks! Here's hoping.



  • Hello!
    I would also love this functinoality, hence I started developing it.
    It is working, but I have no idea how to be able to edit the Admin Control Panel in order to set the categories I want to moderate (actually is an array).

    Any hint? Thanks in advance.

    I think there is an "error" in the source code: the reputation is not taken in count....here below is better explained.
    I post the code hoping to be helpful.

    I added two variables, the first defining the IDs of the Categories I wnat to moderate, the second (maybe it could be avoided) to store a boolean:

    var queuedCategories = [1, 2];
    var shouldReallyQueue;
    

    Then I edited the Posts.shouldQueue = function (uid, data, callback) as it follows:
    First, in the "const shouldQueue" I replaced the "0" with "meta.config.newbiePostDelayThreshold" (otherwise the reputation is not thaken in count):
    const shouldQueue = meta.config.postQueue && (!userData.uid || userData.reputation < meta.config.newbiePostDelayThreshold || userData.postcount <= 0);

    Hence I added a new step in the async.waterfall:

    function (result, next) {
    	shouldReallyQueue = result.shouldQueue;
    	if (result.data.tid !== undefined)
    		topics.getTopicField(result.data.tid, 'cid', next);
    	else
    		plugins.fireHook('filter:post.shouldQueue', {
    			categoryId : result.data.cid,
    			shouldReallyQueue: shouldReallyQueue,
    		}, next);
    },
    

    editing the last check so:

    next(null, result.shouldReallyQueue && (queuedCategories.indexOf(result.categoryId) > -1));
    

    Hence, my "Posts.shouldQueue" looks now:

    Posts.shouldQueue = function (uid, data, callback) {
    	async.waterfall([
    		function (next) {
    			user.getUserFields(uid, ['uid', 'reputation', 'postcount'], next);
    		},
    		function (userData, next) {
    			const shouldQueue = meta.config.postQueue && (!userData.uid || userData.reputation < meta.config.newbiePostDelayThreshold || userData.postcount <= 0);
    			plugins.fireHook('filter:post.shouldQueue', {
    				shouldQueue: shouldQueue,
    				uid: uid,
    				data: data,
    			}, next);
    		},
    		function (result, next) {
    			shouldReallyQueue = result.shouldQueue;
    			if (result.data.tid !== undefined)
    				topics.getTopicField(result.data.tid, 'cid', next);
    			else
    				plugins.fireHook('filter:post.shouldQueue', {
    					categoryId : result.data.cid,
    					shouldReallyQueue: shouldReallyQueue,
    				}, next);
    		},
    		function (result, next) {
    			next(null, result.shouldReallyQueue && (queuedCategories.indexOf(result.categoryId) > -1));
    		},
    	], callback);
    };
    

  • Gamers

    I was interested in that functionality as well, so I developed my own version of it.
    It can be found here and already is in nbbpm (can be installed from ACP by searching for nodebb-plugin-category-queue)
    It has some basic ACP (list of categories with options to queue new topics from them or not queue), and only works on new topics, not all posts (that is actually by design, as - after all - you have done the work on filtering posts already. It's just that I was looking for only sending new topics to queue)


Log in to reply
 

Suggested Topics

  • 1
  • 1
  • 15
  • 2
  • 7
| |