Topic plugin hooks or if first post

NodeBB Development
  • Was looking at writing a plugin that adds additional data to the first post. like say a topic status mabye (availabiity/sold out). Would it be best to put that as a topic field item? or post field on the first post? If topic, i think there would need to be additional plugin hooks. if first post, is there an attribute to a post that is passed to the plugin hooks that it is the first? I didn't see one when depuging out the postData

  • We don't have any attributes stored in the post objects telling if they are the first post in a topic. The way to tell if the post is the first can be done by checking the redis list 'tid:' + tid + ':posts'.

    For example :

    function isMainPost(tid, pid, callback) {
        RDB.lrange('tid:' + tid + ':posts', 0, 0, function(err, pids) {
            if(err) {
                return callback(err, null);
            }
            callback(null, pids[0] === pid);
        });
    }
    

    We don't have that function yet but we can add that to posts.js.

  • function isMainPost(tid, pid, callback) {
    RDB.lrange('tid:' + tid + ':posts', 0, 0, function(err, pids) {
    if(err) {
    return callback(err, null);
    }
    callback(null, pids[0] === pid);
    });
    }

    Kool, looks like there is already a function PostTools.isMain to do that after further investigation. Will see what i can do with that.

  • Ahh looks like it's already there just doesn't return error 😛 I will add that now.


Suggested Topics