@amityco/ts-sdk-react-native 6.32.7-289cad7.0 → 6.32.7-686c44c.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 (96) hide show
  1. package/dist/@types/core/events.d.ts +16 -2
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/payload.d.ts +3 -0
  4. package/dist/@types/core/payload.d.ts.map +1 -1
  5. package/dist/@types/domains/message.d.ts +1 -0
  6. package/dist/@types/domains/message.d.ts.map +1 -1
  7. package/dist/@types/domains/pinnedPost.d.ts +1 -0
  8. package/dist/@types/domains/pinnedPost.d.ts.map +1 -1
  9. package/dist/@types/domains/reaction.d.ts +8 -2
  10. package/dist/@types/domains/reaction.d.ts.map +1 -1
  11. package/dist/@types/domains/user.d.ts +4 -0
  12. package/dist/@types/domains/user.d.ts.map +1 -1
  13. package/dist/communityRepository/communityMembership/events/utils.d.ts.map +1 -1
  14. package/dist/communityRepository/utils/communityWithMembership.d.ts.map +1 -1
  15. package/dist/feedRepository/api/queryGlobalFeed.d.ts.map +1 -1
  16. package/dist/index.cjs.js +919 -570
  17. package/dist/index.esm.js +919 -570
  18. package/dist/index.umd.js +3 -3
  19. package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.d.ts +13 -0
  20. package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.d.ts.map +1 -0
  21. package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostPaginationController.d.ts +13 -0
  22. package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostPaginationController.d.ts.map +1 -0
  23. package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostQueryStreamController.d.ts +15 -0
  24. package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostQueryStreamController.d.ts.map +1 -0
  25. package/dist/postRepository/observers/getGlobalPinnedPosts.d.ts +10 -0
  26. package/dist/postRepository/observers/getGlobalPinnedPosts.d.ts.map +1 -0
  27. package/dist/postRepository/observers/index.d.ts +1 -0
  28. package/dist/postRepository/observers/index.d.ts.map +1 -1
  29. package/dist/reactionRepository/api/addReaction.d.ts.map +1 -1
  30. package/dist/reactionRepository/api/removeReaction.d.ts.map +1 -1
  31. package/dist/reactionRepository/events/onReactorAddedLocal.d.ts +19 -0
  32. package/dist/reactionRepository/events/onReactorAddedLocal.d.ts.map +1 -0
  33. package/dist/reactionRepository/events/onReactorRemovedLocal.d.ts +19 -0
  34. package/dist/reactionRepository/events/onReactorRemovedLocal.d.ts.map +1 -0
  35. package/dist/reactionRepository/observers/getReactions/ReactionLiveCollectionController.d.ts +13 -0
  36. package/dist/reactionRepository/observers/getReactions/ReactionLiveCollectionController.d.ts.map +1 -0
  37. package/dist/reactionRepository/observers/getReactions/ReactionPaginationController.d.ts +5 -0
  38. package/dist/reactionRepository/observers/getReactions/ReactionPaginationController.d.ts.map +1 -0
  39. package/dist/reactionRepository/observers/getReactions/ReactionQueryStreamController.d.ts +14 -0
  40. package/dist/reactionRepository/observers/getReactions/ReactionQueryStreamController.d.ts.map +1 -0
  41. package/dist/reactionRepository/observers/{getReactions.d.ts → getReactions/getReactions.d.ts} +1 -1
  42. package/dist/reactionRepository/observers/getReactions/getReactions.d.ts.map +1 -0
  43. package/dist/reactionRepository/observers/getReactions/index.d.ts +2 -0
  44. package/dist/reactionRepository/observers/getReactions/index.d.ts.map +1 -0
  45. package/dist/reactionRepository/observers/index.d.ts +1 -1
  46. package/dist/reactionRepository/observers/index.d.ts.map +1 -1
  47. package/dist/storyRepository/observers/getGlobalStoryTargets/GlobalStoryLiveCollectionController.d.ts.map +1 -1
  48. package/dist/storyRepository/observers/getGlobalStoryTargets/GlobalStoryQueryStreamController.d.ts +1 -1
  49. package/dist/storyRepository/observers/getGlobalStoryTargets/GlobalStoryQueryStreamController.d.ts.map +1 -1
  50. package/dist/userRepository/constants/index.d.ts +5 -0
  51. package/dist/userRepository/constants/index.d.ts.map +1 -0
  52. package/dist/userRepository/index.d.ts +1 -0
  53. package/dist/userRepository/index.d.ts.map +1 -1
  54. package/dist/userRepository/observers/getBlockedUsers/BlockedUserLiveCollectionController.d.ts.map +1 -1
  55. package/dist/userRepository/observers/getBlockedUsers/BlockedUserQueryStreamController.d.ts +3 -2
  56. package/dist/userRepository/observers/getBlockedUsers/BlockedUserQueryStreamController.d.ts.map +1 -1
  57. package/dist/utils/linkedObject/messageLinkedObject.d.ts.map +1 -1
  58. package/package.json +1 -1
  59. package/src/@types/core/events.ts +18 -6
  60. package/src/@types/core/payload.ts +4 -0
  61. package/src/@types/domains/message.ts +1 -0
  62. package/src/@types/domains/pin.ts +1 -1
  63. package/src/@types/domains/pinnedPost.ts +2 -0
  64. package/src/@types/domains/reaction.ts +9 -3
  65. package/src/@types/domains/user.ts +6 -0
  66. package/src/communityRepository/communityMembership/events/utils.ts +4 -2
  67. package/src/communityRepository/utils/communityWithMembership.ts +15 -8
  68. package/src/feedRepository/api/queryGlobalFeed.ts +4 -1
  69. package/src/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.ts +96 -0
  70. package/src/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostPaginationController.ts +19 -0
  71. package/src/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostQueryStreamController.ts +88 -0
  72. package/src/postRepository/observers/getGlobalPinnedPosts.ts +42 -0
  73. package/src/postRepository/observers/index.ts +1 -0
  74. package/src/reactionRepository/api/addReaction.ts +23 -1
  75. package/src/reactionRepository/api/removeReaction.ts +25 -2
  76. package/src/reactionRepository/events/onReactorAddedLocal.ts +95 -0
  77. package/src/reactionRepository/events/onReactorRemovedLocal.ts +94 -0
  78. package/src/reactionRepository/observers/getReactions/ReactionLiveCollectionController.ts +111 -0
  79. package/src/reactionRepository/observers/getReactions/ReactionPaginationController.ts +30 -0
  80. package/src/reactionRepository/observers/getReactions/ReactionQueryStreamController.ts +92 -0
  81. package/src/reactionRepository/observers/getReactions/getReactions.ts +57 -0
  82. package/src/reactionRepository/observers/getReactions/index.ts +1 -0
  83. package/src/reactionRepository/observers/index.ts +1 -1
  84. package/src/storyRepository/events/onStoryReactionAdded.ts +3 -3
  85. package/src/storyRepository/events/onStoryReactionRemoved.ts +3 -3
  86. package/src/storyRepository/observers/getGlobalStoryTargets/GlobalStoryLiveCollectionController.ts +5 -0
  87. package/src/storyRepository/observers/getGlobalStoryTargets/GlobalStoryQueryStreamController.ts +5 -2
  88. package/src/userRepository/constants/index.ts +4 -0
  89. package/src/userRepository/index.ts +1 -0
  90. package/src/userRepository/observers/getBlockedUsers/BlockedUserLiveCollectionController.ts +12 -1
  91. package/src/userRepository/observers/getBlockedUsers/BlockedUserQueryStreamController.ts +13 -5
  92. package/src/userRepository/relationship/follow/observers/getFollowers/FollowerLiveCollectionController.ts +1 -1
  93. package/src/userRepository/relationship/follow/observers/getFollowings/FollowingLiveCollectionController.ts +1 -1
  94. package/src/utils/linkedObject/messageLinkedObject.ts +4 -0
  95. package/dist/reactionRepository/observers/getReactions.d.ts.map +0 -1
  96. package/src/reactionRepository/observers/getReactions.ts +0 -146
package/dist/index.cjs.js CHANGED
@@ -5895,6 +5895,10 @@ const messageLinkedObject = (message) => {
5895
5895
  },
5896
5896
  get deliveredCount() {
5897
5897
  return getMessageReadCount(message).deliveredCount;
5898
+ },
5899
+ get creator() {
5900
+ var _a;
5901
+ return (_a = pullFromCache(['user', 'get', message.creatorId])) === null || _a === void 0 ? void 0 : _a.data;
5898
5902
  }, markRead: () => markReadMessage(message) });
5899
5903
  };
5900
5904
 
@@ -10248,6 +10252,18 @@ class QueryStreamController {
10248
10252
  }
10249
10253
  }
10250
10254
 
10255
+ var EnumFollowActions;
10256
+ (function (EnumFollowActions) {
10257
+ EnumFollowActions["OnRequested"] = "onRequested";
10258
+ EnumFollowActions["OnAccepted"] = "onAccepted";
10259
+ EnumFollowActions["OnDeclined"] = "onDeclined";
10260
+ EnumFollowActions["OnCanceled"] = "onCanceled";
10261
+ EnumFollowActions["OnFollowed"] = "onFollowed";
10262
+ EnumFollowActions["OnUnfollowed"] = "onUnfollowed";
10263
+ EnumFollowActions["OnDeleted"] = "onDeleted";
10264
+ EnumFollowActions["OnUserDeleted"] = "onUserDeleted";
10265
+ })(EnumFollowActions || (EnumFollowActions = {}));
10266
+
10251
10267
  class BlockedUserQueryStreamController extends QueryStreamController {
10252
10268
  constructor(query, cacheKey, notifyChange, preparePayload) {
10253
10269
  super(query, cacheKey);
@@ -10276,10 +10292,13 @@ class BlockedUserQueryStreamController extends QueryStreamController {
10276
10292
  }
10277
10293
  }
10278
10294
  reactor(action) {
10279
- return (followStatus) => {
10295
+ return (targetUser) => {
10280
10296
  var _a;
10281
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
10282
- pushToCache(this.cacheKey, collection);
10297
+ if (action === EnumFollowActions.OnFollowed) {
10298
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
10299
+ const updatedCollection = collection === null || collection === void 0 ? void 0 : collection.data.filter(id => id !== targetUser.userId);
10300
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: updatedCollection }));
10301
+ }
10283
10302
  this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
10284
10303
  };
10285
10304
  }
@@ -10476,560 +10495,593 @@ var EnumUserActions;
10476
10495
  EnumUserActions["OnUserFlagCleared"] = "onUserFlagCleared";
10477
10496
  })(EnumUserActions || (EnumUserActions = {}));
10478
10497
 
10479
- class BlockedUserLiveCollectionController extends LiveCollectionController {
10480
- constructor(query, callback) {
10481
- const queryStreamId = hash__default["default"](query);
10482
- const cacheKey = ['blockedUsers', 'collection', queryStreamId];
10483
- const paginationController = new BlockedUserPaginationController(query);
10484
- super(paginationController, queryStreamId, cacheKey, callback);
10485
- this.query = query;
10486
- this.queryStreamController = new BlockedUserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareBlockedUserPayload);
10487
- this.callback = callback.bind(this);
10488
- this.loadPage({ initial: true });
10489
- }
10490
- setup() {
10491
- var _a;
10492
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
10493
- if (!collection) {
10494
- pushToCache(this.cacheKey, {
10495
- data: [],
10496
- params: {},
10497
- });
10498
+ const createFollowEventSubscriber = (event, callback) => {
10499
+ const client = getActiveClient();
10500
+ const filter = (data) => {
10501
+ const payload = prepareFollowersPayload(data);
10502
+ if (!client.cache) {
10503
+ callback(payload.follows[0]);
10498
10504
  }
10499
- }
10500
- async persistModel(queryPayload) {
10501
- await this.queryStreamController.saveToMainDB(queryPayload);
10502
- }
10503
- persistQueryStream({ response, direction, refresh, }) {
10504
- this.queryStreamController.appendToQueryStream(response, direction, refresh);
10505
- }
10506
- startSubscription() {
10507
- return this.queryStreamController.subscribeRTE([
10508
- {
10509
- fn: onUserDeleted$2,
10510
- action: EnumUserActions.OnUserDeleted,
10511
- },
10512
- ]);
10513
- }
10514
- notifyChange({ origin, loading, error }) {
10515
- var _a, _b;
10516
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
10517
- if (!collection)
10518
- return;
10519
- const data = this.applyFilter((_b = collection.data
10520
- .map(id => pullFromCache(['user', 'get', id]))
10521
- .filter(isNonNullable)
10522
- .map(({ data }) => data)
10523
- .map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
10524
- if (!this.shouldNotify(data) && origin === 'event')
10525
- return;
10526
- this.callback({
10527
- onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
10528
- data,
10529
- hasNextPage: !!this.paginationController.getNextToken(),
10530
- loading,
10531
- error,
10532
- });
10533
- }
10534
- // eslint-disable-next-line class-methods-use-this
10535
- applyFilter(data) {
10536
- let users = data;
10537
- users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
10538
- return users;
10539
- }
10540
- }
10505
+ else {
10506
+ ingestInCache(payload);
10507
+ callback(payload.follows[0]);
10508
+ }
10509
+ };
10510
+ return createEventSubscriber(client, event, event, filter);
10511
+ };
10512
+ const createLocalFollowEventSubscriber = (event, callback) => {
10513
+ const client = getActiveClient();
10514
+ const filter = (data) => {
10515
+ const payload = prepareFollowStatusPayload(data);
10516
+ if (!client.cache) {
10517
+ callback(payload.follows[0]);
10518
+ }
10519
+ else {
10520
+ ingestInCache(payload);
10521
+ callback(payload.follows[0]);
10522
+ }
10523
+ };
10524
+ return createEventSubscriber(client, event, event, filter);
10525
+ };
10541
10526
 
10542
- /* begin_public_function
10543
- id: user.get_blocked_users
10544
- */
10545
10527
  /**
10546
10528
  * ```js
10547
- * import { UserRepository } from '@amityco/ts-sdk-react-native'
10548
- * const unblockedUser = await UserRepository.blockUser('userId')
10529
+ * import { onUserFollowed } from '@amityco/ts-sdk-react-native'
10530
+ * const dispose = onUserFollowed(status => {
10531
+ * // ...
10532
+ * })
10549
10533
  * ```
10550
10534
  *
10551
- * Blocks a {@link Amity.InternalUser}
10535
+ * Fired when a user follows another users and confirmation is not required
10552
10536
  *
10553
- * @param params The params to get blocked {@link Amity.InternalUser}s
10554
- * @param callback to recieve updates on unblocked {@link Amity.InternalUser}s
10555
- * @returns {@link Amity.Unsubscriber} to unsubscribe from collection
10537
+ * @param callback The function to call when the event was fired
10538
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
10556
10539
  *
10557
- * @category Post API
10558
- * @async
10540
+ * @category Follow Events
10559
10541
  */
10560
- const getBlockedUsers$1 = (params, callback, config) => {
10561
- const { log, cache } = getActiveClient();
10562
- if (!cache) {
10563
- console.log(ENABLE_CACHE_MESSAGE);
10564
- }
10565
- const timestamp = Date.now();
10566
- log(`getBlockedUsers(tmpid: ${timestamp}) > listen`);
10567
- const blockedUserLiveCollection = new BlockedUserLiveCollectionController(params, callback);
10568
- const disposers = blockedUserLiveCollection.startSubscription();
10569
- const cacheKey = blockedUserLiveCollection.getCacheKey();
10570
- disposers.push(() => dropFromCache(cacheKey));
10571
- return () => {
10572
- log(`getBlockedUsers(tmpid: ${timestamp}) > dispose`);
10573
- disposers.forEach(fn => fn());
10574
- dropFromCache(cacheKey);
10575
- };
10576
- };
10577
- /* end_public_function */
10578
-
10579
- /* eslint-disable no-use-before-define */
10580
- const getBlockedUsers = (params, callback, config) => {
10581
- console.log('Deprecation Notice: UserRepository.Relationship.getBlockedUsers will be deprecated on 9th June 2023, please use UserRepository.getBlockedUsers instead.');
10582
- return getBlockedUsers$1(params, callback);
10583
- };
10542
+ const onUserFollowed = (callback) => createFollowEventSubscriber('follow.created', callback);
10584
10543
 
10585
- /* begin_public_function
10586
- id: user.relationship.follow
10587
- */
10588
10544
  /**
10589
10545
  * ```js
10590
- * import { follow } from '@amityco/ts-sdk-react-native'
10591
- * const status = await follow('foobar')
10546
+ * import { onUserUnfollowed } from '@amityco/ts-sdk-react-native'
10547
+ * const dispose = onUserFollowed(status => {
10548
+ * // ...
10549
+ * })
10592
10550
  * ```
10593
10551
  *
10594
- * Follow the user
10552
+ * Fired when a user unfollows
10595
10553
  *
10596
- * @param userId the ID of the {@link Amity.InternalUser}
10597
- * @returns the status {@link Amity.FollowStatus}
10554
+ * @param callback The function to call when the event was fired
10555
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
10598
10556
  *
10599
- * @category Follow API
10600
- * @async
10557
+ * @category Follow Events
10601
10558
  */
10602
- const follow = async (userId) => {
10603
- const client = getActiveClient();
10604
- client.log('follow/follow', userId);
10605
- const { data } = await client.http.post(`/api/v4/me/following/${userId}`);
10606
- const cachedAt = client.cache && Date.now();
10607
- if (client.cache) {
10608
- ingestInCache(data, { cachedAt });
10609
- }
10610
- const payload = prepareFollowStatusPayload(data);
10611
- if (data.follows[0].status === 'accepted') {
10612
- fireEvent('local.follow.created', payload);
10613
- }
10614
- else {
10615
- fireEvent('local.follow.requested', payload);
10616
- }
10617
- return {
10618
- data: data.follows[0],
10619
- cachedAt,
10620
- };
10621
- };
10622
- /* end_public_function */
10559
+ const onUserUnfollowed = (callback) => createFollowEventSubscriber('follow.unfollowed', callback);
10623
10560
 
10624
- /* begin_public_function
10625
- id: user.relationship.unfollow
10626
- */
10627
10561
  /**
10628
10562
  * ```js
10629
- * import { unfollow } from '@amityco/ts-sdk-react-native'
10630
- * await unfollow('foobar')
10563
+ * import { onFollowerDeleted } from '@amityco/ts-sdk-react-native'
10564
+ * const dispose = onFollowerDeleted(status => {
10565
+ * // ...
10566
+ * })
10631
10567
  * ```
10632
10568
  *
10633
- * Cancel the follow request or unfollow the user
10569
+ * Fired when a follower has been deleted
10634
10570
  *
10635
- * @param userId the ID of the {@link Amity.InternalUser}
10636
- * @returns A success boolean if the user {@link Amity.InternalUser} was unfollowed
10571
+ * @param callback The function to call when the event was fired
10572
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
10637
10573
  *
10638
- * @category Follow API
10639
- * @async
10574
+ * @category Follow Events
10640
10575
  */
10641
- const unfollow = async (userId) => {
10642
- const client = getActiveClient();
10643
- client.log('follow/unfollow', userId);
10644
- const { data } = await client.http.delete(`/api/v4/me/following/${userId}`);
10645
- if (client.cache) {
10646
- ingestInCache(data);
10647
- }
10648
- const payload = prepareFollowStatusPayload(data);
10649
- fireEvent('local.follow.unfollowed', payload);
10650
- return true;
10651
- };
10652
- /* end_public_function */
10576
+ const onFollowerDeleted = (callback) => createFollowEventSubscriber('follow.followerDeleted', callback);
10653
10577
 
10654
10578
  /**
10655
- * @deprecated This API renamed to `acceptMyFollower`.
10656
- * Please use acceptMyFollower() instead.
10657
- *
10658
10579
  * ```js
10659
- * import { acceptFollower } from '@amityco/ts-sdk-react-native'
10660
- * await acceptFollower('foobar')
10580
+ * import { onFollowerRequested } from '@amityco/ts-sdk-react-native'
10581
+ * const dispose = onFollowerRequested(status => {
10582
+ * // ...
10583
+ * })
10661
10584
  * ```
10662
10585
  *
10663
- * Accept the follow request
10586
+ * Fired when a user follows another users and confirmation is required
10664
10587
  *
10665
- * @param userId the ID of the {@link Amity.InternalUser} follower
10666
- * @returns A success boolean if the follow request was accepted
10588
+ * @param callback The function to call when the event was fired
10589
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
10667
10590
  *
10668
- * @category Follow API
10669
- * @async
10591
+ * @category Follow Events
10670
10592
  */
10671
- const acceptFollower = async (userId) => {
10672
- const client = getActiveClient();
10673
- client.log('follow/acceptFollower', userId);
10674
- const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
10675
- if (client.cache) {
10676
- ingestInCache(data);
10677
- }
10678
- const payload = prepareFollowStatusPayload(data);
10679
- fireEvent('local.follow.accepted', payload);
10680
- return true;
10681
- };
10593
+ const onFollowerRequested = (callback) => createFollowEventSubscriber('follow.requested', callback);
10682
10594
 
10683
- /* begin_public_function
10684
- id: user.relationship.accept_follow
10685
- */
10686
10595
  /**
10687
10596
  * ```js
10688
- * import { UserRepository } from '@amityco/ts-sdk-react-native'
10689
- * await UserRepository.Relationship.acceptMyFollower('foobar')
10597
+ * import { onFollowRequestCanceled } from '@amityco/ts-sdk-react-native'
10598
+ * const dispose = onFollowRequestCanceled(status => {
10599
+ * // ...
10600
+ * })
10690
10601
  * ```
10691
10602
  *
10692
- * Accept the follow request
10603
+ * Fired when a follow request has been canceled
10693
10604
  *
10694
- * @param userId the ID of the {@link Amity.InternalUser} follower
10695
- * @returns A success boolean if the follow request was accepted
10605
+ * @param callback The function to call when the event was fired
10606
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
10696
10607
  *
10697
- * @category Follow API
10698
- * @async
10608
+ * @category Follow Events
10699
10609
  */
10700
- const acceptMyFollower = async (userId) => {
10701
- const client = getActiveClient();
10702
- client.log('follow/acceptMyFollower', userId);
10703
- const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
10704
- if (client.cache) {
10705
- ingestInCache(data);
10706
- }
10707
- const payload = prepareFollowStatusPayload(data);
10708
- fireEvent('local.follow.accepted', payload);
10709
- return true;
10710
- };
10711
- /* end_public_function */
10610
+ const onFollowRequestCanceled = (callback) => createFollowEventSubscriber('follow.requestCanceled', callback);
10712
10611
 
10713
10612
  /**
10714
- * @deprecated This API renamed to `declineMyFollower`.
10715
- * Please use declineMyFollower() instead.
10613
+ * ```js
10614
+ * import { onFollowRequestAccepted } from '@amityco/ts-sdk-react-native'
10615
+ * const dispose = onFollowRequestAccepted(status => {
10616
+ * // ...
10617
+ * })
10618
+ * ```
10619
+ *
10620
+ * Fired when a follow request has been accepted
10621
+ *
10622
+ * @param callback The function to call when the event was fired
10623
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
10716
10624
  *
10625
+ * @category Follow Events
10626
+ */
10627
+ const onFollowRequestAccepted = (callback) => createFollowEventSubscriber('follow.accepted', callback);
10628
+
10629
+ /**
10717
10630
  * ```js
10718
- * import { declineFollower } from '@amityco/ts-sdk-react-native'
10719
- * await declineFollower('foobar')
10631
+ * import { onFollowRequestDeclined } from '@amityco/ts-sdk-react-native'
10632
+ * const dispose = onFollowRequestDeclined(status => {
10633
+ * // ...
10634
+ * })
10720
10635
  * ```
10721
10636
  *
10722
- * Decline the follow request or delete the follower
10637
+ * Fired when a follow request has been declined
10723
10638
  *
10724
- * @param userId the ID of the {@link Amity.InternalUser} follower
10725
- * @returns A success boolean if the follow request was decline
10639
+ * @param callback The function to call when the event was fired
10640
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
10726
10641
  *
10727
- * @category Follow API
10728
- * @async
10642
+ * @category Follow Events
10729
10643
  */
10730
- const declineFollower = async (userId) => {
10731
- const client = getActiveClient();
10732
- client.log('follow/declineFollower', userId);
10733
- const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
10734
- if (client.cache) {
10735
- ingestInCache(data);
10736
- }
10737
- const payload = prepareFollowStatusPayload(data);
10738
- fireEvent('local.follow.requestDeclined', payload);
10739
- return true;
10740
- };
10644
+ const onFollowRequestDeclined = (callback) => createFollowEventSubscriber('follow.requestDeclined', callback);
10741
10645
 
10742
- /* begin_public_function
10743
- id: user.relationship.decline_follow
10744
- */
10745
10646
  /**
10746
10647
  * ```js
10747
- * import { UserRepository } from '@amityco/ts-sdk-react-native'
10748
- * await UserRepository.Relationship.declineMyFollower('foobar')
10648
+ * import { getFollowInfo } from '@amityco/ts-sdk-react-native'
10649
+ * const { data: followInfo } = await getFollowInfo('foobar')
10749
10650
  * ```
10750
10651
  *
10751
- * Decline the follow request or delete the follower
10652
+ * Fetches the number of followers, followings, pending requests and the follow status for current user
10752
10653
  *
10753
- * @param userId the ID of the {@link Amity.InternalUser} follower
10754
- * @returns A success boolean if the follow request was decline
10654
+ * @param userId the ID of the {@link Amity.InternalUser}
10655
+ * @returns the associated {@link Amity.FollowInfo} object
10755
10656
  *
10756
10657
  * @category Follow API
10757
10658
  * @async
10758
10659
  */
10759
- const declineMyFollower = async (userId) => {
10660
+ const getFollowInfo$1 = async (userId) => {
10661
+ var _a, _b;
10760
10662
  const client = getActiveClient();
10761
- client.log('follow/declineMyFollower', userId);
10762
- const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
10663
+ client.log('follow/getFollowInfo', userId);
10664
+ const { data } = await client.http.get(client.userId === userId ? `/api/v4/me/followInfo` : `/api/v5/users/${userId}/followInfo`);
10665
+ const cachedAt = client.cache && Date.now();
10666
+ const followInfo = 'follows' in data
10667
+ ? Object.assign(Object.assign({}, data.followCounts[0]), { status: (_b = (_a = data.follows) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.status }) : data.followCounts[0];
10763
10668
  if (client.cache) {
10764
- ingestInCache(data);
10669
+ pushToCache(['followInfo', 'get', userId], followInfo, {
10670
+ cachedAt,
10671
+ });
10765
10672
  }
10766
- const payload = prepareFollowStatusPayload(data);
10767
- fireEvent('local.follow.requestDeclined', payload);
10768
- return true;
10769
- };
10770
- /* end_public_function */
10771
-
10772
- const createFollowEventSubscriber = (event, callback) => {
10773
- const client = getActiveClient();
10774
- const filter = (data) => {
10775
- const payload = prepareFollowersPayload(data);
10776
- if (!client.cache) {
10777
- callback(payload.follows[0]);
10778
- }
10779
- else {
10780
- ingestInCache(payload);
10781
- callback(payload.follows[0]);
10782
- }
10673
+ return {
10674
+ data: followInfo,
10675
+ cachedAt,
10783
10676
  };
10784
- return createEventSubscriber(client, event, event, filter);
10785
10677
  };
10786
- const createLocalFollowEventSubscriber = (event, callback) => {
10787
- const client = getActiveClient();
10788
- const filter = (data) => {
10789
- const payload = prepareFollowStatusPayload(data);
10790
- if (!client.cache) {
10791
- callback(payload.follows[0]);
10792
- }
10793
- else {
10794
- ingestInCache(payload);
10795
- callback(payload.follows[0]);
10796
- }
10797
- };
10798
- return createEventSubscriber(client, event, event, filter);
10799
- };
10800
-
10801
10678
  /**
10802
10679
  * ```js
10803
- * import { onUserFollowed } from '@amityco/ts-sdk-react-native'
10804
- * const dispose = onUserFollowed(status => {
10805
- * // ...
10806
- * })
10680
+ * import { getFollowInfo } from '@amityco/ts-sdk-react-native'
10681
+ * const { data: followInfo } = getFollowInfo.locally('foobar')
10807
10682
  * ```
10808
10683
  *
10809
- * Fired when a user follows another users and confirmation is not required
10684
+ * Fetches the number of followers, followings, pending requests and the follow status for current user from cache
10810
10685
  *
10811
- * @param callback The function to call when the event was fired
10812
- * @returns an {@link Amity.Unsubscriber} function to stop listening
10686
+ * @param userId the ID of the {@link Amity.InternalUser}
10687
+ * @returns the associated {@link Amity.FollowInfo} object
10813
10688
  *
10814
- * @category Follow Events
10689
+ * @category Follow API
10815
10690
  */
10816
- const onUserFollowed = (callback) => createFollowEventSubscriber('follow.created', callback);
10691
+ getFollowInfo$1.locally = (userId) => {
10692
+ const client = getActiveClient();
10693
+ client.log('follow/getFollowInfo.locally', userId);
10694
+ if (!client.cache) {
10695
+ return;
10696
+ }
10697
+ const cached = pullFromCache(['followInfo', 'get', userId]);
10698
+ if (!cached) {
10699
+ return;
10700
+ }
10701
+ return {
10702
+ data: cached.data,
10703
+ cachedAt: cached.cachedAt,
10704
+ };
10705
+ };
10817
10706
 
10818
10707
  /**
10819
10708
  * ```js
10820
- * import { onUserUnfollowed } from '@amityco/ts-sdk-react-native'
10821
- * const dispose = onUserFollowed(status => {
10709
+ * import { onFollowInfoUpdated } from '@amityco/ts-sdk-react-native'
10710
+ * const dispose = onFollowInfoUpdated(followInfo => {
10822
10711
  * // ...
10823
10712
  * })
10824
10713
  * ```
10825
10714
  *
10826
- * Fired when a user unfollows
10715
+ * Fired when a {@link Amity.FollowInfo} has been updated
10827
10716
  *
10828
10717
  * @param callback The function to call when the event was fired
10829
10718
  * @returns an {@link Amity.Unsubscriber} function to stop listening
10830
10719
  *
10831
10720
  * @category Follow Events
10832
10721
  */
10833
- const onUserUnfollowed = (callback) => createFollowEventSubscriber('follow.unfollowed', callback);
10722
+ const onFollowInfoUpdated = (callback) => {
10723
+ const handler = async (payload) => {
10724
+ const [{ data: followInfoFrom }, { data: followInfoTo }] = await Promise.all([
10725
+ getFollowInfo$1(payload.from),
10726
+ getFollowInfo$1(payload.to),
10727
+ ]);
10728
+ callback(followInfoFrom);
10729
+ callback(followInfoTo);
10730
+ };
10731
+ const disposers = [
10732
+ createFollowEventSubscriber('follow.created', handler),
10733
+ createFollowEventSubscriber('follow.requested', handler),
10734
+ createFollowEventSubscriber('follow.accepted', handler),
10735
+ createFollowEventSubscriber('follow.unfollowed', handler),
10736
+ createFollowEventSubscriber('follow.requestCanceled', handler),
10737
+ createFollowEventSubscriber('follow.requestDeclined', handler),
10738
+ createFollowEventSubscriber('follow.followerDeleted', handler),
10739
+ createLocalFollowEventSubscriber('local.follow.created', handler),
10740
+ createLocalFollowEventSubscriber('local.follow.requested', handler),
10741
+ createLocalFollowEventSubscriber('local.follow.accepted', handler),
10742
+ createLocalFollowEventSubscriber('local.follow.unfollowed', handler),
10743
+ createLocalFollowEventSubscriber('local.follow.requestDeclined', handler),
10744
+ ];
10745
+ return () => {
10746
+ disposers.forEach(fn => fn());
10747
+ };
10748
+ };
10834
10749
 
10835
- /**
10836
- * ```js
10837
- * import { onFollowerDeleted } from '@amityco/ts-sdk-react-native'
10838
- * const dispose = onFollowerDeleted(status => {
10839
- * // ...
10840
- * })
10841
- * ```
10842
- *
10843
- * Fired when a follower has been deleted
10844
- *
10845
- * @param callback The function to call when the event was fired
10846
- * @returns an {@link Amity.Unsubscriber} function to stop listening
10847
- *
10848
- * @category Follow Events
10849
- */
10850
- const onFollowerDeleted = (callback) => createFollowEventSubscriber('follow.followerDeleted', callback);
10750
+ const onLocalUserFollowed = (callback) => createLocalFollowEventSubscriber('local.follow.created', callback);
10751
+
10752
+ const onLocalUserUnfollowed = (callback) => createLocalFollowEventSubscriber('local.follow.unfollowed', callback);
10753
+
10754
+ const onLocalFollowerRequested = (callback) => createLocalFollowEventSubscriber('local.follow.requested', callback);
10755
+
10756
+ const onLocalFollowRequestAccepted = (callback) => createLocalFollowEventSubscriber('local.follow.accepted', callback);
10851
10757
 
10758
+ const onLocalFollowRequestDeclined = (callback) => createLocalFollowEventSubscriber('local.follow.requestDeclined', callback);
10759
+
10760
+ const convertEventPayload = (eventHandler, sourceModelProp, destinationDomain) => (callback) => eventHandler(sourceModel => {
10761
+ var _a, _b;
10762
+ if (!sourceModel) {
10763
+ return sourceModel;
10764
+ }
10765
+ const client = getActiveClient();
10766
+ const { objectSyncMap } = client;
10767
+ /*
10768
+ * NOTE: For objects created locally (optimistic creation), the SDK stores them with their local ID as the cache key, which is used throughout the entire SDK session (in-memory) for syncing updates.
10769
+ * If the payload or response only contains the remote ID of the same object, the SDK will look up the corresponding local ID to retrieve the object.
10770
+ */
10771
+ const resolvedId = isLocalId(sourceModel[sourceModelProp])
10772
+ ? sourceModel[sourceModelProp]
10773
+ : (_a = objectSyncMap.get(sourceModel[sourceModelProp])) !== null && _a !== void 0 ? _a : sourceModel[sourceModelProp];
10774
+ const model = (_b = pullFromCache([
10775
+ destinationDomain,
10776
+ 'get',
10777
+ `${resolvedId}`,
10778
+ ])) === null || _b === void 0 ? void 0 : _b.data;
10779
+ if (!model)
10780
+ return;
10781
+ return callback(model);
10782
+ });
10783
+
10784
+ class BlockedUserLiveCollectionController extends LiveCollectionController {
10785
+ constructor(query, callback) {
10786
+ const queryStreamId = hash__default["default"](query);
10787
+ const cacheKey = ['blockedUsers', 'collection', queryStreamId];
10788
+ const paginationController = new BlockedUserPaginationController(query);
10789
+ super(paginationController, queryStreamId, cacheKey, callback);
10790
+ this.query = query;
10791
+ this.queryStreamController = new BlockedUserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareBlockedUserPayload);
10792
+ this.callback = callback.bind(this);
10793
+ this.loadPage({ initial: true });
10794
+ }
10795
+ setup() {
10796
+ var _a;
10797
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
10798
+ if (!collection) {
10799
+ pushToCache(this.cacheKey, {
10800
+ data: [],
10801
+ params: {},
10802
+ });
10803
+ }
10804
+ }
10805
+ async persistModel(queryPayload) {
10806
+ await this.queryStreamController.saveToMainDB(queryPayload);
10807
+ }
10808
+ persistQueryStream({ response, direction, refresh, }) {
10809
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
10810
+ }
10811
+ startSubscription() {
10812
+ return this.queryStreamController.subscribeRTE([
10813
+ {
10814
+ fn: onUserDeleted$2,
10815
+ action: EnumUserActions.OnUserDeleted,
10816
+ },
10817
+ // In the case of unblocking a user, we need to subscribe to the follow events
10818
+ {
10819
+ fn: convertEventPayload(onLocalUserFollowed, 'to', 'user'),
10820
+ action: EnumFollowActions.OnFollowed,
10821
+ },
10822
+ {
10823
+ fn: convertEventPayload(onUserFollowed, 'to', 'user'),
10824
+ action: EnumFollowActions.OnFollowed,
10825
+ },
10826
+ ]);
10827
+ }
10828
+ notifyChange({ origin, loading, error }) {
10829
+ var _a, _b;
10830
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
10831
+ if (!collection)
10832
+ return;
10833
+ const data = this.applyFilter((_b = collection.data
10834
+ .map(id => pullFromCache(['user', 'get', id]))
10835
+ .filter(isNonNullable)
10836
+ .map(({ data }) => data)
10837
+ .map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
10838
+ if (!this.shouldNotify(data) && origin === 'event')
10839
+ return;
10840
+ this.callback({
10841
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
10842
+ data,
10843
+ hasNextPage: !!this.paginationController.getNextToken(),
10844
+ loading,
10845
+ error,
10846
+ });
10847
+ }
10848
+ // eslint-disable-next-line class-methods-use-this
10849
+ applyFilter(data) {
10850
+ let users = data;
10851
+ users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
10852
+ return users;
10853
+ }
10854
+ }
10855
+
10856
+ /* begin_public_function
10857
+ id: user.get_blocked_users
10858
+ */
10852
10859
  /**
10853
10860
  * ```js
10854
- * import { onFollowerRequested } from '@amityco/ts-sdk-react-native'
10855
- * const dispose = onFollowerRequested(status => {
10856
- * // ...
10857
- * })
10861
+ * import { UserRepository } from '@amityco/ts-sdk-react-native'
10862
+ * const unblockedUser = await UserRepository.blockUser('userId')
10858
10863
  * ```
10859
10864
  *
10860
- * Fired when a user follows another users and confirmation is required
10865
+ * Blocks a {@link Amity.InternalUser}
10861
10866
  *
10862
- * @param callback The function to call when the event was fired
10863
- * @returns an {@link Amity.Unsubscriber} function to stop listening
10867
+ * @param params The params to get blocked {@link Amity.InternalUser}s
10868
+ * @param callback to recieve updates on unblocked {@link Amity.InternalUser}s
10869
+ * @returns {@link Amity.Unsubscriber} to unsubscribe from collection
10864
10870
  *
10865
- * @category Follow Events
10871
+ * @category Post API
10872
+ * @async
10866
10873
  */
10867
- const onFollowerRequested = (callback) => createFollowEventSubscriber('follow.requested', callback);
10874
+ const getBlockedUsers$1 = (params, callback, config) => {
10875
+ const { log, cache } = getActiveClient();
10876
+ if (!cache) {
10877
+ console.log(ENABLE_CACHE_MESSAGE);
10878
+ }
10879
+ const timestamp = Date.now();
10880
+ log(`getBlockedUsers(tmpid: ${timestamp}) > listen`);
10881
+ const blockedUserLiveCollection = new BlockedUserLiveCollectionController(params, callback);
10882
+ const disposers = blockedUserLiveCollection.startSubscription();
10883
+ const cacheKey = blockedUserLiveCollection.getCacheKey();
10884
+ disposers.push(() => dropFromCache(cacheKey));
10885
+ return () => {
10886
+ log(`getBlockedUsers(tmpid: ${timestamp}) > dispose`);
10887
+ disposers.forEach(fn => fn());
10888
+ dropFromCache(cacheKey);
10889
+ };
10890
+ };
10891
+ /* end_public_function */
10892
+
10893
+ /* eslint-disable no-use-before-define */
10894
+ const getBlockedUsers = (params, callback, config) => {
10895
+ console.log('Deprecation Notice: UserRepository.Relationship.getBlockedUsers will be deprecated on 9th June 2023, please use UserRepository.getBlockedUsers instead.');
10896
+ return getBlockedUsers$1(params, callback);
10897
+ };
10868
10898
 
10899
+ /* begin_public_function
10900
+ id: user.relationship.follow
10901
+ */
10869
10902
  /**
10870
10903
  * ```js
10871
- * import { onFollowRequestCanceled } from '@amityco/ts-sdk-react-native'
10872
- * const dispose = onFollowRequestCanceled(status => {
10873
- * // ...
10874
- * })
10904
+ * import { follow } from '@amityco/ts-sdk-react-native'
10905
+ * const status = await follow('foobar')
10875
10906
  * ```
10876
10907
  *
10877
- * Fired when a follow request has been canceled
10908
+ * Follow the user
10878
10909
  *
10879
- * @param callback The function to call when the event was fired
10880
- * @returns an {@link Amity.Unsubscriber} function to stop listening
10910
+ * @param userId the ID of the {@link Amity.InternalUser}
10911
+ * @returns the status {@link Amity.FollowStatus}
10881
10912
  *
10882
- * @category Follow Events
10913
+ * @category Follow API
10914
+ * @async
10883
10915
  */
10884
- const onFollowRequestCanceled = (callback) => createFollowEventSubscriber('follow.requestCanceled', callback);
10916
+ const follow = async (userId) => {
10917
+ const client = getActiveClient();
10918
+ client.log('follow/follow', userId);
10919
+ const { data } = await client.http.post(`/api/v4/me/following/${userId}`);
10920
+ const cachedAt = client.cache && Date.now();
10921
+ if (client.cache) {
10922
+ ingestInCache(data, { cachedAt });
10923
+ }
10924
+ const payload = prepareFollowStatusPayload(data);
10925
+ if (data.follows[0].status === 'accepted') {
10926
+ fireEvent('local.follow.created', payload);
10927
+ }
10928
+ else {
10929
+ fireEvent('local.follow.requested', payload);
10930
+ }
10931
+ return {
10932
+ data: data.follows[0],
10933
+ cachedAt,
10934
+ };
10935
+ };
10936
+ /* end_public_function */
10885
10937
 
10938
+ /* begin_public_function
10939
+ id: user.relationship.unfollow
10940
+ */
10886
10941
  /**
10887
10942
  * ```js
10888
- * import { onFollowRequestAccepted } from '@amityco/ts-sdk-react-native'
10889
- * const dispose = onFollowRequestAccepted(status => {
10890
- * // ...
10891
- * })
10943
+ * import { unfollow } from '@amityco/ts-sdk-react-native'
10944
+ * await unfollow('foobar')
10892
10945
  * ```
10893
10946
  *
10894
- * Fired when a follow request has been accepted
10947
+ * Cancel the follow request or unfollow the user
10895
10948
  *
10896
- * @param callback The function to call when the event was fired
10897
- * @returns an {@link Amity.Unsubscriber} function to stop listening
10949
+ * @param userId the ID of the {@link Amity.InternalUser}
10950
+ * @returns A success boolean if the user {@link Amity.InternalUser} was unfollowed
10898
10951
  *
10899
- * @category Follow Events
10952
+ * @category Follow API
10953
+ * @async
10900
10954
  */
10901
- const onFollowRequestAccepted = (callback) => createFollowEventSubscriber('follow.accepted', callback);
10955
+ const unfollow = async (userId) => {
10956
+ const client = getActiveClient();
10957
+ client.log('follow/unfollow', userId);
10958
+ const { data } = await client.http.delete(`/api/v4/me/following/${userId}`);
10959
+ if (client.cache) {
10960
+ ingestInCache(data);
10961
+ }
10962
+ const payload = prepareFollowStatusPayload(data);
10963
+ fireEvent('local.follow.unfollowed', payload);
10964
+ return true;
10965
+ };
10966
+ /* end_public_function */
10902
10967
 
10903
10968
  /**
10969
+ * @deprecated This API renamed to `acceptMyFollower`.
10970
+ * Please use acceptMyFollower() instead.
10971
+ *
10904
10972
  * ```js
10905
- * import { onFollowRequestDeclined } from '@amityco/ts-sdk-react-native'
10906
- * const dispose = onFollowRequestDeclined(status => {
10907
- * // ...
10908
- * })
10973
+ * import { acceptFollower } from '@amityco/ts-sdk-react-native'
10974
+ * await acceptFollower('foobar')
10909
10975
  * ```
10910
10976
  *
10911
- * Fired when a follow request has been declined
10977
+ * Accept the follow request
10912
10978
  *
10913
- * @param callback The function to call when the event was fired
10914
- * @returns an {@link Amity.Unsubscriber} function to stop listening
10979
+ * @param userId the ID of the {@link Amity.InternalUser} follower
10980
+ * @returns A success boolean if the follow request was accepted
10915
10981
  *
10916
- * @category Follow Events
10982
+ * @category Follow API
10983
+ * @async
10917
10984
  */
10918
- const onFollowRequestDeclined = (callback) => createFollowEventSubscriber('follow.requestDeclined', callback);
10985
+ const acceptFollower = async (userId) => {
10986
+ const client = getActiveClient();
10987
+ client.log('follow/acceptFollower', userId);
10988
+ const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
10989
+ if (client.cache) {
10990
+ ingestInCache(data);
10991
+ }
10992
+ const payload = prepareFollowStatusPayload(data);
10993
+ fireEvent('local.follow.accepted', payload);
10994
+ return true;
10995
+ };
10919
10996
 
10997
+ /* begin_public_function
10998
+ id: user.relationship.accept_follow
10999
+ */
10920
11000
  /**
10921
11001
  * ```js
10922
- * import { getFollowInfo } from '@amityco/ts-sdk-react-native'
10923
- * const { data: followInfo } = await getFollowInfo('foobar')
11002
+ * import { UserRepository } from '@amityco/ts-sdk-react-native'
11003
+ * await UserRepository.Relationship.acceptMyFollower('foobar')
10924
11004
  * ```
10925
11005
  *
10926
- * Fetches the number of followers, followings, pending requests and the follow status for current user
11006
+ * Accept the follow request
10927
11007
  *
10928
- * @param userId the ID of the {@link Amity.InternalUser}
10929
- * @returns the associated {@link Amity.FollowInfo} object
11008
+ * @param userId the ID of the {@link Amity.InternalUser} follower
11009
+ * @returns A success boolean if the follow request was accepted
10930
11010
  *
10931
11011
  * @category Follow API
10932
11012
  * @async
10933
11013
  */
10934
- const getFollowInfo$1 = async (userId) => {
10935
- var _a, _b;
11014
+ const acceptMyFollower = async (userId) => {
10936
11015
  const client = getActiveClient();
10937
- client.log('follow/getFollowInfo', userId);
10938
- const { data } = await client.http.get(client.userId === userId ? `/api/v4/me/followInfo` : `/api/v5/users/${userId}/followInfo`);
10939
- const cachedAt = client.cache && Date.now();
10940
- const followInfo = 'follows' in data
10941
- ? Object.assign(Object.assign({}, data.followCounts[0]), { status: (_b = (_a = data.follows) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.status }) : data.followCounts[0];
11016
+ client.log('follow/acceptMyFollower', userId);
11017
+ const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
10942
11018
  if (client.cache) {
10943
- pushToCache(['followInfo', 'get', userId], followInfo, {
10944
- cachedAt,
10945
- });
11019
+ ingestInCache(data);
10946
11020
  }
10947
- return {
10948
- data: followInfo,
10949
- cachedAt,
10950
- };
11021
+ const payload = prepareFollowStatusPayload(data);
11022
+ fireEvent('local.follow.accepted', payload);
11023
+ return true;
10951
11024
  };
11025
+ /* end_public_function */
11026
+
10952
11027
  /**
11028
+ * @deprecated This API renamed to `declineMyFollower`.
11029
+ * Please use declineMyFollower() instead.
11030
+ *
10953
11031
  * ```js
10954
- * import { getFollowInfo } from '@amityco/ts-sdk-react-native'
10955
- * const { data: followInfo } = getFollowInfo.locally('foobar')
11032
+ * import { declineFollower } from '@amityco/ts-sdk-react-native'
11033
+ * await declineFollower('foobar')
10956
11034
  * ```
10957
11035
  *
10958
- * Fetches the number of followers, followings, pending requests and the follow status for current user from cache
11036
+ * Decline the follow request or delete the follower
10959
11037
  *
10960
- * @param userId the ID of the {@link Amity.InternalUser}
10961
- * @returns the associated {@link Amity.FollowInfo} object
11038
+ * @param userId the ID of the {@link Amity.InternalUser} follower
11039
+ * @returns A success boolean if the follow request was decline
10962
11040
  *
10963
11041
  * @category Follow API
11042
+ * @async
10964
11043
  */
10965
- getFollowInfo$1.locally = (userId) => {
11044
+ const declineFollower = async (userId) => {
10966
11045
  const client = getActiveClient();
10967
- client.log('follow/getFollowInfo.locally', userId);
10968
- if (!client.cache) {
10969
- return;
10970
- }
10971
- const cached = pullFromCache(['followInfo', 'get', userId]);
10972
- if (!cached) {
10973
- return;
11046
+ client.log('follow/declineFollower', userId);
11047
+ const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
11048
+ if (client.cache) {
11049
+ ingestInCache(data);
10974
11050
  }
10975
- return {
10976
- data: cached.data,
10977
- cachedAt: cached.cachedAt,
10978
- };
11051
+ const payload = prepareFollowStatusPayload(data);
11052
+ fireEvent('local.follow.requestDeclined', payload);
11053
+ return true;
10979
11054
  };
10980
11055
 
11056
+ /* begin_public_function
11057
+ id: user.relationship.decline_follow
11058
+ */
10981
11059
  /**
10982
11060
  * ```js
10983
- * import { onFollowInfoUpdated } from '@amityco/ts-sdk-react-native'
10984
- * const dispose = onFollowInfoUpdated(followInfo => {
10985
- * // ...
10986
- * })
11061
+ * import { UserRepository } from '@amityco/ts-sdk-react-native'
11062
+ * await UserRepository.Relationship.declineMyFollower('foobar')
10987
11063
  * ```
10988
11064
  *
10989
- * Fired when a {@link Amity.FollowInfo} has been updated
11065
+ * Decline the follow request or delete the follower
10990
11066
  *
10991
- * @param callback The function to call when the event was fired
10992
- * @returns an {@link Amity.Unsubscriber} function to stop listening
11067
+ * @param userId the ID of the {@link Amity.InternalUser} follower
11068
+ * @returns A success boolean if the follow request was decline
10993
11069
  *
10994
- * @category Follow Events
11070
+ * @category Follow API
11071
+ * @async
10995
11072
  */
10996
- const onFollowInfoUpdated = (callback) => {
10997
- const handler = async (payload) => {
10998
- const [{ data: followInfoFrom }, { data: followInfoTo }] = await Promise.all([
10999
- getFollowInfo$1(payload.from),
11000
- getFollowInfo$1(payload.to),
11001
- ]);
11002
- callback(followInfoFrom);
11003
- callback(followInfoTo);
11004
- };
11005
- const disposers = [
11006
- createFollowEventSubscriber('follow.created', handler),
11007
- createFollowEventSubscriber('follow.requested', handler),
11008
- createFollowEventSubscriber('follow.accepted', handler),
11009
- createFollowEventSubscriber('follow.unfollowed', handler),
11010
- createFollowEventSubscriber('follow.requestCanceled', handler),
11011
- createFollowEventSubscriber('follow.requestDeclined', handler),
11012
- createFollowEventSubscriber('follow.followerDeleted', handler),
11013
- createLocalFollowEventSubscriber('local.follow.created', handler),
11014
- createLocalFollowEventSubscriber('local.follow.requested', handler),
11015
- createLocalFollowEventSubscriber('local.follow.accepted', handler),
11016
- createLocalFollowEventSubscriber('local.follow.unfollowed', handler),
11017
- createLocalFollowEventSubscriber('local.follow.requestDeclined', handler),
11018
- ];
11019
- return () => {
11020
- disposers.forEach(fn => fn());
11021
- };
11022
- };
11023
-
11024
- const onLocalUserFollowed = (callback) => createLocalFollowEventSubscriber('local.follow.created', callback);
11025
-
11026
- const onLocalUserUnfollowed = (callback) => createLocalFollowEventSubscriber('local.follow.unfollowed', callback);
11027
-
11028
- const onLocalFollowerRequested = (callback) => createLocalFollowEventSubscriber('local.follow.requested', callback);
11029
-
11030
- const onLocalFollowRequestAccepted = (callback) => createLocalFollowEventSubscriber('local.follow.accepted', callback);
11031
-
11032
- const onLocalFollowRequestDeclined = (callback) => createLocalFollowEventSubscriber('local.follow.requestDeclined', callback);
11073
+ const declineMyFollower = async (userId) => {
11074
+ const client = getActiveClient();
11075
+ client.log('follow/declineMyFollower', userId);
11076
+ const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
11077
+ if (client.cache) {
11078
+ ingestInCache(data);
11079
+ }
11080
+ const payload = prepareFollowStatusPayload(data);
11081
+ fireEvent('local.follow.requestDeclined', payload);
11082
+ return true;
11083
+ };
11084
+ /* end_public_function */
11033
11085
 
11034
11086
  /**
11035
11087
  * ```js
@@ -11159,18 +11211,6 @@ class FollowerPaginationController extends PaginationController {
11159
11211
  }
11160
11212
  }
11161
11213
 
11162
- var EnumFollowActions;
11163
- (function (EnumFollowActions) {
11164
- EnumFollowActions["OnRequested"] = "onRequested";
11165
- EnumFollowActions["OnAccepted"] = "onAccepted";
11166
- EnumFollowActions["OnDeclined"] = "onDeclined";
11167
- EnumFollowActions["OnCanceled"] = "onCanceled";
11168
- EnumFollowActions["OnFollowed"] = "onFollowed";
11169
- EnumFollowActions["OnUnfollowed"] = "onUnfollowed";
11170
- EnumFollowActions["OnDeleted"] = "onDeleted";
11171
- EnumFollowActions["OnUserDeleted"] = "onUserDeleted";
11172
- })(EnumFollowActions || (EnumFollowActions = {}));
11173
-
11174
11214
  class FollowerQueryStreamController extends QueryStreamController {
11175
11215
  constructor(query, cacheKey, notifyChange, preparePayload) {
11176
11216
  super(query, cacheKey);
@@ -11248,7 +11288,7 @@ const onFollowerUserDeleted = ({ userId }) => (callback) => {
11248
11288
 
11249
11289
  class FollowerLiveCollectionController extends LiveCollectionController {
11250
11290
  constructor(query, callback) {
11251
- const queryStreamId = hash__default["default"](query);
11291
+ const queryStreamId = hash__default["default"](Object.assign(Object.assign({}, query), { type: 'follower' }));
11252
11292
  const cacheKey = ['follow', 'collection', queryStreamId];
11253
11293
  const paginationController = new FollowerPaginationController(query);
11254
11294
  super(paginationController, queryStreamId, cacheKey, callback);
@@ -11453,7 +11493,7 @@ const onFollowingUserDeleted = ({ userId }) => (callback) => {
11453
11493
 
11454
11494
  class FollowingLiveCollectionController extends LiveCollectionController {
11455
11495
  constructor(query, callback) {
11456
- const queryStreamId = hash__default["default"](query);
11496
+ const queryStreamId = hash__default["default"](Object.assign(Object.assign({}, query), { type: 'following' }));
11457
11497
  const cacheKey = ['follow', 'collection', queryStreamId];
11458
11498
  const paginationController = new FollowingPaginationController(query);
11459
11499
  super(paginationController, queryStreamId, cacheKey, callback);
@@ -12543,6 +12583,12 @@ const getReachedUsers = (params, callback) => {
12543
12583
  };
12544
12584
  };
12545
12585
 
12586
+ var AmityUserSearchMatchType;
12587
+ (function (AmityUserSearchMatchType) {
12588
+ AmityUserSearchMatchType["DEFAULT"] = "default";
12589
+ AmityUserSearchMatchType["PARTIAL"] = "partial";
12590
+ })(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
12591
+
12546
12592
  var index$j = /*#__PURE__*/Object.freeze({
12547
12593
  __proto__: null,
12548
12594
  Relationship: index$k,
@@ -12562,7 +12608,8 @@ var index$j = /*#__PURE__*/Object.freeze({
12562
12608
  getBlockedUsers: getBlockedUsers$1,
12563
12609
  searchUserByDisplayName: searchUserByDisplayName,
12564
12610
  getViewedUsers: getViewedUsers,
12565
- getReachedUsers: getReachedUsers
12611
+ getReachedUsers: getReachedUsers,
12612
+ get AmityUserSearchMatchType () { return AmityUserSearchMatchType; }
12566
12613
  });
12567
12614
 
12568
12615
  /* begin_public_function
@@ -13359,16 +13406,19 @@ function isCurrentUserPartOfCommunity(c, m) {
13359
13406
  }
13360
13407
  /*
13361
13408
  * For mqtt events server will not send user specific data as it's broadcasted
13362
- * to multiple users. Althought this can be calculated, it's not scalable. Hence
13363
- * the client SDK needs to calculate this info
13409
+ * to multiple users and it also does not include communityUser
13410
+ *
13411
+ * Client SDK needs to check for the existing isJoined field in cache data before calculating.
13412
+ * Althought this can be calculated, it's not scalable.
13364
13413
  */
13365
13414
  function updateMembershipStatus(communities, communityUsers) {
13366
13415
  return communities.map(c => {
13367
- if (c.isJoined == null) {
13368
- const isJoined = communityUsers.some(m => isCurrentUserPartOfCommunity(c, m) && isMember(m.communityMembership));
13369
- return Object.assign(Object.assign({}, c), { isJoined });
13416
+ const cachedCommunity = pullFromCache(['community', 'get', c.communityId]);
13417
+ if ((cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data) && (cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data.hasOwnProperty('isJoined'))) {
13418
+ return Object.assign(Object.assign({}, cachedCommunity.data), c);
13370
13419
  }
13371
- return c;
13420
+ const isJoined = communityUsers.some(m => isCurrentUserPartOfCommunity(c, m) && isMember(m.communityMembership));
13421
+ return Object.assign(Object.assign({}, c), { isJoined });
13372
13422
  });
13373
13423
  }
13374
13424
 
@@ -13469,7 +13519,7 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
13469
13519
  referenceType,
13470
13520
  reactionName,
13471
13521
  });
13472
- await client.http.post('/api/v2/reactions', {
13522
+ const { data } = await client.http.post('/api/v2/reactions', {
13473
13523
  referenceId,
13474
13524
  referenceType,
13475
13525
  reactionName,
@@ -13487,12 +13537,33 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
13487
13537
  if (referenceType === 'comment') {
13488
13538
  fireEvent('local.comment.addReaction', {
13489
13539
  comment: updatedModel,
13540
+ reactor: {
13541
+ userId: client.userId,
13542
+ reactionName,
13543
+ reactionId: data.addedId,
13544
+ },
13490
13545
  });
13491
13546
  return true;
13492
13547
  }
13493
13548
  if (referenceType === 'post') {
13494
13549
  fireEvent('local.post.addReaction', {
13495
13550
  post: updatedModel,
13551
+ reactor: {
13552
+ userId: client.userId,
13553
+ reactionName,
13554
+ reactionId: data.addedId,
13555
+ },
13556
+ });
13557
+ return true;
13558
+ }
13559
+ if (referenceType === 'story') {
13560
+ fireEvent('local.story.reactionAdded', {
13561
+ story: updatedModel,
13562
+ reactor: {
13563
+ userId: client.userId,
13564
+ reactionName,
13565
+ reactionId: data.addedId,
13566
+ },
13496
13567
  });
13497
13568
  return true;
13498
13569
  }
@@ -13567,7 +13638,7 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
13567
13638
  referenceType,
13568
13639
  reactionName,
13569
13640
  });
13570
- await client.http.delete(`/api/v2/reactions`, {
13641
+ const { data } = await client.http.delete(`/api/v2/reactions`, {
13571
13642
  data: {
13572
13643
  referenceId,
13573
13644
  referenceType,
@@ -13587,12 +13658,33 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
13587
13658
  if (referenceType === 'comment') {
13588
13659
  fireEvent('local.comment.removeReaction', {
13589
13660
  comment: updatedModel,
13661
+ reactor: {
13662
+ reactionId: data.removedId,
13663
+ reactionName,
13664
+ userId: client.userId,
13665
+ },
13590
13666
  });
13591
13667
  return true;
13592
13668
  }
13593
13669
  if (referenceType === 'post') {
13594
13670
  fireEvent('local.post.removeReaction', {
13595
13671
  post: updatedModel,
13672
+ reactor: {
13673
+ reactionId: data.removedId,
13674
+ reactionName,
13675
+ userId: client.userId,
13676
+ },
13677
+ });
13678
+ return true;
13679
+ }
13680
+ if (referenceType === 'story') {
13681
+ fireEvent('local.story.reactionAdded', {
13682
+ story: updatedModel,
13683
+ reactor: {
13684
+ userId: client.userId,
13685
+ reactionName,
13686
+ reactionId: data.removedId,
13687
+ },
13596
13688
  });
13597
13689
  return true;
13598
13690
  }
@@ -13616,7 +13708,7 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
13616
13708
  * @category Reaction API
13617
13709
  * */
13618
13710
  removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
13619
- var _a, _b, _c, _d, _e;
13711
+ var _a, _b, _c, _d;
13620
13712
  const client = getActiveClient();
13621
13713
  client.log('reaction/removeReaction.optimistically', {
13622
13714
  referenceId,
@@ -13637,7 +13729,7 @@ removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
13637
13729
  cachedAt: UNSYNCED_OBJECT_CACHED_AT_VALUE,
13638
13730
  });
13639
13731
  dispatchReactable(referenceType, reaction);
13640
- return (_e = !((_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName))) !== null && _e !== void 0 ? _e : false;
13732
+ return !((_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName));
13641
13733
  };
13642
13734
 
13643
13735
  const getMatchPostSetting = (value) => {
@@ -14459,73 +14551,262 @@ const onReactorRemoved = (referenceType, referenceId, callback) => {
14459
14551
 
14460
14552
  const REFERENCE_API_V5 = 5;
14461
14553
 
14554
+ class ReactionPaginationController extends PaginationController {
14555
+ async getRequest(queryParams, token) {
14556
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
14557
+ const options = token ? { token } : { limit };
14558
+ const client = getActiveClient();
14559
+ client.log('reaction/queryReactions', queryParams);
14560
+ const path = '/api/v3/reactions';
14561
+ const { data: queryResponse } = await this.http.get(path, {
14562
+ params: Object.assign(Object.assign({}, params), { referenceVersion: REFERENCE_API_V5, // Need to put this param to make it can query reaction for message in sub-channel
14563
+ options }),
14564
+ });
14565
+ return queryResponse;
14566
+ }
14567
+ }
14568
+
14569
+ class ReactionQueryStreamController extends QueryStreamController {
14570
+ constructor(query, cacheKey, notifyChange, preparePayload) {
14571
+ super(query, cacheKey);
14572
+ this.notifyChange = notifyChange;
14573
+ this.preparePayload = preparePayload;
14574
+ }
14575
+ async saveToMainDB(response) {
14576
+ var _a;
14577
+ const processedPayload = await this.preparePayload(response);
14578
+ const client = getActiveClient();
14579
+ const cachedAt = client.cache && Date.now();
14580
+ if (client.cache) {
14581
+ const { reactions } = processedPayload, restPayload = __rest(processedPayload, ["reactions"]);
14582
+ ingestInCache(Object.assign(Object.assign({}, restPayload), { reactions, reactors: (_a = reactions[0]) === null || _a === void 0 ? void 0 : _a.reactors }), { cachedAt });
14583
+ }
14584
+ }
14585
+ appendToQueryStream(response, direction, refresh = false) {
14586
+ var _a, _b, _c, _d;
14587
+ const reactors = (_b = (_a = response.reactions[0]) === null || _a === void 0 ? void 0 : _a.reactors) !== null && _b !== void 0 ? _b : [];
14588
+ if (refresh) {
14589
+ pushToCache(this.cacheKey, {
14590
+ data: reactors.map(getResolver('reactor')),
14591
+ });
14592
+ }
14593
+ else {
14594
+ const collection = (_c = pullFromCache(this.cacheKey)) === null || _c === void 0 ? void 0 : _c.data;
14595
+ const reactions = (_d = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _d !== void 0 ? _d : [];
14596
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...reactions, ...reactors.map(getResolver('reactor'))])] }));
14597
+ }
14598
+ }
14599
+ reactor(action) {
14600
+ return (reaction) => {
14601
+ var _a;
14602
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
14603
+ if (!collection)
14604
+ return;
14605
+ if (action === "onAdded" /* Amity.ReactionActionTypeEnum.OnAdded */) {
14606
+ collection.data = [...new Set([reaction.reactionId, ...collection.data])];
14607
+ }
14608
+ else if (action === "onRemoved" /* Amity.ReactionActionTypeEnum.OnRemoved */) {
14609
+ collection.data = collection.data.filter(p => p !== reaction.reactionId);
14610
+ }
14611
+ pushToCache(this.cacheKey, collection);
14612
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
14613
+ };
14614
+ }
14615
+ subscribeRTE(createSubscriber) {
14616
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
14617
+ }
14618
+ }
14619
+
14462
14620
  /**
14463
14621
  * ```js
14464
- * import { queryReactions } from '@amityco/ts-sdk-react-native'
14465
- * const { data: reactions, prevPage, nextPage } = await queryReactions({
14466
- * referenceId: 'postId',
14467
- * referenceType: 'post',
14622
+ * import { onReactorRemovedLocal } from '@amityco/ts-sdk'
14623
+ * const dispose = onReactorRemoved('post', postId, reactor => {
14624
+ * // ...
14468
14625
  * })
14469
14626
  * ```
14470
14627
  *
14471
- * Queries a paginable list of {@link Amity.Reaction} objects
14628
+ * Fired when an {@link Amity.InternalReactor} has been removed
14472
14629
  *
14473
- * @param query The query parameters
14474
- * @returns A page of {@link Amity.Reaction} objects
14630
+ * @param {@link Amity.ReactableType} referenceType
14631
+ * @param {string} referenceId
14632
+ * @param callback The function to call when the event was fired
14633
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
14475
14634
  *
14476
- * @reaction Reaction API
14477
- * @async
14635
+ * @category Events
14478
14636
  * */
14479
- const queryReactions = async (query) => {
14637
+ const onReactorRemovedLocal = (referenceType, referenceId, callback) => {
14480
14638
  const client = getActiveClient();
14481
- client.log('reaction/queryReactions', query);
14482
- const _a = query !== null && query !== void 0 ? query : {}, { page = { limit: 10 } } = _a, params = __rest(_a, ["page"]);
14483
- const { data } = await client.http.get(`/api/v3/reactions`, {
14484
- params: Object.assign(Object.assign({}, params), { referenceVersion: REFERENCE_API_V5, options: {
14485
- token: toToken(page, 'afterbeforeraw'),
14486
- } }),
14487
- });
14488
- const { paging } = data, payload = __rest(data, ["paging"]);
14489
- const { reactions } = payload;
14490
- // FIXME: correct reactions type in model
14491
- // @ts-ignore
14492
- ingestInCache(Object.assign(Object.assign({}, payload), { reactions })); // Save reaction response into cache
14493
- ingestInCache(Object.assign(Object.assign({}, payload), { reactors: reactions[0].reactors })); // Save reactors data into cache for support reaction query
14494
- const nextPage = toPageRaw(paging.next);
14495
- const prevPage = toPageRaw(paging.previous);
14496
- return { data: reactions, prevPage, nextPage };
14639
+ const callbackWrapper = (referenceType_, referenceId_, reaction) => {
14640
+ if (referenceType_ === referenceType && referenceId_ === referenceId) {
14641
+ callback(reaction);
14642
+ }
14643
+ };
14644
+ if (referenceType === 'message') {
14645
+ const filter = async (rawPayload) => {
14646
+ const payload = await prepareMessagePayload(rawPayload);
14647
+ if (!payload.reactions[0])
14648
+ return;
14649
+ ingestInCache(payload);
14650
+ callbackWrapper('message', payload.messages[0].messageId, payload.reactions[0]);
14651
+ };
14652
+ return createEventSubscriber(client, 'reaction/onReactorRemoved', 'message.reactionRemoved', filter);
14653
+ }
14654
+ if (referenceType === 'post') {
14655
+ const filter = (payload) => {
14656
+ callbackWrapper('post', payload.post.postId, payload.reactor);
14657
+ };
14658
+ return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
14659
+ }
14660
+ if (referenceType === 'story') {
14661
+ const filter = (payload) => {
14662
+ const { reactions } = payload, rest = __rest(payload, ["reactions"]);
14663
+ ingestInCache(rest);
14664
+ ingestInCache({ reactors: reactions });
14665
+ if (payload.stories.length === 0 || payload.reactions.length === 0)
14666
+ return;
14667
+ callbackWrapper('story', payload.stories[0].storyId, payload.reactions[0]);
14668
+ };
14669
+ return createEventSubscriber(client, 'story.reactionRemoved', 'story.reactionRemoved', filter);
14670
+ }
14671
+ const filter = (payload) => {
14672
+ callbackWrapper('comment', payload.comment.commentId, payload.reactor);
14673
+ };
14674
+ return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
14497
14675
  };
14498
14676
 
14499
14677
  /**
14500
14678
  * ```js
14501
- * import { queryReactor } from '@amityco/ts-sdk-react-native'
14502
- * const { data: reactions, prevPage, nextPage } = await queryReactor({
14503
- * referenceId: 'postId',
14504
- * referenceType: 'post',
14679
+ * import { onReactorAddedLocal } from '@amityco/ts-sdk'
14680
+ * const dispose = onReactorAdded('post', postId, reactor => {
14681
+ * // ...
14505
14682
  * })
14506
14683
  * ```
14507
14684
  *
14508
- * Queries a paginable list of {@link Amity.InternalReactor} objects
14685
+ * Fired when an {@link Amity.InternalReactor} has been added
14509
14686
  *
14510
- * @param query The query parameters
14511
- * @returns A page of {@link Amity.InternalReactor} objects
14687
+ * @param {@link Amity.ReactableType} referenceType
14688
+ * @param {string} referenceId
14689
+ * @param callback The function to call when the event was fired
14690
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
14512
14691
  *
14513
- * @reaction Reaction API
14514
- * @async
14692
+ * @category Events
14515
14693
  * */
14516
- const queryReactor = async (query) => {
14694
+ const onReactorAddedLocal = (referenceType, referenceId, callback) => {
14517
14695
  const client = getActiveClient();
14518
- client.log('reaction/queryReactor', query);
14519
- const _a = await queryReactions(query), { data } = _a, response = __rest(_a, ["data"]);
14520
- return Object.assign(Object.assign({}, response), { data: data[0].reactors });
14696
+ const callbackWrapper = (referenceType_, referenceId_, reaction) => {
14697
+ if (referenceType_ === referenceType && referenceId_ === referenceId) {
14698
+ callback(reaction);
14699
+ }
14700
+ };
14701
+ if (referenceType === 'message') {
14702
+ const filter = async (rawPayload) => {
14703
+ const payload = await prepareMessagePayload(rawPayload);
14704
+ if (!payload.reactions[0])
14705
+ return;
14706
+ ingestInCache(payload);
14707
+ ingestInCache({ reactors: payload.reactions });
14708
+ callbackWrapper('message', payload.messages[0].messageId, payload.reactions[0]);
14709
+ };
14710
+ return createEventSubscriber(client, 'reaction/onReactorAdded', 'message.reactionAdded', filter);
14711
+ }
14712
+ if (referenceType === 'post') {
14713
+ const filter = (payload) => {
14714
+ callbackWrapper('post', payload.post.postId, payload.reactor);
14715
+ };
14716
+ return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
14717
+ }
14718
+ if (referenceType === 'story') {
14719
+ const filter = (payload) => {
14720
+ const { reactions } = payload, rest = __rest(payload, ["reactions"]);
14721
+ ingestInCache(rest);
14722
+ ingestInCache({ reactors: reactions });
14723
+ if (payload.stories.length === 0 || payload.reactions.length === 0)
14724
+ return;
14725
+ callbackWrapper('story', payload.stories[0].storyId, payload.reactions[0]);
14726
+ };
14727
+ return createEventSubscriber(client, 'story.reactionAdded', 'story.reactionAdded', filter);
14728
+ }
14729
+ const filter = (payload) => {
14730
+ callbackWrapper('comment', payload.comment.commentId, payload.reactor);
14731
+ };
14732
+ return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
14521
14733
  };
14522
14734
 
14735
+ class ReactionLiveCollectionController extends LiveCollectionController {
14736
+ constructor(query, callback) {
14737
+ const queryStreamId = hash__default["default"](query);
14738
+ const cacheKey = ['reaction', 'collection', queryStreamId];
14739
+ const paginationController = new ReactionPaginationController(query);
14740
+ super(paginationController, queryStreamId, cacheKey, callback);
14741
+ this.query = query;
14742
+ this.queryStreamController = new ReactionQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), payload => payload);
14743
+ this.callback = callback.bind(this);
14744
+ this.loadPage({ initial: true });
14745
+ }
14746
+ setup() {
14747
+ var _a;
14748
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
14749
+ if (!collection) {
14750
+ pushToCache(this.cacheKey, {
14751
+ data: [],
14752
+ params: {},
14753
+ });
14754
+ }
14755
+ }
14756
+ async persistModel(queryPayload) {
14757
+ await this.queryStreamController.saveToMainDB(queryPayload);
14758
+ }
14759
+ persistQueryStream({ response, direction, refresh, }) {
14760
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
14761
+ }
14762
+ startSubscription() {
14763
+ return this.queryStreamController.subscribeRTE([
14764
+ {
14765
+ fn: callback => onReactorAdded(this.query.referenceType, this.query.referenceId, callback),
14766
+ action: "onAdded" /* Amity.ReactionActionTypeEnum.OnAdded */,
14767
+ },
14768
+ {
14769
+ fn: callback => onReactorRemoved(this.query.referenceType, this.query.referenceId, callback),
14770
+ action: "onRemoved" /* Amity.ReactionActionTypeEnum.OnRemoved */,
14771
+ },
14772
+ {
14773
+ fn: callback => onReactorRemovedLocal(this.query.referenceType, this.query.referenceId, callback),
14774
+ action: "onRemoved" /* Amity.ReactionActionTypeEnum.OnRemoved */,
14775
+ },
14776
+ {
14777
+ fn: callback => onReactorAddedLocal(this.query.referenceType, this.query.referenceId, callback),
14778
+ action: "onRemoved" /* Amity.ReactionActionTypeEnum.OnRemoved */,
14779
+ },
14780
+ ]);
14781
+ }
14782
+ notifyChange({ origin, loading, error }) {
14783
+ var _a, _b;
14784
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
14785
+ if (!collection)
14786
+ return;
14787
+ const data = (_b = collection.data
14788
+ .map(reactorId => pullFromCache(['reactor', 'get', reactorId]))
14789
+ .filter(Boolean)
14790
+ .map(({ data }) => LinkedObject.reactor(data))) !== null && _b !== void 0 ? _b : [];
14791
+ if (!this.shouldNotify(data) && origin === 'event')
14792
+ return;
14793
+ this.callback({
14794
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
14795
+ data,
14796
+ hasNextPage: !!this.paginationController.getNextToken(),
14797
+ loading,
14798
+ error,
14799
+ });
14800
+ }
14801
+ }
14802
+
14803
+ /* eslint-disable no-use-before-define */
14523
14804
  /* begin_public_function
14524
14805
  id: reaction.query
14525
14806
  */
14526
14807
  /**
14527
14808
  * ```js
14528
- * import { getReactions } from '@amityco/ts-sdk-react-native'
14809
+ * import { getReactions } from '@amityco/ts-sdk'
14529
14810
  *
14530
14811
  * let reactions = []
14531
14812
  * const unsub = liveReactions({
@@ -14545,73 +14826,19 @@ const queryReactor = async (query) => {
14545
14826
  */
14546
14827
  const getReactions = (params, callback, config) => {
14547
14828
  const { log, cache } = getActiveClient();
14548
- if (!cache) {
14549
- console.log('For using Live Collection feature you need to enable Cache!');
14550
- }
14829
+ // if (!cache) {
14830
+ // console.log('For using Live Collection feature you need to enable Cache!');
14831
+ // }
14551
14832
  const timestamp = Date.now();
14552
- log(`liveReactions(tmpid: ${timestamp}) > listen`);
14553
- const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
14554
- const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
14555
- const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
14556
- const disposers = [];
14557
- const cacheKey = [
14558
- 'reaction',
14559
- 'collection',
14560
- { referenceId: params.referenceId, referenceType: params.referenceType },
14561
- ];
14562
- const responder = (data) => {
14563
- var _a, _b;
14564
- const reactions = (_a = data.data
14565
- .map(reactorId => pullFromCache(['reactor', 'get', reactorId]))
14566
- .filter(Boolean)
14567
- .map(({ data }) => LinkedObject.reactor(data))) !== null && _a !== void 0 ? _a : [];
14568
- callback({
14569
- onNextPage: onFetch,
14570
- data: reactions,
14571
- hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
14572
- loading: data.loading,
14573
- error: data.error,
14574
- });
14575
- };
14576
- const realtimeRouter = (action) => (reaction) => {
14577
- var _a;
14578
- const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
14579
- if (!collection)
14580
- return;
14581
- if (action === 'onAdded') {
14582
- collection.data = [...new Set([reaction.reactionId, ...collection.data])];
14583
- }
14584
- else if (action === 'onRemoved') {
14585
- collection.data = collection.data.filter(p => p !== reaction.reactionId);
14586
- }
14587
- pushToCache(cacheKey, collection);
14588
- responder(collection);
14589
- };
14590
- const onFetch = (initial = false) => {
14591
- var _a, _b, _c, _d;
14592
- const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
14593
- const reactions = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
14594
- if (!initial && reactions.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
14595
- return;
14596
- const query = createQuery(queryReactor, Object.assign(Object.assign({}, queryParams), { page: (_d = (!initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined)) !== null && _d !== void 0 ? _d : { limit } }));
14597
- runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
14598
- const data = {
14599
- loading,
14600
- error,
14601
- params: { page },
14602
- data: reactions,
14603
- };
14604
- if (result) {
14605
- data.data = [...new Set([...reactions, ...result.map(getResolver('reactor'))])];
14606
- }
14607
- pushToCache(cacheKey, data);
14608
- responder(data);
14609
- }, queryOptions(policy));
14610
- };
14611
- disposers.push(onReactorAdded(queryParams.referenceType, queryParams.referenceId, realtimeRouter('onAdded')), onReactorRemoved(queryParams.referenceType, queryParams.referenceId, realtimeRouter('onRemoved')));
14612
- onFetch(true);
14833
+ log(`getReactions(tmpid: ${timestamp}) > listen`);
14834
+ const reactionLiveCollection = new ReactionLiveCollectionController(params, callback);
14835
+ const disposers = reactionLiveCollection.startSubscription();
14836
+ const cacheKey = reactionLiveCollection.getCacheKey();
14837
+ disposers.push(() => {
14838
+ dropFromCache(cacheKey);
14839
+ });
14613
14840
  return () => {
14614
- log(`liveReactions(tmpid: ${timestamp}) > dispose`);
14841
+ log(`getReactions(tmpid: ${timestamp}) > dispose`);
14615
14842
  disposers.forEach(fn => fn());
14616
14843
  };
14617
14844
  };
@@ -15117,30 +15344,6 @@ const unmuteChannel = async (channelId) => {
15117
15344
  };
15118
15345
  /* end_public_function */
15119
15346
 
15120
- const convertEventPayload = (eventHandler, sourceModelProp, destinationDomain) => (callback) => eventHandler(sourceModel => {
15121
- var _a, _b;
15122
- if (!sourceModel) {
15123
- return sourceModel;
15124
- }
15125
- const client = getActiveClient();
15126
- const { objectSyncMap } = client;
15127
- /*
15128
- * NOTE: For objects created locally (optimistic creation), the SDK stores them with their local ID as the cache key, which is used throughout the entire SDK session (in-memory) for syncing updates.
15129
- * If the payload or response only contains the remote ID of the same object, the SDK will look up the corresponding local ID to retrieve the object.
15130
- */
15131
- const resolvedId = isLocalId(sourceModel[sourceModelProp])
15132
- ? sourceModel[sourceModelProp]
15133
- : (_a = objectSyncMap.get(sourceModel[sourceModelProp])) !== null && _a !== void 0 ? _a : sourceModel[sourceModelProp];
15134
- const model = (_b = pullFromCache([
15135
- destinationDomain,
15136
- 'get',
15137
- `${resolvedId}`,
15138
- ])) === null || _b === void 0 ? void 0 : _b.data;
15139
- if (!model)
15140
- return;
15141
- return callback(model);
15142
- });
15143
-
15144
15347
  /**
15145
15348
  * ```js
15146
15349
  * import { observeChannel } from '@amityco/ts-sdk-react-native'
@@ -19290,7 +19493,8 @@ const createCommunityMemberEventSubscriber = (event, callback) => {
19290
19493
  callback(preparedPayload.communities[0], getEventRelatedMember(event, preparedPayload));
19291
19494
  }
19292
19495
  else {
19293
- ingestInCache(preparedPayload);
19496
+ // NOTE: The event payload should be merge with existing cache data
19497
+ ingestInCache(preparedPayload, undefined, false);
19294
19498
  const community = pullFromCache([
19295
19499
  'community',
19296
19500
  'get',
@@ -19327,7 +19531,8 @@ const createLocalCommunityMemberEventSubscriber = (event, callback) => {
19327
19531
  callback(preparedPayload.communities[0], getEventRelatedMember(event, preparedPayload));
19328
19532
  }
19329
19533
  else {
19330
- ingestInCache(preparedPayload);
19534
+ // NOTE: The event payload should be merge with existing cache data
19535
+ ingestInCache(preparedPayload, undefined, false);
19331
19536
  const community = pullFromCache([
19332
19537
  'community',
19333
19538
  'get',
@@ -21417,9 +21622,10 @@ const queryGlobalFeed = async (query) => {
21417
21622
  const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
21418
21623
  const data = prepareMembershipPayload(payload, 'communityUsers');
21419
21624
  const { posts } = data;
21625
+ const { communities: processedCommunity } = prepareCommunityPayload(data);
21420
21626
  const cachedAt = client.cache && Date.now();
21421
21627
  if (client.cache) {
21422
- ingestInCache(data);
21628
+ ingestInCache(Object.assign(Object.assign({}, data), { communitis: processedCommunity }));
21423
21629
  const cacheKey = [
21424
21630
  'globalFeed',
21425
21631
  'query',
@@ -23734,6 +23940,145 @@ const getPinnedPosts = (params, callback, config) => {
23734
23940
  };
23735
23941
  };
23736
23942
 
23943
+ class GlobalPinnedPostPaginationController extends PaginationController {
23944
+ async getRequest(queryParams, token) {
23945
+ __rest(queryParams, ["limit"]);
23946
+ const path = '/api/v1/pinned-posts/global';
23947
+ const { data: queryResponse } = await this.http.get(path);
23948
+ return queryResponse;
23949
+ }
23950
+ }
23951
+
23952
+ class GlobalPinnedPostQueryStreamController extends QueryStreamController {
23953
+ constructor(query, cacheKey, notifyChange, preparePayload) {
23954
+ super(query, cacheKey);
23955
+ this.notifyChange = notifyChange;
23956
+ this.preparePayload = preparePayload;
23957
+ }
23958
+ // eslint-disable-next-line class-methods-use-this
23959
+ async saveToMainDB(response) {
23960
+ const client = getActiveClient();
23961
+ const cachedAt = client.cache && Date.now();
23962
+ if (client.cache) {
23963
+ ingestInCache(response, { cachedAt });
23964
+ }
23965
+ }
23966
+ appendToQueryStream(response, direction, refresh = false) {
23967
+ var _a, _b;
23968
+ if (refresh) {
23969
+ pushToCache(this.cacheKey, {
23970
+ data: response.pins.map(getResolver('pin')),
23971
+ });
23972
+ }
23973
+ else {
23974
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
23975
+ const pinnedPosts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
23976
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...pinnedPosts, ...response.pins.map(getResolver('pin'))])] }));
23977
+ this.notifyChange({
23978
+ origin: "server" /* Amity.LiveDataOrigin.SERVER */,
23979
+ loading: false,
23980
+ });
23981
+ }
23982
+ }
23983
+ reactor(action) {
23984
+ return (post) => {
23985
+ var _a;
23986
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
23987
+ if (!collection)
23988
+ return;
23989
+ if (action === EnumPostActions.OnPostDeleted) {
23990
+ collection.data = collection.data.filter(referenceId => referenceId !== `global#${post.postId}`);
23991
+ }
23992
+ pushToCache(this.cacheKey, collection);
23993
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
23994
+ };
23995
+ }
23996
+ subscribeRTE(createSubscriber) {
23997
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
23998
+ }
23999
+ }
24000
+
24001
+ class GlobalPinnedPostLiveCollectionController extends LiveCollectionController {
24002
+ constructor(query, callback) {
24003
+ const queryStreamId = hash__default["default"](query);
24004
+ const cacheKey = ['pinnedPosts', 'collection', queryStreamId];
24005
+ const paginationController = new GlobalPinnedPostPaginationController(query);
24006
+ super(paginationController, queryStreamId, cacheKey, callback);
24007
+ this.query = query;
24008
+ this.queryStreamController = new GlobalPinnedPostQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), response => response);
24009
+ this.callback = callback.bind(this);
24010
+ this.loadPage({ initial: true });
24011
+ }
24012
+ setup() {
24013
+ var _a;
24014
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24015
+ if (!collection) {
24016
+ pushToCache(this.cacheKey, {
24017
+ data: [],
24018
+ params: {},
24019
+ });
24020
+ }
24021
+ }
24022
+ async persistModel(queryPayload) {
24023
+ await this.queryStreamController.saveToMainDB(queryPayload);
24024
+ }
24025
+ persistQueryStream({ response, direction, refresh, }) {
24026
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
24027
+ }
24028
+ // eslint-disable-next-line class-methods-use-this
24029
+ startSubscription() {
24030
+ return this.queryStreamController.subscribeRTE([
24031
+ { fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
24032
+ {
24033
+ fn: onPostDeleted,
24034
+ action: EnumPostActions.OnPostDeleted,
24035
+ },
24036
+ ]);
24037
+ }
24038
+ notifyChange({ origin, loading, error }) {
24039
+ var _a, _b;
24040
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24041
+ if (!collection)
24042
+ return;
24043
+ const data = ((_b = collection.data
24044
+ .map(id => pullFromCache(['pin', 'get', id]))
24045
+ .filter(isNonNullable)
24046
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.pinnedPost);
24047
+ if (!this.shouldNotify(data) && origin === 'event')
24048
+ return;
24049
+ this.callback({
24050
+ data,
24051
+ loading,
24052
+ error,
24053
+ });
24054
+ }
24055
+ }
24056
+
24057
+ /**
24058
+ * Get global pinned posts
24059
+ *
24060
+ * @returns the global pinned post(s)
24061
+ *
24062
+ * @category Pined Posts Live Collection
24063
+ *
24064
+ */
24065
+ const getGlobalPinnedPosts = (params, callback, config) => {
24066
+ const { log, cache } = getActiveClient();
24067
+ // if (!cache) {
24068
+ // console.log(ENABLE_CACHE_MESSAGE);
24069
+ // }
24070
+ const timestamp = Date.now();
24071
+ log(`getGlobalPinnedPosts(tmpid: ${timestamp}) > listen`);
24072
+ const globalPinnedPostLiveCollection = new GlobalPinnedPostLiveCollectionController(params, callback);
24073
+ const disposers = globalPinnedPostLiveCollection.startSubscription();
24074
+ const cacheKey = globalPinnedPostLiveCollection.getCacheKey();
24075
+ disposers.push(() => dropFromCache(cacheKey));
24076
+ return () => {
24077
+ log(`getGlobalPinnedPosts(tmpid: ${timestamp}) > dispose`);
24078
+ disposers.forEach(fn => fn());
24079
+ };
24080
+ };
24081
+
23737
24082
  class SemanticSearchPostPaginationController extends PaginationController {
23738
24083
  async getRequest(queryParams, token) {
23739
24084
  const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
@@ -23995,6 +24340,7 @@ var index$5 = /*#__PURE__*/Object.freeze({
23995
24340
  getPost: getPost$1,
23996
24341
  getPosts: getPosts,
23997
24342
  getPinnedPosts: getPinnedPosts,
24343
+ getGlobalPinnedPosts: getGlobalPinnedPosts,
23998
24344
  semanticSearchPosts: semanticSearchPosts
23999
24345
  });
24000
24346
 
@@ -25539,8 +25885,8 @@ const onStoryReactionAdded = (callback) => {
25539
25885
  const onStoryReactionAddedLocal = (callback) => {
25540
25886
  const client = getActiveClient();
25541
25887
  const filter = async (payload) => {
25542
- ingestInCache(payload);
25543
- callback(payload.stories);
25888
+ ingestInCache({ stories: [payload.story] });
25889
+ callback([payload.story]);
25544
25890
  };
25545
25891
  const disposers = [
25546
25892
  createEventSubscriber(client, 'onStoryReactionAdded', 'local.story.reactionAdded', filter),
@@ -25569,8 +25915,8 @@ const onStoryReactionRemoved = (callback) => {
25569
25915
  const onStoryReactionRemovedLocal = (callback) => {
25570
25916
  const client = getActiveClient();
25571
25917
  const filter = async (payload) => {
25572
- ingestInCache(payload);
25573
- callback(payload.stories);
25918
+ ingestInCache({ stories: [payload.story] });
25919
+ callback([payload.story]);
25574
25920
  };
25575
25921
  const disposers = [
25576
25922
  createEventSubscriber(client, 'onStoryReactionRemoved', 'local.story.reactionRemoved', filter),
@@ -26110,12 +26456,12 @@ const updateLocalList = (cacheKey, targetIds) => {
26110
26456
  pushToCache(cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...storyTargets, ...targetIds])] }));
26111
26457
  };
26112
26458
  class GlobalStoryQueryStreamController extends QueryStreamController {
26113
- constructor(query, cacheKey, notifyChange, paginationController) {
26459
+ constructor(query, cacheKey, notifyChange, paginationController, preparePayload) {
26114
26460
  super(query, cacheKey);
26115
26461
  this.notifyChange = notifyChange;
26116
26462
  this.paginationController = paginationController;
26117
26463
  // Fix ESLint, "Expected 'this' to be used by class method"
26118
- this.preparePayload = payload => payload;
26464
+ this.preparePayload = preparePayload;
26119
26465
  }
26120
26466
  saveToMainDB(response) {
26121
26467
  const client = getActiveClient();
@@ -26207,7 +26553,10 @@ class GlobalStoryLiveCollectionController extends LiveCollectionController {
26207
26553
  const paginationController = new GlobalStoryPageController(query);
26208
26554
  super(paginationController, queryStreamId, cacheKey, callback);
26209
26555
  this.query = query;
26210
- this.queryStreamController = new GlobalStoryQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), paginationController);
26556
+ this.queryStreamController = new GlobalStoryQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), paginationController, (data) => {
26557
+ const _a = prepareCommunityPayload(Object.assign(Object.assign({}, data), { feeds: [] })), rest = __rest(_a, ["feeds"]);
26558
+ return Object.assign(Object.assign({}, data), rest);
26559
+ });
26211
26560
  this.paginationController = paginationController;
26212
26561
  this.callback = callback.bind(this);
26213
26562
  this.loadPage({ initial: true });