Link Search Menu Expand Document

Fetch

/api/v2/feed/fetch

Post

posts

profiles

groups

users

jwt

pgn


Purpose

To allow a user to fetch all the posts from users that he/she follows that he/she is allowed to see in his/her feed.

Body Content [input]

{
    uid: 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 all records from the posts collection having a uid not 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.
    • If the record has a value for its groupID field, find the group corresponding to that groupID and check if uid is a value among that group’s members field with a status of accepted. If that is not the case, remove that record.
    • Else, if the record does not have a value for its groupID field and has a value of followers for its visibility field, check if uid is among the values of the following field or if it is equal to the uid of the post itself. If that is not the case, remove that record.
    • 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.
  • Appends also all the posts having a value for their uid field corresponding to the one passwd.
  • 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.