@amityco/ts-sdk 7.33.1 → 7.33.2-1e78722.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.
Files changed (52) hide show
  1. package/dist/@types/core/payload.d.ts +4 -0
  2. package/dist/@types/core/payload.d.ts.map +1 -1
  3. package/dist/@types/domains/content.d.ts +5 -0
  4. package/dist/@types/domains/content.d.ts.map +1 -1
  5. package/dist/@types/domains/feed.d.ts +14 -0
  6. package/dist/@types/domains/feed.d.ts.map +1 -1
  7. package/dist/@types/domains/follow.d.ts +7 -0
  8. package/dist/@types/domains/follow.d.ts.map +1 -1
  9. package/dist/@types/domains/notification.d.ts +15 -3
  10. package/dist/@types/domains/notification.d.ts.map +1 -1
  11. package/dist/client/api/getFeedSettings.d.ts +3 -1
  12. package/dist/client/api/getFeedSettings.d.ts.map +1 -1
  13. package/dist/client/api/setupLoginSubscriptions.d.ts.map +1 -1
  14. package/dist/feedRepository/index.d.ts +1 -1
  15. package/dist/feedRepository/index.d.ts.map +1 -1
  16. package/dist/feedRepository/observers/getFollowingFeed/LiveCollectionController.d.ts +13 -0
  17. package/dist/feedRepository/observers/getFollowingFeed/LiveCollectionController.d.ts.map +1 -0
  18. package/dist/feedRepository/observers/getFollowingFeed/PaginationController.d.ts +10 -0
  19. package/dist/feedRepository/observers/getFollowingFeed/PaginationController.d.ts.map +1 -0
  20. package/dist/feedRepository/observers/getFollowingFeed/QueryStreamController.d.ts +22 -0
  21. package/dist/feedRepository/observers/getFollowingFeed/QueryStreamController.d.ts.map +1 -0
  22. package/dist/feedRepository/observers/getFollowingFeed.d.ts +35 -0
  23. package/dist/feedRepository/observers/getFollowingFeed.d.ts.map +1 -0
  24. package/dist/feedRepository/observers/index.d.ts +1 -0
  25. package/dist/feedRepository/observers/index.d.ts.map +1 -1
  26. package/dist/feedRepository/observers/tests/integration/getFollowingFeed.integration.test.d.ts +2 -0
  27. package/dist/feedRepository/observers/tests/integration/getFollowingFeed.integration.test.d.ts.map +1 -0
  28. package/dist/feedRepository/observers/tests/unit/FollowingFeedQueryStreamController.test.d.ts +2 -0
  29. package/dist/feedRepository/observers/tests/unit/FollowingFeedQueryStreamController.test.d.ts.map +1 -0
  30. package/dist/index.cjs.js +697 -261
  31. package/dist/index.esm.js +628 -192
  32. package/dist/index.umd.js +2 -2
  33. package/dist/userRepository/relationship/block/api/blockUser.d.ts.map +1 -1
  34. package/dist/userRepository/relationship/follow/api/follow.d.ts.map +1 -1
  35. package/dist/userRepository/relationship/follow/api/getAllFollowings.d.ts +34 -0
  36. package/dist/userRepository/relationship/follow/api/getAllFollowings.d.ts.map +1 -0
  37. package/dist/userRepository/relationship/follow/api/index.d.ts +1 -0
  38. package/dist/userRepository/relationship/follow/api/index.d.ts.map +1 -1
  39. package/dist/userRepository/relationship/follow/api/tests/getAllFollowings.test.d.ts +2 -0
  40. package/dist/userRepository/relationship/follow/api/tests/getAllFollowings.test.d.ts.map +1 -0
  41. package/dist/userRepository/relationship/follow/api/tests/integration/getAllFollowings.integration.test.d.ts +2 -0
  42. package/dist/userRepository/relationship/follow/api/tests/integration/getAllFollowings.integration.test.d.ts.map +1 -0
  43. package/dist/userRepository/relationship/follow/api/unfollow.d.ts.map +1 -1
  44. package/dist/userRepository/services/FollowingSyncEngine/followRealtimeOnLoginHandler.d.ts +19 -0
  45. package/dist/userRepository/services/FollowingSyncEngine/followRealtimeOnLoginHandler.d.ts.map +1 -0
  46. package/dist/userRepository/services/FollowingSyncEngine/followingSyncEngine.d.ts +61 -0
  47. package/dist/userRepository/services/FollowingSyncEngine/followingSyncEngine.d.ts.map +1 -0
  48. package/dist/userRepository/services/FollowingSyncEngine/followingSyncEngineOnLoginHandler.d.ts +3 -0
  49. package/dist/userRepository/services/FollowingSyncEngine/followingSyncEngineOnLoginHandler.d.ts.map +1 -0
  50. package/dist/utils/constants.d.ts +1 -0
  51. package/dist/utils/constants.d.ts.map +1 -1
  52. package/package.json +1 -1
package/dist/index.cjs.js CHANGED
@@ -262,6 +262,14 @@ exports.FeedSortByEnum = void 0;
262
262
  FeedSortByEnum["LastUpdated"] = "lastUpdated";
263
263
  FeedSortByEnum["FirstUpdated"] = "firstUpdated";
264
264
  })(exports.FeedSortByEnum || (exports.FeedSortByEnum = {}));
265
+ /** Sort order of the following feed (`GET /api/v1/me/following-feeds`). */
266
+ exports.FollowingFeedSortByEnum = void 0;
267
+ (function (FollowingFeedSortByEnum) {
268
+ /** Server-ranked. The backend default when `sortBy` is not sent. */
269
+ FollowingFeedSortByEnum["CustomRanking"] = "customRanking";
270
+ /** Newest first. */
271
+ FollowingFeedSortByEnum["LastCreated"] = "lastCreated";
272
+ })(exports.FollowingFeedSortByEnum || (exports.FollowingFeedSortByEnum = {}));
265
273
  exports.FeedSourceEnum = void 0;
266
274
  (function (FeedSourceEnum) {
267
275
  FeedSourceEnum["Community"] = "community";
@@ -390,6 +398,7 @@ const YEAR = 365 * DAY;
390
398
  const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
391
399
  const API_ENDPOINTS = {
392
400
  forYouFeed: '/api/v1/feeds/for-you',
401
+ followingFeed: '/api/v1/me/following-feeds',
393
402
  commentReviewQueue: (communityId) => `/api/v3/communities/${encodeURIComponent(communityId)}/comments/review-queue`,
394
403
  };
395
404
  // The review-queue route defaults to 10, not the SDK-wide page size, and caps at 100
@@ -1983,13 +1992,13 @@ class SessionWatcher {
1983
1992
  this._listener.clear();
1984
1993
  }
1985
1994
  }
1986
- let instance$b;
1995
+ let instance$c;
1987
1996
  var SessionWatcher$1 = {
1988
1997
  getInstance: () => {
1989
- if (!instance$b) {
1990
- instance$b = new SessionWatcher();
1998
+ if (!instance$c) {
1999
+ instance$c = new SessionWatcher();
1991
2000
  }
1992
- return instance$b;
2001
+ return instance$c;
1993
2002
  },
1994
2003
  };
1995
2004
 
@@ -2656,13 +2665,13 @@ class NetworkActivitiesWatcher {
2656
2665
  this._listener.clear();
2657
2666
  }
2658
2667
  }
2659
- let instance$a;
2668
+ let instance$b;
2660
2669
  var NetworkActivitiesWatcher$1 = {
2661
2670
  getInstance: () => {
2662
- if (!instance$a) {
2663
- instance$a = new NetworkActivitiesWatcher();
2671
+ if (!instance$b) {
2672
+ instance$b = new NetworkActivitiesWatcher();
2664
2673
  }
2665
- return instance$a;
2674
+ return instance$b;
2666
2675
  },
2667
2676
  };
2668
2677
 
@@ -2923,11 +2932,11 @@ class AutoSubscriptionManager {
2923
2932
  this.seed();
2924
2933
  }
2925
2934
  }
2926
- let instance$9 = null;
2935
+ let instance$a = null;
2927
2936
  const getAutoSubscriptionManager = () => {
2928
- if (!instance$9)
2929
- instance$9 = new AutoSubscriptionManager();
2930
- return instance$9;
2937
+ if (!instance$a)
2938
+ instance$a = new AutoSubscriptionManager();
2939
+ return instance$a;
2931
2940
  };
2932
2941
  /** Resets the registry to its default baseline when the session ends. */
2933
2942
  const resetAutoSubscriptionsOnLogout = () => onSessionStateChange(state => {
@@ -6257,9 +6266,11 @@ const validateTexts = async (texts) => {
6257
6266
  * import { getFeedSettings } from '@amityco/ts-sdk'
6258
6267
  * const feedSettings = await getFeedSettings()
6259
6268
  * const postFeedSetting = feedSettings.post
6269
+ * const isAutoPlayEnabled = postFeedSetting?.find(({ contentType }) => contentType === 'video')?.autoPlay
6260
6270
  * ```
6261
6271
  *
6262
- * Fetches a {@link Amity.FeedSettings} object
6272
+ * Fetches a {@link Amity.FeedSettings} object. Video content settings always
6273
+ * carry `autoPlay`, which is `false` when the server omits it.
6263
6274
  *
6264
6275
  * @returns A Promise of {@link Amity.FeedSettings} object
6265
6276
  *
@@ -6270,7 +6281,14 @@ const getFeedSettings = async () => {
6270
6281
  const client = getActiveClient();
6271
6282
  const { data } = await client.http.get(`/api/v3/network-settings/feed-setting`);
6272
6283
  return Object.fromEntries(data.feedSettings.map(({ feedType, contentSettings }) => {
6273
- return [feedType, contentSettings];
6284
+ return [
6285
+ feedType,
6286
+ contentSettings === null || contentSettings === void 0 ? void 0 : contentSettings.map(setting => {
6287
+ var _a;
6288
+ return setting.contentType === 'video'
6289
+ ? Object.assign(Object.assign({}, setting), { autoPlay: (_a = setting.autoPlay) !== null && _a !== void 0 ? _a : false }) : setting;
6290
+ }),
6291
+ ];
6274
6292
  }));
6275
6293
  };
6276
6294
 
@@ -7001,13 +7019,13 @@ class AnalyticsEngine {
7001
7019
  this._eventCapturer.resetAllBuckets();
7002
7020
  }
7003
7021
  }
7004
- let instance$8;
7022
+ let instance$9;
7005
7023
  var AnalyticsEngine$1 = {
7006
7024
  getInstance: () => {
7007
- if (!instance$8) {
7008
- instance$8 = new AnalyticsEngine();
7025
+ if (!instance$9) {
7026
+ instance$9 = new AnalyticsEngine();
7009
7027
  }
7010
- return instance$8;
7028
+ return instance$9;
7011
7029
  },
7012
7030
  };
7013
7031
 
@@ -7234,12 +7252,12 @@ class MessageReadReceiptSyncEngine {
7234
7252
  }
7235
7253
  }
7236
7254
  }
7237
- let instance$7 = null;
7255
+ let instance$8 = null;
7238
7256
  var ReadReceiptSyncEngine = {
7239
7257
  getInstance: () => {
7240
- if (!instance$7)
7241
- instance$7 = new MessageReadReceiptSyncEngine();
7242
- return instance$7;
7258
+ if (!instance$8)
7259
+ instance$8 = new MessageReadReceiptSyncEngine();
7260
+ return instance$8;
7243
7261
  },
7244
7262
  };
7245
7263
 
@@ -7493,12 +7511,12 @@ class LegacyMessageReadReceiptSyncEngine {
7493
7511
  }
7494
7512
  }
7495
7513
  }
7496
- let instance$6 = null;
7514
+ let instance$7 = null;
7497
7515
  var LegacyReadReceiptSyncEngine = {
7498
7516
  getInstance: () => {
7499
- if (!instance$6)
7500
- instance$6 = new LegacyMessageReadReceiptSyncEngine();
7501
- return instance$6;
7517
+ if (!instance$7)
7518
+ instance$7 = new LegacyMessageReadReceiptSyncEngine();
7519
+ return instance$7;
7502
7520
  },
7503
7521
  };
7504
7522
 
@@ -7744,12 +7762,12 @@ class ObjectResolverEngine {
7744
7762
  this.stopResolver();
7745
7763
  }
7746
7764
  }
7747
- let instance$5 = null;
7765
+ let instance$6 = null;
7748
7766
  var ObjectResolverEngine$1 = {
7749
7767
  getInstance: () => {
7750
- if (!instance$5)
7751
- instance$5 = new ObjectResolverEngine();
7752
- return instance$5;
7768
+ if (!instance$6)
7769
+ instance$6 = new ObjectResolverEngine();
7770
+ return instance$6;
7753
7771
  },
7754
7772
  };
7755
7773
 
@@ -7899,13 +7917,13 @@ class LiveReactionSyncEngine {
7899
7917
  this.stopReactionsSync();
7900
7918
  }
7901
7919
  }
7902
- let instance$4;
7920
+ let instance$5;
7903
7921
  var ReactionSyncEngine = {
7904
7922
  getInstance: () => {
7905
- if (!instance$4) {
7906
- instance$4 = new LiveReactionSyncEngine();
7923
+ if (!instance$5) {
7924
+ instance$5 = new LiveReactionSyncEngine();
7907
7925
  }
7908
- return instance$4;
7926
+ return instance$5;
7909
7927
  },
7910
7928
  };
7911
7929
 
@@ -7936,7 +7954,7 @@ function prepareBlockedUserPayload(response) {
7936
7954
  }
7937
7955
 
7938
7956
  const BLOCK_LIST_LIMIT$1 = 100;
7939
- const TTL_MS$1 = 5 * 60 * 1000; // 5 minutes
7957
+ const TTL_MS$2 = 5 * 60 * 1000; // 5 minutes
7940
7958
  /**
7941
7959
  * Session-scoped singleton engine that manages TTL-based fetching and caching
7942
7960
  * of blocked users. Provides a lazy `ensureFetched()` gate for the
@@ -7974,7 +7992,7 @@ class BlockedUserSyncEngine {
7974
7992
  isCacheExpired() {
7975
7993
  if (this.lastFetchedAt === null)
7976
7994
  return true;
7977
- return Date.now() - this.lastFetchedAt > TTL_MS$1;
7995
+ return Date.now() - this.lastFetchedAt > TTL_MS$2;
7978
7996
  }
7979
7997
  /**
7980
7998
  * Ensures the local store is populated with fresh blocked-user data.
@@ -8029,12 +8047,12 @@ class BlockedUserSyncEngine {
8029
8047
  .map(userLinkedObject);
8030
8048
  }
8031
8049
  }
8032
- let instance$3 = null;
8050
+ let instance$4 = null;
8033
8051
  var BlockedUserSyncEngine$1 = {
8034
8052
  getInstance: () => {
8035
- if (!instance$3)
8036
- instance$3 = new BlockedUserSyncEngine();
8037
- return instance$3;
8053
+ if (!instance$4)
8054
+ instance$4 = new BlockedUserSyncEngine();
8055
+ return instance$4;
8038
8056
  },
8039
8057
  };
8040
8058
 
@@ -8065,7 +8083,7 @@ function prepareBlockingUserPayload(response) {
8065
8083
  }
8066
8084
 
8067
8085
  const BLOCK_LIST_LIMIT = 100;
8068
- const TTL_MS = 5 * 60 * 1000; // 5 minutes
8086
+ const TTL_MS$1 = 5 * 60 * 1000; // 5 minutes
8069
8087
  /**
8070
8088
  * Session-scoped singleton engine that manages TTL-based fetching and caching
8071
8089
  * of blocking users (the "blocked-by" list — users who blocked the current
@@ -8104,7 +8122,7 @@ class BlockingUserSyncEngine {
8104
8122
  isCacheExpired() {
8105
8123
  if (this.lastFetchedAt === null)
8106
8124
  return true;
8107
- return Date.now() - this.lastFetchedAt > TTL_MS;
8125
+ return Date.now() - this.lastFetchedAt > TTL_MS$1;
8108
8126
  }
8109
8127
  /**
8110
8128
  * Ensures the local store is populated with fresh blocking-user data.
@@ -8159,12 +8177,12 @@ class BlockingUserSyncEngine {
8159
8177
  .map(userLinkedObject);
8160
8178
  }
8161
8179
  }
8162
- let instance$2 = null;
8180
+ let instance$3 = null;
8163
8181
  var BlockingUserSyncEngine$1 = {
8164
8182
  getInstance: () => {
8165
- if (!instance$2)
8166
- instance$2 = new BlockingUserSyncEngine();
8167
- return instance$2;
8183
+ if (!instance$3)
8184
+ instance$3 = new BlockingUserSyncEngine();
8185
+ return instance$3;
8168
8186
  },
8169
8187
  };
8170
8188
 
@@ -8274,6 +8292,336 @@ var blockRealtimeOnLoginHandler = () => {
8274
8292
  return () => disposers.forEach(dispose => dispose());
8275
8293
  };
8276
8294
 
8295
+ const TTL_MS = 5 * 60 * 1000; // 5 minutes, as BlockedUserSyncEngine
8296
+ const isKept = (status) => status === 'accepted' || status === 'pending';
8297
+ /**
8298
+ * Session-scoped singleton engine behind `getAllFollowings()`: a 5-minute fetch gate
8299
+ * on `GET /api/v4/me/following-ids`, copied from BlockedUserSyncEngine.
8300
+ *
8301
+ * - `onSessionEstablished()` is a no-op — the fetch is lazy, on the first call
8302
+ * - `onSessionDestroyed()` resets `lastFetchedAt` and empties the list, so the next
8303
+ * session fetches again
8304
+ * - `ensureFetched()` fetches only when the window expired or nothing was fetched yet;
8305
+ * `lastFetchedAt` moves only on success
8306
+ * - the answer holds ids and statuses only, so the engine keeps it in memory — user id →
8307
+ * status — replaced on each fetch, never merged: a follow removed on another device
8308
+ * drops out at the next fetch. Nothing is written to the follow or user cache.
8309
+ * - `onFollowChanged()` applies every follow change of the session by its status; a change
8310
+ * that arrives while a fetch is in flight is replayed on top of the answer, so the older
8311
+ * answer does not drop it. Concurrent calls share one in-flight fetch.
8312
+ *
8313
+ * @internal
8314
+ */
8315
+ class FollowingSyncEngine {
8316
+ constructor() {
8317
+ /** Epoch ms of the last successful fetch. null = never fetched in this session. */
8318
+ this.lastFetchedAt = null;
8319
+ /** user id → status, in order: the session's changes first, then the answer's order. */
8320
+ this.followings = new Map();
8321
+ /** Bumped on sign-out, so a fetch from the old session cannot fill the new one. */
8322
+ this.session = 0;
8323
+ /** The in-flight fetch, shared by concurrent calls. */
8324
+ this.fetching = null;
8325
+ /** Changes applied while `fetching` is in flight, replayed on top of its answer. */
8326
+ this.changesDuringFetch = [];
8327
+ }
8328
+ /** No-op — the fetch is lazy, triggered by getAllFollowings(). */
8329
+ // eslint-disable-next-line class-methods-use-this
8330
+ onSessionEstablished() {
8331
+ // intentionally empty
8332
+ }
8333
+ /** Resets the window so the next session starts with a fresh fetch. */
8334
+ onSessionDestroyed() {
8335
+ this.lastFetchedAt = null;
8336
+ this.followings = new Map();
8337
+ this.fetching = null;
8338
+ this.changesDuringFetch = [];
8339
+ this.session += 1;
8340
+ }
8341
+ /** No-op — the window does not depend on the token. */
8342
+ // eslint-disable-next-line class-methods-use-this
8343
+ onTokenExpired() {
8344
+ // intentionally empty
8345
+ }
8346
+ /**
8347
+ * Called for every follow change the SDK sees during the session. A follow whose
8348
+ * `from` is another user is ignored. Status `accepted` or `pending` sets the user with
8349
+ * that status and moves them to the front; any other status (`none` after an unfollow,
8350
+ * a cancel, a decline or a removed follower; `blocked`) removes them.
8351
+ */
8352
+ onFollowChanged(follow) {
8353
+ if (!follow || follow.from !== getActiveClient().userId)
8354
+ return;
8355
+ if (this.fetching)
8356
+ this.changesDuringFetch.push(follow);
8357
+ this.apply(follow);
8358
+ }
8359
+ apply(follow) {
8360
+ const rest = [...this.followings].filter(([userId]) => userId !== follow.to);
8361
+ this.followings = new Map(isKept(follow.status) ? [[follow.to, follow.status], ...rest] : rest);
8362
+ }
8363
+ isCacheExpired() {
8364
+ if (this.lastFetchedAt === null)
8365
+ return true;
8366
+ return Date.now() - this.lastFetchedAt > TTL_MS;
8367
+ }
8368
+ /**
8369
+ * Fetches whom the user follows (up to 5,000 ids and statuses, one response, no
8370
+ * `status` so both accepted and pending come back) when the window has expired. A
8371
+ * failure propagates and leaves the window and the list unchanged, so the next call
8372
+ * retries.
8373
+ */
8374
+ async ensureFetched() {
8375
+ if (!this.isCacheExpired())
8376
+ return;
8377
+ if (!this.fetching) {
8378
+ const { session } = this;
8379
+ this.changesDuringFetch = [];
8380
+ this.fetching = this.fetch(session).finally(() => {
8381
+ if (session !== this.session)
8382
+ return;
8383
+ this.fetching = null;
8384
+ this.changesDuringFetch = [];
8385
+ });
8386
+ }
8387
+ await this.fetching;
8388
+ }
8389
+ async fetch(session) {
8390
+ var _a;
8391
+ const client = getActiveClient();
8392
+ const { data } = await client.http.get('/api/v4/me/following-ids');
8393
+ if (session !== this.session)
8394
+ return; // signed out while in flight
8395
+ // replaced, never merged
8396
+ this.followings = new Map(((_a = data === null || data === void 0 ? void 0 : data.follows) !== null && _a !== void 0 ? _a : [])
8397
+ .filter(follow => isKept(follow.status))
8398
+ .map(follow => [follow.userId, follow.status]));
8399
+ // a change made while the request was in flight is newer than the answer
8400
+ this.changesDuringFetch.forEach(change => this.apply(change));
8401
+ this.lastFetchedAt = Date.now();
8402
+ }
8403
+ /** The kept entries, in order. */
8404
+ getFollowings() {
8405
+ return [...this.followings].map(([userId, status]) => ({ userId, status }));
8406
+ }
8407
+ }
8408
+ let instance$2 = null;
8409
+ var FollowingSyncEngine$1 = {
8410
+ getInstance: () => {
8411
+ if (!instance$2)
8412
+ instance$2 = new FollowingSyncEngine();
8413
+ return instance$2;
8414
+ },
8415
+ };
8416
+
8417
+ var followingSyncEngineOnLoginHandler = () => {
8418
+ const followingSyncEngine = FollowingSyncEngine$1.getInstance();
8419
+ onSessionStateChange(state => {
8420
+ if (state === "established" /* Amity.SessionStates.ESTABLISHED */) {
8421
+ followingSyncEngine.onSessionEstablished();
8422
+ }
8423
+ else if (state === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
8424
+ followingSyncEngine.onTokenExpired();
8425
+ }
8426
+ else {
8427
+ followingSyncEngine.onSessionDestroyed();
8428
+ }
8429
+ });
8430
+ return () => {
8431
+ followingSyncEngine.onSessionDestroyed();
8432
+ };
8433
+ };
8434
+
8435
+ const createFollowEventSubscriber = (event, callback) => {
8436
+ const client = getActiveClient();
8437
+ const filter = (data) => {
8438
+ const payload = prepareFollowersPayload(data);
8439
+ if (!client.cache) {
8440
+ callback(payload.follows[0]);
8441
+ }
8442
+ else {
8443
+ ingestInCache(payload);
8444
+ callback(payload.follows[0]);
8445
+ }
8446
+ };
8447
+ return createEventSubscriber(client, event, event, filter);
8448
+ };
8449
+ const createLocalFollowEventSubscriber = (event, callback) => {
8450
+ const client = getActiveClient();
8451
+ const filter = (data) => {
8452
+ const payload = prepareFollowStatusPayload(data);
8453
+ if (!client.cache) {
8454
+ callback(payload.follows[0]);
8455
+ }
8456
+ else {
8457
+ ingestInCache(payload);
8458
+ callback(payload.follows[0]);
8459
+ }
8460
+ };
8461
+ return createEventSubscriber(client, event, event, filter);
8462
+ };
8463
+
8464
+ /**
8465
+ * ```js
8466
+ * import { onUserFollowed } from '@amityco/ts-sdk'
8467
+ * const dispose = onUserFollowed(status => {
8468
+ * // ...
8469
+ * })
8470
+ * ```
8471
+ *
8472
+ * Fired when a user follows another users and confirmation is not required
8473
+ *
8474
+ * @param callback The function to call when the event was fired
8475
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
8476
+ *
8477
+ * @category Follow Events
8478
+ */
8479
+ const onUserFollowed = (callback) => createFollowEventSubscriber('follow.created', callback);
8480
+
8481
+ /**
8482
+ * ```js
8483
+ * import { onFollowerRequested } from '@amityco/ts-sdk'
8484
+ * const dispose = onFollowerRequested(status => {
8485
+ * // ...
8486
+ * })
8487
+ * ```
8488
+ *
8489
+ * Fired when a user follows another users and confirmation is required
8490
+ *
8491
+ * @param callback The function to call when the event was fired
8492
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
8493
+ *
8494
+ * @category Follow Events
8495
+ */
8496
+ const onFollowerRequested = (callback) => createFollowEventSubscriber('follow.requested', callback);
8497
+
8498
+ /**
8499
+ * ```js
8500
+ * import { onFollowRequestAccepted } from '@amityco/ts-sdk'
8501
+ * const dispose = onFollowRequestAccepted(status => {
8502
+ * // ...
8503
+ * })
8504
+ * ```
8505
+ *
8506
+ * Fired when a follow request has been accepted
8507
+ *
8508
+ * @param callback The function to call when the event was fired
8509
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
8510
+ *
8511
+ * @category Follow Events
8512
+ */
8513
+ const onFollowRequestAccepted = (callback) => createFollowEventSubscriber('follow.accepted', callback);
8514
+
8515
+ /**
8516
+ * ```js
8517
+ * import { onUserUnfollowed } from '@amityco/ts-sdk'
8518
+ * const dispose = onUserFollowed(status => {
8519
+ * // ...
8520
+ * })
8521
+ * ```
8522
+ *
8523
+ * Fired when a user unfollows
8524
+ *
8525
+ * @param callback The function to call when the event was fired
8526
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
8527
+ *
8528
+ * @category Follow Events
8529
+ */
8530
+ const onUserUnfollowed = (callback) => createFollowEventSubscriber('follow.unfollowed', callback);
8531
+
8532
+ /**
8533
+ * ```js
8534
+ * import { onFollowRequestCanceled } from '@amityco/ts-sdk'
8535
+ * const dispose = onFollowRequestCanceled(status => {
8536
+ * // ...
8537
+ * })
8538
+ * ```
8539
+ *
8540
+ * Fired when a follow request has been canceled
8541
+ *
8542
+ * @param callback The function to call when the event was fired
8543
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
8544
+ *
8545
+ * @category Follow Events
8546
+ */
8547
+ const onFollowRequestCanceled = (callback) => createFollowEventSubscriber('follow.requestCanceled', callback);
8548
+
8549
+ /**
8550
+ * ```js
8551
+ * import { onFollowRequestDeclined } from '@amityco/ts-sdk'
8552
+ * const dispose = onFollowRequestDeclined(status => {
8553
+ * // ...
8554
+ * })
8555
+ * ```
8556
+ *
8557
+ * Fired when a follow request has been declined
8558
+ *
8559
+ * @param callback The function to call when the event was fired
8560
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
8561
+ *
8562
+ * @category Follow Events
8563
+ */
8564
+ const onFollowRequestDeclined = (callback) => createFollowEventSubscriber('follow.requestDeclined', callback);
8565
+
8566
+ /**
8567
+ * ```js
8568
+ * import { onFollowerDeleted } from '@amityco/ts-sdk'
8569
+ * const dispose = onFollowerDeleted(status => {
8570
+ * // ...
8571
+ * })
8572
+ * ```
8573
+ *
8574
+ * Fired when a follower has been deleted
8575
+ *
8576
+ * @param callback The function to call when the event was fired
8577
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
8578
+ *
8579
+ * @category Follow Events
8580
+ */
8581
+ const onFollowerDeleted = (callback) => createFollowEventSubscriber('follow.followerDeleted', callback);
8582
+
8583
+ const onLocalUserFollowed = (callback) => createLocalFollowEventSubscriber('local.follow.created', callback);
8584
+
8585
+ const onLocalFollowerRequested = (callback) => createLocalFollowEventSubscriber('local.follow.requested', callback);
8586
+
8587
+ const onLocalUserUnfollowed = (callback) => createLocalFollowEventSubscriber('local.follow.unfollowed', callback);
8588
+
8589
+ // Each event file directly, not the events barrel: the barrel's onFollowInfoUpdated imports
8590
+ /**
8591
+ * Keeps `getAllFollowings()` current for the whole session: every follow change — from
8592
+ * this device (local echo) or another (MQTT) — goes to `FollowingSyncEngine.onFollowChanged`,
8593
+ * which ignores follows of other users and applies the rest by status: a follow adds the
8594
+ * user as accepted, a request as pending, an accepted request turns accepted, and an
8595
+ * unfollow, a canceled or declined request, a removed follower or a block takes the user out.
8596
+ * `blockUser` also calls the engine itself: its local event swaps `from` and `to`.
8597
+ * `user.didBlock` is read here rather than through `onUserDidBlock`, which passes on only
8598
+ * the payload's first follow: every follow in it goes to the engine, as on Android and iOS,
8599
+ * so the signed-in user's block is applied wherever it sits in the payload.
8600
+ * The MQTT events arrive on the followers and followings topics of the BLOCK
8601
+ * auto-subscription (on by default).
8602
+ *
8603
+ * Registered via `setupLoginSubscriptions`; the returned unsubscriber is torn
8604
+ * down on logout.
8605
+ */
8606
+ var followRealtimeOnLoginHandler = () => {
8607
+ const engine = FollowingSyncEngine$1.getInstance();
8608
+ const apply = (follow) => engine.onFollowChanged(follow);
8609
+ const disposers = [
8610
+ onUserFollowed(apply),
8611
+ onFollowerRequested(apply),
8612
+ onFollowRequestAccepted(apply),
8613
+ onUserUnfollowed(apply),
8614
+ onFollowRequestCanceled(apply),
8615
+ onFollowRequestDeclined(apply),
8616
+ onFollowerDeleted(apply),
8617
+ createEventSubscriber(getActiveClient(), 'user.didBlock', 'user.didBlock', payload => { var _a; return ((_a = payload === null || payload === void 0 ? void 0 : payload.follows) !== null && _a !== void 0 ? _a : []).forEach(apply); }),
8618
+ onLocalUserFollowed(apply),
8619
+ onLocalFollowerRequested(apply),
8620
+ onLocalUserUnfollowed(apply),
8621
+ ];
8622
+ return () => disposers.forEach(dispose => dispose());
8623
+ };
8624
+
8277
8625
  class CursorController {
8278
8626
  constructor(networkId, userId) {
8279
8627
  this.networkId = networkId;
@@ -8922,7 +9270,7 @@ const setupLoginSubscriptions = (unsubWatcher) => {
8922
9270
  // NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
8923
9271
  // the channel because currently backend can't handle this, so every time a user is banned from
8924
9272
  // a channel or the channel is deleted the channel's unread count will not be reset to zero
8925
- onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler(), blockingUserSyncEngineOnLoginHandler(), blockRealtimeOnLoginHandler(), resetAutoSubscriptionsOnLogout(), CursorController.clearOnLogout(), postCommentCountEngineOnLoginHandler(), channelActivityOnLoginHandler(), userFlagByMeOnLoginHandler());
9273
+ onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler(), blockingUserSyncEngineOnLoginHandler(), blockRealtimeOnLoginHandler(), followingSyncEngineOnLoginHandler(), followRealtimeOnLoginHandler(), resetAutoSubscriptionsOnLogout(), CursorController.clearOnLogout(), postCommentCountEngineOnLoginHandler(), channelActivityOnLoginHandler(), userFlagByMeOnLoginHandler());
8926
9274
  if (client.useLegacyUnreadCount) {
8927
9275
  subscriptions.push(readReceiptSyncEngineOnLoginHandler());
8928
9276
  }
@@ -11251,6 +11599,14 @@ const blockUser = async (userId) => {
11251
11599
  };
11252
11600
  const payload = prepareFollowStatusPayload(blockedUnfollowStatus);
11253
11601
  fireEvent('local.follow.unfollowed', payload);
11602
+ // the local event above swaps from and to, so getAllFollowings() cannot see this block in it
11603
+ if (client.userId) {
11604
+ FollowingSyncEngine$1.getInstance().onFollowChanged({
11605
+ from: client.userId,
11606
+ to: userId,
11607
+ status: 'blocked',
11608
+ });
11609
+ }
11254
11610
  return data;
11255
11611
  };
11256
11612
  /* end_public_function */
@@ -11315,6 +11671,8 @@ const follow = async (userId) => {
11315
11671
  ingestInCache(data, { cachedAt });
11316
11672
  }
11317
11673
  const payload = prepareFollowStatusPayload(data);
11674
+ // at once: the local event below is delivered on a later tick
11675
+ FollowingSyncEngine$1.getInstance().onFollowChanged(data.follows[0]);
11318
11676
  if (data.follows[0].status === 'accepted') {
11319
11677
  fireEvent('local.follow.created', payload);
11320
11678
  }
@@ -11326,245 +11684,144 @@ const follow = async (userId) => {
11326
11684
  cachedAt,
11327
11685
  };
11328
11686
  };
11329
- /* end_public_function */
11330
-
11331
- /* begin_public_function
11332
- id: user.relationship.unfollow
11333
- */
11334
- /**
11335
- * ```js
11336
- * import { unfollow } from '@amityco/ts-sdk'
11337
- * await unfollow('foobar')
11338
- * ```
11339
- *
11340
- * Cancel the follow request or unfollow the user
11341
- *
11342
- * @param userId the ID of the {@link Amity.InternalUser}
11343
- * @returns A success boolean if the user {@link Amity.InternalUser} was unfollowed
11344
- *
11345
- * @category Follow API
11346
- * @async
11347
- */
11348
- const unfollow = async (userId) => {
11349
- const client = getActiveClient();
11350
- client.log('follow/unfollow', userId);
11351
- const { data } = await client.http.delete(`/api/v4/me/following/${userId}`);
11352
- if (client.cache) {
11353
- ingestInCache(data);
11354
- }
11355
- const payload = prepareFollowStatusPayload(data);
11356
- fireEvent('local.follow.unfollowed', payload);
11357
- return true;
11358
- };
11359
- /* end_public_function */
11360
-
11361
- /* begin_public_function
11362
- id: user.relationship.accept_follow
11363
- */
11364
- /**
11365
- * ```js
11366
- * import { UserRepository } from '@amityco/ts-sdk'
11367
- * await UserRepository.Relationship.acceptMyFollower('foobar')
11368
- * ```
11369
- *
11370
- * Accept the follow request
11371
- *
11372
- * @param userId the ID of the {@link Amity.InternalUser} follower
11373
- * @returns A success boolean if the follow request was accepted
11374
- *
11375
- * @category Follow API
11376
- * @async
11377
- */
11378
- const acceptMyFollower = async (userId) => {
11379
- const client = getActiveClient();
11380
- client.log('follow/acceptMyFollower', userId);
11381
- const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
11382
- if (client.cache) {
11383
- ingestInCache(data);
11384
- }
11385
- const payload = prepareFollowStatusPayload(data);
11386
- fireEvent('local.follow.accepted', payload);
11387
- return true;
11388
- };
11389
- /* end_public_function */
11390
-
11391
- /* begin_public_function
11392
- id: user.relationship.decline_follow
11393
- */
11394
- /**
11395
- * ```js
11396
- * import { UserRepository } from '@amityco/ts-sdk'
11397
- * await UserRepository.Relationship.declineMyFollower('foobar')
11398
- * ```
11399
- *
11400
- * Decline the follow request or delete the follower
11401
- *
11402
- * @param userId the ID of the {@link Amity.InternalUser} follower
11403
- * @returns A success boolean if the follow request was decline
11404
- *
11405
- * @category Follow API
11406
- * @async
11407
- */
11408
- const declineMyFollower = async (userId) => {
11409
- const client = getActiveClient();
11410
- client.log('follow/declineMyFollower', userId);
11411
- const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
11412
- if (client.cache) {
11413
- ingestInCache(data);
11414
- }
11415
- const payload = prepareFollowStatusPayload(data);
11416
- fireEvent('local.follow.requestDeclined', payload);
11417
- return true;
11418
- };
11419
- /* end_public_function */
11420
-
11421
- const createFollowEventSubscriber = (event, callback) => {
11422
- const client = getActiveClient();
11423
- const filter = (data) => {
11424
- const payload = prepareFollowersPayload(data);
11425
- if (!client.cache) {
11426
- callback(payload.follows[0]);
11427
- }
11428
- else {
11429
- ingestInCache(payload);
11430
- callback(payload.follows[0]);
11431
- }
11432
- };
11433
- return createEventSubscriber(client, event, event, filter);
11434
- };
11435
- const createLocalFollowEventSubscriber = (event, callback) => {
11436
- const client = getActiveClient();
11437
- const filter = (data) => {
11438
- const payload = prepareFollowStatusPayload(data);
11439
- if (!client.cache) {
11440
- callback(payload.follows[0]);
11441
- }
11442
- else {
11443
- ingestInCache(payload);
11444
- callback(payload.follows[0]);
11445
- }
11446
- };
11447
- return createEventSubscriber(client, event, event, filter);
11448
- };
11449
-
11450
- /**
11451
- * ```js
11452
- * import { onUserFollowed } from '@amityco/ts-sdk'
11453
- * const dispose = onUserFollowed(status => {
11454
- * // ...
11455
- * })
11456
- * ```
11457
- *
11458
- * Fired when a user follows another users and confirmation is not required
11459
- *
11460
- * @param callback The function to call when the event was fired
11461
- * @returns an {@link Amity.Unsubscriber} function to stop listening
11462
- *
11463
- * @category Follow Events
11464
- */
11465
- const onUserFollowed = (callback) => createFollowEventSubscriber('follow.created', callback);
11466
-
11467
- /**
11468
- * ```js
11469
- * import { onUserUnfollowed } from '@amityco/ts-sdk'
11470
- * const dispose = onUserFollowed(status => {
11471
- * // ...
11472
- * })
11473
- * ```
11474
- *
11475
- * Fired when a user unfollows
11476
- *
11477
- * @param callback The function to call when the event was fired
11478
- * @returns an {@link Amity.Unsubscriber} function to stop listening
11479
- *
11480
- * @category Follow Events
11481
- */
11482
- const onUserUnfollowed = (callback) => createFollowEventSubscriber('follow.unfollowed', callback);
11483
-
11484
- /**
11485
- * ```js
11486
- * import { onFollowerDeleted } from '@amityco/ts-sdk'
11487
- * const dispose = onFollowerDeleted(status => {
11488
- * // ...
11489
- * })
11490
- * ```
11491
- *
11492
- * Fired when a follower has been deleted
11493
- *
11494
- * @param callback The function to call when the event was fired
11495
- * @returns an {@link Amity.Unsubscriber} function to stop listening
11496
- *
11497
- * @category Follow Events
11498
- */
11499
- const onFollowerDeleted = (callback) => createFollowEventSubscriber('follow.followerDeleted', callback);
11687
+ /* end_public_function */
11500
11688
 
11689
+ /* begin_public_function
11690
+ id: user.relationship.unfollow
11691
+ */
11501
11692
  /**
11502
11693
  * ```js
11503
- * import { onFollowerRequested } from '@amityco/ts-sdk'
11504
- * const dispose = onFollowerRequested(status => {
11505
- * // ...
11506
- * })
11694
+ * import { unfollow } from '@amityco/ts-sdk'
11695
+ * await unfollow('foobar')
11507
11696
  * ```
11508
11697
  *
11509
- * Fired when a user follows another users and confirmation is required
11698
+ * Cancel the follow request or unfollow the user
11510
11699
  *
11511
- * @param callback The function to call when the event was fired
11512
- * @returns an {@link Amity.Unsubscriber} function to stop listening
11700
+ * @param userId the ID of the {@link Amity.InternalUser}
11701
+ * @returns A success boolean if the user {@link Amity.InternalUser} was unfollowed
11513
11702
  *
11514
- * @category Follow Events
11703
+ * @category Follow API
11704
+ * @async
11515
11705
  */
11516
- const onFollowerRequested = (callback) => createFollowEventSubscriber('follow.requested', callback);
11706
+ const unfollow = async (userId) => {
11707
+ const client = getActiveClient();
11708
+ client.log('follow/unfollow', userId);
11709
+ const { data } = await client.http.delete(`/api/v4/me/following/${userId}`);
11710
+ if (client.cache) {
11711
+ ingestInCache(data);
11712
+ }
11713
+ const payload = prepareFollowStatusPayload(data);
11714
+ // at once: the local event below is delivered on a later tick
11715
+ FollowingSyncEngine$1.getInstance().onFollowChanged(data.follows[0]);
11716
+ fireEvent('local.follow.unfollowed', payload);
11717
+ return true;
11718
+ };
11719
+ /* end_public_function */
11517
11720
 
11721
+ /* begin_public_function
11722
+ id: user.relationship.accept_follow
11723
+ */
11518
11724
  /**
11519
11725
  * ```js
11520
- * import { onFollowRequestCanceled } from '@amityco/ts-sdk'
11521
- * const dispose = onFollowRequestCanceled(status => {
11522
- * // ...
11523
- * })
11726
+ * import { UserRepository } from '@amityco/ts-sdk'
11727
+ * await UserRepository.Relationship.acceptMyFollower('foobar')
11524
11728
  * ```
11525
11729
  *
11526
- * Fired when a follow request has been canceled
11730
+ * Accept the follow request
11527
11731
  *
11528
- * @param callback The function to call when the event was fired
11529
- * @returns an {@link Amity.Unsubscriber} function to stop listening
11732
+ * @param userId the ID of the {@link Amity.InternalUser} follower
11733
+ * @returns A success boolean if the follow request was accepted
11530
11734
  *
11531
- * @category Follow Events
11735
+ * @category Follow API
11736
+ * @async
11532
11737
  */
11533
- const onFollowRequestCanceled = (callback) => createFollowEventSubscriber('follow.requestCanceled', callback);
11738
+ const acceptMyFollower = async (userId) => {
11739
+ const client = getActiveClient();
11740
+ client.log('follow/acceptMyFollower', userId);
11741
+ const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
11742
+ if (client.cache) {
11743
+ ingestInCache(data);
11744
+ }
11745
+ const payload = prepareFollowStatusPayload(data);
11746
+ fireEvent('local.follow.accepted', payload);
11747
+ return true;
11748
+ };
11749
+ /* end_public_function */
11534
11750
 
11751
+ /* begin_public_function
11752
+ id: user.relationship.decline_follow
11753
+ */
11535
11754
  /**
11536
11755
  * ```js
11537
- * import { onFollowRequestAccepted } from '@amityco/ts-sdk'
11538
- * const dispose = onFollowRequestAccepted(status => {
11539
- * // ...
11540
- * })
11756
+ * import { UserRepository } from '@amityco/ts-sdk'
11757
+ * await UserRepository.Relationship.declineMyFollower('foobar')
11541
11758
  * ```
11542
11759
  *
11543
- * Fired when a follow request has been accepted
11760
+ * Decline the follow request or delete the follower
11544
11761
  *
11545
- * @param callback The function to call when the event was fired
11546
- * @returns an {@link Amity.Unsubscriber} function to stop listening
11762
+ * @param userId the ID of the {@link Amity.InternalUser} follower
11763
+ * @returns A success boolean if the follow request was decline
11547
11764
  *
11548
- * @category Follow Events
11765
+ * @category Follow API
11766
+ * @async
11549
11767
  */
11550
- const onFollowRequestAccepted = (callback) => createFollowEventSubscriber('follow.accepted', callback);
11768
+ const declineMyFollower = async (userId) => {
11769
+ const client = getActiveClient();
11770
+ client.log('follow/declineMyFollower', userId);
11771
+ const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
11772
+ if (client.cache) {
11773
+ ingestInCache(data);
11774
+ }
11775
+ const payload = prepareFollowStatusPayload(data);
11776
+ fireEvent('local.follow.requestDeclined', payload);
11777
+ return true;
11778
+ };
11779
+ /* end_public_function */
11551
11780
 
11781
+ /* begin_public_function
11782
+ id: user.relationship.get_all_followings
11783
+ */
11552
11784
  /**
11553
11785
  * ```js
11554
- * import { onFollowRequestDeclined } from '@amityco/ts-sdk'
11555
- * const dispose = onFollowRequestDeclined(status => {
11556
- * // ...
11557
- * })
11786
+ * import { UserRepository } from '@amityco/ts-sdk'
11787
+ *
11788
+ * const followings = await UserRepository.Relationship.getAllFollowings()
11789
+ * const statusOf = new Map(followings.map(f => [f.userId, f.status]))
11790
+ * // 'accepted' → no button; 'pending' → Pending; missing → Follow
11558
11791
  * ```
11559
11792
  *
11560
- * Fired when a follow request has been declined
11793
+ * Returns whom the signed-in user follows as a one-shot list of at most 5,000 (the most a
11794
+ * user can follow), from one request with no paging: each followed user's id and the
11795
+ * follow's status — `accepted`, or `pending` for a request not yet accepted. A user
11796
+ * missing from the list is not followed. The list holds ids and statuses only, no user
11797
+ * profiles.
11561
11798
  *
11562
- * @param callback The function to call when the event was fired
11563
- * @returns an {@link Amity.Unsubscriber} function to stop listening
11799
+ * Use it to show the follow button next to each author in the post feed: match each
11800
+ * author by user id against `userId`.
11564
11801
  *
11565
- * @category Follow Events
11802
+ * Keeping the app current: the function answers once, so call it again to see changes —
11803
+ * for example when more posts load or when the feed comes back into view. The answer is
11804
+ * kept on the device for 5 minutes, so a call within that window costs no request. Changes
11805
+ * made in this app show at once. Changes made elsewhere — on another device, or by the
11806
+ * other user accepting a request or removing the user as a follower — show once their
11807
+ * real-time event arrives; the SDK receives these on the followers and followings topics
11808
+ * of `AmityAutoSubscription.BLOCK`, on by default. An event missed while offline, or with
11809
+ * that subscription turned off, shows at the next fetch, after the 5 minutes.
11810
+ *
11811
+ * @returns A promise that resolves to the signed-in user's {@link Amity.FollowingUserStatus} list
11812
+ *
11813
+ * @category Follow API
11814
+ * @async
11566
11815
  */
11567
- const onFollowRequestDeclined = (callback) => createFollowEventSubscriber('follow.requestDeclined', callback);
11816
+ const getAllFollowings = async () => {
11817
+ const client = getActiveClient();
11818
+ client.log('follow/getAllFollowings');
11819
+ const engine = FollowingSyncEngine$1.getInstance();
11820
+ // Fetch only when the 5-minute window has expired (no-op otherwise)
11821
+ await engine.ensureFetched();
11822
+ return engine.getFollowings();
11823
+ };
11824
+ /* end_public_function */
11568
11825
 
11569
11826
  /**
11570
11827
  * ```js
@@ -11670,12 +11927,6 @@ const onFollowInfoUpdated = (callback) => {
11670
11927
  };
11671
11928
  };
11672
11929
 
11673
- const onLocalUserFollowed = (callback) => createLocalFollowEventSubscriber('local.follow.created', callback);
11674
-
11675
- const onLocalUserUnfollowed = (callback) => createLocalFollowEventSubscriber('local.follow.unfollowed', callback);
11676
-
11677
- const onLocalFollowerRequested = (callback) => createLocalFollowEventSubscriber('local.follow.requested', callback);
11678
-
11679
11930
  const onLocalFollowRequestAccepted = (callback) => createLocalFollowEventSubscriber('local.follow.accepted', callback);
11680
11931
 
11681
11932
  const onLocalFollowRequestDeclined = (callback) => createLocalFollowEventSubscriber('local.follow.requestDeclined', callback);
@@ -12397,6 +12648,7 @@ var index$s = /*#__PURE__*/Object.freeze({
12397
12648
  unfollow: unfollow,
12398
12649
  acceptMyFollower: acceptMyFollower,
12399
12650
  declineMyFollower: declineMyFollower,
12651
+ getAllFollowings: getAllFollowings,
12400
12652
  onUserFollowed: onUserFollowed,
12401
12653
  onUserUnfollowed: onUserUnfollowed,
12402
12654
  onFollowerDeleted: onFollowerDeleted,
@@ -14142,7 +14394,7 @@ const getWatchSessionStorage = () => {
14142
14394
  return storageInstance;
14143
14395
  };
14144
14396
 
14145
- const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDHo80SecH7FuF2\nhFYnb+l26/VN8UMLXAQFLnxciNTEwkGVFMpdezlH8rU2HtUJL4RETogbAOLVY0XM\njs6sPn8G1nALmh9qeDpUtVqFOVtBHxEZ910TLOtQiunjqJKO5nWdqZ71EC3OFluR\niGQkO84BiIFbv37ub7xl3S8XarbtKoLcyVpkDHi+1wx1pgCAn6gtBUgckPL5NR8j\nLseabl3HAXQfhTCKo4tmOFM2Dxwl1IUMmIJrJg/aIU/U0tj/1Eoo7mG0JcNWX19l\nW3EecCbi0ncCJOrkUdwlBrcjaMayaX/ubEwyUeTGiLdyc4L3GRLHjyK8xgVNXRMH\nbZWJ2a5NAgMBAAECggEASxuE+35zTFO/XydKgmvIGcWL9FbgMlXb7Vcf0nBoG945\nbiz0NVc2paraIhJXc608xbYF3qLmtAE1MVBI0ORyRdBHNxY024l/6H6SH60Ed+uI\nM4ysp5ourY6Vj+DLwpdRiI9YDjqYAQDIUmhNxJP7XPhOMoZI6st+xZQBM34ic/bv\nAMSJm9OZphSp3+qXVkFZztr2mxD2EZSJJLYxi8BCdgM2qhazalbcJ6zDKHCZWVWm\n8RRxDGldyMb/237JxETzP40tAlzOZDmBAbUgEnurDJ93RVDIE3rbZUshwgeQd18a\nem096mWgvB1AIKYgsTAR3pw+V19YWAjq/glP6fz8wQKBgQD/oQq+ukKF0PRgBeM5\ngeTjSwsdGppQLmf5ndujvoiz/TpdjDEPu6R8kigQr1rG2t4K/yfdZoI8RdmJD1al\n3Q7N9hofooSy4rj6E3txzWZCHJjHad2cnCp/O26HiReGAl7wTcfTmNdiFHhZQzm5\nJBkvWAiwuvQMNfEbnXxw6/vIDwKBgQDH7fX8gsc77JLvAWgp1MaQN/sbqVb6JeT1\nFQfR8E/WFCSmzQBtNzd5KgYuCeelwr/8DyYytvN2BzCYZXp73gI1jF3YlW5jVn74\nOY6TwQ095digwo6Z0yuxopdIOApKgAkL9PRKgNrqAf3NAyMua6lOGifzjDojC3KU\nfylQmxMn4wKBgHp2B9O/H0dEBw5JQ8W0+JX6yWQz7mEjGiR2/1W+XXb8hQ1zr709\nw1r6Gb+EghRpnZ3fBpYGGbYOMFx8wKHM+N6qW3F0ReX8v2juFGE8aRSa5oYBrWzt\nU16Idjbv8hj84cZ1PJmdyvDtpYn9rpWHOZl4rxEbPvbqkIsOMyNVqdT5AoGAOSge\nmwIIU2le2FVeohbibXiToWTYKMuMmURZ5/r72AgKMmWJKbAPe+Q3wBG01/7FRBpQ\noU8Ma0HC8s6QJbliiEyIx9JwrJWd1vkdecBHONrtA4ibm/5zD2WcOllLF+FitLhi\n3qnX6+6F0IaFGFBPJrTzlv0P4dTz/OAdv52V7GECgYEA2TttOKBAqWllgOaZOkql\nLVMJVmgR7s6tLi1+cEP8ZcapV9aRbRzTAKXm4f8AEhtlG9F9kCOvHYCYGi6JaiWJ\nZkHjeex3T+eE6Di6y5Bm/Ift5jtVhJ4jCVwHOKTMej79NPUFTJfv8hCo29haBDv6\nRXFrv+T21KCcw8k3sJeJWWQ=\n-----END PRIVATE KEY-----";
14397
+ const privateKey = "MIIEpQIBAAKCAQEAwAEc/oZgYIvKSUG/C3mONYLR4ZPgAjMEX4bJ+xqqakUDRtqlNO+eZs2blQ1Ko0DBkqPExyQezvjibH5W2UZBV5RaBTlTcNVKTToMBEGesAfaEcM3qUyQHxdbFYZv6P4sb14dcwxTQ8usmaV8ooiR1Fcaso5ZWYcZ8Hb46FbQ7OoVumsBtPWwfZ4f003o5VCl6AIM6lcLv9UDLlFVYhE+PeXpRHtfWlGqxMvqC9oinlwhL6nWv6VjQXW4nhcib72dPBzfHT7k/PMKto2SxALYdb68ENiAGuJLWi3AUHSyYCJK2w7wIlWfJUAI0v26ub10IpExr6D5QuW2577jjP93iwIDAQABAoIBAFWfqXhwIIatkFY+9Z1+ZcbDQimgsmMIsUiQaX6Lk7e0cxOj6czDlxYtVtaPiNtow2pLkjNkjkCqiP7tEHnwdK9DvylZOTa2R15NJpK3WLcTqVIGhsn/FL5owfvFah6zSsmXZParZm5zY9NZE03ALZhOB9/cz0e3kf/EbpfeL2mW7MApyiUt5i09ycchroOpcWp73ipIxvgigtZyUGFmsQicWhUs28F0D7w4Qfk76yG3nqXeb+BAMhCaIaa/k/aAxhiZG/ygEQWQrcC8gfe+jyicMAQPDEVS9YuUMGsLjIjKuVLZzp2xirQnhc2i2zVNEIvG6soprPOBEMQugzrtX5ECgYEA3b7KAbBIbDl1e4ZSCWhHdHkiWVZHaopsR/LhqDDNhXjWjq3AesgV6k0j9EdziMn/HmmOso0bz99GTV3JZf4A9ztTLumJlkHbdVtlgOqSjrFLj12rH9KXTheyIhWSpUmm8+WB1xasFbqpvJaGo7F3pd2Fqj1XR4mp5BO7c/t7LJ0CgYEA3aouEzXQ9THRKYocdfY69EI1Il1t/d/RSqqd9BxEjxBgxkM13ZiYIn/R4WW/nCUrlmhxG44Aa2Gob4Ahfsui2xKTg/g/3Zk/rAxAEGkfOLGoenaJMD41fH4wUq3FRYwkvnaMb9Hd6f/TlBHslIRa2NN58bSBGJCyBP2b59+2+EcCgYEAixDVRXvV37GlYUOa/XVdosk5Zoe6oDGRuQm0xbNdoUBoZvDHDvme7ONWEiQha/8qtVsD+CyQ7awcPfb8kK9c0bBt+bTS6d4BkTcxkEkMgtrkBVR8Nqfu5jXsLH4VCv4G61zbMhZw8+ut+az5YX2yCN7Frj9sFlxapMRPQmzMEe0CgYEAumsAzM8ZqNv4mAK65Mnr0rhLj1cbxcKRdUYACOgtEFQpzxN/HZnTeFAe5nx3pI3uFlRHq3DFEYnT6dHMWaJQmAULYpVIwMi9L6gtyJ9fzoI6uqMtxRDMUqKdaSsTGOY/kJ6KhQ/unXi1K3XXjR+yd1+C0q+HUm1+CYxvrZYLfskCgYEArsEy+IQOiqniJ0NE2vVUF+UK/IRZaic9YKcpov5Ot7Vvzm/MnnW4N1ljVskocETBWMmPUvNSExVjPebi+rxd8fa5kY8BJScPTzMFbunZn/wjtGdcM10qdlVQ9doG61A/9P3ezFKCfS4AvF/H/59LcSx2Bh28fp3/efiVIOpVd4Y=";
14146
14398
  /*
14147
14399
  * The crypto algorithm used for importing key and signing string
14148
14400
  */
@@ -30481,6 +30733,189 @@ const getForYouFeed = (callback) => {
30481
30733
  };
30482
30734
  /* end_public_function */
30483
30735
 
30736
+ class FollowingFeedQueryStreamController extends QueryStreamController {
30737
+ constructor(query, cacheKey, notifyChange, preparePayload) {
30738
+ super(query, cacheKey);
30739
+ this.notifyChange = notifyChange;
30740
+ this.preparePayload = preparePayload;
30741
+ }
30742
+ async saveToMainDB(response) {
30743
+ const processedPayload = await this.preparePayload(response);
30744
+ const client = getActiveClient();
30745
+ const cachedAt = client.cache && Date.now();
30746
+ if (client.cache) {
30747
+ ingestInCache(processedPayload, { cachedAt });
30748
+ }
30749
+ }
30750
+ appendToQueryStream(response, direction, refresh = false) {
30751
+ var _a, _b;
30752
+ if (refresh) {
30753
+ pushToCache(this.cacheKey, {
30754
+ data: response.posts.map(getResolver('post')),
30755
+ });
30756
+ }
30757
+ else {
30758
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30759
+ const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
30760
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
30761
+ }
30762
+ }
30763
+ /**
30764
+ * The SDK does not know the viewer's follow list or the network's `social.globalFeed`
30765
+ * switches, so it cannot tell whether a new post belongs in this feed. A created or
30766
+ * approved post, by anyone (the current user included), never changes the list: it
30767
+ * appears on the next first-page load. Deleted and declined posts are removed; any
30768
+ * other event re-emits so listed posts render their new state.
30769
+ */
30770
+ reactor(action) {
30771
+ return (post) => {
30772
+ var _a;
30773
+ if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
30774
+ return;
30775
+ }
30776
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30777
+ if (!collection)
30778
+ return;
30779
+ // A child post event never adds or removes an entry; it re-emits only when its parent is listed
30780
+ if (post.parentPostId) {
30781
+ if (!collection.data.includes(post.parentPostId))
30782
+ return;
30783
+ }
30784
+ else if (action === EnumPostActions.OnPostDeleted ||
30785
+ action === EnumPostActions.OnPostDeclined) {
30786
+ collection.data = collection.data.filter(postId => postId !== post.postId);
30787
+ }
30788
+ pushToCache(this.cacheKey, collection);
30789
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
30790
+ };
30791
+ }
30792
+ subscribeRTE(createSubscriber) {
30793
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
30794
+ }
30795
+ }
30796
+
30797
+ /**
30798
+ * `GET /api/v1/me/following-feeds` reads `limit` and `token` as flat query params.
30799
+ * Unlike the global feed, they must not be nested in `options`: the endpoint forwards
30800
+ * only `{ limit, token }`, so a nested token would be dropped and every page would be page one.
30801
+ */
30802
+ class FollowingFeedPaginationController extends PaginationController {
30803
+ async getRequest(queryParams, token) {
30804
+ const { limit = COLLECTION_DEFAULT_PAGINATION_SIZE, sortBy } = queryParams;
30805
+ const params = token ? { token } : { limit };
30806
+ if (sortBy)
30807
+ params.sortBy = sortBy;
30808
+ const { data: queryResponse } = await this.http.get(API_ENDPOINTS.followingFeed, { params });
30809
+ return queryResponse;
30810
+ }
30811
+ }
30812
+
30813
+ class FollowingFeedLiveCollectionController extends LiveCollectionController {
30814
+ constructor(query, callback) {
30815
+ const queryStreamId = hash__default["default"](query);
30816
+ const cacheKey = ['followingFeed', 'collection', queryStreamId];
30817
+ const paginationController = new FollowingFeedPaginationController(query);
30818
+ super(paginationController, queryStreamId, cacheKey, callback);
30819
+ this.query = query;
30820
+ this.queryStreamController = new FollowingFeedQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
30821
+ this.callback = callback.bind(this);
30822
+ this.loadPage({ initial: true });
30823
+ }
30824
+ setup() {
30825
+ var _a;
30826
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30827
+ if (!collection) {
30828
+ pushToCache(this.cacheKey, {
30829
+ data: [],
30830
+ params: {},
30831
+ });
30832
+ }
30833
+ }
30834
+ async persistModel(queryPayload) {
30835
+ await this.queryStreamController.saveToMainDB(queryPayload);
30836
+ }
30837
+ persistQueryStream({ response, direction, refresh, }) {
30838
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
30839
+ }
30840
+ startSubscription() {
30841
+ return this.queryStreamController.subscribeRTE(getGlobalFeedSubscriptions(this.cacheKey));
30842
+ }
30843
+ notifyChange({ origin, loading, error }) {
30844
+ var _a, _b;
30845
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30846
+ if (!collection)
30847
+ return;
30848
+ const data = ((_b = collection.data
30849
+ .map(id => pullFromCache(['post', 'get', id]))
30850
+ .filter(isNonNullable)
30851
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
30852
+ if (!this.shouldNotify(data) && origin === 'event')
30853
+ return;
30854
+ this.callback({
30855
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
30856
+ data,
30857
+ hasNextPage: !!this.paginationController.getNextToken(),
30858
+ loading,
30859
+ error,
30860
+ });
30861
+ }
30862
+ }
30863
+
30864
+ /* begin_public_function
30865
+ id: feed.query.following_feed
30866
+ api_style: live_collection
30867
+ */
30868
+ /**
30869
+ * ```js
30870
+ * import { FeedRepository, FollowingFeedSortByEnum } from '@amityco/ts-sdk'
30871
+ *
30872
+ * const unsub = FeedRepository.getFollowingFeed(
30873
+ * { sortBy: FollowingFeedSortByEnum.LastCreated, limit: 20 },
30874
+ * ({ data: posts, hasNextPage, onNextPage, loading, error }) => processResponse(posts),
30875
+ * )
30876
+ * ```
30877
+ *
30878
+ * Observe all mutations on a list of {@link Amity.Post} for the current user's following feed.
30879
+ * Which posts match is decided by the server, from the network's `social.globalFeed` setting:
30880
+ * - `lastCreated`: posts by the users the current user follows, plus the current user's own
30881
+ * posts, newest first.
30882
+ * - `customRanking` (the default): server-ranked posts by the current user, the users they
30883
+ * follow and the communities they joined.
30884
+ *
30885
+ * A new post, the current user's own included, is not added in real time: it appears
30886
+ * when the feed is next loaded from the first page (for example, a new subscription).
30887
+ * With `customRanking` the server may take up to 5 minutes to include it.
30888
+ * Deleted and declined posts are removed at once.
30889
+ *
30890
+ * When the network enforces module entitlement and the `feed` module is not entitled,
30891
+ * the request fails with `400325` (`ModuleNotEntitled`), reported through `error`.
30892
+ *
30893
+ * @param params.sortBy order of the feed. When omitted, the server default (`customRanking`) applies
30894
+ * @param params.limit page size of the first request (1 - 100)
30895
+ * @param callback the function to call when new data are available
30896
+ * @param config
30897
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the posts
30898
+ *
30899
+ * @category Posts Live Collection
30900
+ */
30901
+ const getFollowingFeed = (params, callback, config) => {
30902
+ const { log, cache } = getActiveClient();
30903
+ if (!cache) {
30904
+ console.log(ENABLE_CACHE_MESSAGE);
30905
+ }
30906
+ const timestamp = Date.now();
30907
+ log(`getFollowingFeed(tmpid: ${timestamp}) > listen`);
30908
+ const liveCollection = new FollowingFeedLiveCollectionController(params, callback);
30909
+ const disposers = liveCollection.startSubscription();
30910
+ const cacheKey = liveCollection.getCacheKey();
30911
+ disposers.push(() => dropFromCache(cacheKey));
30912
+ return () => {
30913
+ log(`getFollowingFeed(tmpid: ${timestamp}) > dispose`);
30914
+ disposers.forEach(fn => fn());
30915
+ };
30916
+ };
30917
+ /* end_public_function */
30918
+
30484
30919
  var index$e = /*#__PURE__*/Object.freeze({
30485
30920
  __proto__: null,
30486
30921
  queryGlobalFeed: queryGlobalFeed,
@@ -30489,6 +30924,7 @@ var index$e = /*#__PURE__*/Object.freeze({
30489
30924
  getUserFeed: getUserFeed,
30490
30925
  getCommunityFeed: getCommunityFeed,
30491
30926
  getForYouFeed: getForYouFeed,
30927
+ getFollowingFeed: getFollowingFeed,
30492
30928
  AmityForYouFeedDisabledError: AmityForYouFeedDisabledError
30493
30929
  });
30494
30930