snapcap
API ReferenceClasses

Friends

Class: Friends

Defined in: api/friends/manager.ts:57

Concrete IFriendsManager implementation.

Constructed once per SnapcapClient and held as SnapcapClient.friends. See IFriendsManager for the full method-level documentation.

See

IFriendsManager

Implements

Methods

acceptRequest()

acceptRequest(userId: string): Promise<void>;

Defined in: api/friends/manager.ts:108

Accept an incoming friend request.

Equivalent on the wire to IFriendsMutations.sendRequest with source: ADDED_BY_ADDED_ME_BACK — the SPA path. Surfaced as a named verb because the inbox flow has its own consumer mental model; acceptRequest(req.fromUserId) reads more clearly than sendRequest(req.fromUserId, { source: 4 }).

Parameters

ParameterTypeDescription
userIdstringHyphenated UUID of the requester whose request to accept (the fromUserId field on a ReceivedRequest).

Returns

Promise<void>

Implementation of

IFriendsManager.acceptRequest


block()

block(userId: string): Promise<void>;

Defined in: api/friends/manager.ts:98

Block a user — also removes any existing friend link.

Parameters

ParameterTypeDescription
userIdstringHyphenated UUID of the user to block.

Returns

Promise<void>

Implementation of

IFriendsManager.block


getUsers()

getUsers(userIds: string[], opts?: {
  refresh?: boolean;
}): Promise<FriendsUser[]>;

Defined in: api/friends/manager.ts:145

Resolve a list of user IDs to User records (username + display name).

Cache-first: each ID is looked up in the bundle's state.user.publicUsers cache; only IDs that miss are sent to Snap's GetSnapchatterPublicInfo. Pass { refresh: true } to force a fresh RPC for every ID.

Parameters

ParameterTypeDescription
userIdsstring[]Hyphenated UUIDs to resolve.
opts?{ refresh?: boolean; }refresh: true re-fetches all IDs, ignoring the cache. Defaults to cache-first.
opts.refresh?boolean-

Returns

Promise<FriendsUser[]>

Resolved User records in the same order as userIds. IDs the server returned no record for (deleted accounts, blocks) appear with notFound: true.

Implementation of

IFriendsManager.getUsers


list()

list(): Promise<Friend[]>;

Defined in: api/friends/manager.ts:130

All friends in the logged-in user's social graph (excluding self).

Returns

Promise<Friend[]>

Mutually-confirmed friends as Friend records.

Implementation of

IFriendsManager.list


on()

on<K>(
   event: K, 
   cb: FriendsEvents[K], 
   opts?: {
  signal?: AbortSignal;
}): Subscription;

Defined in: api/friends/manager.ts:168

Subscribe to a typed friends event. Returns a Subscription — call it to unsubscribe, or use sub.signal to tie the subscription's life to anything that takes an AbortSignal.

Type Parameters

Type ParameterDescription
K extends keyof FriendsEvents

Parameters

ParameterTypeDescription
eventKEvent name from FriendsEvents.
cbFriendsEvents[K]Callback fired with the event payload (type narrows on event).
opts?{ signal?: AbortSignal; }Optional signal — when the passed AbortSignal aborts, the subscription is torn down automatically. The returned sub.signal reflects the combined lifetime (fires on either path).
opts.signal?AbortSignal-

Returns

Subscription

A Subscription — a callable unsubscribe thunk with .signal attached.

Implementation of

IFriendsManager.on


onChange()

onChange(cb: (snap: FriendsSnapshot) => void): Unsubscribe;

Defined in: api/friends/manager.ts:163

Fire cb whenever any part of the friend graph changes — mutuals, incoming requests, or outgoing requests.

The callback receives a full FriendsSnapshot reflecting the new state. Initial state is NOT replayed — call snapshot() once after subscribing if you need a baseline.

Parameters

ParameterTypeDescription
cb(snap: FriendsSnapshot) => voidSubscriber invoked with the latest snapshot on every relevant change.

Returns

Unsubscribe

An Unsubscribe thunk; idempotent on repeat calls.

Implementation of

IFriendsManager.onChange


receivedRequests()

receivedRequests(): Promise<ReceivedRequest[]>;

Defined in: api/friends/manager.ts:135

All pending received friend requests.

Returns

Promise<ReceivedRequest[]>

Inbound ReceivedRequest records waiting for accept / reject / ignore.

Implementation of

IFriendsManager.receivedRequests


refresh()

refresh(): Promise<void>;

Defined in: api/friends/manager.ts:125

Force an explicit re-sync from the server — pulls the latest mutuals

  • outgoing requests (via SyncFriendData) AND incoming requests (via IncomingFriendSync).

Returns

Promise<void>

Remarks

The bundle does NOT auto-poll for fresh state — the SPA's React layer normally drives that cadence, and we don't load React. So consumers who want event subscriptions like IFriendsSubscriptions.on("request:received") to actually fire must drive their own refresh cadence. Common patterns:

  • Call refresh() in a setInterval (every 10–30s for inbox-style monitoring, every 60s+ for less time-sensitive use cases).
  • Call refresh() on demand right before a snapshot read.

Best-effort — failures are swallowed (the existing userSlice.syncFriends pattern). Subsequent reads return whatever is in cache.

Implementation of

IFriendsManager.refresh


rejectRequest()

rejectRequest(userId: string): Promise<void>;

Defined in: api/friends/manager.ts:113

Reject (ignore) an incoming friend request.

Maps to Snap's IgnoreFriends RPC — the same path the SPA's "Ignore" button uses. Once rejected, the request disappears from IFriendsReads.receivedRequests.

Parameters

ParameterTypeDescription
userIdstringHyphenated UUID of the requester whose request to reject (the fromUserId field on a ReceivedRequest).

Returns

Promise<void>

Implementation of

IFriendsManager.rejectRequest


remove()

remove(userId: string): Promise<void>;

Defined in: api/friends/manager.ts:93

Remove a friend from the social graph.

Parameters

ParameterTypeDescription
userIdstringHyphenated UUID of the friend to remove.

Returns

Promise<void>

Remarks

Why this doesn't work: Snap's web SPA itself doesn't expose "Remove Friend" anywhere in its UI — friend mutations like remove, block, and unblock are restricted to the mobile clients (iOS / Android) and the server enforces this at the policy layer. We verified empirically:

  • The request reaches the server: RemoveFriends → 200 grpc=0.
  • The body encodes correctly (we tested with empty pageSessionId, a random UUID, and the real sc-a-nonce session cookie value — all yield the same outcome).
  • The bundle's chat module never calls RemoveFriends from any code path — the SPA's right-click menu on a friend chat shows only Message Notifications, Delete Chats, Clear from Chat Feed.
  • After the call, friends.list() still returns the supposedly-removed account as mutual on both sides (we tested symmetric removes too).

What does work: IFriendsMutations.sendRequest (web supports AddFriends), IFriendsMutations.acceptRequest, IFriendsMutations.rejectRequest.

Workarounds: none from web. To actually unfriend an account, the user must do it from the official mobile app.

Implementation of

IFriendsManager.remove


search(query: string): Promise<FriendsUser[]>;

Defined in: api/friends/manager.ts:150

Search Snap's user index by username / display-name fragment.

Parameters

ParameterTypeDescription
querystringFree-text query — Snap's "Add Friends" search box matches both usernames and display names, with prefix and substring weighting.

Returns

Promise<FriendsUser[]>

A list of matching User records. Empty when query is empty or no users match.

Implementation of

IFriendsManager.search


sendRequest()

sendRequest(userId: string, opts?: {
  source?: FriendSource;
}): Promise<void>;

Defined in: api/friends/manager.ts:88

Send a friend request / add a user to the friend list.

Resolves once the server acknowledges.

Parameters

ParameterTypeDescription
userIdstringHyphenated UUID of the user to add.
opts?{ source?: FriendSource; }Advanced overrides; ignore for the common case. The one knob is source — anti-spam attribution context (mirrors what the SPA stamps on the request to identify which UI surface triggered the add). Defaults to FriendSource.ADDED_BY_USERNAME. Override only if you're explicitly mimicking a different UX flow (QR-code add, deep-link add, etc.).
opts.source?FriendSource-

Returns

Promise<void>

Implementation of

IFriendsManager.sendRequest


sentRequests()

sentRequests(): Promise<SentRequest[]>;

Defined in: api/friends/manager.ts:140

All pending sent friend requests (the logged-in user's adds waiting for the recipient to accept).

Returns

Promise<SentRequest[]>

Outbound SentRequest records.

Implementation of

IFriendsManager.sentRequests


snapshot()

snapshot(): Promise<FriendsSnapshot>;

Defined in: api/friends/manager.ts:120

Canonical point-in-time view of the friend graph — mutuals + pending requests in both directions.

Returns

Promise<FriendsSnapshot>

A FriendsSnapshot with all three slots populated.

Remarks

The split read accessors (IFriendsReads.list, IFriendsReads.receivedRequests, IFriendsReads.sentRequests) all project from this.

Implementation of

IFriendsManager.snapshot


unblock()

unblock(userId: string): Promise<void>;

Defined in: api/friends/manager.ts:103

Unblock a previously-blocked user.

Parameters

ParameterTypeDescription
userIdstringHyphenated UUID of the user to unblock.

Returns

Promise<void>

Implementation of

IFriendsManager.unblock

On this page