How can i prevent bumping of topics from certain categories?


  • Gamers

    I have "Latest topic" widget in my forum and its showing topics for latest posts from all categories. I want to prevent showing of topics from certian categories. Is this possible?

    Also, how can i prevent replying to a topic if the owner already replied to the topic within 24 hours.

    Sorry for my bad english. :smile:

    I am assuming there is no out of the box solution for this. But it would be nice to add it to nodebb. Most of the other forum softwares have feature like this. Meanwhile is it possible to do it developing a plugin?

    Like filtering the API which is used by the widget to get the topics?



  • May be this? filter:recent.build


  • Community Rep

    24 hours?! That's a pretty long time for restricting replies.

    There's no hook to filter recent topics, so you would have to add it to the widget code before the render function.

    data.topics = data.topics.filter(function(topic){
    	// Don't allow topics in category 1
    	return (topic.cid !== '1');
    });
    

  • Community Rep

    @qgp9 said:

    May be this? filter:recent.build

    That hook is for the recent route controller. That would work if he was only filtering the recent topics page. But it will not get called when the recent topics widget is rendered.


  • Gamers

    @yariplus said:

    24 hours?! That's a pretty long time for restricting replies.

    There's no hook to filter recent topics, so you would have to add it to the widget code before the render function.

    data.topics = data.topics.filter(function(topic){
    	// Don't allow topics in category 1
    	return (topic.cid !== '1');
    });
    

    Ok. I'll try this and post my results here.

    Meanwhile is there any way to restrict the user replying to his own topic within 24 hours?


  • Community Rep

    Meanwhile is there any way to restrict the user replying to his own topic within 24 hours?

    Yep writing it out now, it's a bit more complicated.


  • Community Rep

    To restrict replies by the last reply time, you need to do two things.

    On the server side, hook into filter:topic.reply, it is passed data with the tid. Look up the last post and owner using the tid. Then, if the last post was made by the owner, and the timestamp of the last post is less then a day from now, return an error.

    On the client, you'll want to disable the reply button if the last post fulfills the same requirements above. You can use ajaxify.data to get the information you need.

    Server filter:topic.reply hook example:

    plugin.topicReply = function (data, next) {
    	var tid = data.tid;
    
    	Topics.getLatestUndeletedReply(tid, function(err, pid) {
    		if (err) return next(null, data);
    		Posts.getPostFields(pid, ['timestamp', 'uid'], function (err, lastPost) {
    			if (err) return next(null, data);
    			Topics.isOwner(tid, lastPost.uid, function (err, isOwner) {
    				if (err) return next(null, data);
    				if (isOwner && lastPost.timestamp + 86400000 > Date.now()) {
    					return next(new Error('Not enough time passed.'));
    				}else{
    					next(null, data);
    				}
    			});
    		});
    	});
    });
    

    client.js example

    $(window).on('action:ajaxify.end', function(){
      // If the user is at a page with a reply button.
      if ($('[component="topic/reply"]').length && ajaxify.data.posts) {
        var first = ajaxify.data.posts[0];
        var last = ajaxify.data.posts[ajaxify.data.posts.length-1];
    	// If the last poster is the owner,
    	// and they posted less than a day ago,
    	// disable the reply button.
        if (last.uid === first.uid && last.timestamp + 86400000 > Date.now()) $('[component="topic/reply"]').addClass('disabled');
      }
    });
    

    It's late for me, I might have messed up somewhere.

    Also, you can reduce the server code a lot by using async.waterfall and async.apply


Log in to reply
 

Looks like your connection to NodeBB was lost, please wait while we try to reconnect.