Link Search Menu Expand Document

Create

/api/v2/group/create

Post

groups

profiles

notifications

jwt


Purpose

To allow a user to create a group.

Body Content [input]

{
    uid: string,
    membersID: string[],
    name: string,
    description: string,
    icon: string,
    cover_image: string,
    privacy: string
}

Returns if valid [output]

{
    groupID: string,
    error: 0
}

What the API does

  • Ensures that privacy is either set to private or public, and defaults to public.
  • Generates a groupID.
  • Loops through membersID with each value corresponding to memberID and:
    • Fetches the profile for the record with a uid corresponding to the uid passed (src) [404].
    • Fetches the profile for the record with a uid corresponding to memberID (dest) [404].
    • Ensures that neither uid is found in dest’s blocked field nor that memberID is found in src’s blocked field [403].
    • Ensures that uid is found in dest’s followers field [403].
    • Saves a new invite in dest’s group_invites with the generated groupID and uses pending as value for the state field.
    • Generates a new notificationID and a timestamp corresponding to the current date and time, and creates a new object in the notifications collection with the following data:
      {
      uid: memberID,
      notificationID: notificationID,
      content: `uid.${uid} invited you to the group.${groupID} group`,
      profileID: uid,
      type: "group_invite",
      created_on: timestamp,
      read: false,
      redirect: `/group/${groupID}`
      }
      
    • Generates a new object with the passed name, description, privacy, icon, cover_image and the generated groupID. Records will be added to the members field with each one corresponding to the current user’s uid, with a value of false for is_admin and has_muted, and uses a value of pending for the status field. A record will be similarly created for the current user using the uid passed, but with values of true for is_admin, false for has_muted and accepted for status.