Documentation
¶
Index ¶
- Constants
- Variables
- func AddFriend(ctx context.Context, pool *pgxpool.Pool, sourceID, destinationID string) error
- func AddFriendWithOpts(ctx context.Context, pool *pgxpool.Pool, ...) error
- func AddGroupUsers(ctx context.Context, pool *pgxpool.Pool, callerID, groupID string, ...) error
- func BanGroupUsers(ctx context.Context, pool *pgxpool.Pool, callerID, groupID string, ...) error
- func BlockUser(ctx context.Context, pool *pgxpool.Pool, sourceID, destinationID string) error
- func DeleteFriend(ctx context.Context, pool *pgxpool.Pool, sourceID, destinationID string, ...) error
- func DeleteGroup(ctx context.Context, pool *pgxpool.Pool, callerID, id string) error
- func DemoteMember(ctx context.Context, pool *pgxpool.Pool, kickerID, userID, groupID string) error
- func FetchFacebookFriendIDs(ctx context.Context, accessToken string) ([]string, error)
- func FetchSteamFriendIDs(ctx context.Context, publisherKey, steamID string) ([]string, error)
- func FriendMetadataUpdate(ctx context.Context, pool *pgxpool.Pool, userID, friendID string, ...) error
- func GetUserRole(ctx context.Context, pool *pgxpool.Pool, userID, groupID string) (int, error)
- func ImportFacebookFriends(ctx context.Context, pool *pgxpool.Pool, userID, username, token string, ...) error
- func ImportFriendsFromProviderIDs(ctx context.Context, pool *pgxpool.Pool, userID, username, column string, ...) error
- func ImportSteamFriends(ctx context.Context, pool *pgxpool.Pool, userID, username, steamToken string, ...) error
- func IsGroupMember(ctx context.Context, pool *pgxpool.Pool, userID, groupID string) (bool, error)
- func JoinGroup(ctx context.Context, pool *pgxpool.Pool, userID, groupID string, ...) error
- func KickMember(ctx context.Context, pool *pgxpool.Pool, kickerID, userID, groupID string) error
- func LeaveGroup(ctx context.Context, pool *pgxpool.Pool, userID, groupID string) error
- func ParseLegacyPositionCursor(cursor string) int64
- func PromoteMember(ctx context.Context, pool *pgxpool.Pool, kickerID, userID, groupID string) error
- func ResolveUserIDs(ctx context.Context, pool *pgxpool.Pool, ids, usernames []string) ([]string, error)
- func UnblockUser(ctx context.Context, pool *pgxpool.Pool, sourceID, destinationID string) error
- func UpdateGroup(ctx context.Context, pool *pgxpool.Pool, ...) error
- func UpdateGroupMaxCount(ctx context.Context, pool *pgxpool.Pool, id string, maxCount int) error
- func UserExistsAndDoesNotBlock(ctx context.Context, pool *pgxpool.Pool, checkUserID, blocksUserID string) (bool, error)
- func UsersGetFriendStatus(ctx context.Context, pool *pgxpool.Pool, userID string, friendIDs []string) (map[string]int, error)
- type ChannelBroadcaster
- type Config
- type CreateGroupParams
- type FacebookFriendProfile
- type Friend
- type FriendNotifier
- type FriendOfFriend
- type FriendUser
- type Group
- func CreateGroup(ctx context.Context, pool *pgxpool.Pool, ...) (*Group, error)
- func CreateGroupWithParams(ctx context.Context, pool *pgxpool.Pool, creatorID string, p CreateGroupParams) (*Group, error)
- func GroupsGetID(ctx context.Context, pool *pgxpool.Pool, ids []string) ([]*Group, error)
- func GroupsGetRandom(ctx context.Context, pool *pgxpool.Pool, count int) ([]*Group, error)
- func ListGroups(ctx context.Context, pool *pgxpool.Pool, name, langTag string, open *bool, ...) ([]*Group, string, error)
- type GroupMember
- type NoopNotifier
- type SteamFriendProfile
- type UserGroupRelation
Constants ¶
const ( StateFriend = 0 StateInviteSent = 1 StateInviteReceived = 2 StateBlocked = 3 )
FriendState represents the states of a social edge.
const ( NotificationCodeFriendRequest = -2 NotificationCodeFriendAccept = -3 NotificationCodeFriendImport = -1001 // UGE extension (Facebook/Steam import); -6 reserved for FriendJoinGame NotificationCodeFriendRemove = -9 )
Notification codes for friend events (reference-engine aligned).
const ( DefaultMaxFriends = 1000 DefaultMaxPending = 100 DefaultListLimit = 100 MaxListLimit = 1000 )
Default limits (PRD-07).
const ( GroupStateOpen = 0 GroupStateClosed = 1 )
GroupState represents whether a group is open or closed.
const ( RoleSuperAdmin = 0 RoleAdmin = 1 RoleMember = 2 RoleJoinRequest = 3 RoleBanned = 4 )
GroupMemberState represents the membership roles.
const ( NotificationCodeGroupAdd = -4 NotificationCodeGroupJoinRequest = -5 )
Group notification codes (reference-engine aligned).
const ( GroupChannelMsgJoin int16 = 3 GroupChannelMsgAdd int16 = 4 GroupChannelMsgLeave int16 = 5 GroupChannelMsgKick int16 = 6 GroupChannelMsgPromote int16 = 7 GroupChannelMsgBan int16 = 8 GroupChannelMsgDemote int16 = 9 )
Group channel message codes (ADR-0013 / reference-aligned).
Variables ¶
var ( ErrCannotAddSelf = errors.New("cannot add yourself as friend") ErrCannotBlockSelf = errors.New("cannot block yourself") ErrFriendLimitReached = errors.New("friend count limit reached") ErrPendingLimitReached = errors.New("pending friend request limit reached") ErrInvalidCursor = errors.New("invalid friends cursor") )
var ImportHTTPClient = &http.Client{Timeout: 15 * time.Second}
ImportHTTPClient is overridable for tests.
Functions ¶
func AddFriendWithOpts ¶
func AddFriendWithOpts(ctx context.Context, pool *pgxpool.Pool, sourceID, destinationID, metadata string, cfg Config, notifier FriendNotifier) error
AddFriendWithOpts is AddFriend with metadata, limits, and notifier.
func AddGroupUsers ¶
func AddGroupUsers(ctx context.Context, pool *pgxpool.Pool, callerID, groupID string, userIDs []string, notifier FriendNotifier) error
AddGroupUsers adds users as members or accepts join requests (admin+). Empty callerID = authoritative.
func BanGroupUsers ¶
func BanGroupUsers(ctx context.Context, pool *pgxpool.Pool, callerID, groupID string, userIDs []string) error
BanGroupUsers bans users: remove membership edges; insert unidirectional group→user state 4.
func DeleteFriend ¶
func DeleteFriend(ctx context.Context, pool *pgxpool.Pool, sourceID, destinationID string, notifier FriendNotifier) error
DeleteFriend deletes friend relationships, rejects invites, or unblocks.
func DeleteGroup ¶
DeleteGroup soft-disables a group (superadmin). Empty callerID = authoritative hard cleanup of edges + disable.
func DemoteMember ¶
DemoteMember lowers a user's role one step toward member.
func FetchFacebookFriendIDs ¶
FetchFacebookFriendIDs retrieves Facebook friend IDs for the given access token.
func FetchSteamFriendIDs ¶
FetchSteamFriendIDs retrieves Steam friend IDs for the given steam user.
func FriendMetadataUpdate ¶
func FriendMetadataUpdate(ctx context.Context, pool *pgxpool.Pool, userID, friendID string, metadata map[string]any) error
FriendMetadataUpdate updates edge metadata for source→destination.
func GetUserRole ¶
GetUserRole retrieves the role of a user in a group.
func ImportFacebookFriends ¶
func ImportFacebookFriends(ctx context.Context, pool *pgxpool.Pool, userID, username, token string, reset bool, notifier FriendNotifier) error
ImportFacebookFriends imports Facebook friends matching existing users.
func ImportFriendsFromProviderIDs ¶
func ImportFriendsFromProviderIDs(ctx context.Context, pool *pgxpool.Pool, userID, username, column string, providerIDs []string, provider string, reset bool, notifier FriendNotifier) error
ImportFriendsFromProviderIDs is a test helper that skips external HTTP and matches by column.
func ImportSteamFriends ¶
func ImportSteamFriends(ctx context.Context, pool *pgxpool.Pool, userID, username, steamToken string, reset bool, notifier FriendNotifier) error
ImportSteamFriends imports Steam friends matching existing users.
func IsGroupMember ¶
IsGroupMember reports whether user has membership state <= RoleMember.
func JoinGroup ¶
func JoinGroup(ctx context.Context, pool *pgxpool.Pool, userID, groupID string, notifier FriendNotifier) error
JoinGroup joins an open group or queues a join request for a closed group.
func KickMember ¶
KickMember removes a user from a group if kicker has proper authority. Also used to reject join requests (state 3) without changing edge_count.
func LeaveGroup ¶
LeaveGroup removes a member from a group.
func ParseLegacyPositionCursor ¶
ParseLegacyPositionCursor parses a legacy integer position cursor.
func PromoteMember ¶
PromoteMember raises a user's role (member→admin→superadmin) one step.
func ResolveUserIDs ¶
func ResolveUserIDs(ctx context.Context, pool *pgxpool.Pool, ids, usernames []string) ([]string, error)
ResolveUserIDs resolves usernames to IDs and merges with provided IDs.
func UnblockUser ¶
UnblockUser removes a block edge (same as delete when only block exists).
func UpdateGroup ¶
func UpdateGroup(ctx context.Context, pool *pgxpool.Pool, callerID, id, name, description, avatarURL, langTag string, open bool, metadata string) error
UpdateGroup updates group metadata; callerID empty = authoritative.
func UpdateGroupMaxCount ¶
UpdateGroupMaxCount sets max_count (runtime/console).
Types ¶
type ChannelBroadcaster ¶
type ChannelBroadcaster interface {
BroadcastGroupChannelMessage(ctx context.Context, groupID string, code int16, content, senderID, username string)
}
ChannelBroadcaster emits group lifecycle events onto the group chat stream.
var DefaultChannelBroadcaster ChannelBroadcaster = noopChannelBroadcaster{}
DefaultChannelBroadcaster is set by the API/socket layer at startup.
type CreateGroupParams ¶
type CreateGroupParams struct {
Name string
Description string
AvatarURL string
LangTag string
Metadata string
Open bool
MaxCount int
}
CreateGroupParams configures group creation.
type FacebookFriendProfile ¶
FacebookFriendProfile is a minimal Facebook friend profile.
type Friend ¶
type Friend struct {
User FriendUser
State int
UpdateTime time.Time
Metadata string
Position int64
}
Friend represents a friend record with edge metadata.
func GetFriends ¶
GetFriends returns all active mutual friends of a user.
type FriendNotifier ¶
type FriendNotifier interface {
Notify(ctx context.Context, userID, subject, content string, code int16, senderID string) error
}
FriendNotifier dispatches friend-related notifications.
var DefaultNotifier FriendNotifier = NoopNotifier{}
DefaultNotifier is used when callers pass nil.
type FriendOfFriend ¶
type FriendOfFriend struct {
Referrer string
User FriendUser
}
FriendOfFriend is a friends-of-friends discovery result.
type FriendUser ¶
type FriendUser struct {
ID string
Username string
DisplayName string
AvatarURL string
LangTag string
Location string
Timezone string
Metadata string
CreateTime time.Time
UpdateTime time.Time
EdgeCount int32
}
FriendUser holds profile fields returned in friend lists.
type Group ¶
type Group struct {
ID string
CreatorID string
Name string
Description string
AvatarURL string
LangTag string
Metadata string
State int
EdgeCount int
MaxCount int
CreateTime time.Time
UpdateTime time.Time
DisableTime time.Time
}
Group represents a guild/clan record.
func CreateGroup ¶
func CreateGroup(ctx context.Context, pool *pgxpool.Pool, creatorID, name, description, avatarURL, langTag string) (*Group, error)
CreateGroup creates a new group and designates the creator as SuperAdmin. Legacy helper: open=true, max_count=100.
func CreateGroupWithParams ¶
func CreateGroupWithParams(ctx context.Context, pool *pgxpool.Pool, creatorID string, p CreateGroupParams) (*Group, error)
CreateGroupWithParams creates a group with full options.
func GroupsGetID ¶
GroupsGetID returns groups by IDs (active only).
func GroupsGetRandom ¶
GroupsGetRandom returns up to count random active groups.
type GroupMember ¶
type NoopNotifier ¶
type NoopNotifier struct{}
NoopNotifier is a no-op FriendNotifier used in tests.
type SteamFriendProfile ¶
type SteamFriendProfile struct {
SteamID uint64 `json:"steamid"`
}
SteamFriendProfile is a minimal Steam friend profile.