@amityco/ts-sdk
Version:
Amity Social Cloud Typescript SDK
56 lines • 2.51 kB
TypeScript
/**
* Session-scoped singleton engine that manages TTL-based fetching and caching
* of blocking users (the "blocked-by" list — users who blocked the current
* user). Provides a lazy `ensureFetched()` gate for the `getAllBlockingUsers()`
* API. Directional inverse of {@link BlockedUserSyncEngine}.
*
* Key behaviours:
* - `onSessionEstablished()` is a no-op — fetch is lazy, triggered only by consumer call
* - `onSessionDestroyed()` resets `lastFetchedAt` to null (ensures fresh fetch on next session)
* - `ensureFetched()` fetches from server only when cache is expired or never fetched
* - `lastFetchedAt` is only updated on successful fetch
* - reads query the follow cache live, so block/unblock changes are reflected
* even within the TTL window
*
* @internal
*/
declare class BlockingUserSyncEngine {
/** Epoch ms of last successful fetch. null = never fetched in this session. */
private lastFetchedAt;
/** No-op — fetch is lazy, triggered by consumer calling getAllBlockingUsers(). */
onSessionEstablished(): void;
/** Resets state so the next session starts with a cold cache. */
onSessionDestroyed(): void;
/** No-op for this engine. */
onTokenExpired(): void;
private isCacheExpired;
/**
* Ensures the local store is populated with fresh blocking-user data.
*
* - If the cache is still within the 5-minute TTL window: resolves immediately
* (no server call).
* - If the cache is expired (or never fetched): fetches from the server,
* persists the payload to the cache, and updates `lastFetchedAt`.
*
* On failure the error propagates to the caller and `lastFetchedAt` is NOT
* updated, so the next call will retry.
*/
ensureFetched(): Promise<void>;
/**
* Returns the "blocked-by" users by querying the follow cache live — the
* incoming direction (`to === me`, `status === 'blocked'`). Reading the cache
* (not a fetched snapshot) means RTE `user.didBlock` / `user.didUnblock`
* changes are reflected even within the TTL window.
*
* Applies the spec-mandated query (REQ-012/013/014):
* - filter `to === currentUserId`, `status === 'blocked'`, blocker not deleted
* - sort by `updatedAt` DESC
* - hard limit of 100 results
*/
getCachedUsers(): Amity.User[];
}
declare const _default: {
getInstance: () => BlockingUserSyncEngine;
};
export default _default;
//# sourceMappingURL=blockingUserSyncEngine.d.ts.map