@amityco/ts-sdk 7.33.2-74d47a9.0 → 7.33.2-840ee4f3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/api/setupLoginSubscriptions.d.ts.map +1 -1
- package/dist/index.cjs.js +201 -5
- package/dist/index.esm.js +201 -5
- package/dist/index.umd.js +1 -1
- package/dist/userRepository/api/getAllFollowers.d.ts +19 -0
- package/dist/userRepository/api/getAllFollowers.d.ts.map +1 -0
- package/dist/userRepository/api/getAllFollowings.d.ts +21 -0
- package/dist/userRepository/api/getAllFollowings.d.ts.map +1 -0
- package/dist/userRepository/api/index.d.ts +2 -0
- package/dist/userRepository/api/index.d.ts.map +1 -1
- package/dist/userRepository/api/tests/integration/getAllFollowers.integration.test.d.ts +2 -0
- package/dist/userRepository/api/tests/integration/getAllFollowers.integration.test.d.ts.map +1 -0
- package/dist/userRepository/services/FollowUserSyncEngine/followUserSyncEngine.d.ts +60 -0
- package/dist/userRepository/services/FollowUserSyncEngine/followUserSyncEngine.d.ts.map +1 -0
- package/dist/userRepository/services/FollowUserSyncEngine/followUserSyncEngineOnLoginHandler.d.ts +3 -0
- package/dist/userRepository/services/FollowUserSyncEngine/followUserSyncEngineOnLoginHandler.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setupLoginSubscriptions.d.ts","sourceRoot":"","sources":["../../../src/client/api/setupLoginSubscriptions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"setupLoginSubscriptions.d.ts","sourceRoot":"","sources":["../../../src/client/api/setupLoginSubscriptions.ts"],"names":[],"mappings":"AA2BA;;;;;;;;GAQG;AACH,eAAO,MAAM,uBAAuB,iBAAkB,MAAM,YAAY,KAAG,MAAM,YAAY,EAoE5F,CAAC"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -7945,7 +7945,7 @@ function prepareBlockedUserPayload(response) {
|
|
|
7945
7945
|
}
|
|
7946
7946
|
|
|
7947
7947
|
const BLOCK_LIST_LIMIT$1 = 100;
|
|
7948
|
-
const TTL_MS$
|
|
7948
|
+
const TTL_MS$2 = 5 * 60 * 1000; // 5 minutes
|
|
7949
7949
|
/**
|
|
7950
7950
|
* Session-scoped singleton engine that manages TTL-based fetching and caching
|
|
7951
7951
|
* of blocked users. Provides a lazy `ensureFetched()` gate for the
|
|
@@ -7983,7 +7983,7 @@ class BlockedUserSyncEngine {
|
|
|
7983
7983
|
isCacheExpired() {
|
|
7984
7984
|
if (this.lastFetchedAt === null)
|
|
7985
7985
|
return true;
|
|
7986
|
-
return Date.now() - this.lastFetchedAt > TTL_MS$
|
|
7986
|
+
return Date.now() - this.lastFetchedAt > TTL_MS$2;
|
|
7987
7987
|
}
|
|
7988
7988
|
/**
|
|
7989
7989
|
* Ensures the local store is populated with fresh blocked-user data.
|
|
@@ -8074,7 +8074,7 @@ function prepareBlockingUserPayload(response) {
|
|
|
8074
8074
|
}
|
|
8075
8075
|
|
|
8076
8076
|
const BLOCK_LIST_LIMIT = 100;
|
|
8077
|
-
const TTL_MS = 5 * 60 * 1000; // 5 minutes
|
|
8077
|
+
const TTL_MS$1 = 5 * 60 * 1000; // 5 minutes
|
|
8078
8078
|
/**
|
|
8079
8079
|
* Session-scoped singleton engine that manages TTL-based fetching and caching
|
|
8080
8080
|
* of blocking users (the "blocked-by" list — users who blocked the current
|
|
@@ -8113,7 +8113,7 @@ class BlockingUserSyncEngine {
|
|
|
8113
8113
|
isCacheExpired() {
|
|
8114
8114
|
if (this.lastFetchedAt === null)
|
|
8115
8115
|
return true;
|
|
8116
|
-
return Date.now() - this.lastFetchedAt > TTL_MS;
|
|
8116
|
+
return Date.now() - this.lastFetchedAt > TTL_MS$1;
|
|
8117
8117
|
}
|
|
8118
8118
|
/**
|
|
8119
8119
|
* Ensures the local store is populated with fresh blocking-user data.
|
|
@@ -8208,6 +8208,138 @@ function prepareFollowStatusPayload(response) {
|
|
|
8208
8208
|
return Object.assign(Object.assign({}, rest), { follows });
|
|
8209
8209
|
}
|
|
8210
8210
|
|
|
8211
|
+
const FOLLOW_LIST_LIMIT = 100;
|
|
8212
|
+
const TTL_MS = 5 * 60 * 1000; // 5 minutes
|
|
8213
|
+
const ENDPOINTS = {
|
|
8214
|
+
followers: '/api/v4/me/followers',
|
|
8215
|
+
followings: '/api/v4/me/following',
|
|
8216
|
+
};
|
|
8217
|
+
/**
|
|
8218
|
+
* Session-scoped singleton engine that manages TTL-based fetching and caching
|
|
8219
|
+
* of the current user's accepted followers or followings. Provides a lazy
|
|
8220
|
+
* `ensureFetched()` gate for the `getAllFollowers()` / `getAllFollowings()` APIs.
|
|
8221
|
+
*
|
|
8222
|
+
* Key behaviours:
|
|
8223
|
+
* - `onSessionEstablished()` is a no-op — fetch is lazy, triggered only by consumer call
|
|
8224
|
+
* - `onSessionDestroyed()` resets `lastFetchedAt` to null (ensures fresh fetch on next session)
|
|
8225
|
+
* - `ensureFetched()` fetches from server only when cache is expired or never fetched
|
|
8226
|
+
* - `lastFetchedAt` is only updated on successful fetch
|
|
8227
|
+
* - reads query the follow cache live, so follow / unfollow / remove-follower
|
|
8228
|
+
* changes are reflected even within the TTL window
|
|
8229
|
+
*
|
|
8230
|
+
* @internal
|
|
8231
|
+
*/
|
|
8232
|
+
class FollowUserSyncEngine {
|
|
8233
|
+
constructor(direction) {
|
|
8234
|
+
/** Epoch ms of last successful fetch. null = never fetched in this session. */
|
|
8235
|
+
this.lastFetchedAt = null;
|
|
8236
|
+
this.direction = direction;
|
|
8237
|
+
}
|
|
8238
|
+
/** No-op — fetch is lazy, triggered by consumer calling the API. */
|
|
8239
|
+
// eslint-disable-next-line class-methods-use-this
|
|
8240
|
+
onSessionEstablished() {
|
|
8241
|
+
// intentionally empty
|
|
8242
|
+
}
|
|
8243
|
+
/** Resets state so the next session starts with a cold cache. */
|
|
8244
|
+
onSessionDestroyed() {
|
|
8245
|
+
this.lastFetchedAt = null;
|
|
8246
|
+
}
|
|
8247
|
+
/** No-op for this engine. */
|
|
8248
|
+
// eslint-disable-next-line class-methods-use-this
|
|
8249
|
+
onTokenExpired() {
|
|
8250
|
+
// intentionally empty
|
|
8251
|
+
}
|
|
8252
|
+
isCacheExpired() {
|
|
8253
|
+
if (this.lastFetchedAt === null)
|
|
8254
|
+
return true;
|
|
8255
|
+
return Date.now() - this.lastFetchedAt > TTL_MS;
|
|
8256
|
+
}
|
|
8257
|
+
/**
|
|
8258
|
+
* Ensures the local store is populated with fresh follow data.
|
|
8259
|
+
*
|
|
8260
|
+
* - If the cache is still within the 5-minute TTL window: resolves immediately
|
|
8261
|
+
* (no server call).
|
|
8262
|
+
* - If the cache is expired (or never fetched): fetches the first page
|
|
8263
|
+
* (limit 100) of accepted follows, persists the payload to the cache, and
|
|
8264
|
+
* updates `lastFetchedAt`.
|
|
8265
|
+
*
|
|
8266
|
+
* On failure the error propagates to the caller and `lastFetchedAt` is NOT
|
|
8267
|
+
* updated, so the next call will retry.
|
|
8268
|
+
*/
|
|
8269
|
+
async ensureFetched() {
|
|
8270
|
+
if (!this.isCacheExpired())
|
|
8271
|
+
return;
|
|
8272
|
+
const client = getActiveClient();
|
|
8273
|
+
const { data } = await client.http.get(ENDPOINTS[this.direction], { params: { status: 'accepted', options: { limit: FOLLOW_LIST_LIMIT }, isDeleted: false } });
|
|
8274
|
+
const cachedAt = client.cache && Date.now();
|
|
8275
|
+
if (client.cache) {
|
|
8276
|
+
ingestInCache(prepareFollowersPayload(data), { cachedAt });
|
|
8277
|
+
}
|
|
8278
|
+
// Only update timestamp on success — failure leaves it unchanged so the
|
|
8279
|
+
// next call retries.
|
|
8280
|
+
this.lastFetchedAt = Date.now();
|
|
8281
|
+
}
|
|
8282
|
+
/**
|
|
8283
|
+
* Returns the followers / followings by querying the follow cache live.
|
|
8284
|
+
*
|
|
8285
|
+
* - filter `status === 'accepted'` and the current user on the matching side
|
|
8286
|
+
* of the edge, other user not deleted
|
|
8287
|
+
* - sort by `updatedAt` DESC
|
|
8288
|
+
* - hard limit of 100 results
|
|
8289
|
+
*/
|
|
8290
|
+
getCachedUsers() {
|
|
8291
|
+
var _a;
|
|
8292
|
+
const client = getActiveClient();
|
|
8293
|
+
if (!client.cache)
|
|
8294
|
+
return [];
|
|
8295
|
+
const { userId } = client;
|
|
8296
|
+
const isFollowers = this.direction === 'followers';
|
|
8297
|
+
return ((_a = queryCache(['follow', 'get'])) !== null && _a !== void 0 ? _a : [])
|
|
8298
|
+
.map(entry => entry.data)
|
|
8299
|
+
.filter(follow => (follow === null || follow === void 0 ? void 0 : follow.status) === 'accepted' &&
|
|
8300
|
+
(isFollowers ? follow.to === userId : follow.from === userId))
|
|
8301
|
+
.sort((a, b) => { var _a, _b; return (((_a = a.updatedAt) !== null && _a !== void 0 ? _a : '') < ((_b = b.updatedAt) !== null && _b !== void 0 ? _b : '') ? 1 : -1); })
|
|
8302
|
+
.map(follow => {
|
|
8303
|
+
var _a;
|
|
8304
|
+
return (_a = pullFromCache(['user', 'get', isFollowers ? follow.from : follow.to])) === null || _a === void 0 ? void 0 : _a.data;
|
|
8305
|
+
})
|
|
8306
|
+
.filter((user) => user != null && user.isDeleted !== true)
|
|
8307
|
+
.slice(0, FOLLOW_LIST_LIMIT)
|
|
8308
|
+
.map(userLinkedObject);
|
|
8309
|
+
}
|
|
8310
|
+
}
|
|
8311
|
+
const instances = {};
|
|
8312
|
+
var FollowUserSyncEngine$1 = {
|
|
8313
|
+
getInstance: (direction) => {
|
|
8314
|
+
if (!instances[direction])
|
|
8315
|
+
instances[direction] = new FollowUserSyncEngine(direction);
|
|
8316
|
+
return instances[direction];
|
|
8317
|
+
},
|
|
8318
|
+
};
|
|
8319
|
+
|
|
8320
|
+
var followUserSyncEngineOnLoginHandler = () => {
|
|
8321
|
+
const engines = [
|
|
8322
|
+
FollowUserSyncEngine$1.getInstance('followers'),
|
|
8323
|
+
FollowUserSyncEngine$1.getInstance('followings'),
|
|
8324
|
+
];
|
|
8325
|
+
onSessionStateChange(state => {
|
|
8326
|
+
engines.forEach(engine => {
|
|
8327
|
+
if (state === "established" /* Amity.SessionStates.ESTABLISHED */) {
|
|
8328
|
+
engine.onSessionEstablished();
|
|
8329
|
+
}
|
|
8330
|
+
else if (state === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
|
|
8331
|
+
engine.onTokenExpired();
|
|
8332
|
+
}
|
|
8333
|
+
else {
|
|
8334
|
+
engine.onSessionDestroyed();
|
|
8335
|
+
}
|
|
8336
|
+
});
|
|
8337
|
+
});
|
|
8338
|
+
return () => {
|
|
8339
|
+
engines.forEach(engine => engine.onSessionDestroyed());
|
|
8340
|
+
};
|
|
8341
|
+
};
|
|
8342
|
+
|
|
8211
8343
|
/**
|
|
8212
8344
|
* Subscribes to a block MQTT event (`user.didBlock` / `user.didUnblock`),
|
|
8213
8345
|
* ingests the carried `FollowersPayload` (follows + users) into the cache so
|
|
@@ -8931,7 +9063,7 @@ const setupLoginSubscriptions = (unsubWatcher) => {
|
|
|
8931
9063
|
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
8932
9064
|
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
8933
9065
|
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
8934
|
-
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler(), blockingUserSyncEngineOnLoginHandler(), blockRealtimeOnLoginHandler(), resetAutoSubscriptionsOnLogout(), CursorController.clearOnLogout(), postCommentCountEngineOnLoginHandler(), channelActivityOnLoginHandler(), userFlagByMeOnLoginHandler());
|
|
9066
|
+
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler(), blockingUserSyncEngineOnLoginHandler(), followUserSyncEngineOnLoginHandler(), blockRealtimeOnLoginHandler(), resetAutoSubscriptionsOnLogout(), CursorController.clearOnLogout(), postCommentCountEngineOnLoginHandler(), channelActivityOnLoginHandler(), userFlagByMeOnLoginHandler());
|
|
8935
9067
|
if (client.useLegacyUnreadCount) {
|
|
8936
9068
|
subscriptions.push(readReceiptSyncEngineOnLoginHandler());
|
|
8937
9069
|
}
|
|
@@ -16309,6 +16441,68 @@ const getAllBlockingUsers = async () => {
|
|
|
16309
16441
|
};
|
|
16310
16442
|
/* end_public_function */
|
|
16311
16443
|
|
|
16444
|
+
/* begin_public_function
|
|
16445
|
+
id: user.get_all_followers
|
|
16446
|
+
*/
|
|
16447
|
+
/**
|
|
16448
|
+
* ```js
|
|
16449
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
16450
|
+
* const followers = await UserRepository.getAllFollowers()
|
|
16451
|
+
* ```
|
|
16452
|
+
*
|
|
16453
|
+
* Returns all users who follow the current user (accepted follows only) as a
|
|
16454
|
+
* non-paginated list (limit 100) with TTL-based caching (5-minute window).
|
|
16455
|
+
* Within the TTL window, subsequent calls resolve instantly from the local store
|
|
16456
|
+
* without any server call. After the TTL expires, the next call triggers a fresh
|
|
16457
|
+
* server fetch.
|
|
16458
|
+
*
|
|
16459
|
+
* @returns A promise that resolves to an array of follower {@link Amity.User} objects
|
|
16460
|
+
*
|
|
16461
|
+
* @category Follow API
|
|
16462
|
+
* @async
|
|
16463
|
+
*/
|
|
16464
|
+
const getAllFollowers = async () => {
|
|
16465
|
+
const client = getActiveClient();
|
|
16466
|
+
client.log('user/getAllFollowers');
|
|
16467
|
+
const engine = FollowUserSyncEngine$1.getInstance('followers');
|
|
16468
|
+
// Ensure data is fetched (no-op if cache is fresh)
|
|
16469
|
+
await engine.ensureFetched();
|
|
16470
|
+
return engine.getCachedUsers();
|
|
16471
|
+
};
|
|
16472
|
+
/* end_public_function */
|
|
16473
|
+
|
|
16474
|
+
/* begin_public_function
|
|
16475
|
+
id: user.get_all_followings
|
|
16476
|
+
*/
|
|
16477
|
+
/**
|
|
16478
|
+
* ```js
|
|
16479
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
16480
|
+
* const followings = await UserRepository.getAllFollowings()
|
|
16481
|
+
* ```
|
|
16482
|
+
*
|
|
16483
|
+
* Returns all users the current user follows (accepted follows only) as a
|
|
16484
|
+
* non-paginated list (limit 100) with TTL-based caching (5-minute window).
|
|
16485
|
+
* Within the TTL window, subsequent calls resolve instantly from the local store
|
|
16486
|
+
* without any server call. After the TTL expires, the next call triggers a fresh
|
|
16487
|
+
* server fetch.
|
|
16488
|
+
*
|
|
16489
|
+
* The directional inverse of {@link getAllFollowers}.
|
|
16490
|
+
*
|
|
16491
|
+
* @returns A promise that resolves to an array of followed {@link Amity.User} objects
|
|
16492
|
+
*
|
|
16493
|
+
* @category Follow API
|
|
16494
|
+
* @async
|
|
16495
|
+
*/
|
|
16496
|
+
const getAllFollowings = async () => {
|
|
16497
|
+
const client = getActiveClient();
|
|
16498
|
+
client.log('user/getAllFollowings');
|
|
16499
|
+
const engine = FollowUserSyncEngine$1.getInstance('followings');
|
|
16500
|
+
// Ensure data is fetched (no-op if cache is fresh)
|
|
16501
|
+
await engine.ensureFetched();
|
|
16502
|
+
return engine.getCachedUsers();
|
|
16503
|
+
};
|
|
16504
|
+
/* end_public_function */
|
|
16505
|
+
|
|
16312
16506
|
/**
|
|
16313
16507
|
* ```js
|
|
16314
16508
|
* import { onUserUpdated } from '@amityco/ts-sdk'
|
|
@@ -17411,6 +17605,8 @@ var index$r = /*#__PURE__*/Object.freeze({
|
|
|
17411
17605
|
isUserFlaggedByMe: isUserFlaggedByMe,
|
|
17412
17606
|
getAllBlockedUsers: getAllBlockedUsers,
|
|
17413
17607
|
getAllBlockingUsers: getAllBlockingUsers,
|
|
17608
|
+
getAllFollowers: getAllFollowers,
|
|
17609
|
+
getAllFollowings: getAllFollowings,
|
|
17414
17610
|
onUserUpdated: onUserUpdated,
|
|
17415
17611
|
onUserDeleted: onUserDeleted$2,
|
|
17416
17612
|
onUserFlagged: onUserFlagged,
|
package/dist/index.esm.js
CHANGED
|
@@ -7945,7 +7945,7 @@ function prepareBlockedUserPayload(response) {
|
|
|
7945
7945
|
}
|
|
7946
7946
|
|
|
7947
7947
|
const BLOCK_LIST_LIMIT$1 = 100;
|
|
7948
|
-
const TTL_MS$
|
|
7948
|
+
const TTL_MS$2 = 5 * 60 * 1000; // 5 minutes
|
|
7949
7949
|
/**
|
|
7950
7950
|
* Session-scoped singleton engine that manages TTL-based fetching and caching
|
|
7951
7951
|
* of blocked users. Provides a lazy `ensureFetched()` gate for the
|
|
@@ -7983,7 +7983,7 @@ class BlockedUserSyncEngine {
|
|
|
7983
7983
|
isCacheExpired() {
|
|
7984
7984
|
if (this.lastFetchedAt === null)
|
|
7985
7985
|
return true;
|
|
7986
|
-
return Date.now() - this.lastFetchedAt > TTL_MS$
|
|
7986
|
+
return Date.now() - this.lastFetchedAt > TTL_MS$2;
|
|
7987
7987
|
}
|
|
7988
7988
|
/**
|
|
7989
7989
|
* Ensures the local store is populated with fresh blocked-user data.
|
|
@@ -8074,7 +8074,7 @@ function prepareBlockingUserPayload(response) {
|
|
|
8074
8074
|
}
|
|
8075
8075
|
|
|
8076
8076
|
const BLOCK_LIST_LIMIT = 100;
|
|
8077
|
-
const TTL_MS = 5 * 60 * 1000; // 5 minutes
|
|
8077
|
+
const TTL_MS$1 = 5 * 60 * 1000; // 5 minutes
|
|
8078
8078
|
/**
|
|
8079
8079
|
* Session-scoped singleton engine that manages TTL-based fetching and caching
|
|
8080
8080
|
* of blocking users (the "blocked-by" list — users who blocked the current
|
|
@@ -8113,7 +8113,7 @@ class BlockingUserSyncEngine {
|
|
|
8113
8113
|
isCacheExpired() {
|
|
8114
8114
|
if (this.lastFetchedAt === null)
|
|
8115
8115
|
return true;
|
|
8116
|
-
return Date.now() - this.lastFetchedAt > TTL_MS;
|
|
8116
|
+
return Date.now() - this.lastFetchedAt > TTL_MS$1;
|
|
8117
8117
|
}
|
|
8118
8118
|
/**
|
|
8119
8119
|
* Ensures the local store is populated with fresh blocking-user data.
|
|
@@ -8208,6 +8208,138 @@ function prepareFollowStatusPayload(response) {
|
|
|
8208
8208
|
return Object.assign(Object.assign({}, rest), { follows });
|
|
8209
8209
|
}
|
|
8210
8210
|
|
|
8211
|
+
const FOLLOW_LIST_LIMIT = 100;
|
|
8212
|
+
const TTL_MS = 5 * 60 * 1000; // 5 minutes
|
|
8213
|
+
const ENDPOINTS = {
|
|
8214
|
+
followers: '/api/v4/me/followers',
|
|
8215
|
+
followings: '/api/v4/me/following',
|
|
8216
|
+
};
|
|
8217
|
+
/**
|
|
8218
|
+
* Session-scoped singleton engine that manages TTL-based fetching and caching
|
|
8219
|
+
* of the current user's accepted followers or followings. Provides a lazy
|
|
8220
|
+
* `ensureFetched()` gate for the `getAllFollowers()` / `getAllFollowings()` APIs.
|
|
8221
|
+
*
|
|
8222
|
+
* Key behaviours:
|
|
8223
|
+
* - `onSessionEstablished()` is a no-op — fetch is lazy, triggered only by consumer call
|
|
8224
|
+
* - `onSessionDestroyed()` resets `lastFetchedAt` to null (ensures fresh fetch on next session)
|
|
8225
|
+
* - `ensureFetched()` fetches from server only when cache is expired or never fetched
|
|
8226
|
+
* - `lastFetchedAt` is only updated on successful fetch
|
|
8227
|
+
* - reads query the follow cache live, so follow / unfollow / remove-follower
|
|
8228
|
+
* changes are reflected even within the TTL window
|
|
8229
|
+
*
|
|
8230
|
+
* @internal
|
|
8231
|
+
*/
|
|
8232
|
+
class FollowUserSyncEngine {
|
|
8233
|
+
constructor(direction) {
|
|
8234
|
+
/** Epoch ms of last successful fetch. null = never fetched in this session. */
|
|
8235
|
+
this.lastFetchedAt = null;
|
|
8236
|
+
this.direction = direction;
|
|
8237
|
+
}
|
|
8238
|
+
/** No-op — fetch is lazy, triggered by consumer calling the API. */
|
|
8239
|
+
// eslint-disable-next-line class-methods-use-this
|
|
8240
|
+
onSessionEstablished() {
|
|
8241
|
+
// intentionally empty
|
|
8242
|
+
}
|
|
8243
|
+
/** Resets state so the next session starts with a cold cache. */
|
|
8244
|
+
onSessionDestroyed() {
|
|
8245
|
+
this.lastFetchedAt = null;
|
|
8246
|
+
}
|
|
8247
|
+
/** No-op for this engine. */
|
|
8248
|
+
// eslint-disable-next-line class-methods-use-this
|
|
8249
|
+
onTokenExpired() {
|
|
8250
|
+
// intentionally empty
|
|
8251
|
+
}
|
|
8252
|
+
isCacheExpired() {
|
|
8253
|
+
if (this.lastFetchedAt === null)
|
|
8254
|
+
return true;
|
|
8255
|
+
return Date.now() - this.lastFetchedAt > TTL_MS;
|
|
8256
|
+
}
|
|
8257
|
+
/**
|
|
8258
|
+
* Ensures the local store is populated with fresh follow data.
|
|
8259
|
+
*
|
|
8260
|
+
* - If the cache is still within the 5-minute TTL window: resolves immediately
|
|
8261
|
+
* (no server call).
|
|
8262
|
+
* - If the cache is expired (or never fetched): fetches the first page
|
|
8263
|
+
* (limit 100) of accepted follows, persists the payload to the cache, and
|
|
8264
|
+
* updates `lastFetchedAt`.
|
|
8265
|
+
*
|
|
8266
|
+
* On failure the error propagates to the caller and `lastFetchedAt` is NOT
|
|
8267
|
+
* updated, so the next call will retry.
|
|
8268
|
+
*/
|
|
8269
|
+
async ensureFetched() {
|
|
8270
|
+
if (!this.isCacheExpired())
|
|
8271
|
+
return;
|
|
8272
|
+
const client = getActiveClient();
|
|
8273
|
+
const { data } = await client.http.get(ENDPOINTS[this.direction], { params: { status: 'accepted', options: { limit: FOLLOW_LIST_LIMIT }, isDeleted: false } });
|
|
8274
|
+
const cachedAt = client.cache && Date.now();
|
|
8275
|
+
if (client.cache) {
|
|
8276
|
+
ingestInCache(prepareFollowersPayload(data), { cachedAt });
|
|
8277
|
+
}
|
|
8278
|
+
// Only update timestamp on success — failure leaves it unchanged so the
|
|
8279
|
+
// next call retries.
|
|
8280
|
+
this.lastFetchedAt = Date.now();
|
|
8281
|
+
}
|
|
8282
|
+
/**
|
|
8283
|
+
* Returns the followers / followings by querying the follow cache live.
|
|
8284
|
+
*
|
|
8285
|
+
* - filter `status === 'accepted'` and the current user on the matching side
|
|
8286
|
+
* of the edge, other user not deleted
|
|
8287
|
+
* - sort by `updatedAt` DESC
|
|
8288
|
+
* - hard limit of 100 results
|
|
8289
|
+
*/
|
|
8290
|
+
getCachedUsers() {
|
|
8291
|
+
var _a;
|
|
8292
|
+
const client = getActiveClient();
|
|
8293
|
+
if (!client.cache)
|
|
8294
|
+
return [];
|
|
8295
|
+
const { userId } = client;
|
|
8296
|
+
const isFollowers = this.direction === 'followers';
|
|
8297
|
+
return ((_a = queryCache(['follow', 'get'])) !== null && _a !== void 0 ? _a : [])
|
|
8298
|
+
.map(entry => entry.data)
|
|
8299
|
+
.filter(follow => (follow === null || follow === void 0 ? void 0 : follow.status) === 'accepted' &&
|
|
8300
|
+
(isFollowers ? follow.to === userId : follow.from === userId))
|
|
8301
|
+
.sort((a, b) => { var _a, _b; return (((_a = a.updatedAt) !== null && _a !== void 0 ? _a : '') < ((_b = b.updatedAt) !== null && _b !== void 0 ? _b : '') ? 1 : -1); })
|
|
8302
|
+
.map(follow => {
|
|
8303
|
+
var _a;
|
|
8304
|
+
return (_a = pullFromCache(['user', 'get', isFollowers ? follow.from : follow.to])) === null || _a === void 0 ? void 0 : _a.data;
|
|
8305
|
+
})
|
|
8306
|
+
.filter((user) => user != null && user.isDeleted !== true)
|
|
8307
|
+
.slice(0, FOLLOW_LIST_LIMIT)
|
|
8308
|
+
.map(userLinkedObject);
|
|
8309
|
+
}
|
|
8310
|
+
}
|
|
8311
|
+
const instances = {};
|
|
8312
|
+
var FollowUserSyncEngine$1 = {
|
|
8313
|
+
getInstance: (direction) => {
|
|
8314
|
+
if (!instances[direction])
|
|
8315
|
+
instances[direction] = new FollowUserSyncEngine(direction);
|
|
8316
|
+
return instances[direction];
|
|
8317
|
+
},
|
|
8318
|
+
};
|
|
8319
|
+
|
|
8320
|
+
var followUserSyncEngineOnLoginHandler = () => {
|
|
8321
|
+
const engines = [
|
|
8322
|
+
FollowUserSyncEngine$1.getInstance('followers'),
|
|
8323
|
+
FollowUserSyncEngine$1.getInstance('followings'),
|
|
8324
|
+
];
|
|
8325
|
+
onSessionStateChange(state => {
|
|
8326
|
+
engines.forEach(engine => {
|
|
8327
|
+
if (state === "established" /* Amity.SessionStates.ESTABLISHED */) {
|
|
8328
|
+
engine.onSessionEstablished();
|
|
8329
|
+
}
|
|
8330
|
+
else if (state === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
|
|
8331
|
+
engine.onTokenExpired();
|
|
8332
|
+
}
|
|
8333
|
+
else {
|
|
8334
|
+
engine.onSessionDestroyed();
|
|
8335
|
+
}
|
|
8336
|
+
});
|
|
8337
|
+
});
|
|
8338
|
+
return () => {
|
|
8339
|
+
engines.forEach(engine => engine.onSessionDestroyed());
|
|
8340
|
+
};
|
|
8341
|
+
};
|
|
8342
|
+
|
|
8211
8343
|
/**
|
|
8212
8344
|
* Subscribes to a block MQTT event (`user.didBlock` / `user.didUnblock`),
|
|
8213
8345
|
* ingests the carried `FollowersPayload` (follows + users) into the cache so
|
|
@@ -8931,7 +9063,7 @@ const setupLoginSubscriptions = (unsubWatcher) => {
|
|
|
8931
9063
|
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
8932
9064
|
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
8933
9065
|
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
8934
|
-
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler(), blockingUserSyncEngineOnLoginHandler(), blockRealtimeOnLoginHandler(), resetAutoSubscriptionsOnLogout(), CursorController.clearOnLogout(), postCommentCountEngineOnLoginHandler(), channelActivityOnLoginHandler(), userFlagByMeOnLoginHandler());
|
|
9066
|
+
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler(), blockingUserSyncEngineOnLoginHandler(), followUserSyncEngineOnLoginHandler(), blockRealtimeOnLoginHandler(), resetAutoSubscriptionsOnLogout(), CursorController.clearOnLogout(), postCommentCountEngineOnLoginHandler(), channelActivityOnLoginHandler(), userFlagByMeOnLoginHandler());
|
|
8935
9067
|
if (client.useLegacyUnreadCount) {
|
|
8936
9068
|
subscriptions.push(readReceiptSyncEngineOnLoginHandler());
|
|
8937
9069
|
}
|
|
@@ -16309,6 +16441,68 @@ const getAllBlockingUsers = async () => {
|
|
|
16309
16441
|
};
|
|
16310
16442
|
/* end_public_function */
|
|
16311
16443
|
|
|
16444
|
+
/* begin_public_function
|
|
16445
|
+
id: user.get_all_followers
|
|
16446
|
+
*/
|
|
16447
|
+
/**
|
|
16448
|
+
* ```js
|
|
16449
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
16450
|
+
* const followers = await UserRepository.getAllFollowers()
|
|
16451
|
+
* ```
|
|
16452
|
+
*
|
|
16453
|
+
* Returns all users who follow the current user (accepted follows only) as a
|
|
16454
|
+
* non-paginated list (limit 100) with TTL-based caching (5-minute window).
|
|
16455
|
+
* Within the TTL window, subsequent calls resolve instantly from the local store
|
|
16456
|
+
* without any server call. After the TTL expires, the next call triggers a fresh
|
|
16457
|
+
* server fetch.
|
|
16458
|
+
*
|
|
16459
|
+
* @returns A promise that resolves to an array of follower {@link Amity.User} objects
|
|
16460
|
+
*
|
|
16461
|
+
* @category Follow API
|
|
16462
|
+
* @async
|
|
16463
|
+
*/
|
|
16464
|
+
const getAllFollowers = async () => {
|
|
16465
|
+
const client = getActiveClient();
|
|
16466
|
+
client.log('user/getAllFollowers');
|
|
16467
|
+
const engine = FollowUserSyncEngine$1.getInstance('followers');
|
|
16468
|
+
// Ensure data is fetched (no-op if cache is fresh)
|
|
16469
|
+
await engine.ensureFetched();
|
|
16470
|
+
return engine.getCachedUsers();
|
|
16471
|
+
};
|
|
16472
|
+
/* end_public_function */
|
|
16473
|
+
|
|
16474
|
+
/* begin_public_function
|
|
16475
|
+
id: user.get_all_followings
|
|
16476
|
+
*/
|
|
16477
|
+
/**
|
|
16478
|
+
* ```js
|
|
16479
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
16480
|
+
* const followings = await UserRepository.getAllFollowings()
|
|
16481
|
+
* ```
|
|
16482
|
+
*
|
|
16483
|
+
* Returns all users the current user follows (accepted follows only) as a
|
|
16484
|
+
* non-paginated list (limit 100) with TTL-based caching (5-minute window).
|
|
16485
|
+
* Within the TTL window, subsequent calls resolve instantly from the local store
|
|
16486
|
+
* without any server call. After the TTL expires, the next call triggers a fresh
|
|
16487
|
+
* server fetch.
|
|
16488
|
+
*
|
|
16489
|
+
* The directional inverse of {@link getAllFollowers}.
|
|
16490
|
+
*
|
|
16491
|
+
* @returns A promise that resolves to an array of followed {@link Amity.User} objects
|
|
16492
|
+
*
|
|
16493
|
+
* @category Follow API
|
|
16494
|
+
* @async
|
|
16495
|
+
*/
|
|
16496
|
+
const getAllFollowings = async () => {
|
|
16497
|
+
const client = getActiveClient();
|
|
16498
|
+
client.log('user/getAllFollowings');
|
|
16499
|
+
const engine = FollowUserSyncEngine$1.getInstance('followings');
|
|
16500
|
+
// Ensure data is fetched (no-op if cache is fresh)
|
|
16501
|
+
await engine.ensureFetched();
|
|
16502
|
+
return engine.getCachedUsers();
|
|
16503
|
+
};
|
|
16504
|
+
/* end_public_function */
|
|
16505
|
+
|
|
16312
16506
|
/**
|
|
16313
16507
|
* ```js
|
|
16314
16508
|
* import { onUserUpdated } from '@amityco/ts-sdk'
|
|
@@ -17411,6 +17605,8 @@ var index$r = /*#__PURE__*/Object.freeze({
|
|
|
17411
17605
|
isUserFlaggedByMe: isUserFlaggedByMe,
|
|
17412
17606
|
getAllBlockedUsers: getAllBlockedUsers,
|
|
17413
17607
|
getAllBlockingUsers: getAllBlockingUsers,
|
|
17608
|
+
getAllFollowers: getAllFollowers,
|
|
17609
|
+
getAllFollowings: getAllFollowings,
|
|
17414
17610
|
onUserUpdated: onUserUpdated,
|
|
17415
17611
|
onUserDeleted: onUserDeleted$2,
|
|
17416
17612
|
onUserFlagged: onUserFlagged,
|