how can I get any of the post metadata when filtering a post?

NodeBB Plugins
  • #1

    Is there any way to see the unique id of the post that the filter:post.parse is running against?
    Right now I can only see the post content from inside the function mapped to that filter above. I am not sure how to get a unique identifier to figure out which post exactly I am in.

    I thought about using data.url attribute but that could actually point to any post in the current topic. So at most, that could give me the topic id, but not a unique identifier for the post.

    Also, am I right to think that there is a unique post id somewhere, or do I have to combine topic id with post id to create a unique identifier?

    My goal is to store some data against the current post that my plugin is filtering, but I am not sure how to do that yet.

  • NodeBB

    This would require a change to parse('filter:post.parse', raw, callback); and sending in the post id.

    Each post has a unique id called pid and its stored in the post object with the content.

    We can probably do this for 0.6.0 since it will break plugins which use that hook.

  • #3

    @baris thanks for the quick reply, can you think of any workaround that I could try for now to get the pid?

  • NodeBB

    If you don't mind getting your hands dirty you can modify core and change PostTools.parse to

    PostTools.parse = function(uid, pid, content, callback) {
    	parse('filter:post.parse', {uid: uid, pid: pid, content: content}, callback);

    Obviously you will have to fix the places where PostTools.parse is used and update any plugins that you use that uses filter:post.parse ie the markdown plugin.

    Other than that there is no easy way to get the pid from post content.

  • #5

    @baris said:

    If you don't mind getting your hands dirty you can modify core and change PostTools.parse

    me -> 😨

    I was thinking to extract the topic id from data.url and pass it back to the plugin backend to store, and then limit my plugin to one instance per topic for now. But I think that would be even worst, and when 0.6.0 arrives I would have to fix it anyways.

    I am a bit scared to touch the core stuff, but I may give your suggestion a try since it is less hacky, and better long term solution.

Suggested Topics

| | | |