Hello, I want to get all the posts from a Topic

Plugin Development
  • Hello,

    I'm using I wrote this to get all the posts from a Topic...

    const topicData = {
             posts: posts.posts,
             category: topic[0].cid,
             cid: topic[0].cid,
             tid: topic[0].tid,
             mainPid: topic[0].mainPid,
           const topicWithPosts = await Topic.getTopicWithPosts(

    But i'm getting this...

      posts: [],
      category: {
        bgColor: '#fda34b',
        cid: 1,
        class: 'col-md-3 col-xs-6',
        color: '#fff',
        description: 'Announcements regarding our community',
        descriptionParsed: '<p>Announcements regarding our community</p>\n',
        disabled: 0,
        icon: 'fa-bullhorn',
        imageClass: 'cover',
        isSection: 0,
        link: '',
        name: 'Announcements',
        numRecentReplies: 1,
        order: 1,
        parentCid: 0,
        post_count: 30,
        slug: '1/announcements',
        topic_count: 4,
        minTags: 0,
        maxTags: 5,
        totalPostCount: 30,
        totalTopicCount: 4
      cid: 1,
      tid: 6,
      mainPid: 37,
      tags: [],
      tagWhitelist: [],
      minTags: 0,
      maxTags: 5,
      thread_tools: [],
      isFollowing: false,
      isNotFollowing: true,
      isIgnoring: false,
      bookmark: null,
      postSharing: [],
      deleter: null,
      merger: null,
      related: [],
      unreplied: false,
      icons: []

    I just want to get all the posts from that topic when a person clics to see the replies from a post. Nodebb gives me the replies from that specific post, but I want to get all the posts from that specific topic.

    You can see that the posts array are empty. For your information, i'm using filter:post.getPosts hook and
    const topic = await Topic.getTopicsByTids([posts.posts[0].tid], posts.uid) method before the Topic.getTopicWithPosts() method to get the topic info I needed to pass in.


  • You need to pass the correct parameters to the function
    await topics.getTopicWithPosts(topicData, 'tid:' topicData.tid + ':posts', uid, 0, -1, false);

  • @baris Thanks. It worked πŸ™‚

Suggested Topics

  • 0 Votes
    9 Posts

    @eeeee Probably local to the user computer πŸ™‚

    You can generally use non-http URIs for launching different applications. If you were ever redirected from a desktop or mobile app to a browser to log in you've probably seen this in action. Windows actually uses some internally and usually transparently for the user (for example, to abuse their monopoly, MS started using microsoft-edge: scheme instead of https: in some links in Windows to only allow opening them in Edge. They didn't have to build some highly custom mechanism, just restrict other apps from registering this scheme), but usually can be just registered by applications you install. What they do also depends on the application - for example, I think calculator: only launches the calculator app (or at least the obvious way to write math doesn't work), but others can launch specific actions and even pass some information (for example, authentication token for the web login use case I mentioned). For example Spotify allows linking to artists, playlists, albums etc. via spotify: scheme and steam supports doing a ton of things via URI, including launching and even installing/uninstalling games.

    All you need is an <a> tag with the right href= set. So yeah, you can put that kind of a link in a widget, but if they wanted to have it be an action under a post, especially if it was supposed to include some information from the post, it wouldn't be that simple.
    (side note: NodeBB doesn't allow links using non-standard schemes in markdown, so you can't just put something like this in a post or signature)

  • 0 Votes
    5 Posts

    thx a lot !!!!
    it's work finally!

  • 0 Votes
    2 Posts

    Hi @avan-sardar, welcome!

    find a topic based on uid and a custom session ID

    Is this a requirement? If your plugin is listening for something like action:post.save, then you can process the stripe payment.

    The action hook itself also sends the post data, which contains the pid and tid. Without more context, I am afraid I will not be able to help further.

  • 0 Votes
    3 Posts

    @pichalite thank to your suggest it works I have only topics that aren't "Pin". If I do this:


    The topics show in this way:

    0_1470823128648_Schermata del 2016-08-10 11:45:59.png
    In the image I can see that "primo creato " topic that I have PIN it's the last but I want to become the first.

    I want that when I PIN a topic, this must be the first among the topics (now it is the last).

    In plugin.json I put this hook:

    "hook": "filter:category.topics.prepare", "method": "ordina_zero"

    and in library I do this:

    converter.ordina_zero = function(data, callback) { //Prendo quale element del sorted ha cliccato user.getSettings(data['uid'], function(err, settings) { if (settings.categoryTopicSort === 'zero') { data.reverse = false; data.set = 'cid:' + data.cid + ':tids:posts'; } callback(null, data); }); };

    My purpose is show the PIN topic at the beginning and after show the topics with their order. Can you help me?

  • 0 Votes
    5 Posts

    Boy, that was quick! Thanks πŸ™‚