Access Post Information

Each post is represented by Post instance. Each instance of Post holds several information such as data, reactions, comments, metadata, child posts, etc. For text posts, you can access the actual data for the post through the data property.

Post with images or files follow Parent - Child relationship. Each image or file uploaded will be a separate child post. Any text that you set while creating an image/file post will act as a Parent post. Parent post contains childrenPosts property which gives you an array of post ids.

You can access data for child post through the same data property for child post. For image post, the shape of data will be { imageId: string } and for file post, { fileId: string }.

Let's consider our post contains some text and one image. This means that a parent post would be a text post and its child post will be an image post. Here is how we can access it.

const parentPost = PostRepository.postForId(parentPostId)

parentPost.on(“dataUpdated”, parentModel => {
    console.log(parentModel.data)) // contains .text

    const childrenPosts = parentModel.children.map(childPostId => (
      PostRepository.postForId(childPostId)
    ))

    childrenPosts.forEach(childPost => {
       childPost.on(“dataUpdated”, childModel => console.log(childModel.data)) // contains .imageId
    })
})

Last updated