Link Search Menu Expand Document

Fetch Group

/api/v2/feed/fetch/group

Post

posts

profiles

groups

users

jwt

pgn


Purpose

To allow a user to fetch all the posts found in one specific group.

Body Content [input]

{
    uid: string,
    groupID: string
}

Returns if valid [output]

{
    posts: {
        uid: string,
        postID: string,
        content: string,
        posted_on: Date,
        modified_on: Date,
        reacts: string[],
        groupID: string,
        shareID: string,
        comments: {
            uid: string,
            commentID: string,
            reply_to: string,
            posted_on: Date,
            modified_on: Date,
            reacts: string[],
            visibility: string
        }[],
        visibility: string,
        allow_comments: bool,
        senderName: string,
        senderUsername: string,
        groupName: string
    }[],
    error: 0,
    amount: int
}

What the API does

  • Finds the profile corresponding to the uid passed and fetches a list of all values inside of the following and blocked fields.
  • Finds the group being referenced using the value of the groupID field passed [404].
  • Checks if the found group has a value for its privacy field that is set to public or if there is a record in its members field with a uid corresponding to the one passed and with a status of accepted [403].
  • Finds all records from the posts collection having a value for their groupID field corresponding to the one passed.
  • Loops through each of these post records and:
    • Removes that record if it has a visibility set to none.
    • If the record does not have a visibility of none, followers or public, fetch the members field of the AccessGroup corresponding to the value of the visibility field and if uid is not among the values of that members field, remove the record.
    • Remove that record if it has a visibility set to none.
    • Removes that record if the value of its uid field is among that of the fetched blocked field above.
    • Finds the profile that has a uid corresponding to that of the current post record, and removes that record if the blocked field contains the uid passed.
    • Loop through each of the comment of the comments field of that record and:
      • Create a new data structure removedComments for the commentIDs of removed comments.
      • Remove that comment if it has a visibility set to none.
      • If the comment does not have a visibility of none, followers or public, fetch the members field of the AccessGroup corresponding to the value of the visibility field and if uid is not among the values of that members field, remove the comment.
      • Removes that comment if the value of its uid field is among those of the fetched blocked field above.
      • Finds the profile that has a uid corresponding to that of the current comment, and removes that comment if the uid passed is among the values of blocked field.
      • If the comment has a visibility of followers fetch the followers field of the profile corresponding to the value of the uid field of that comment and if uid is not among these values or is not equal to the value of the uid field of the comment itself, remove the comment.
      • Append the value of the commentID field of all removed comments to removedComments.
      • Loop through all comments again, and remove all those who have a value for their reply_to field corresponding to a value inside of the removedComments array.
  • Sort all the posts by date in descending order of when they were posted based on the value of their posted_on field.
  • Adds a senderName and senderUsername field to each of the posts having a value equal to that of the name and username of the user who posted it identified by the value of its uid field.
  • Adds a groupName field to each of the posts corresponding to the name of the group if they have a value for their groupID field.