@amityco/ts-sdk 7.33.1 → 7.33.2-1f204b87.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 (30) 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/follow.d.ts +7 -0
  6. package/dist/@types/domains/follow.d.ts.map +1 -1
  7. package/dist/client/api/getFeedSettings.d.ts +3 -1
  8. package/dist/client/api/getFeedSettings.d.ts.map +1 -1
  9. package/dist/client/api/setupLoginSubscriptions.d.ts.map +1 -1
  10. package/dist/index.cjs.js +432 -191
  11. package/dist/index.esm.js +432 -191
  12. package/dist/index.umd.js +2 -2
  13. package/dist/userRepository/relationship/block/api/blockUser.d.ts.map +1 -1
  14. package/dist/userRepository/relationship/follow/api/follow.d.ts.map +1 -1
  15. package/dist/userRepository/relationship/follow/api/getAllFollowings.d.ts +35 -0
  16. package/dist/userRepository/relationship/follow/api/getAllFollowings.d.ts.map +1 -0
  17. package/dist/userRepository/relationship/follow/api/index.d.ts +1 -0
  18. package/dist/userRepository/relationship/follow/api/index.d.ts.map +1 -1
  19. package/dist/userRepository/relationship/follow/api/tests/getAllFollowings.test.d.ts +2 -0
  20. package/dist/userRepository/relationship/follow/api/tests/getAllFollowings.test.d.ts.map +1 -0
  21. package/dist/userRepository/relationship/follow/api/tests/integration/getAllFollowings.integration.test.d.ts +2 -0
  22. package/dist/userRepository/relationship/follow/api/tests/integration/getAllFollowings.integration.test.d.ts.map +1 -0
  23. package/dist/userRepository/relationship/follow/api/unfollow.d.ts.map +1 -1
  24. package/dist/userRepository/services/FollowingSyncEngine/followRealtimeOnLoginHandler.d.ts +16 -0
  25. package/dist/userRepository/services/FollowingSyncEngine/followRealtimeOnLoginHandler.d.ts.map +1 -0
  26. package/dist/userRepository/services/FollowingSyncEngine/followingSyncEngine.d.ts +61 -0
  27. package/dist/userRepository/services/FollowingSyncEngine/followingSyncEngine.d.ts.map +1 -0
  28. package/dist/userRepository/services/FollowingSyncEngine/followingSyncEngineOnLoginHandler.d.ts +3 -0
  29. package/dist/userRepository/services/FollowingSyncEngine/followingSyncEngineOnLoginHandler.d.ts.map +1 -0
  30. package/package.json +1 -1
package/dist/index.cjs.js CHANGED
@@ -1983,13 +1983,13 @@ class SessionWatcher {
1983
1983
  this._listener.clear();
1984
1984
  }
1985
1985
  }
1986
- let instance$b;
1986
+ let instance$c;
1987
1987
  var SessionWatcher$1 = {
1988
1988
  getInstance: () => {
1989
- if (!instance$b) {
1990
- instance$b = new SessionWatcher();
1989
+ if (!instance$c) {
1990
+ instance$c = new SessionWatcher();
1991
1991
  }
1992
- return instance$b;
1992
+ return instance$c;
1993
1993
  },
1994
1994
  };
1995
1995
 
@@ -2656,13 +2656,13 @@ class NetworkActivitiesWatcher {
2656
2656
  this._listener.clear();
2657
2657
  }
2658
2658
  }
2659
- let instance$a;
2659
+ let instance$b;
2660
2660
  var NetworkActivitiesWatcher$1 = {
2661
2661
  getInstance: () => {
2662
- if (!instance$a) {
2663
- instance$a = new NetworkActivitiesWatcher();
2662
+ if (!instance$b) {
2663
+ instance$b = new NetworkActivitiesWatcher();
2664
2664
  }
2665
- return instance$a;
2665
+ return instance$b;
2666
2666
  },
2667
2667
  };
2668
2668
 
@@ -2923,11 +2923,11 @@ class AutoSubscriptionManager {
2923
2923
  this.seed();
2924
2924
  }
2925
2925
  }
2926
- let instance$9 = null;
2926
+ let instance$a = null;
2927
2927
  const getAutoSubscriptionManager = () => {
2928
- if (!instance$9)
2929
- instance$9 = new AutoSubscriptionManager();
2930
- return instance$9;
2928
+ if (!instance$a)
2929
+ instance$a = new AutoSubscriptionManager();
2930
+ return instance$a;
2931
2931
  };
2932
2932
  /** Resets the registry to its default baseline when the session ends. */
2933
2933
  const resetAutoSubscriptionsOnLogout = () => onSessionStateChange(state => {
@@ -6257,9 +6257,11 @@ const validateTexts = async (texts) => {
6257
6257
  * import { getFeedSettings } from '@amityco/ts-sdk'
6258
6258
  * const feedSettings = await getFeedSettings()
6259
6259
  * const postFeedSetting = feedSettings.post
6260
+ * const isAutoPlayEnabled = postFeedSetting?.find(({ contentType }) => contentType === 'video')?.autoPlay
6260
6261
  * ```
6261
6262
  *
6262
- * Fetches a {@link Amity.FeedSettings} object
6263
+ * Fetches a {@link Amity.FeedSettings} object. Video content settings always
6264
+ * carry `autoPlay`, which is `false` when the server omits it.
6263
6265
  *
6264
6266
  * @returns A Promise of {@link Amity.FeedSettings} object
6265
6267
  *
@@ -6270,7 +6272,14 @@ const getFeedSettings = async () => {
6270
6272
  const client = getActiveClient();
6271
6273
  const { data } = await client.http.get(`/api/v3/network-settings/feed-setting`);
6272
6274
  return Object.fromEntries(data.feedSettings.map(({ feedType, contentSettings }) => {
6273
- return [feedType, contentSettings];
6275
+ return [
6276
+ feedType,
6277
+ contentSettings === null || contentSettings === void 0 ? void 0 : contentSettings.map(setting => {
6278
+ var _a;
6279
+ return setting.contentType === 'video'
6280
+ ? Object.assign(Object.assign({}, setting), { autoPlay: (_a = setting.autoPlay) !== null && _a !== void 0 ? _a : false }) : setting;
6281
+ }),
6282
+ ];
6274
6283
  }));
6275
6284
  };
6276
6285
 
@@ -7001,13 +7010,13 @@ class AnalyticsEngine {
7001
7010
  this._eventCapturer.resetAllBuckets();
7002
7011
  }
7003
7012
  }
7004
- let instance$8;
7013
+ let instance$9;
7005
7014
  var AnalyticsEngine$1 = {
7006
7015
  getInstance: () => {
7007
- if (!instance$8) {
7008
- instance$8 = new AnalyticsEngine();
7016
+ if (!instance$9) {
7017
+ instance$9 = new AnalyticsEngine();
7009
7018
  }
7010
- return instance$8;
7019
+ return instance$9;
7011
7020
  },
7012
7021
  };
7013
7022
 
@@ -7234,12 +7243,12 @@ class MessageReadReceiptSyncEngine {
7234
7243
  }
7235
7244
  }
7236
7245
  }
7237
- let instance$7 = null;
7246
+ let instance$8 = null;
7238
7247
  var ReadReceiptSyncEngine = {
7239
7248
  getInstance: () => {
7240
- if (!instance$7)
7241
- instance$7 = new MessageReadReceiptSyncEngine();
7242
- return instance$7;
7249
+ if (!instance$8)
7250
+ instance$8 = new MessageReadReceiptSyncEngine();
7251
+ return instance$8;
7243
7252
  },
7244
7253
  };
7245
7254
 
@@ -7493,12 +7502,12 @@ class LegacyMessageReadReceiptSyncEngine {
7493
7502
  }
7494
7503
  }
7495
7504
  }
7496
- let instance$6 = null;
7505
+ let instance$7 = null;
7497
7506
  var LegacyReadReceiptSyncEngine = {
7498
7507
  getInstance: () => {
7499
- if (!instance$6)
7500
- instance$6 = new LegacyMessageReadReceiptSyncEngine();
7501
- return instance$6;
7508
+ if (!instance$7)
7509
+ instance$7 = new LegacyMessageReadReceiptSyncEngine();
7510
+ return instance$7;
7502
7511
  },
7503
7512
  };
7504
7513
 
@@ -7744,12 +7753,12 @@ class ObjectResolverEngine {
7744
7753
  this.stopResolver();
7745
7754
  }
7746
7755
  }
7747
- let instance$5 = null;
7756
+ let instance$6 = null;
7748
7757
  var ObjectResolverEngine$1 = {
7749
7758
  getInstance: () => {
7750
- if (!instance$5)
7751
- instance$5 = new ObjectResolverEngine();
7752
- return instance$5;
7759
+ if (!instance$6)
7760
+ instance$6 = new ObjectResolverEngine();
7761
+ return instance$6;
7753
7762
  },
7754
7763
  };
7755
7764
 
@@ -7899,13 +7908,13 @@ class LiveReactionSyncEngine {
7899
7908
  this.stopReactionsSync();
7900
7909
  }
7901
7910
  }
7902
- let instance$4;
7911
+ let instance$5;
7903
7912
  var ReactionSyncEngine = {
7904
7913
  getInstance: () => {
7905
- if (!instance$4) {
7906
- instance$4 = new LiveReactionSyncEngine();
7914
+ if (!instance$5) {
7915
+ instance$5 = new LiveReactionSyncEngine();
7907
7916
  }
7908
- return instance$4;
7917
+ return instance$5;
7909
7918
  },
7910
7919
  };
7911
7920
 
@@ -7936,7 +7945,7 @@ function prepareBlockedUserPayload(response) {
7936
7945
  }
7937
7946
 
7938
7947
  const BLOCK_LIST_LIMIT$1 = 100;
7939
- const TTL_MS$1 = 5 * 60 * 1000; // 5 minutes
7948
+ const TTL_MS$2 = 5 * 60 * 1000; // 5 minutes
7940
7949
  /**
7941
7950
  * Session-scoped singleton engine that manages TTL-based fetching and caching
7942
7951
  * of blocked users. Provides a lazy `ensureFetched()` gate for the
@@ -7974,7 +7983,7 @@ class BlockedUserSyncEngine {
7974
7983
  isCacheExpired() {
7975
7984
  if (this.lastFetchedAt === null)
7976
7985
  return true;
7977
- return Date.now() - this.lastFetchedAt > TTL_MS$1;
7986
+ return Date.now() - this.lastFetchedAt > TTL_MS$2;
7978
7987
  }
7979
7988
  /**
7980
7989
  * Ensures the local store is populated with fresh blocked-user data.
@@ -8029,12 +8038,12 @@ class BlockedUserSyncEngine {
8029
8038
  .map(userLinkedObject);
8030
8039
  }
8031
8040
  }
8032
- let instance$3 = null;
8041
+ let instance$4 = null;
8033
8042
  var BlockedUserSyncEngine$1 = {
8034
8043
  getInstance: () => {
8035
- if (!instance$3)
8036
- instance$3 = new BlockedUserSyncEngine();
8037
- return instance$3;
8044
+ if (!instance$4)
8045
+ instance$4 = new BlockedUserSyncEngine();
8046
+ return instance$4;
8038
8047
  },
8039
8048
  };
8040
8049
 
@@ -8065,7 +8074,7 @@ function prepareBlockingUserPayload(response) {
8065
8074
  }
8066
8075
 
8067
8076
  const BLOCK_LIST_LIMIT = 100;
8068
- const TTL_MS = 5 * 60 * 1000; // 5 minutes
8077
+ const TTL_MS$1 = 5 * 60 * 1000; // 5 minutes
8069
8078
  /**
8070
8079
  * Session-scoped singleton engine that manages TTL-based fetching and caching
8071
8080
  * of blocking users (the "blocked-by" list — users who blocked the current
@@ -8104,7 +8113,7 @@ class BlockingUserSyncEngine {
8104
8113
  isCacheExpired() {
8105
8114
  if (this.lastFetchedAt === null)
8106
8115
  return true;
8107
- return Date.now() - this.lastFetchedAt > TTL_MS;
8116
+ return Date.now() - this.lastFetchedAt > TTL_MS$1;
8108
8117
  }
8109
8118
  /**
8110
8119
  * Ensures the local store is populated with fresh blocking-user data.
@@ -8159,12 +8168,12 @@ class BlockingUserSyncEngine {
8159
8168
  .map(userLinkedObject);
8160
8169
  }
8161
8170
  }
8162
- let instance$2 = null;
8171
+ let instance$3 = null;
8163
8172
  var BlockingUserSyncEngine$1 = {
8164
8173
  getInstance: () => {
8165
- if (!instance$2)
8166
- instance$2 = new BlockingUserSyncEngine();
8167
- return instance$2;
8174
+ if (!instance$3)
8175
+ instance$3 = new BlockingUserSyncEngine();
8176
+ return instance$3;
8168
8177
  },
8169
8178
  };
8170
8179
 
@@ -8274,6 +8283,333 @@ var blockRealtimeOnLoginHandler = () => {
8274
8283
  return () => disposers.forEach(dispose => dispose());
8275
8284
  };
8276
8285
 
8286
+ const TTL_MS = 5 * 60 * 1000; // 5 minutes, as BlockedUserSyncEngine
8287
+ const isKept = (status) => status === 'accepted' || status === 'pending';
8288
+ /**
8289
+ * Session-scoped singleton engine behind `getAllFollowings()`: a 5-minute fetch gate
8290
+ * on `GET /api/v4/me/following-ids`, copied from BlockedUserSyncEngine.
8291
+ *
8292
+ * - `onSessionEstablished()` is a no-op — the fetch is lazy, on the first call
8293
+ * - `onSessionDestroyed()` resets `lastFetchedAt` and empties the list, so the next
8294
+ * session fetches again
8295
+ * - `ensureFetched()` fetches only when the window expired or nothing was fetched yet;
8296
+ * `lastFetchedAt` moves only on success
8297
+ * - the answer holds ids and statuses only, so the engine keeps it in memory — user id →
8298
+ * status — replaced on each fetch, never merged: a follow removed on another device
8299
+ * drops out at the next fetch. Nothing is written to the follow or user cache.
8300
+ * - `onFollowChanged()` applies every follow change of the session by its status; a change
8301
+ * that arrives while a fetch is in flight is replayed on top of the answer, so the older
8302
+ * answer does not drop it. Concurrent calls share one in-flight fetch.
8303
+ *
8304
+ * @internal
8305
+ */
8306
+ class FollowingSyncEngine {
8307
+ constructor() {
8308
+ /** Epoch ms of the last successful fetch. null = never fetched in this session. */
8309
+ this.lastFetchedAt = null;
8310
+ /** user id → status, in order: the session's changes first, then the answer's order. */
8311
+ this.followings = new Map();
8312
+ /** Bumped on sign-out, so a fetch from the old session cannot fill the new one. */
8313
+ this.session = 0;
8314
+ /** The in-flight fetch, shared by concurrent calls. */
8315
+ this.fetching = null;
8316
+ /** Changes applied while `fetching` is in flight, replayed on top of its answer. */
8317
+ this.changesDuringFetch = [];
8318
+ }
8319
+ /** No-op — the fetch is lazy, triggered by getAllFollowings(). */
8320
+ // eslint-disable-next-line class-methods-use-this
8321
+ onSessionEstablished() {
8322
+ // intentionally empty
8323
+ }
8324
+ /** Resets the window so the next session starts with a fresh fetch. */
8325
+ onSessionDestroyed() {
8326
+ this.lastFetchedAt = null;
8327
+ this.followings = new Map();
8328
+ this.fetching = null;
8329
+ this.changesDuringFetch = [];
8330
+ this.session += 1;
8331
+ }
8332
+ /** No-op — the window does not depend on the token. */
8333
+ // eslint-disable-next-line class-methods-use-this
8334
+ onTokenExpired() {
8335
+ // intentionally empty
8336
+ }
8337
+ /**
8338
+ * Called for every follow change the SDK sees during the session. A follow whose
8339
+ * `from` is another user is ignored. Status `accepted` or `pending` sets the user with
8340
+ * that status and moves them to the front; any other status (`none` after an unfollow,
8341
+ * a cancel, a decline or a removed follower; `blocked`) removes them.
8342
+ */
8343
+ onFollowChanged(follow) {
8344
+ if (!follow || follow.from !== getActiveClient().userId)
8345
+ return;
8346
+ if (this.fetching)
8347
+ this.changesDuringFetch.push(follow);
8348
+ this.apply(follow);
8349
+ }
8350
+ apply(follow) {
8351
+ const rest = [...this.followings].filter(([userId]) => userId !== follow.to);
8352
+ this.followings = new Map(isKept(follow.status) ? [[follow.to, follow.status], ...rest] : rest);
8353
+ }
8354
+ isCacheExpired() {
8355
+ if (this.lastFetchedAt === null)
8356
+ return true;
8357
+ return Date.now() - this.lastFetchedAt > TTL_MS;
8358
+ }
8359
+ /**
8360
+ * Fetches whom the user follows (up to 5,000 ids and statuses, one response, no
8361
+ * `status` so both accepted and pending come back) when the window has expired. A
8362
+ * failure propagates and leaves the window and the list unchanged, so the next call
8363
+ * retries.
8364
+ */
8365
+ async ensureFetched() {
8366
+ if (!this.isCacheExpired())
8367
+ return;
8368
+ if (!this.fetching) {
8369
+ const { session } = this;
8370
+ this.changesDuringFetch = [];
8371
+ this.fetching = this.fetch(session).finally(() => {
8372
+ if (session !== this.session)
8373
+ return;
8374
+ this.fetching = null;
8375
+ this.changesDuringFetch = [];
8376
+ });
8377
+ }
8378
+ await this.fetching;
8379
+ }
8380
+ async fetch(session) {
8381
+ var _a;
8382
+ const client = getActiveClient();
8383
+ const { data } = await client.http.get('/api/v4/me/following-ids');
8384
+ if (session !== this.session)
8385
+ return; // signed out while in flight
8386
+ // replaced, never merged
8387
+ this.followings = new Map(((_a = data === null || data === void 0 ? void 0 : data.follows) !== null && _a !== void 0 ? _a : [])
8388
+ .filter(follow => isKept(follow.status))
8389
+ .map(follow => [follow.userId, follow.status]));
8390
+ // a change made while the request was in flight is newer than the answer
8391
+ this.changesDuringFetch.forEach(change => this.apply(change));
8392
+ this.lastFetchedAt = Date.now();
8393
+ }
8394
+ /** The kept entries, in order. */
8395
+ getFollowings() {
8396
+ return [...this.followings].map(([userId, status]) => ({ userId, status }));
8397
+ }
8398
+ }
8399
+ let instance$2 = null;
8400
+ var FollowingSyncEngine$1 = {
8401
+ getInstance: () => {
8402
+ if (!instance$2)
8403
+ instance$2 = new FollowingSyncEngine();
8404
+ return instance$2;
8405
+ },
8406
+ };
8407
+
8408
+ var followingSyncEngineOnLoginHandler = () => {
8409
+ const followingSyncEngine = FollowingSyncEngine$1.getInstance();
8410
+ onSessionStateChange(state => {
8411
+ if (state === "established" /* Amity.SessionStates.ESTABLISHED */) {
8412
+ followingSyncEngine.onSessionEstablished();
8413
+ }
8414
+ else if (state === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
8415
+ followingSyncEngine.onTokenExpired();
8416
+ }
8417
+ else {
8418
+ followingSyncEngine.onSessionDestroyed();
8419
+ }
8420
+ });
8421
+ return () => {
8422
+ followingSyncEngine.onSessionDestroyed();
8423
+ };
8424
+ };
8425
+
8426
+ const createFollowEventSubscriber = (event, callback) => {
8427
+ const client = getActiveClient();
8428
+ const filter = (data) => {
8429
+ const payload = prepareFollowersPayload(data);
8430
+ if (!client.cache) {
8431
+ callback(payload.follows[0]);
8432
+ }
8433
+ else {
8434
+ ingestInCache(payload);
8435
+ callback(payload.follows[0]);
8436
+ }
8437
+ };
8438
+ return createEventSubscriber(client, event, event, filter);
8439
+ };
8440
+ const createLocalFollowEventSubscriber = (event, callback) => {
8441
+ const client = getActiveClient();
8442
+ const filter = (data) => {
8443
+ const payload = prepareFollowStatusPayload(data);
8444
+ if (!client.cache) {
8445
+ callback(payload.follows[0]);
8446
+ }
8447
+ else {
8448
+ ingestInCache(payload);
8449
+ callback(payload.follows[0]);
8450
+ }
8451
+ };
8452
+ return createEventSubscriber(client, event, event, filter);
8453
+ };
8454
+
8455
+ /**
8456
+ * ```js
8457
+ * import { onUserFollowed } from '@amityco/ts-sdk'
8458
+ * const dispose = onUserFollowed(status => {
8459
+ * // ...
8460
+ * })
8461
+ * ```
8462
+ *
8463
+ * Fired when a user follows another users and confirmation is not required
8464
+ *
8465
+ * @param callback The function to call when the event was fired
8466
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
8467
+ *
8468
+ * @category Follow Events
8469
+ */
8470
+ const onUserFollowed = (callback) => createFollowEventSubscriber('follow.created', callback);
8471
+
8472
+ /**
8473
+ * ```js
8474
+ * import { onFollowerRequested } from '@amityco/ts-sdk'
8475
+ * const dispose = onFollowerRequested(status => {
8476
+ * // ...
8477
+ * })
8478
+ * ```
8479
+ *
8480
+ * Fired when a user follows another users and confirmation is required
8481
+ *
8482
+ * @param callback The function to call when the event was fired
8483
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
8484
+ *
8485
+ * @category Follow Events
8486
+ */
8487
+ const onFollowerRequested = (callback) => createFollowEventSubscriber('follow.requested', callback);
8488
+
8489
+ /**
8490
+ * ```js
8491
+ * import { onFollowRequestAccepted } from '@amityco/ts-sdk'
8492
+ * const dispose = onFollowRequestAccepted(status => {
8493
+ * // ...
8494
+ * })
8495
+ * ```
8496
+ *
8497
+ * Fired when a follow request has been accepted
8498
+ *
8499
+ * @param callback The function to call when the event was fired
8500
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
8501
+ *
8502
+ * @category Follow Events
8503
+ */
8504
+ const onFollowRequestAccepted = (callback) => createFollowEventSubscriber('follow.accepted', callback);
8505
+
8506
+ /**
8507
+ * ```js
8508
+ * import { onUserUnfollowed } from '@amityco/ts-sdk'
8509
+ * const dispose = onUserFollowed(status => {
8510
+ * // ...
8511
+ * })
8512
+ * ```
8513
+ *
8514
+ * Fired when a user unfollows
8515
+ *
8516
+ * @param callback The function to call when the event was fired
8517
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
8518
+ *
8519
+ * @category Follow Events
8520
+ */
8521
+ const onUserUnfollowed = (callback) => createFollowEventSubscriber('follow.unfollowed', callback);
8522
+
8523
+ /**
8524
+ * ```js
8525
+ * import { onFollowRequestCanceled } from '@amityco/ts-sdk'
8526
+ * const dispose = onFollowRequestCanceled(status => {
8527
+ * // ...
8528
+ * })
8529
+ * ```
8530
+ *
8531
+ * Fired when a follow request has been canceled
8532
+ *
8533
+ * @param callback The function to call when the event was fired
8534
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
8535
+ *
8536
+ * @category Follow Events
8537
+ */
8538
+ const onFollowRequestCanceled = (callback) => createFollowEventSubscriber('follow.requestCanceled', callback);
8539
+
8540
+ /**
8541
+ * ```js
8542
+ * import { onFollowRequestDeclined } from '@amityco/ts-sdk'
8543
+ * const dispose = onFollowRequestDeclined(status => {
8544
+ * // ...
8545
+ * })
8546
+ * ```
8547
+ *
8548
+ * Fired when a follow request has been declined
8549
+ *
8550
+ * @param callback The function to call when the event was fired
8551
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
8552
+ *
8553
+ * @category Follow Events
8554
+ */
8555
+ const onFollowRequestDeclined = (callback) => createFollowEventSubscriber('follow.requestDeclined', callback);
8556
+
8557
+ /**
8558
+ * ```js
8559
+ * import { onFollowerDeleted } from '@amityco/ts-sdk'
8560
+ * const dispose = onFollowerDeleted(status => {
8561
+ * // ...
8562
+ * })
8563
+ * ```
8564
+ *
8565
+ * Fired when a follower has been deleted
8566
+ *
8567
+ * @param callback The function to call when the event was fired
8568
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
8569
+ *
8570
+ * @category Follow Events
8571
+ */
8572
+ const onFollowerDeleted = (callback) => createFollowEventSubscriber('follow.followerDeleted', callback);
8573
+
8574
+ const onLocalUserFollowed = (callback) => createLocalFollowEventSubscriber('local.follow.created', callback);
8575
+
8576
+ const onLocalFollowerRequested = (callback) => createLocalFollowEventSubscriber('local.follow.requested', callback);
8577
+
8578
+ const onLocalUserUnfollowed = (callback) => createLocalFollowEventSubscriber('local.follow.unfollowed', callback);
8579
+
8580
+ // Each event file directly, not the events barrel: the barrel's onFollowInfoUpdated imports
8581
+ /**
8582
+ * Keeps `getAllFollowings()` current for the whole session: every follow change — from
8583
+ * this device (local echo) or another (MQTT) — goes to `FollowingSyncEngine.onFollowChanged`,
8584
+ * which ignores follows of other users and applies the rest by status: a follow adds the
8585
+ * user as accepted, a request as pending, an accepted request turns accepted, and an
8586
+ * unfollow, a canceled or declined request, a removed follower or a block takes the user out.
8587
+ * `blockUser` also calls the engine itself: its local event swaps `from` and `to`.
8588
+ * The MQTT events arrive on the followers and followings topics of the BLOCK
8589
+ * auto-subscription (on by default).
8590
+ *
8591
+ * Registered via `setupLoginSubscriptions`; the returned unsubscriber is torn
8592
+ * down on logout.
8593
+ */
8594
+ var followRealtimeOnLoginHandler = () => {
8595
+ const engine = FollowingSyncEngine$1.getInstance();
8596
+ const apply = (follow) => engine.onFollowChanged(follow);
8597
+ const disposers = [
8598
+ onUserFollowed(apply),
8599
+ onFollowerRequested(apply),
8600
+ onFollowRequestAccepted(apply),
8601
+ onUserUnfollowed(apply),
8602
+ onFollowRequestCanceled(apply),
8603
+ onFollowRequestDeclined(apply),
8604
+ onFollowerDeleted(apply),
8605
+ onUserDidBlock(apply),
8606
+ onLocalUserFollowed(apply),
8607
+ onLocalFollowerRequested(apply),
8608
+ onLocalUserUnfollowed(apply),
8609
+ ];
8610
+ return () => disposers.forEach(dispose => dispose());
8611
+ };
8612
+
8277
8613
  class CursorController {
8278
8614
  constructor(networkId, userId) {
8279
8615
  this.networkId = networkId;
@@ -8922,7 +9258,7 @@ const setupLoginSubscriptions = (unsubWatcher) => {
8922
9258
  // NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
8923
9259
  // the channel because currently backend can't handle this, so every time a user is banned from
8924
9260
  // 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());
9261
+ onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler(), blockingUserSyncEngineOnLoginHandler(), blockRealtimeOnLoginHandler(), followingSyncEngineOnLoginHandler(), followRealtimeOnLoginHandler(), resetAutoSubscriptionsOnLogout(), CursorController.clearOnLogout(), postCommentCountEngineOnLoginHandler(), channelActivityOnLoginHandler(), userFlagByMeOnLoginHandler());
8926
9262
  if (client.useLegacyUnreadCount) {
8927
9263
  subscriptions.push(readReceiptSyncEngineOnLoginHandler());
8928
9264
  }
@@ -11251,6 +11587,14 @@ const blockUser = async (userId) => {
11251
11587
  };
11252
11588
  const payload = prepareFollowStatusPayload(blockedUnfollowStatus);
11253
11589
  fireEvent('local.follow.unfollowed', payload);
11590
+ // the local event above swaps from and to, so getAllFollowings() cannot see this block in it
11591
+ if (client.userId) {
11592
+ FollowingSyncEngine$1.getInstance().onFollowChanged({
11593
+ from: client.userId,
11594
+ to: userId,
11595
+ status: 'blocked',
11596
+ });
11597
+ }
11254
11598
  return data;
11255
11599
  };
11256
11600
  /* end_public_function */
@@ -11315,6 +11659,8 @@ const follow = async (userId) => {
11315
11659
  ingestInCache(data, { cachedAt });
11316
11660
  }
11317
11661
  const payload = prepareFollowStatusPayload(data);
11662
+ // at once: the local event below is delivered on a later tick
11663
+ FollowingSyncEngine$1.getInstance().onFollowChanged(data.follows[0]);
11318
11664
  if (data.follows[0].status === 'accepted') {
11319
11665
  fireEvent('local.follow.created', payload);
11320
11666
  }
@@ -11353,6 +11699,8 @@ const unfollow = async (userId) => {
11353
11699
  ingestInCache(data);
11354
11700
  }
11355
11701
  const payload = prepareFollowStatusPayload(data);
11702
+ // at once: the local event below is delivered on a later tick
11703
+ FollowingSyncEngine$1.getInstance().onFollowChanged(data.follows[0]);
11356
11704
  fireEvent('local.follow.unfollowed', payload);
11357
11705
  return true;
11358
11706
  };
@@ -11418,153 +11766,51 @@ const declineMyFollower = async (userId) => {
11418
11766
  };
11419
11767
  /* end_public_function */
11420
11768
 
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);
11500
-
11501
- /**
11502
- * ```js
11503
- * import { onFollowerRequested } from '@amityco/ts-sdk'
11504
- * const dispose = onFollowerRequested(status => {
11505
- * // ...
11506
- * })
11507
- * ```
11508
- *
11509
- * Fired when a user follows another users and confirmation is required
11510
- *
11511
- * @param callback The function to call when the event was fired
11512
- * @returns an {@link Amity.Unsubscriber} function to stop listening
11513
- *
11514
- * @category Follow Events
11515
- */
11516
- const onFollowerRequested = (callback) => createFollowEventSubscriber('follow.requested', callback);
11517
-
11769
+ /* begin_public_function
11770
+ id: user.relationship.get_all_followings
11771
+ */
11518
11772
  /**
11519
11773
  * ```js
11520
- * import { onFollowRequestCanceled } from '@amityco/ts-sdk'
11521
- * const dispose = onFollowRequestCanceled(status => {
11522
- * // ...
11523
- * })
11524
- * ```
11525
- *
11526
- * Fired when a follow request has been canceled
11527
- *
11528
- * @param callback The function to call when the event was fired
11529
- * @returns an {@link Amity.Unsubscriber} function to stop listening
11774
+ * import { UserRepository } from '@amityco/ts-sdk'
11530
11775
  *
11531
- * @category Follow Events
11532
- */
11533
- const onFollowRequestCanceled = (callback) => createFollowEventSubscriber('follow.requestCanceled', callback);
11534
-
11535
- /**
11536
- * ```js
11537
- * import { onFollowRequestAccepted } from '@amityco/ts-sdk'
11538
- * const dispose = onFollowRequestAccepted(status => {
11539
- * // ...
11540
- * })
11776
+ * const followings = await UserRepository.Relationship.getAllFollowings()
11777
+ * const statusOf = new Map(followings.map(f => [f.userId, f.status]))
11778
+ * // 'accepted' → no button; 'pending' → Pending; missing → Follow
11541
11779
  * ```
11542
11780
  *
11543
- * Fired when a follow request has been accepted
11544
- *
11545
- * @param callback The function to call when the event was fired
11546
- * @returns an {@link Amity.Unsubscriber} function to stop listening
11781
+ * Returns whom the signed-in user follows as a one-shot list of at most 5,000 (the most a
11782
+ * user can follow), from one request with no paging: each followed user's id and the
11783
+ * follow's status — `accepted`, or `pending` for a request not yet accepted. A user
11784
+ * missing from the list is not followed. The list holds ids and statuses only, no user
11785
+ * profiles.
11547
11786
  *
11548
- * @category Follow Events
11549
- */
11550
- const onFollowRequestAccepted = (callback) => createFollowEventSubscriber('follow.accepted', callback);
11551
-
11552
- /**
11553
- * ```js
11554
- * import { onFollowRequestDeclined } from '@amityco/ts-sdk'
11555
- * const dispose = onFollowRequestDeclined(status => {
11556
- * // ...
11557
- * })
11558
- * ```
11787
+ * Use it to show the follow button next to each author in the post feed: match each
11788
+ * author by user id against `userId`.
11559
11789
  *
11560
- * Fired when a follow request has been declined
11790
+ * Keeping the app current: the function answers once, so call it again to see changes —
11791
+ * for example when more posts load, when the feed comes back into view, or on a follow
11792
+ * event (`onUserFollowed`, `onUserUnfollowed`, `onFollowRequestAccepted`). The answer is
11793
+ * kept on the device for 5 minutes, so a call within that window costs no request. Changes
11794
+ * made in this app show at once. Changes made elsewhere — on another device, or by the
11795
+ * other user accepting a request or removing the user as a follower — show once their
11796
+ * real-time event arrives; the SDK receives these on the followers and followings topics
11797
+ * of `AmityAutoSubscription.BLOCK`, on by default. An event missed while offline, or with
11798
+ * that subscription turned off, shows at the next fetch, after the 5 minutes.
11561
11799
  *
11562
- * @param callback The function to call when the event was fired
11563
- * @returns an {@link Amity.Unsubscriber} function to stop listening
11800
+ * @returns A promise that resolves to the signed-in user's {@link Amity.FollowingUserStatus} list
11564
11801
  *
11565
- * @category Follow Events
11802
+ * @category Follow API
11803
+ * @async
11566
11804
  */
11567
- const onFollowRequestDeclined = (callback) => createFollowEventSubscriber('follow.requestDeclined', callback);
11805
+ const getAllFollowings = async () => {
11806
+ const client = getActiveClient();
11807
+ client.log('follow/getAllFollowings');
11808
+ const engine = FollowingSyncEngine$1.getInstance();
11809
+ // Fetch only when the 5-minute window has expired (no-op otherwise)
11810
+ await engine.ensureFetched();
11811
+ return engine.getFollowings();
11812
+ };
11813
+ /* end_public_function */
11568
11814
 
11569
11815
  /**
11570
11816
  * ```js
@@ -11670,12 +11916,6 @@ const onFollowInfoUpdated = (callback) => {
11670
11916
  };
11671
11917
  };
11672
11918
 
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
11919
  const onLocalFollowRequestAccepted = (callback) => createLocalFollowEventSubscriber('local.follow.accepted', callback);
11680
11920
 
11681
11921
  const onLocalFollowRequestDeclined = (callback) => createLocalFollowEventSubscriber('local.follow.requestDeclined', callback);
@@ -12397,6 +12637,7 @@ var index$s = /*#__PURE__*/Object.freeze({
12397
12637
  unfollow: unfollow,
12398
12638
  acceptMyFollower: acceptMyFollower,
12399
12639
  declineMyFollower: declineMyFollower,
12640
+ getAllFollowings: getAllFollowings,
12400
12641
  onUserFollowed: onUserFollowed,
12401
12642
  onUserUnfollowed: onUserUnfollowed,
12402
12643
  onFollowerDeleted: onFollowerDeleted,
@@ -14142,7 +14383,7 @@ const getWatchSessionStorage = () => {
14142
14383
  return storageInstance;
14143
14384
  };
14144
14385
 
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\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NN58bSBGJCyBP2b59+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
14387
  /*
14147
14388
  * The crypto algorithm used for importing key and signing string
14148
14389
  */