Block friend Invites #

Players can block and unblock friend invites from a specific account, or block all incoming friend invites.

Block and unblock a single account #

The Friend API’s Block() method allows a player to block friend invites sent by a specific account. Any pending invitations from the blocked account are automatically deleted. If the players are friends, they will be removed from the others’ friend list as a part of the block call.

If a blocked player attempts to send a friend invite, they receive the Friend_BlockedByInvitee error.

The Unblock() method allows a player to unblock an account on their block list.

This guide is based on an example Unreal project using the Third Person Unreal C++ project template. The example project is named ‘Narwhal’, update references accordingly.

Source\Narwhal\NarwhalPlayerController.h


// ...
class NARWHAL_API ANarwhalPlayerController : public APlayerController
{
    GENERATED_BODY()

public:
  // ...

	UFUNCTION(Exec)
	void Block(const FString& SocialId);

	UFUNCTION(Exec)
	void Unblock(const FString& SocialId);

  // ...
};

Source\Narwhal\NarwhalPlayerController.cpp

void ANarwhalPlayerController::Block(const FString &SocialId) {
  Player->FriendApi().Block(
      SocialId, FOnCompleteDelegate::CreateUObject(
                    this, &ANarwhalPlayerController::OnFriendUpdate));
}
void ANarwhalPlayerController::Unblock(const FString &SocialId) {
  Player->FriendApi().Unblock(
      SocialId, FOnCompleteDelegate::CreateUObject(
                    this, &ANarwhalPlayerController::OnFriendUpdate));
}

View block list #

The GetBlockedList() function returns all accounts on a player’s block list.

Unreal:

Player->FriendApi().GetBlockedList();

Disable or enable all incoming friend invites #

Developers can allow players to disable or enable all incoming invites from any account using the DisableIncomingFriendInvites and EnableIncomingFriendInvites apis. By default, all players can receive invites.

Disabling or enabling incoming invites does not add or remove accounts from a player’s block list.

Source\Narwhal\NarwhalPlayerController.h


// ...
class NARWHAL_API ANarwhalPlayerController : public APlayerController
{
    GENERATED_BODY()

public:
  // ...

	UFUNCTION(Exec)
	void DisableFriendInvites();

	UFUNCTION(Exec)
	void EnableFriendInvites();

  // ...
};

Source\Narwhal\NarwhalPlayerController.cpp

void ANarwhalPlayerController::DisableFriendInvites() {
  Player->FriendApi().DisableIncomingFriendInvites(
      FOnCompleteDelegate::CreateUObject(
          this, &ANarwhalPlayerController::OnFriendUpdate));
}
void ANarwhalPlayerController::EnableFriendInvites() {
  Player->FriendApi().EnableIncomingFriendInvites(
      FOnCompleteDelegate::CreateUObject(
          this, &ANarwhalPlayerController::OnFriendUpdate));
}