Packages
game_server_sdk
1.0.1
1.0.1082
1.0.1079
1.0.1078
1.0.1077
1.0.1076
1.0.1075
1.0.1074
1.0.1073
1.0.1070
1.0.1068
1.0.1067
1.0.1063
1.0.1059
1.0.1058
1.0.1057
1.0.1056
1.0.1055
1.0.1050
1.0.1049
1.0.1048
1.0.1047
1.0.1046
1.0.1044
1.0.1043
1.0.1042
1.0.1041
1.0.1040
1.0.1039
1.0.1038
1.0.1034
1.0.1033
1.0.1029
1.0.1028
1.0.1026
1.0.1025
1.0.1024
1.0.1023
1.0.1022
1.0.1021
1.0.1020
1.0.1019
1.0.1018
1.0.1017
1.0.1016
1.0.1015
1.0.1014
1.0.1013
1.0.1012
1.0.1011
1.0.1009
1.0.1008
1.0.1007
1.0.1006
1.0.1005
1.0.1004
1.0.1003
1.0.1001
1.0.999
1.0.998
1.0.997
1.0.996
1.0.995
1.0.994
1.0.993
1.0.992
1.0.991
1.0.990
1.0.989
1.0.988
1.0.987
1.0.986
1.0.985
1.0.984
1.0.983
1.0.982
1.0.981
1.0.980
1.0.979
1.0.978
1.0.977
1.0.976
1.0.975
1.0.974
1.0.973
1.0.972
1.0.971
1.0.970
1.0.969
1.0.968
1.0.967
1.0.966
1.0.965
1.0.964
1.0.963
1.0.962
1.0.961
1.0.959
1.0.958
1.0.956
1.0.951
1.0.950
1.0.943
1.0.942
1.0.941
1.0.940
1.0.938
1.0.936
1.0.935
1.0.931
1.0.929
1.0.928
1.0.927
1.0.926
1.0.925
1.0.924
1.0.923
1.0.921
1.0.920
1.0.919
1.0.918
1.0.917
1.0.916
1.0.911
1.0.910
1.0.902
1.0.899
1.0.898
1.0.897
1.0.896
1.0.894
1.0.893
1.0.891
1.0.890
1.0.889
1.0.888
1.0.887
1.0.886
1.0.885
1.0.884
1.0.883
1.0.882
1.0.881
1.0.880
1.0.879
1.0.878
1.0.877
1.0.26
1.0.25
1.0.22
1.0.21
1.0.20
1.0.19
1.0.15
1.0.14
1.0.13
1.0.12
1.0.10
1.0.9
1.0.8
1.0.7
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0
0.1.0
SDK for GameServer hooks development. Provides type specs, documentation, and IDE autocomplete for GameServer modules without requiring the full server.
Current section
Files
Jump to
Current section
Files
lib/game_server/friends.ex
defmodule GameServer.Friends do
@moduledoc ~S"""
Friends context - handles friend requests and relationships.
Basic semantics:
- A single `friendships` row represents a directed request from requester -> target.
- status: "pending" | "accepted" | "rejected" | "blocked"
- When a user accepts a pending incoming request, that request becomes `accepted`.
If a reverse pending request exists, it will be removed to avoid duplicate rows.
- Listing friends returns the other user from rows with status `accepted` in either
direction.
## Usage
# Create a friend request (requester -> target)
{:ok, friendship} = GameServer.Friends.create_request(requester_id, target_id)
# Accept a pending incoming request (performed by the target)
{:ok, accepted} = GameServer.Friends.accept_friend_request(friendship.id, %GameServer.Accounts.User{id: target_id})
# List accepted friends for a user (paginated)
friends = GameServer.Friends.list_friends_for_user(user_id, page: 1, page_size: 25)
# Count accepted friends for a user
count = GameServer.Friends.count_friends_for_user(user_id)
# Remove a friendship (either direction)
{:ok, _} = GameServer.Friends.remove_friend(user_id, friend_id)
**Note:** This is an SDK stub. Calling these functions will raise an error.
The actual implementation runs on the GameServer.
"""
@doc ~S"""
Accept a friend request (only the target may accept). Returns {:ok, friendship}.
"""
@spec accept_friend_request(integer(), GameServer.Accounts.User.t()) ::
{:ok, GameServer.Friends.Friendship.t()} | {:error, term()}
def accept_friend_request(_friendship_id, _user) do
raise "GameServer.Friends.accept_friend_request/2 is a stub - only available at runtime on GameServer"
end
@doc ~S"""
Block an incoming request (only the target may block). Returns {:ok, friendship} with status "blocked".
"""
@spec block_friend_request(integer(), GameServer.Accounts.User.t()) ::
{:ok, GameServer.Friends.Friendship.t()} | {:error, term()}
def block_friend_request(_friendship_id, _user) do
raise "GameServer.Friends.block_friend_request/2 is a stub - only available at runtime on GameServer"
end
@doc ~S"""
Cancel an outgoing friend request (only the requester may cancel).
"""
def cancel_request(_friendship_id, _user) do
raise "GameServer.Friends.cancel_request/2 is a stub - only available at runtime on GameServer"
end
@doc ~S"""
Count blocked friendships for a user (number of blocked rows where user is target).
"""
def count_blocked_for_user(_user_id) do
raise "GameServer.Friends.count_blocked_for_user/1 is a stub - only available at runtime on GameServer"
end
@doc ~S"""
Count accepted friends for a given user (distinct other user ids).
"""
def count_friends_for_user(_user_id) do
raise "GameServer.Friends.count_friends_for_user/1 is a stub - only available at runtime on GameServer"
end
@doc ~S"""
Count incoming pending friend requests for a user.
"""
def count_incoming_requests(_user_id) do
raise "GameServer.Friends.count_incoming_requests/1 is a stub - only available at runtime on GameServer"
end
@doc ~S"""
Count outgoing pending friend requests for a user.
"""
def count_outgoing_requests(_user_id) do
raise "GameServer.Friends.count_outgoing_requests/1 is a stub - only available at runtime on GameServer"
end
@doc ~S"""
Create a friend request from requester -> target.
If a reverse pending request exists (target -> requester) it will be accepted instead.
Returns {:ok, friendship} on success or {:error, reason}.
"""
@spec create_request(GameServer.Accounts.User.t() | integer(), integer()) ::
{:ok, GameServer.Friends.Friendship.t()} | {:error, any()}
def create_request(_requester_id, _target_id) do
raise "GameServer.Friends.create_request/2 is a stub - only available at runtime on GameServer"
end
@doc ~S"""
Get friendship between two users (ordered requester->target) if exists
"""
def get_by_pair(_requester_id, _target_id) do
raise "GameServer.Friends.get_by_pair/2 is a stub - only available at runtime on GameServer"
end
@doc ~S"""
Get friendship by id
"""
def get_friendship!(_id) do
raise "GameServer.Friends.get_friendship!/1 is a stub - only available at runtime on GameServer"
end
@doc ~S"""
List blocked friendships for a user (Friendship structs where the user is the blocker / target).
"""
def list_blocked_for_user(_user_id) do
raise "GameServer.Friends.list_blocked_for_user/1 is a stub - only available at runtime on GameServer"
end
@doc ~S"""
List blocked friendships for a user (Friendship structs where the user is the blocker / target).
"""
def list_blocked_for_user(_user_id, _opts) do
raise "GameServer.Friends.list_blocked_for_user/2 is a stub - only available at runtime on GameServer"
end
@doc ~S"""
List accepted friends for a given user id - returns list of User structs.
## Options
See `t:GameServer.Types.pagination_opts/0` for available options.
"""
def list_friends_for_user(_user_id) do
raise "GameServer.Friends.list_friends_for_user/1 is a stub - only available at runtime on GameServer"
end
@doc ~S"""
List accepted friends for a given user id - returns list of User structs.
## Options
See `t:GameServer.Types.pagination_opts/0` for available options.
"""
@spec list_friends_for_user(
integer() | GameServer.Accounts.User.t(),
GameServer.Types.pagination_opts()
) :: [GameServer.Accounts.User.t()]
def list_friends_for_user(_user_id, _opts) do
raise "GameServer.Friends.list_friends_for_user/2 is a stub - only available at runtime on GameServer"
end
@doc ~S"""
List incoming pending friend requests for a user (Friendship structs).
## Options
See `t:GameServer.Types.pagination_opts/0` for available options.
"""
def list_incoming_requests(_user_id) do
raise "GameServer.Friends.list_incoming_requests/1 is a stub - only available at runtime on GameServer"
end
@doc ~S"""
List incoming pending friend requests for a user (Friendship structs).
## Options
See `t:GameServer.Types.pagination_opts/0` for available options.
"""
@spec list_incoming_requests(
integer() | GameServer.Accounts.User.t(),
GameServer.Types.pagination_opts()
) :: [GameServer.Friends.Friendship.t()]
def list_incoming_requests(_user_id, _opts) do
raise "GameServer.Friends.list_incoming_requests/2 is a stub - only available at runtime on GameServer"
end
@doc ~S"""
List outgoing pending friend requests for a user (Friendship structs).
## Options
See `t:GameServer.Types.pagination_opts/0` for available options.
"""
def list_outgoing_requests(_user_id) do
raise "GameServer.Friends.list_outgoing_requests/1 is a stub - only available at runtime on GameServer"
end
@doc ~S"""
List outgoing pending friend requests for a user (Friendship structs).
## Options
See `t:GameServer.Types.pagination_opts/0` for available options.
"""
@spec list_outgoing_requests(
integer() | GameServer.Accounts.User.t(),
GameServer.Types.pagination_opts()
) :: [GameServer.Friends.Friendship.t()]
def list_outgoing_requests(_user_id, _opts) do
raise "GameServer.Friends.list_outgoing_requests/2 is a stub - only available at runtime on GameServer"
end
@doc ~S"""
Reject a friend request (only the target may reject). Returns {:ok, friendship}.
"""
@spec reject_friend_request(integer(), GameServer.Accounts.User.t()) ::
{:ok, GameServer.Friends.Friendship.t()} | {:error, term()}
def reject_friend_request(_friendship_id, _user) do
raise "GameServer.Friends.reject_friend_request/2 is a stub - only available at runtime on GameServer"
end
@doc ~S"""
Remove a friendship (either direction) - only participating users may call this.
"""
@spec remove_friend(integer(), integer()) :: {:ok, GameServer.Friends.Friendship.t()} | {:error, term()}
def remove_friend(_user_id, _friend_id) do
raise "GameServer.Friends.remove_friend/2 is a stub - only available at runtime on GameServer"
end
@doc false
def subscribe_user(_user_id) do
raise "GameServer.Friends.subscribe_user/1 is a stub - only available at runtime on GameServer"
end
@doc ~S"""
Unblock a previously-blocked friendship (only the user who blocked may unblock). Returns {:ok, :unblocked} on success.
"""
@spec unblock_friendship(integer(), GameServer.Accounts.User.t()) ::
{:ok, :unblocked} | {:error, term()}
def unblock_friendship(_friendship_id, _user) do
raise "GameServer.Friends.unblock_friendship/2 is a stub - only available at runtime on GameServer"
end
@doc false
def unsubscribe_user(_user_id) do
raise "GameServer.Friends.unsubscribe_user/1 is a stub - only available at runtime on GameServer"
end
end