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(
             topicData,
             undefined,
             posts.uid
           );
    

    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.

    Thanks.

  • 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
    3 Posts
    299 Views
  • 0 Votes
    3 Posts
    1381 Views
  • 0 Votes
    2 Posts
    1535 Views
  • Posts with widgets

    Unsolved Plugin Development
    0 Votes
    3 Posts
    1997 Views
  • 0 Votes
    3 Posts
    1806 Views