• Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
v3.5.2 Latest
Buy Hosting

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

Scheduled Pinned Locked Moved Plugin Development
3 Posts 2 Posters 394 Views
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Aisar G.A Offline
    Aisar G.A Offline
    Aisar G.
    wrote on last edited by Aisar G.
    #1

    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.

    1 Reply Last reply
    1
  • barisB Offline
    barisB Offline
    <baris> NodeBB
    wrote on last edited by
    #2

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

    Aisar G.A 1 Reply Last reply
    0
  • Aisar G.A Offline
    Aisar G.A Offline
    Aisar G.
    replied to <baris> on last edited by
    #3

    @baris Thanks. It worked 🙂

    1 Reply Last reply
    0

Copyright © 2023 NodeBB | Contributors
  • Login

  • Don't have an account? Register

  • Login or register to search.
Powered by NodeBB Contributors
  • First post
    Last post
0
  • Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development