Documentation

RelationshipsApi

Import

Import

  • const { RelationshipsApi } = require("@unity-services/friends-1.0");

Constructors

Constructor

Methods

Create Relationship

  • createRelationship(withPresence?: boolean, withProfile?: boolean, addRelationshipRequest?: AddRelationshipRequest, options?: AxiosRequestConfig<any>): Promise<AxiosResponse<Relationship, any>>
  • Creates a relationship with one or more members. A relationship has a type and a list of members who are the users involved in the relationship. The requirements for creating a relationship are different depending on the type of the relationship. Each member of the relationship can also be given an optional role which may indicate some semantic of the the relationship. A member can be identified by their user id or profile name. For most relationships, if the caller is a user and is not included in the members list, that user's membership is inferred to exist using the appropriate role. For example, if you create a FRIEND_REQUEST relationship with one member, the caller is inferred to be the source of the relationship. ## Relationship Types ### FRIEND_REQUEST Relationship A FRIEND_REQUEST relationship indicates that a user would like to create a friendship with another user. If no FRIEND relationship (i.e. friendship) exists between the two users then the receiving game client will be notified that a FRIEND_REQUEST relationship has been created, and the game can choose to notify the user and provide a mechanism for them to accept the friend request. A friend request is accepted by creating a reciprocal FRIEND_REQUEST relationship targeting the originating user. A FRIEND_REQUEST relationship can ONLY have two members. The members have a role of either SOURCE or TARGET to indicate the sender and the receiver of the request. If not provided the caller of the API will be inferred to be the SOURCE and the other member will be the TARGET. A user cannot create a relationship with themselves as the TARGET. ### FRIEND Relationship A FRIEND relationship cannot be directly created by a user, but is implicitly created when both users have created FRIEND_REQUEST relationships with each other (i.e. sent and accepted a friend request). A service account or admin user can directly create a FRIEND relationship between specific users. A FRIEND relationship is not directed, so the members of the relationships do not have an assigned role. ### BLOCK Relationship A BLOCK relationship is a one-way relationship that enables a user to indicate that another user should be prevented from interacting with themselves for certain features and functionality (e.g. hiding presence, preventing the user from sending messages to them, etc.). Presence blocking will be handled by the service to ensure that blocked users are unable to view the presence details of the blocker. For other functionality it is up to the developer to consume the BLOCK relationships data and provide additional functionality. For example, a game client could filter out lobbies created by users that have been blocked, or a game server could prevent a blocked user from joining a game instance.

    summary

    Create a new relationship.

    throws

    {RequiredError}

    memberof

    RelationshipsApi

    Parameters

    • Optional withPresence: boolean
    • Optional withProfile: boolean
    • Optional addRelationshipRequest: AddRelationshipRequest
    • Optional options: AxiosRequestConfig<any>

    Returns Promise<AxiosResponse<Relationship, any>>

Delete Relationship

  • deleteRelationship(relationshipId: string, options?: AxiosRequestConfig<any>): Promise<AxiosResponse<void, any>>
  • Deletes a relationship with the given relationshipId.

    summary

    Delete a relationship.

    throws

    {RequiredError}

    memberof

    RelationshipsApi

    Parameters

    • relationshipId: string

      The relationship ID.

    • Optional options: AxiosRequestConfig<any>

    Returns Promise<AxiosResponse<void, any>>

Get Relationships

  • getRelationships(limit?: number, offset?: number, withPresence?: boolean, withProfile?: boolean, type?: RelationshipType[], options?: AxiosRequestConfig<any>): Promise<AxiosResponse<Relationships, any>>
  • Retrieves a list of all relationships a given user is involved in. Relationships of all types are returned in a single array. It's up to the caller to use the type of the relationship object to determine the appropriate way to handle that relationship. For relationship types that allow it, additional presence and profile data will be provided for each member of the relationship (unless excluded using the withPresence and withProfile parameters). By default, we limit the number of relationships that can be returned in a single request. You can make subsequent requests to this API using the offset parameter to paginate through the remaining relationships.

    summary

    Retrieve a list of relationships.

    throws

    {RequiredError}

    memberof

    RelationshipsApi

    Parameters

    • Optional limit: number
    • Optional offset: number
    • Optional withPresence: boolean
    • Optional withProfile: boolean
    • Optional type: RelationshipType[]
    • Optional options: AxiosRequestConfig<any>

    Returns Promise<AxiosResponse<Relationships, any>>