@amityco/ts-sdk-react-native 6.32.7-289cad7.0 → 6.33.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 (86) hide show
  1. package/.env +26 -26
  2. package/dist/@types/core/events.d.ts +16 -2
  3. package/dist/@types/core/events.d.ts.map +1 -1
  4. package/dist/@types/core/payload.d.ts +3 -0
  5. package/dist/@types/core/payload.d.ts.map +1 -1
  6. package/dist/@types/domains/pinnedPost.d.ts +1 -0
  7. package/dist/@types/domains/pinnedPost.d.ts.map +1 -1
  8. package/dist/@types/domains/reaction.d.ts +8 -2
  9. package/dist/@types/domains/reaction.d.ts.map +1 -1
  10. package/dist/@types/domains/user.d.ts +2 -0
  11. package/dist/@types/domains/user.d.ts.map +1 -1
  12. package/dist/communityRepository/communityMembership/events/utils.d.ts.map +1 -1
  13. package/dist/communityRepository/utils/communityWithMembership.d.ts.map +1 -1
  14. package/dist/feedRepository/api/queryGlobalFeed.d.ts.map +1 -1
  15. package/dist/index.cjs.js +908 -570
  16. package/dist/index.esm.js +766 -428
  17. package/dist/index.umd.js +3 -3
  18. package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.d.ts +13 -0
  19. package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.d.ts.map +1 -0
  20. package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostPaginationController.d.ts +13 -0
  21. package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostPaginationController.d.ts.map +1 -0
  22. package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostQueryStreamController.d.ts +15 -0
  23. package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostQueryStreamController.d.ts.map +1 -0
  24. package/dist/postRepository/observers/getGlobalPinnedPosts.d.ts +10 -0
  25. package/dist/postRepository/observers/getGlobalPinnedPosts.d.ts.map +1 -0
  26. package/dist/postRepository/observers/index.d.ts +1 -0
  27. package/dist/postRepository/observers/index.d.ts.map +1 -1
  28. package/dist/reactionRepository/api/addReaction.d.ts.map +1 -1
  29. package/dist/reactionRepository/api/removeReaction.d.ts.map +1 -1
  30. package/dist/reactionRepository/events/onReactorAddedLocal.d.ts +19 -0
  31. package/dist/reactionRepository/events/onReactorAddedLocal.d.ts.map +1 -0
  32. package/dist/reactionRepository/events/onReactorRemovedLocal.d.ts +19 -0
  33. package/dist/reactionRepository/events/onReactorRemovedLocal.d.ts.map +1 -0
  34. package/dist/reactionRepository/observers/getReactions/ReactionLiveCollectionController.d.ts +13 -0
  35. package/dist/reactionRepository/observers/getReactions/ReactionLiveCollectionController.d.ts.map +1 -0
  36. package/dist/reactionRepository/observers/getReactions/ReactionPaginationController.d.ts +5 -0
  37. package/dist/reactionRepository/observers/getReactions/ReactionPaginationController.d.ts.map +1 -0
  38. package/dist/reactionRepository/observers/getReactions/ReactionQueryStreamController.d.ts +14 -0
  39. package/dist/reactionRepository/observers/getReactions/ReactionQueryStreamController.d.ts.map +1 -0
  40. package/dist/reactionRepository/observers/{getReactions.d.ts → getReactions/getReactions.d.ts} +1 -1
  41. package/dist/reactionRepository/observers/getReactions/getReactions.d.ts.map +1 -0
  42. package/dist/reactionRepository/observers/getReactions/index.d.ts +2 -0
  43. package/dist/reactionRepository/observers/getReactions/index.d.ts.map +1 -0
  44. package/dist/reactionRepository/observers/index.d.ts +1 -1
  45. package/dist/reactionRepository/observers/index.d.ts.map +1 -1
  46. package/dist/storyRepository/observers/getGlobalStoryTargets/GlobalStoryLiveCollectionController.d.ts.map +1 -1
  47. package/dist/storyRepository/observers/getGlobalStoryTargets/GlobalStoryQueryStreamController.d.ts +1 -1
  48. package/dist/storyRepository/observers/getGlobalStoryTargets/GlobalStoryQueryStreamController.d.ts.map +1 -1
  49. package/dist/userRepository/observers/getBlockedUsers/BlockedUserLiveCollectionController.d.ts.map +1 -1
  50. package/dist/userRepository/observers/getBlockedUsers/BlockedUserQueryStreamController.d.ts +3 -2
  51. package/dist/userRepository/observers/getBlockedUsers/BlockedUserQueryStreamController.d.ts.map +1 -1
  52. package/package.json +1 -1
  53. package/src/@types/core/events.ts +18 -6
  54. package/src/@types/core/payload.ts +4 -0
  55. package/src/@types/domains/pin.ts +1 -1
  56. package/src/@types/domains/pinnedPost.ts +2 -0
  57. package/src/@types/domains/reaction.ts +9 -3
  58. package/src/@types/domains/user.ts +2 -0
  59. package/src/communityRepository/communityMembership/events/utils.ts +4 -2
  60. package/src/communityRepository/utils/communityWithMembership.ts +15 -8
  61. package/src/feedRepository/api/queryGlobalFeed.ts +4 -1
  62. package/src/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.ts +96 -0
  63. package/src/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostPaginationController.ts +19 -0
  64. package/src/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostQueryStreamController.ts +88 -0
  65. package/src/postRepository/observers/getGlobalPinnedPosts.ts +42 -0
  66. package/src/postRepository/observers/index.ts +1 -0
  67. package/src/reactionRepository/api/addReaction.ts +23 -1
  68. package/src/reactionRepository/api/removeReaction.ts +25 -2
  69. package/src/reactionRepository/events/onReactorAddedLocal.ts +95 -0
  70. package/src/reactionRepository/events/onReactorRemovedLocal.ts +94 -0
  71. package/src/reactionRepository/observers/getReactions/ReactionLiveCollectionController.ts +111 -0
  72. package/src/reactionRepository/observers/getReactions/ReactionPaginationController.ts +30 -0
  73. package/src/reactionRepository/observers/getReactions/ReactionQueryStreamController.ts +92 -0
  74. package/src/reactionRepository/observers/getReactions/getReactions.ts +57 -0
  75. package/src/reactionRepository/observers/getReactions/index.ts +1 -0
  76. package/src/reactionRepository/observers/index.ts +1 -1
  77. package/src/storyRepository/events/onStoryReactionAdded.ts +3 -3
  78. package/src/storyRepository/events/onStoryReactionRemoved.ts +3 -3
  79. package/src/storyRepository/observers/getGlobalStoryTargets/GlobalStoryLiveCollectionController.ts +5 -0
  80. package/src/storyRepository/observers/getGlobalStoryTargets/GlobalStoryQueryStreamController.ts +5 -2
  81. package/src/userRepository/observers/getBlockedUsers/BlockedUserLiveCollectionController.ts +12 -1
  82. package/src/userRepository/observers/getBlockedUsers/BlockedUserQueryStreamController.ts +13 -5
  83. package/src/userRepository/relationship/follow/observers/getFollowers/FollowerLiveCollectionController.ts +1 -1
  84. package/src/userRepository/relationship/follow/observers/getFollowings/FollowingLiveCollectionController.ts +1 -1
  85. package/dist/reactionRepository/observers/getReactions.d.ts.map +0 -1
  86. package/src/reactionRepository/observers/getReactions.ts +0 -146
package/dist/index.cjs.js CHANGED
@@ -123,8 +123,8 @@ const PostContentType = Object.freeze({
123
123
 
124
124
  function getVersion() {
125
125
  try {
126
- // the string ''v6.32.6-cjs'' should be replaced by actual value by @rollup/plugin-replace
127
- return 'v6.32.6-cjs';
126
+ // the string ''v6.33.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
127
+ return 'v6.33.0-cjs';
128
128
  }
129
129
  catch (error) {
130
130
  return '__dev__';
@@ -10248,6 +10248,18 @@ class QueryStreamController {
10248
10248
  }
10249
10249
  }
10250
10250
 
10251
+ var EnumFollowActions;
10252
+ (function (EnumFollowActions) {
10253
+ EnumFollowActions["OnRequested"] = "onRequested";
10254
+ EnumFollowActions["OnAccepted"] = "onAccepted";
10255
+ EnumFollowActions["OnDeclined"] = "onDeclined";
10256
+ EnumFollowActions["OnCanceled"] = "onCanceled";
10257
+ EnumFollowActions["OnFollowed"] = "onFollowed";
10258
+ EnumFollowActions["OnUnfollowed"] = "onUnfollowed";
10259
+ EnumFollowActions["OnDeleted"] = "onDeleted";
10260
+ EnumFollowActions["OnUserDeleted"] = "onUserDeleted";
10261
+ })(EnumFollowActions || (EnumFollowActions = {}));
10262
+
10251
10263
  class BlockedUserQueryStreamController extends QueryStreamController {
10252
10264
  constructor(query, cacheKey, notifyChange, preparePayload) {
10253
10265
  super(query, cacheKey);
@@ -10276,10 +10288,13 @@ class BlockedUserQueryStreamController extends QueryStreamController {
10276
10288
  }
10277
10289
  }
10278
10290
  reactor(action) {
10279
- return (followStatus) => {
10291
+ return (targetUser) => {
10280
10292
  var _a;
10281
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
10282
- pushToCache(this.cacheKey, collection);
10293
+ if (action === EnumFollowActions.OnFollowed) {
10294
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
10295
+ const updatedCollection = collection === null || collection === void 0 ? void 0 : collection.data.filter(id => id !== targetUser.userId);
10296
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: updatedCollection }));
10297
+ }
10283
10298
  this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
10284
10299
  };
10285
10300
  }
@@ -10476,560 +10491,593 @@ var EnumUserActions;
10476
10491
  EnumUserActions["OnUserFlagCleared"] = "onUserFlagCleared";
10477
10492
  })(EnumUserActions || (EnumUserActions = {}));
10478
10493
 
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
- });
10494
+ const createFollowEventSubscriber = (event, callback) => {
10495
+ const client = getActiveClient();
10496
+ const filter = (data) => {
10497
+ const payload = prepareFollowersPayload(data);
10498
+ if (!client.cache) {
10499
+ callback(payload.follows[0]);
10498
10500
  }
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
- }
10501
+ else {
10502
+ ingestInCache(payload);
10503
+ callback(payload.follows[0]);
10504
+ }
10505
+ };
10506
+ return createEventSubscriber(client, event, event, filter);
10507
+ };
10508
+ const createLocalFollowEventSubscriber = (event, callback) => {
10509
+ const client = getActiveClient();
10510
+ const filter = (data) => {
10511
+ const payload = prepareFollowStatusPayload(data);
10512
+ if (!client.cache) {
10513
+ callback(payload.follows[0]);
10514
+ }
10515
+ else {
10516
+ ingestInCache(payload);
10517
+ callback(payload.follows[0]);
10518
+ }
10519
+ };
10520
+ return createEventSubscriber(client, event, event, filter);
10521
+ };
10541
10522
 
10542
- /* begin_public_function
10543
- id: user.get_blocked_users
10544
- */
10545
10523
  /**
10546
10524
  * ```js
10547
- * import { UserRepository } from '@amityco/ts-sdk-react-native'
10548
- * const unblockedUser = await UserRepository.blockUser('userId')
10525
+ * import { onUserFollowed } from '@amityco/ts-sdk-react-native'
10526
+ * const dispose = onUserFollowed(status => {
10527
+ * // ...
10528
+ * })
10549
10529
  * ```
10550
10530
  *
10551
- * Blocks a {@link Amity.InternalUser}
10531
+ * Fired when a user follows another users and confirmation is not required
10552
10532
  *
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
10533
+ * @param callback The function to call when the event was fired
10534
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
10556
10535
  *
10557
- * @category Post API
10558
- * @async
10536
+ * @category Follow Events
10559
10537
  */
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
- };
10538
+ const onUserFollowed = (callback) => createFollowEventSubscriber('follow.created', callback);
10584
10539
 
10585
- /* begin_public_function
10586
- id: user.relationship.follow
10587
- */
10588
10540
  /**
10589
10541
  * ```js
10590
- * import { follow } from '@amityco/ts-sdk-react-native'
10591
- * const status = await follow('foobar')
10542
+ * import { onUserUnfollowed } from '@amityco/ts-sdk-react-native'
10543
+ * const dispose = onUserFollowed(status => {
10544
+ * // ...
10545
+ * })
10592
10546
  * ```
10593
10547
  *
10594
- * Follow the user
10548
+ * Fired when a user unfollows
10595
10549
  *
10596
- * @param userId the ID of the {@link Amity.InternalUser}
10597
- * @returns the status {@link Amity.FollowStatus}
10550
+ * @param callback The function to call when the event was fired
10551
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
10598
10552
  *
10599
- * @category Follow API
10600
- * @async
10553
+ * @category Follow Events
10601
10554
  */
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 */
10555
+ const onUserUnfollowed = (callback) => createFollowEventSubscriber('follow.unfollowed', callback);
10623
10556
 
10624
- /* begin_public_function
10625
- id: user.relationship.unfollow
10626
- */
10627
10557
  /**
10628
10558
  * ```js
10629
- * import { unfollow } from '@amityco/ts-sdk-react-native'
10630
- * await unfollow('foobar')
10559
+ * import { onFollowerDeleted } from '@amityco/ts-sdk-react-native'
10560
+ * const dispose = onFollowerDeleted(status => {
10561
+ * // ...
10562
+ * })
10631
10563
  * ```
10632
10564
  *
10633
- * Cancel the follow request or unfollow the user
10565
+ * Fired when a follower has been deleted
10634
10566
  *
10635
- * @param userId the ID of the {@link Amity.InternalUser}
10636
- * @returns A success boolean if the user {@link Amity.InternalUser} was unfollowed
10567
+ * @param callback The function to call when the event was fired
10568
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
10637
10569
  *
10638
- * @category Follow API
10639
- * @async
10570
+ * @category Follow Events
10640
10571
  */
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 */
10572
+ const onFollowerDeleted = (callback) => createFollowEventSubscriber('follow.followerDeleted', callback);
10653
10573
 
10654
10574
  /**
10655
- * @deprecated This API renamed to `acceptMyFollower`.
10656
- * Please use acceptMyFollower() instead.
10657
- *
10658
10575
  * ```js
10659
- * import { acceptFollower } from '@amityco/ts-sdk-react-native'
10660
- * await acceptFollower('foobar')
10576
+ * import { onFollowerRequested } from '@amityco/ts-sdk-react-native'
10577
+ * const dispose = onFollowerRequested(status => {
10578
+ * // ...
10579
+ * })
10661
10580
  * ```
10662
10581
  *
10663
- * Accept the follow request
10582
+ * Fired when a user follows another users and confirmation is required
10664
10583
  *
10665
- * @param userId the ID of the {@link Amity.InternalUser} follower
10666
- * @returns A success boolean if the follow request was accepted
10584
+ * @param callback The function to call when the event was fired
10585
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
10667
10586
  *
10668
- * @category Follow API
10669
- * @async
10587
+ * @category Follow Events
10670
10588
  */
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
- };
10589
+ const onFollowerRequested = (callback) => createFollowEventSubscriber('follow.requested', callback);
10682
10590
 
10683
- /* begin_public_function
10684
- id: user.relationship.accept_follow
10685
- */
10686
10591
  /**
10687
10592
  * ```js
10688
- * import { UserRepository } from '@amityco/ts-sdk-react-native'
10689
- * await UserRepository.Relationship.acceptMyFollower('foobar')
10690
- * ```
10593
+ * import { onFollowRequestCanceled } from '@amityco/ts-sdk-react-native'
10594
+ * const dispose = onFollowRequestCanceled(status => {
10595
+ * // ...
10596
+ * })
10597
+ * ```
10691
10598
  *
10692
- * Accept the follow request
10599
+ * Fired when a follow request has been canceled
10693
10600
  *
10694
- * @param userId the ID of the {@link Amity.InternalUser} follower
10695
- * @returns A success boolean if the follow request was accepted
10601
+ * @param callback The function to call when the event was fired
10602
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
10696
10603
  *
10697
- * @category Follow API
10698
- * @async
10604
+ * @category Follow Events
10699
10605
  */
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 */
10606
+ const onFollowRequestCanceled = (callback) => createFollowEventSubscriber('follow.requestCanceled', callback);
10712
10607
 
10713
10608
  /**
10714
- * @deprecated This API renamed to `declineMyFollower`.
10715
- * Please use declineMyFollower() instead.
10609
+ * ```js
10610
+ * import { onFollowRequestAccepted } from '@amityco/ts-sdk-react-native'
10611
+ * const dispose = onFollowRequestAccepted(status => {
10612
+ * // ...
10613
+ * })
10614
+ * ```
10615
+ *
10616
+ * Fired when a follow request has been accepted
10617
+ *
10618
+ * @param callback The function to call when the event was fired
10619
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
10716
10620
  *
10621
+ * @category Follow Events
10622
+ */
10623
+ const onFollowRequestAccepted = (callback) => createFollowEventSubscriber('follow.accepted', callback);
10624
+
10625
+ /**
10717
10626
  * ```js
10718
- * import { declineFollower } from '@amityco/ts-sdk-react-native'
10719
- * await declineFollower('foobar')
10627
+ * import { onFollowRequestDeclined } from '@amityco/ts-sdk-react-native'
10628
+ * const dispose = onFollowRequestDeclined(status => {
10629
+ * // ...
10630
+ * })
10720
10631
  * ```
10721
10632
  *
10722
- * Decline the follow request or delete the follower
10633
+ * Fired when a follow request has been declined
10723
10634
  *
10724
- * @param userId the ID of the {@link Amity.InternalUser} follower
10725
- * @returns A success boolean if the follow request was decline
10635
+ * @param callback The function to call when the event was fired
10636
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
10726
10637
  *
10727
- * @category Follow API
10728
- * @async
10638
+ * @category Follow Events
10729
10639
  */
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
- };
10640
+ const onFollowRequestDeclined = (callback) => createFollowEventSubscriber('follow.requestDeclined', callback);
10741
10641
 
10742
- /* begin_public_function
10743
- id: user.relationship.decline_follow
10744
- */
10745
10642
  /**
10746
10643
  * ```js
10747
- * import { UserRepository } from '@amityco/ts-sdk-react-native'
10748
- * await UserRepository.Relationship.declineMyFollower('foobar')
10644
+ * import { getFollowInfo } from '@amityco/ts-sdk-react-native'
10645
+ * const { data: followInfo } = await getFollowInfo('foobar')
10749
10646
  * ```
10750
10647
  *
10751
- * Decline the follow request or delete the follower
10648
+ * Fetches the number of followers, followings, pending requests and the follow status for current user
10752
10649
  *
10753
- * @param userId the ID of the {@link Amity.InternalUser} follower
10754
- * @returns A success boolean if the follow request was decline
10650
+ * @param userId the ID of the {@link Amity.InternalUser}
10651
+ * @returns the associated {@link Amity.FollowInfo} object
10755
10652
  *
10756
10653
  * @category Follow API
10757
10654
  * @async
10758
10655
  */
10759
- const declineMyFollower = async (userId) => {
10656
+ const getFollowInfo$1 = async (userId) => {
10657
+ var _a, _b;
10760
10658
  const client = getActiveClient();
10761
- client.log('follow/declineMyFollower', userId);
10762
- const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
10659
+ client.log('follow/getFollowInfo', userId);
10660
+ const { data } = await client.http.get(client.userId === userId ? `/api/v4/me/followInfo` : `/api/v5/users/${userId}/followInfo`);
10661
+ const cachedAt = client.cache && Date.now();
10662
+ const followInfo = 'follows' in data
10663
+ ? 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
10664
  if (client.cache) {
10764
- ingestInCache(data);
10665
+ pushToCache(['followInfo', 'get', userId], followInfo, {
10666
+ cachedAt,
10667
+ });
10765
10668
  }
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
- }
10669
+ return {
10670
+ data: followInfo,
10671
+ cachedAt,
10783
10672
  };
10784
- return createEventSubscriber(client, event, event, filter);
10785
10673
  };
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
10674
  /**
10802
10675
  * ```js
10803
- * import { onUserFollowed } from '@amityco/ts-sdk-react-native'
10804
- * const dispose = onUserFollowed(status => {
10805
- * // ...
10806
- * })
10676
+ * import { getFollowInfo } from '@amityco/ts-sdk-react-native'
10677
+ * const { data: followInfo } = getFollowInfo.locally('foobar')
10807
10678
  * ```
10808
10679
  *
10809
- * Fired when a user follows another users and confirmation is not required
10680
+ * Fetches the number of followers, followings, pending requests and the follow status for current user from cache
10810
10681
  *
10811
- * @param callback The function to call when the event was fired
10812
- * @returns an {@link Amity.Unsubscriber} function to stop listening
10682
+ * @param userId the ID of the {@link Amity.InternalUser}
10683
+ * @returns the associated {@link Amity.FollowInfo} object
10813
10684
  *
10814
- * @category Follow Events
10685
+ * @category Follow API
10815
10686
  */
10816
- const onUserFollowed = (callback) => createFollowEventSubscriber('follow.created', callback);
10687
+ getFollowInfo$1.locally = (userId) => {
10688
+ const client = getActiveClient();
10689
+ client.log('follow/getFollowInfo.locally', userId);
10690
+ if (!client.cache) {
10691
+ return;
10692
+ }
10693
+ const cached = pullFromCache(['followInfo', 'get', userId]);
10694
+ if (!cached) {
10695
+ return;
10696
+ }
10697
+ return {
10698
+ data: cached.data,
10699
+ cachedAt: cached.cachedAt,
10700
+ };
10701
+ };
10817
10702
 
10818
10703
  /**
10819
10704
  * ```js
10820
- * import { onUserUnfollowed } from '@amityco/ts-sdk-react-native'
10821
- * const dispose = onUserFollowed(status => {
10705
+ * import { onFollowInfoUpdated } from '@amityco/ts-sdk-react-native'
10706
+ * const dispose = onFollowInfoUpdated(followInfo => {
10822
10707
  * // ...
10823
10708
  * })
10824
10709
  * ```
10825
10710
  *
10826
- * Fired when a user unfollows
10711
+ * Fired when a {@link Amity.FollowInfo} has been updated
10827
10712
  *
10828
10713
  * @param callback The function to call when the event was fired
10829
10714
  * @returns an {@link Amity.Unsubscriber} function to stop listening
10830
10715
  *
10831
10716
  * @category Follow Events
10832
10717
  */
10833
- const onUserUnfollowed = (callback) => createFollowEventSubscriber('follow.unfollowed', callback);
10718
+ const onFollowInfoUpdated = (callback) => {
10719
+ const handler = async (payload) => {
10720
+ const [{ data: followInfoFrom }, { data: followInfoTo }] = await Promise.all([
10721
+ getFollowInfo$1(payload.from),
10722
+ getFollowInfo$1(payload.to),
10723
+ ]);
10724
+ callback(followInfoFrom);
10725
+ callback(followInfoTo);
10726
+ };
10727
+ const disposers = [
10728
+ createFollowEventSubscriber('follow.created', handler),
10729
+ createFollowEventSubscriber('follow.requested', handler),
10730
+ createFollowEventSubscriber('follow.accepted', handler),
10731
+ createFollowEventSubscriber('follow.unfollowed', handler),
10732
+ createFollowEventSubscriber('follow.requestCanceled', handler),
10733
+ createFollowEventSubscriber('follow.requestDeclined', handler),
10734
+ createFollowEventSubscriber('follow.followerDeleted', handler),
10735
+ createLocalFollowEventSubscriber('local.follow.created', handler),
10736
+ createLocalFollowEventSubscriber('local.follow.requested', handler),
10737
+ createLocalFollowEventSubscriber('local.follow.accepted', handler),
10738
+ createLocalFollowEventSubscriber('local.follow.unfollowed', handler),
10739
+ createLocalFollowEventSubscriber('local.follow.requestDeclined', handler),
10740
+ ];
10741
+ return () => {
10742
+ disposers.forEach(fn => fn());
10743
+ };
10744
+ };
10834
10745
 
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);
10746
+ const onLocalUserFollowed = (callback) => createLocalFollowEventSubscriber('local.follow.created', callback);
10747
+
10748
+ const onLocalUserUnfollowed = (callback) => createLocalFollowEventSubscriber('local.follow.unfollowed', callback);
10749
+
10750
+ const onLocalFollowerRequested = (callback) => createLocalFollowEventSubscriber('local.follow.requested', callback);
10751
+
10752
+ const onLocalFollowRequestAccepted = (callback) => createLocalFollowEventSubscriber('local.follow.accepted', callback);
10851
10753
 
10754
+ const onLocalFollowRequestDeclined = (callback) => createLocalFollowEventSubscriber('local.follow.requestDeclined', callback);
10755
+
10756
+ const convertEventPayload = (eventHandler, sourceModelProp, destinationDomain) => (callback) => eventHandler(sourceModel => {
10757
+ var _a, _b;
10758
+ if (!sourceModel) {
10759
+ return sourceModel;
10760
+ }
10761
+ const client = getActiveClient();
10762
+ const { objectSyncMap } = client;
10763
+ /*
10764
+ * 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.
10765
+ * 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.
10766
+ */
10767
+ const resolvedId = isLocalId(sourceModel[sourceModelProp])
10768
+ ? sourceModel[sourceModelProp]
10769
+ : (_a = objectSyncMap.get(sourceModel[sourceModelProp])) !== null && _a !== void 0 ? _a : sourceModel[sourceModelProp];
10770
+ const model = (_b = pullFromCache([
10771
+ destinationDomain,
10772
+ 'get',
10773
+ `${resolvedId}`,
10774
+ ])) === null || _b === void 0 ? void 0 : _b.data;
10775
+ if (!model)
10776
+ return;
10777
+ return callback(model);
10778
+ });
10779
+
10780
+ class BlockedUserLiveCollectionController extends LiveCollectionController {
10781
+ constructor(query, callback) {
10782
+ const queryStreamId = hash__default["default"](query);
10783
+ const cacheKey = ['blockedUsers', 'collection', queryStreamId];
10784
+ const paginationController = new BlockedUserPaginationController(query);
10785
+ super(paginationController, queryStreamId, cacheKey, callback);
10786
+ this.query = query;
10787
+ this.queryStreamController = new BlockedUserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareBlockedUserPayload);
10788
+ this.callback = callback.bind(this);
10789
+ this.loadPage({ initial: true });
10790
+ }
10791
+ setup() {
10792
+ var _a;
10793
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
10794
+ if (!collection) {
10795
+ pushToCache(this.cacheKey, {
10796
+ data: [],
10797
+ params: {},
10798
+ });
10799
+ }
10800
+ }
10801
+ async persistModel(queryPayload) {
10802
+ await this.queryStreamController.saveToMainDB(queryPayload);
10803
+ }
10804
+ persistQueryStream({ response, direction, refresh, }) {
10805
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
10806
+ }
10807
+ startSubscription() {
10808
+ return this.queryStreamController.subscribeRTE([
10809
+ {
10810
+ fn: onUserDeleted$2,
10811
+ action: EnumUserActions.OnUserDeleted,
10812
+ },
10813
+ // In the case of unblocking a user, we need to subscribe to the follow events
10814
+ {
10815
+ fn: convertEventPayload(onLocalUserFollowed, 'to', 'user'),
10816
+ action: EnumFollowActions.OnFollowed,
10817
+ },
10818
+ {
10819
+ fn: convertEventPayload(onUserFollowed, 'to', 'user'),
10820
+ action: EnumFollowActions.OnFollowed,
10821
+ },
10822
+ ]);
10823
+ }
10824
+ notifyChange({ origin, loading, error }) {
10825
+ var _a, _b;
10826
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
10827
+ if (!collection)
10828
+ return;
10829
+ const data = this.applyFilter((_b = collection.data
10830
+ .map(id => pullFromCache(['user', 'get', id]))
10831
+ .filter(isNonNullable)
10832
+ .map(({ data }) => data)
10833
+ .map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
10834
+ if (!this.shouldNotify(data) && origin === 'event')
10835
+ return;
10836
+ this.callback({
10837
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
10838
+ data,
10839
+ hasNextPage: !!this.paginationController.getNextToken(),
10840
+ loading,
10841
+ error,
10842
+ });
10843
+ }
10844
+ // eslint-disable-next-line class-methods-use-this
10845
+ applyFilter(data) {
10846
+ let users = data;
10847
+ users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
10848
+ return users;
10849
+ }
10850
+ }
10851
+
10852
+ /* begin_public_function
10853
+ id: user.get_blocked_users
10854
+ */
10852
10855
  /**
10853
10856
  * ```js
10854
- * import { onFollowerRequested } from '@amityco/ts-sdk-react-native'
10855
- * const dispose = onFollowerRequested(status => {
10856
- * // ...
10857
- * })
10857
+ * import { UserRepository } from '@amityco/ts-sdk-react-native'
10858
+ * const unblockedUser = await UserRepository.blockUser('userId')
10858
10859
  * ```
10859
10860
  *
10860
- * Fired when a user follows another users and confirmation is required
10861
+ * Blocks a {@link Amity.InternalUser}
10861
10862
  *
10862
- * @param callback The function to call when the event was fired
10863
- * @returns an {@link Amity.Unsubscriber} function to stop listening
10863
+ * @param params The params to get blocked {@link Amity.InternalUser}s
10864
+ * @param callback to recieve updates on unblocked {@link Amity.InternalUser}s
10865
+ * @returns {@link Amity.Unsubscriber} to unsubscribe from collection
10864
10866
  *
10865
- * @category Follow Events
10867
+ * @category Post API
10868
+ * @async
10866
10869
  */
10867
- const onFollowerRequested = (callback) => createFollowEventSubscriber('follow.requested', callback);
10870
+ const getBlockedUsers$1 = (params, callback, config) => {
10871
+ const { log, cache } = getActiveClient();
10872
+ if (!cache) {
10873
+ console.log(ENABLE_CACHE_MESSAGE);
10874
+ }
10875
+ const timestamp = Date.now();
10876
+ log(`getBlockedUsers(tmpid: ${timestamp}) > listen`);
10877
+ const blockedUserLiveCollection = new BlockedUserLiveCollectionController(params, callback);
10878
+ const disposers = blockedUserLiveCollection.startSubscription();
10879
+ const cacheKey = blockedUserLiveCollection.getCacheKey();
10880
+ disposers.push(() => dropFromCache(cacheKey));
10881
+ return () => {
10882
+ log(`getBlockedUsers(tmpid: ${timestamp}) > dispose`);
10883
+ disposers.forEach(fn => fn());
10884
+ dropFromCache(cacheKey);
10885
+ };
10886
+ };
10887
+ /* end_public_function */
10888
+
10889
+ /* eslint-disable no-use-before-define */
10890
+ const getBlockedUsers = (params, callback, config) => {
10891
+ console.log('Deprecation Notice: UserRepository.Relationship.getBlockedUsers will be deprecated on 9th June 2023, please use UserRepository.getBlockedUsers instead.');
10892
+ return getBlockedUsers$1(params, callback);
10893
+ };
10868
10894
 
10895
+ /* begin_public_function
10896
+ id: user.relationship.follow
10897
+ */
10869
10898
  /**
10870
10899
  * ```js
10871
- * import { onFollowRequestCanceled } from '@amityco/ts-sdk-react-native'
10872
- * const dispose = onFollowRequestCanceled(status => {
10873
- * // ...
10874
- * })
10900
+ * import { follow } from '@amityco/ts-sdk-react-native'
10901
+ * const status = await follow('foobar')
10875
10902
  * ```
10876
10903
  *
10877
- * Fired when a follow request has been canceled
10904
+ * Follow the user
10878
10905
  *
10879
- * @param callback The function to call when the event was fired
10880
- * @returns an {@link Amity.Unsubscriber} function to stop listening
10906
+ * @param userId the ID of the {@link Amity.InternalUser}
10907
+ * @returns the status {@link Amity.FollowStatus}
10881
10908
  *
10882
- * @category Follow Events
10909
+ * @category Follow API
10910
+ * @async
10883
10911
  */
10884
- const onFollowRequestCanceled = (callback) => createFollowEventSubscriber('follow.requestCanceled', callback);
10912
+ const follow = async (userId) => {
10913
+ const client = getActiveClient();
10914
+ client.log('follow/follow', userId);
10915
+ const { data } = await client.http.post(`/api/v4/me/following/${userId}`);
10916
+ const cachedAt = client.cache && Date.now();
10917
+ if (client.cache) {
10918
+ ingestInCache(data, { cachedAt });
10919
+ }
10920
+ const payload = prepareFollowStatusPayload(data);
10921
+ if (data.follows[0].status === 'accepted') {
10922
+ fireEvent('local.follow.created', payload);
10923
+ }
10924
+ else {
10925
+ fireEvent('local.follow.requested', payload);
10926
+ }
10927
+ return {
10928
+ data: data.follows[0],
10929
+ cachedAt,
10930
+ };
10931
+ };
10932
+ /* end_public_function */
10885
10933
 
10934
+ /* begin_public_function
10935
+ id: user.relationship.unfollow
10936
+ */
10886
10937
  /**
10887
10938
  * ```js
10888
- * import { onFollowRequestAccepted } from '@amityco/ts-sdk-react-native'
10889
- * const dispose = onFollowRequestAccepted(status => {
10890
- * // ...
10891
- * })
10939
+ * import { unfollow } from '@amityco/ts-sdk-react-native'
10940
+ * await unfollow('foobar')
10892
10941
  * ```
10893
10942
  *
10894
- * Fired when a follow request has been accepted
10943
+ * Cancel the follow request or unfollow the user
10895
10944
  *
10896
- * @param callback The function to call when the event was fired
10897
- * @returns an {@link Amity.Unsubscriber} function to stop listening
10945
+ * @param userId the ID of the {@link Amity.InternalUser}
10946
+ * @returns A success boolean if the user {@link Amity.InternalUser} was unfollowed
10898
10947
  *
10899
- * @category Follow Events
10948
+ * @category Follow API
10949
+ * @async
10900
10950
  */
10901
- const onFollowRequestAccepted = (callback) => createFollowEventSubscriber('follow.accepted', callback);
10951
+ const unfollow = async (userId) => {
10952
+ const client = getActiveClient();
10953
+ client.log('follow/unfollow', userId);
10954
+ const { data } = await client.http.delete(`/api/v4/me/following/${userId}`);
10955
+ if (client.cache) {
10956
+ ingestInCache(data);
10957
+ }
10958
+ const payload = prepareFollowStatusPayload(data);
10959
+ fireEvent('local.follow.unfollowed', payload);
10960
+ return true;
10961
+ };
10962
+ /* end_public_function */
10902
10963
 
10903
10964
  /**
10965
+ * @deprecated This API renamed to `acceptMyFollower`.
10966
+ * Please use acceptMyFollower() instead.
10967
+ *
10904
10968
  * ```js
10905
- * import { onFollowRequestDeclined } from '@amityco/ts-sdk-react-native'
10906
- * const dispose = onFollowRequestDeclined(status => {
10907
- * // ...
10908
- * })
10969
+ * import { acceptFollower } from '@amityco/ts-sdk-react-native'
10970
+ * await acceptFollower('foobar')
10909
10971
  * ```
10910
10972
  *
10911
- * Fired when a follow request has been declined
10973
+ * Accept the follow request
10912
10974
  *
10913
- * @param callback The function to call when the event was fired
10914
- * @returns an {@link Amity.Unsubscriber} function to stop listening
10975
+ * @param userId the ID of the {@link Amity.InternalUser} follower
10976
+ * @returns A success boolean if the follow request was accepted
10915
10977
  *
10916
- * @category Follow Events
10978
+ * @category Follow API
10979
+ * @async
10917
10980
  */
10918
- const onFollowRequestDeclined = (callback) => createFollowEventSubscriber('follow.requestDeclined', callback);
10981
+ const acceptFollower = async (userId) => {
10982
+ const client = getActiveClient();
10983
+ client.log('follow/acceptFollower', userId);
10984
+ const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
10985
+ if (client.cache) {
10986
+ ingestInCache(data);
10987
+ }
10988
+ const payload = prepareFollowStatusPayload(data);
10989
+ fireEvent('local.follow.accepted', payload);
10990
+ return true;
10991
+ };
10919
10992
 
10993
+ /* begin_public_function
10994
+ id: user.relationship.accept_follow
10995
+ */
10920
10996
  /**
10921
10997
  * ```js
10922
- * import { getFollowInfo } from '@amityco/ts-sdk-react-native'
10923
- * const { data: followInfo } = await getFollowInfo('foobar')
10998
+ * import { UserRepository } from '@amityco/ts-sdk-react-native'
10999
+ * await UserRepository.Relationship.acceptMyFollower('foobar')
10924
11000
  * ```
10925
11001
  *
10926
- * Fetches the number of followers, followings, pending requests and the follow status for current user
11002
+ * Accept the follow request
10927
11003
  *
10928
- * @param userId the ID of the {@link Amity.InternalUser}
10929
- * @returns the associated {@link Amity.FollowInfo} object
11004
+ * @param userId the ID of the {@link Amity.InternalUser} follower
11005
+ * @returns A success boolean if the follow request was accepted
10930
11006
  *
10931
11007
  * @category Follow API
10932
11008
  * @async
10933
11009
  */
10934
- const getFollowInfo$1 = async (userId) => {
10935
- var _a, _b;
11010
+ const acceptMyFollower = async (userId) => {
10936
11011
  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];
11012
+ client.log('follow/acceptMyFollower', userId);
11013
+ const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
10942
11014
  if (client.cache) {
10943
- pushToCache(['followInfo', 'get', userId], followInfo, {
10944
- cachedAt,
10945
- });
11015
+ ingestInCache(data);
10946
11016
  }
10947
- return {
10948
- data: followInfo,
10949
- cachedAt,
10950
- };
11017
+ const payload = prepareFollowStatusPayload(data);
11018
+ fireEvent('local.follow.accepted', payload);
11019
+ return true;
10951
11020
  };
11021
+ /* end_public_function */
11022
+
10952
11023
  /**
11024
+ * @deprecated This API renamed to `declineMyFollower`.
11025
+ * Please use declineMyFollower() instead.
11026
+ *
10953
11027
  * ```js
10954
- * import { getFollowInfo } from '@amityco/ts-sdk-react-native'
10955
- * const { data: followInfo } = getFollowInfo.locally('foobar')
11028
+ * import { declineFollower } from '@amityco/ts-sdk-react-native'
11029
+ * await declineFollower('foobar')
10956
11030
  * ```
10957
11031
  *
10958
- * Fetches the number of followers, followings, pending requests and the follow status for current user from cache
11032
+ * Decline the follow request or delete the follower
10959
11033
  *
10960
- * @param userId the ID of the {@link Amity.InternalUser}
10961
- * @returns the associated {@link Amity.FollowInfo} object
11034
+ * @param userId the ID of the {@link Amity.InternalUser} follower
11035
+ * @returns A success boolean if the follow request was decline
10962
11036
  *
10963
11037
  * @category Follow API
11038
+ * @async
10964
11039
  */
10965
- getFollowInfo$1.locally = (userId) => {
11040
+ const declineFollower = async (userId) => {
10966
11041
  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;
11042
+ client.log('follow/declineFollower', userId);
11043
+ const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
11044
+ if (client.cache) {
11045
+ ingestInCache(data);
10974
11046
  }
10975
- return {
10976
- data: cached.data,
10977
- cachedAt: cached.cachedAt,
10978
- };
11047
+ const payload = prepareFollowStatusPayload(data);
11048
+ fireEvent('local.follow.requestDeclined', payload);
11049
+ return true;
10979
11050
  };
10980
11051
 
11052
+ /* begin_public_function
11053
+ id: user.relationship.decline_follow
11054
+ */
10981
11055
  /**
10982
11056
  * ```js
10983
- * import { onFollowInfoUpdated } from '@amityco/ts-sdk-react-native'
10984
- * const dispose = onFollowInfoUpdated(followInfo => {
10985
- * // ...
10986
- * })
11057
+ * import { UserRepository } from '@amityco/ts-sdk-react-native'
11058
+ * await UserRepository.Relationship.declineMyFollower('foobar')
10987
11059
  * ```
10988
11060
  *
10989
- * Fired when a {@link Amity.FollowInfo} has been updated
11061
+ * Decline the follow request or delete the follower
10990
11062
  *
10991
- * @param callback The function to call when the event was fired
10992
- * @returns an {@link Amity.Unsubscriber} function to stop listening
11063
+ * @param userId the ID of the {@link Amity.InternalUser} follower
11064
+ * @returns A success boolean if the follow request was decline
10993
11065
  *
10994
- * @category Follow Events
11066
+ * @category Follow API
11067
+ * @async
10995
11068
  */
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);
11069
+ const declineMyFollower = async (userId) => {
11070
+ const client = getActiveClient();
11071
+ client.log('follow/declineMyFollower', userId);
11072
+ const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
11073
+ if (client.cache) {
11074
+ ingestInCache(data);
11075
+ }
11076
+ const payload = prepareFollowStatusPayload(data);
11077
+ fireEvent('local.follow.requestDeclined', payload);
11078
+ return true;
11079
+ };
11080
+ /* end_public_function */
11033
11081
 
11034
11082
  /**
11035
11083
  * ```js
@@ -11159,18 +11207,6 @@ class FollowerPaginationController extends PaginationController {
11159
11207
  }
11160
11208
  }
11161
11209
 
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
11210
  class FollowerQueryStreamController extends QueryStreamController {
11175
11211
  constructor(query, cacheKey, notifyChange, preparePayload) {
11176
11212
  super(query, cacheKey);
@@ -11248,7 +11284,7 @@ const onFollowerUserDeleted = ({ userId }) => (callback) => {
11248
11284
 
11249
11285
  class FollowerLiveCollectionController extends LiveCollectionController {
11250
11286
  constructor(query, callback) {
11251
- const queryStreamId = hash__default["default"](query);
11287
+ const queryStreamId = hash__default["default"](Object.assign(Object.assign({}, query), { type: 'follower' }));
11252
11288
  const cacheKey = ['follow', 'collection', queryStreamId];
11253
11289
  const paginationController = new FollowerPaginationController(query);
11254
11290
  super(paginationController, queryStreamId, cacheKey, callback);
@@ -11453,7 +11489,7 @@ const onFollowingUserDeleted = ({ userId }) => (callback) => {
11453
11489
 
11454
11490
  class FollowingLiveCollectionController extends LiveCollectionController {
11455
11491
  constructor(query, callback) {
11456
- const queryStreamId = hash__default["default"](query);
11492
+ const queryStreamId = hash__default["default"](Object.assign(Object.assign({}, query), { type: 'following' }));
11457
11493
  const cacheKey = ['follow', 'collection', queryStreamId];
11458
11494
  const paginationController = new FollowingPaginationController(query);
11459
11495
  super(paginationController, queryStreamId, cacheKey, callback);
@@ -13359,16 +13395,19 @@ function isCurrentUserPartOfCommunity(c, m) {
13359
13395
  }
13360
13396
  /*
13361
13397
  * 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
13398
+ * to multiple users and it also does not include communityUser
13399
+ *
13400
+ * Client SDK needs to check for the existing isJoined field in cache data before calculating.
13401
+ * Althought this can be calculated, it's not scalable.
13364
13402
  */
13365
13403
  function updateMembershipStatus(communities, communityUsers) {
13366
13404
  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 });
13405
+ const cachedCommunity = pullFromCache(['community', 'get', c.communityId]);
13406
+ if ((cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data) && (cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data.hasOwnProperty('isJoined'))) {
13407
+ return Object.assign(Object.assign({}, cachedCommunity.data), c);
13370
13408
  }
13371
- return c;
13409
+ const isJoined = communityUsers.some(m => isCurrentUserPartOfCommunity(c, m) && isMember(m.communityMembership));
13410
+ return Object.assign(Object.assign({}, c), { isJoined });
13372
13411
  });
13373
13412
  }
13374
13413
 
@@ -13469,7 +13508,7 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
13469
13508
  referenceType,
13470
13509
  reactionName,
13471
13510
  });
13472
- await client.http.post('/api/v2/reactions', {
13511
+ const { data } = await client.http.post('/api/v2/reactions', {
13473
13512
  referenceId,
13474
13513
  referenceType,
13475
13514
  reactionName,
@@ -13487,12 +13526,33 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
13487
13526
  if (referenceType === 'comment') {
13488
13527
  fireEvent('local.comment.addReaction', {
13489
13528
  comment: updatedModel,
13529
+ reactor: {
13530
+ userId: client.userId,
13531
+ reactionName,
13532
+ reactionId: data.addedId,
13533
+ },
13490
13534
  });
13491
13535
  return true;
13492
13536
  }
13493
13537
  if (referenceType === 'post') {
13494
13538
  fireEvent('local.post.addReaction', {
13495
13539
  post: updatedModel,
13540
+ reactor: {
13541
+ userId: client.userId,
13542
+ reactionName,
13543
+ reactionId: data.addedId,
13544
+ },
13545
+ });
13546
+ return true;
13547
+ }
13548
+ if (referenceType === 'story') {
13549
+ fireEvent('local.story.reactionAdded', {
13550
+ story: updatedModel,
13551
+ reactor: {
13552
+ userId: client.userId,
13553
+ reactionName,
13554
+ reactionId: data.addedId,
13555
+ },
13496
13556
  });
13497
13557
  return true;
13498
13558
  }
@@ -13567,7 +13627,7 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
13567
13627
  referenceType,
13568
13628
  reactionName,
13569
13629
  });
13570
- await client.http.delete(`/api/v2/reactions`, {
13630
+ const { data } = await client.http.delete(`/api/v2/reactions`, {
13571
13631
  data: {
13572
13632
  referenceId,
13573
13633
  referenceType,
@@ -13587,12 +13647,33 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
13587
13647
  if (referenceType === 'comment') {
13588
13648
  fireEvent('local.comment.removeReaction', {
13589
13649
  comment: updatedModel,
13650
+ reactor: {
13651
+ reactionId: data.removedId,
13652
+ reactionName,
13653
+ userId: client.userId,
13654
+ },
13590
13655
  });
13591
13656
  return true;
13592
13657
  }
13593
13658
  if (referenceType === 'post') {
13594
13659
  fireEvent('local.post.removeReaction', {
13595
13660
  post: updatedModel,
13661
+ reactor: {
13662
+ reactionId: data.removedId,
13663
+ reactionName,
13664
+ userId: client.userId,
13665
+ },
13666
+ });
13667
+ return true;
13668
+ }
13669
+ if (referenceType === 'story') {
13670
+ fireEvent('local.story.reactionAdded', {
13671
+ story: updatedModel,
13672
+ reactor: {
13673
+ userId: client.userId,
13674
+ reactionName,
13675
+ reactionId: data.removedId,
13676
+ },
13596
13677
  });
13597
13678
  return true;
13598
13679
  }
@@ -13616,7 +13697,7 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
13616
13697
  * @category Reaction API
13617
13698
  * */
13618
13699
  removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
13619
- var _a, _b, _c, _d, _e;
13700
+ var _a, _b, _c, _d;
13620
13701
  const client = getActiveClient();
13621
13702
  client.log('reaction/removeReaction.optimistically', {
13622
13703
  referenceId,
@@ -13637,7 +13718,7 @@ removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
13637
13718
  cachedAt: UNSYNCED_OBJECT_CACHED_AT_VALUE,
13638
13719
  });
13639
13720
  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;
13721
+ return !((_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName));
13641
13722
  };
13642
13723
 
13643
13724
  const getMatchPostSetting = (value) => {
@@ -14459,73 +14540,262 @@ const onReactorRemoved = (referenceType, referenceId, callback) => {
14459
14540
 
14460
14541
  const REFERENCE_API_V5 = 5;
14461
14542
 
14543
+ class ReactionPaginationController extends PaginationController {
14544
+ async getRequest(queryParams, token) {
14545
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
14546
+ const options = token ? { token } : { limit };
14547
+ const client = getActiveClient();
14548
+ client.log('reaction/queryReactions', queryParams);
14549
+ const path = '/api/v3/reactions';
14550
+ const { data: queryResponse } = await this.http.get(path, {
14551
+ 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
14552
+ options }),
14553
+ });
14554
+ return queryResponse;
14555
+ }
14556
+ }
14557
+
14558
+ class ReactionQueryStreamController extends QueryStreamController {
14559
+ constructor(query, cacheKey, notifyChange, preparePayload) {
14560
+ super(query, cacheKey);
14561
+ this.notifyChange = notifyChange;
14562
+ this.preparePayload = preparePayload;
14563
+ }
14564
+ async saveToMainDB(response) {
14565
+ var _a;
14566
+ const processedPayload = await this.preparePayload(response);
14567
+ const client = getActiveClient();
14568
+ const cachedAt = client.cache && Date.now();
14569
+ if (client.cache) {
14570
+ const { reactions } = processedPayload, restPayload = __rest(processedPayload, ["reactions"]);
14571
+ ingestInCache(Object.assign(Object.assign({}, restPayload), { reactions, reactors: (_a = reactions[0]) === null || _a === void 0 ? void 0 : _a.reactors }), { cachedAt });
14572
+ }
14573
+ }
14574
+ appendToQueryStream(response, direction, refresh = false) {
14575
+ var _a, _b, _c, _d;
14576
+ const reactors = (_b = (_a = response.reactions[0]) === null || _a === void 0 ? void 0 : _a.reactors) !== null && _b !== void 0 ? _b : [];
14577
+ if (refresh) {
14578
+ pushToCache(this.cacheKey, {
14579
+ data: reactors.map(getResolver('reactor')),
14580
+ });
14581
+ }
14582
+ else {
14583
+ const collection = (_c = pullFromCache(this.cacheKey)) === null || _c === void 0 ? void 0 : _c.data;
14584
+ const reactions = (_d = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _d !== void 0 ? _d : [];
14585
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...reactions, ...reactors.map(getResolver('reactor'))])] }));
14586
+ }
14587
+ }
14588
+ reactor(action) {
14589
+ return (reaction) => {
14590
+ var _a;
14591
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
14592
+ if (!collection)
14593
+ return;
14594
+ if (action === "onAdded" /* Amity.ReactionActionTypeEnum.OnAdded */) {
14595
+ collection.data = [...new Set([reaction.reactionId, ...collection.data])];
14596
+ }
14597
+ else if (action === "onRemoved" /* Amity.ReactionActionTypeEnum.OnRemoved */) {
14598
+ collection.data = collection.data.filter(p => p !== reaction.reactionId);
14599
+ }
14600
+ pushToCache(this.cacheKey, collection);
14601
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
14602
+ };
14603
+ }
14604
+ subscribeRTE(createSubscriber) {
14605
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
14606
+ }
14607
+ }
14608
+
14462
14609
  /**
14463
14610
  * ```js
14464
- * import { queryReactions } from '@amityco/ts-sdk-react-native'
14465
- * const { data: reactions, prevPage, nextPage } = await queryReactions({
14466
- * referenceId: 'postId',
14467
- * referenceType: 'post',
14611
+ * import { onReactorRemovedLocal } from '@amityco/ts-sdk'
14612
+ * const dispose = onReactorRemoved('post', postId, reactor => {
14613
+ * // ...
14468
14614
  * })
14469
14615
  * ```
14470
14616
  *
14471
- * Queries a paginable list of {@link Amity.Reaction} objects
14617
+ * Fired when an {@link Amity.InternalReactor} has been removed
14472
14618
  *
14473
- * @param query The query parameters
14474
- * @returns A page of {@link Amity.Reaction} objects
14619
+ * @param {@link Amity.ReactableType} referenceType
14620
+ * @param {string} referenceId
14621
+ * @param callback The function to call when the event was fired
14622
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
14475
14623
  *
14476
- * @reaction Reaction API
14477
- * @async
14624
+ * @category Events
14478
14625
  * */
14479
- const queryReactions = async (query) => {
14626
+ const onReactorRemovedLocal = (referenceType, referenceId, callback) => {
14480
14627
  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 };
14628
+ const callbackWrapper = (referenceType_, referenceId_, reaction) => {
14629
+ if (referenceType_ === referenceType && referenceId_ === referenceId) {
14630
+ callback(reaction);
14631
+ }
14632
+ };
14633
+ if (referenceType === 'message') {
14634
+ const filter = async (rawPayload) => {
14635
+ const payload = await prepareMessagePayload(rawPayload);
14636
+ if (!payload.reactions[0])
14637
+ return;
14638
+ ingestInCache(payload);
14639
+ callbackWrapper('message', payload.messages[0].messageId, payload.reactions[0]);
14640
+ };
14641
+ return createEventSubscriber(client, 'reaction/onReactorRemoved', 'message.reactionRemoved', filter);
14642
+ }
14643
+ if (referenceType === 'post') {
14644
+ const filter = (payload) => {
14645
+ callbackWrapper('post', payload.post.postId, payload.reactor);
14646
+ };
14647
+ return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
14648
+ }
14649
+ if (referenceType === 'story') {
14650
+ const filter = (payload) => {
14651
+ const { reactions } = payload, rest = __rest(payload, ["reactions"]);
14652
+ ingestInCache(rest);
14653
+ ingestInCache({ reactors: reactions });
14654
+ if (payload.stories.length === 0 || payload.reactions.length === 0)
14655
+ return;
14656
+ callbackWrapper('story', payload.stories[0].storyId, payload.reactions[0]);
14657
+ };
14658
+ return createEventSubscriber(client, 'story.reactionRemoved', 'story.reactionRemoved', filter);
14659
+ }
14660
+ const filter = (payload) => {
14661
+ callbackWrapper('comment', payload.comment.commentId, payload.reactor);
14662
+ };
14663
+ return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
14497
14664
  };
14498
14665
 
14499
14666
  /**
14500
14667
  * ```js
14501
- * import { queryReactor } from '@amityco/ts-sdk-react-native'
14502
- * const { data: reactions, prevPage, nextPage } = await queryReactor({
14503
- * referenceId: 'postId',
14504
- * referenceType: 'post',
14668
+ * import { onReactorAddedLocal } from '@amityco/ts-sdk'
14669
+ * const dispose = onReactorAdded('post', postId, reactor => {
14670
+ * // ...
14505
14671
  * })
14506
14672
  * ```
14507
14673
  *
14508
- * Queries a paginable list of {@link Amity.InternalReactor} objects
14674
+ * Fired when an {@link Amity.InternalReactor} has been added
14509
14675
  *
14510
- * @param query The query parameters
14511
- * @returns A page of {@link Amity.InternalReactor} objects
14676
+ * @param {@link Amity.ReactableType} referenceType
14677
+ * @param {string} referenceId
14678
+ * @param callback The function to call when the event was fired
14679
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
14512
14680
  *
14513
- * @reaction Reaction API
14514
- * @async
14681
+ * @category Events
14515
14682
  * */
14516
- const queryReactor = async (query) => {
14683
+ const onReactorAddedLocal = (referenceType, referenceId, callback) => {
14517
14684
  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 });
14685
+ const callbackWrapper = (referenceType_, referenceId_, reaction) => {
14686
+ if (referenceType_ === referenceType && referenceId_ === referenceId) {
14687
+ callback(reaction);
14688
+ }
14689
+ };
14690
+ if (referenceType === 'message') {
14691
+ const filter = async (rawPayload) => {
14692
+ const payload = await prepareMessagePayload(rawPayload);
14693
+ if (!payload.reactions[0])
14694
+ return;
14695
+ ingestInCache(payload);
14696
+ ingestInCache({ reactors: payload.reactions });
14697
+ callbackWrapper('message', payload.messages[0].messageId, payload.reactions[0]);
14698
+ };
14699
+ return createEventSubscriber(client, 'reaction/onReactorAdded', 'message.reactionAdded', filter);
14700
+ }
14701
+ if (referenceType === 'post') {
14702
+ const filter = (payload) => {
14703
+ callbackWrapper('post', payload.post.postId, payload.reactor);
14704
+ };
14705
+ return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
14706
+ }
14707
+ if (referenceType === 'story') {
14708
+ const filter = (payload) => {
14709
+ const { reactions } = payload, rest = __rest(payload, ["reactions"]);
14710
+ ingestInCache(rest);
14711
+ ingestInCache({ reactors: reactions });
14712
+ if (payload.stories.length === 0 || payload.reactions.length === 0)
14713
+ return;
14714
+ callbackWrapper('story', payload.stories[0].storyId, payload.reactions[0]);
14715
+ };
14716
+ return createEventSubscriber(client, 'story.reactionAdded', 'story.reactionAdded', filter);
14717
+ }
14718
+ const filter = (payload) => {
14719
+ callbackWrapper('comment', payload.comment.commentId, payload.reactor);
14720
+ };
14721
+ return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
14521
14722
  };
14522
14723
 
14724
+ class ReactionLiveCollectionController extends LiveCollectionController {
14725
+ constructor(query, callback) {
14726
+ const queryStreamId = hash__default["default"](query);
14727
+ const cacheKey = ['reaction', 'collection', queryStreamId];
14728
+ const paginationController = new ReactionPaginationController(query);
14729
+ super(paginationController, queryStreamId, cacheKey, callback);
14730
+ this.query = query;
14731
+ this.queryStreamController = new ReactionQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), payload => payload);
14732
+ this.callback = callback.bind(this);
14733
+ this.loadPage({ initial: true });
14734
+ }
14735
+ setup() {
14736
+ var _a;
14737
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
14738
+ if (!collection) {
14739
+ pushToCache(this.cacheKey, {
14740
+ data: [],
14741
+ params: {},
14742
+ });
14743
+ }
14744
+ }
14745
+ async persistModel(queryPayload) {
14746
+ await this.queryStreamController.saveToMainDB(queryPayload);
14747
+ }
14748
+ persistQueryStream({ response, direction, refresh, }) {
14749
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
14750
+ }
14751
+ startSubscription() {
14752
+ return this.queryStreamController.subscribeRTE([
14753
+ {
14754
+ fn: callback => onReactorAdded(this.query.referenceType, this.query.referenceId, callback),
14755
+ action: "onAdded" /* Amity.ReactionActionTypeEnum.OnAdded */,
14756
+ },
14757
+ {
14758
+ fn: callback => onReactorRemoved(this.query.referenceType, this.query.referenceId, callback),
14759
+ action: "onRemoved" /* Amity.ReactionActionTypeEnum.OnRemoved */,
14760
+ },
14761
+ {
14762
+ fn: callback => onReactorRemovedLocal(this.query.referenceType, this.query.referenceId, callback),
14763
+ action: "onRemoved" /* Amity.ReactionActionTypeEnum.OnRemoved */,
14764
+ },
14765
+ {
14766
+ fn: callback => onReactorAddedLocal(this.query.referenceType, this.query.referenceId, callback),
14767
+ action: "onRemoved" /* Amity.ReactionActionTypeEnum.OnRemoved */,
14768
+ },
14769
+ ]);
14770
+ }
14771
+ notifyChange({ origin, loading, error }) {
14772
+ var _a, _b;
14773
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
14774
+ if (!collection)
14775
+ return;
14776
+ const data = (_b = collection.data
14777
+ .map(reactorId => pullFromCache(['reactor', 'get', reactorId]))
14778
+ .filter(Boolean)
14779
+ .map(({ data }) => LinkedObject.reactor(data))) !== null && _b !== void 0 ? _b : [];
14780
+ if (!this.shouldNotify(data) && origin === 'event')
14781
+ return;
14782
+ this.callback({
14783
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
14784
+ data,
14785
+ hasNextPage: !!this.paginationController.getNextToken(),
14786
+ loading,
14787
+ error,
14788
+ });
14789
+ }
14790
+ }
14791
+
14792
+ /* eslint-disable no-use-before-define */
14523
14793
  /* begin_public_function
14524
14794
  id: reaction.query
14525
14795
  */
14526
14796
  /**
14527
14797
  * ```js
14528
- * import { getReactions } from '@amityco/ts-sdk-react-native'
14798
+ * import { getReactions } from '@amityco/ts-sdk'
14529
14799
  *
14530
14800
  * let reactions = []
14531
14801
  * const unsub = liveReactions({
@@ -14549,69 +14819,15 @@ const getReactions = (params, callback, config) => {
14549
14819
  console.log('For using Live Collection feature you need to enable Cache!');
14550
14820
  }
14551
14821
  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);
14822
+ log(`getReactions(tmpid: ${timestamp}) > listen`);
14823
+ const reactionLiveCollection = new ReactionLiveCollectionController(params, callback);
14824
+ const disposers = reactionLiveCollection.startSubscription();
14825
+ const cacheKey = reactionLiveCollection.getCacheKey();
14826
+ disposers.push(() => {
14827
+ dropFromCache(cacheKey);
14828
+ });
14613
14829
  return () => {
14614
- log(`liveReactions(tmpid: ${timestamp}) > dispose`);
14830
+ log(`getReactions(tmpid: ${timestamp}) > dispose`);
14615
14831
  disposers.forEach(fn => fn());
14616
14832
  };
14617
14833
  };
@@ -15117,30 +15333,6 @@ const unmuteChannel = async (channelId) => {
15117
15333
  };
15118
15334
  /* end_public_function */
15119
15335
 
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
15336
  /**
15145
15337
  * ```js
15146
15338
  * import { observeChannel } from '@amityco/ts-sdk-react-native'
@@ -19290,7 +19482,8 @@ const createCommunityMemberEventSubscriber = (event, callback) => {
19290
19482
  callback(preparedPayload.communities[0], getEventRelatedMember(event, preparedPayload));
19291
19483
  }
19292
19484
  else {
19293
- ingestInCache(preparedPayload);
19485
+ // NOTE: The event payload should be merge with existing cache data
19486
+ ingestInCache(preparedPayload, undefined, false);
19294
19487
  const community = pullFromCache([
19295
19488
  'community',
19296
19489
  'get',
@@ -19327,7 +19520,8 @@ const createLocalCommunityMemberEventSubscriber = (event, callback) => {
19327
19520
  callback(preparedPayload.communities[0], getEventRelatedMember(event, preparedPayload));
19328
19521
  }
19329
19522
  else {
19330
- ingestInCache(preparedPayload);
19523
+ // NOTE: The event payload should be merge with existing cache data
19524
+ ingestInCache(preparedPayload, undefined, false);
19331
19525
  const community = pullFromCache([
19332
19526
  'community',
19333
19527
  'get',
@@ -21417,9 +21611,10 @@ const queryGlobalFeed = async (query) => {
21417
21611
  const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
21418
21612
  const data = prepareMembershipPayload(payload, 'communityUsers');
21419
21613
  const { posts } = data;
21614
+ const { communities: processedCommunity } = prepareCommunityPayload(data);
21420
21615
  const cachedAt = client.cache && Date.now();
21421
21616
  if (client.cache) {
21422
- ingestInCache(data);
21617
+ ingestInCache(Object.assign(Object.assign({}, data), { communitis: processedCommunity }));
21423
21618
  const cacheKey = [
21424
21619
  'globalFeed',
21425
21620
  'query',
@@ -23734,6 +23929,145 @@ const getPinnedPosts = (params, callback, config) => {
23734
23929
  };
23735
23930
  };
23736
23931
 
23932
+ class GlobalPinnedPostPaginationController extends PaginationController {
23933
+ async getRequest(queryParams, token) {
23934
+ __rest(queryParams, ["limit"]);
23935
+ const path = '/api/v1/pinned-posts/global';
23936
+ const { data: queryResponse } = await this.http.get(path);
23937
+ return queryResponse;
23938
+ }
23939
+ }
23940
+
23941
+ class GlobalPinnedPostQueryStreamController extends QueryStreamController {
23942
+ constructor(query, cacheKey, notifyChange, preparePayload) {
23943
+ super(query, cacheKey);
23944
+ this.notifyChange = notifyChange;
23945
+ this.preparePayload = preparePayload;
23946
+ }
23947
+ // eslint-disable-next-line class-methods-use-this
23948
+ async saveToMainDB(response) {
23949
+ const client = getActiveClient();
23950
+ const cachedAt = client.cache && Date.now();
23951
+ if (client.cache) {
23952
+ ingestInCache(response, { cachedAt });
23953
+ }
23954
+ }
23955
+ appendToQueryStream(response, direction, refresh = false) {
23956
+ var _a, _b;
23957
+ if (refresh) {
23958
+ pushToCache(this.cacheKey, {
23959
+ data: response.pins.map(getResolver('pin')),
23960
+ });
23961
+ }
23962
+ else {
23963
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
23964
+ const pinnedPosts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
23965
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...pinnedPosts, ...response.pins.map(getResolver('pin'))])] }));
23966
+ this.notifyChange({
23967
+ origin: "server" /* Amity.LiveDataOrigin.SERVER */,
23968
+ loading: false,
23969
+ });
23970
+ }
23971
+ }
23972
+ reactor(action) {
23973
+ return (post) => {
23974
+ var _a;
23975
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
23976
+ if (!collection)
23977
+ return;
23978
+ if (action === EnumPostActions.OnPostDeleted) {
23979
+ collection.data = collection.data.filter(referenceId => referenceId !== `global#${post.postId}`);
23980
+ }
23981
+ pushToCache(this.cacheKey, collection);
23982
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
23983
+ };
23984
+ }
23985
+ subscribeRTE(createSubscriber) {
23986
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
23987
+ }
23988
+ }
23989
+
23990
+ class GlobalPinnedPostLiveCollectionController extends LiveCollectionController {
23991
+ constructor(query, callback) {
23992
+ const queryStreamId = hash__default["default"](query);
23993
+ const cacheKey = ['pinnedPosts', 'collection', queryStreamId];
23994
+ const paginationController = new GlobalPinnedPostPaginationController(query);
23995
+ super(paginationController, queryStreamId, cacheKey, callback);
23996
+ this.query = query;
23997
+ this.queryStreamController = new GlobalPinnedPostQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), response => response);
23998
+ this.callback = callback.bind(this);
23999
+ this.loadPage({ initial: true });
24000
+ }
24001
+ setup() {
24002
+ var _a;
24003
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24004
+ if (!collection) {
24005
+ pushToCache(this.cacheKey, {
24006
+ data: [],
24007
+ params: {},
24008
+ });
24009
+ }
24010
+ }
24011
+ async persistModel(queryPayload) {
24012
+ await this.queryStreamController.saveToMainDB(queryPayload);
24013
+ }
24014
+ persistQueryStream({ response, direction, refresh, }) {
24015
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
24016
+ }
24017
+ // eslint-disable-next-line class-methods-use-this
24018
+ startSubscription() {
24019
+ return this.queryStreamController.subscribeRTE([
24020
+ { fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
24021
+ {
24022
+ fn: onPostDeleted,
24023
+ action: EnumPostActions.OnPostDeleted,
24024
+ },
24025
+ ]);
24026
+ }
24027
+ notifyChange({ origin, loading, error }) {
24028
+ var _a, _b;
24029
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24030
+ if (!collection)
24031
+ return;
24032
+ const data = ((_b = collection.data
24033
+ .map(id => pullFromCache(['pin', 'get', id]))
24034
+ .filter(isNonNullable)
24035
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.pinnedPost);
24036
+ if (!this.shouldNotify(data) && origin === 'event')
24037
+ return;
24038
+ this.callback({
24039
+ data,
24040
+ loading,
24041
+ error,
24042
+ });
24043
+ }
24044
+ }
24045
+
24046
+ /**
24047
+ * Get global pinned posts
24048
+ *
24049
+ * @returns the global pinned post(s)
24050
+ *
24051
+ * @category Pined Posts Live Collection
24052
+ *
24053
+ */
24054
+ const getGlobalPinnedPosts = (params, callback, config) => {
24055
+ const { log, cache } = getActiveClient();
24056
+ if (!cache) {
24057
+ console.log(ENABLE_CACHE_MESSAGE);
24058
+ }
24059
+ const timestamp = Date.now();
24060
+ log(`getGlobalPinnedPosts(tmpid: ${timestamp}) > listen`);
24061
+ const globalPinnedPostLiveCollection = new GlobalPinnedPostLiveCollectionController(params, callback);
24062
+ const disposers = globalPinnedPostLiveCollection.startSubscription();
24063
+ const cacheKey = globalPinnedPostLiveCollection.getCacheKey();
24064
+ disposers.push(() => dropFromCache(cacheKey));
24065
+ return () => {
24066
+ log(`getGlobalPinnedPosts(tmpid: ${timestamp}) > dispose`);
24067
+ disposers.forEach(fn => fn());
24068
+ };
24069
+ };
24070
+
23737
24071
  class SemanticSearchPostPaginationController extends PaginationController {
23738
24072
  async getRequest(queryParams, token) {
23739
24073
  const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
@@ -23995,6 +24329,7 @@ var index$5 = /*#__PURE__*/Object.freeze({
23995
24329
  getPost: getPost$1,
23996
24330
  getPosts: getPosts,
23997
24331
  getPinnedPosts: getPinnedPosts,
24332
+ getGlobalPinnedPosts: getGlobalPinnedPosts,
23998
24333
  semanticSearchPosts: semanticSearchPosts
23999
24334
  });
24000
24335
 
@@ -24884,7 +25219,7 @@ var index$3 = /*#__PURE__*/Object.freeze({
24884
25219
  getPoll: getPoll
24885
25220
  });
24886
25221
 
24887
- const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDAARz+hmBgi8pJ\nQb8LeY41gtHhk+ACMwRfhsn7GqpqRQNG2qU0755mzZuVDUqjQMGSo8THJB7O+OJs\nflbZRkFXlFoFOVNw1UpNOgwEQZ6wB9oRwzepTJAfF1sVhm/o/ixvXh1zDFNDy6yZ\npXyiiJHUVxqyjllZhxnwdvjoVtDs6hW6awG09bB9nh/TTejlUKXoAgzqVwu/1QMu\nUVViET495elEe19aUarEy+oL2iKeXCEvqda/pWNBdbieFyJvvZ08HN8dPuT88wq2\njZLEAth1vrwQ2IAa4ktaLcBQdLJgIkrbDvAiVZ8lQAjS/bq5vXQikTGvoPlC5bbn\nvuOM/3eLAgMBAAECggEAVZ+peHAghq2QVj71nX5lxsNCKaCyYwixSJBpfouTt7Rz\nE6PpzMOXFi1W1o+I22jDakuSM2SOQKqI/u0QefB0r0O/KVk5NrZHXk0mkrdYtxOp\nUgaGyf8UvmjB+8VqHrNKyZdk9qtmbnNj01kTTcAtmE4H39zPR7eR/8Rul94vaZbs\nwCnKJS3mLT3JxyGug6lxanveKkjG+CKC1nJQYWaxCJxaFSzbwXQPvDhB+TvrIbee\npd5v4EAyEJohpr+T9oDGGJkb/KARBZCtwLyB976PKJwwBA8MRVL1i5QwawuMiMq5\nUtnOnbGKtCeFzaLbNU0Qi8bqyims84EQxC6DOu1fkQKBgQDdvsoBsEhsOXV7hlIJ\naEd0eSJZVkdqimxH8uGoMM2FeNaOrcB6yBXqTSP0R3OIyf8eaY6yjRvP30ZNXcll\n/gD3O1Mu6YmWQdt1W2WA6pKOsUuPXasf0pdOF7IiFZKlSabz5YHXFqwVuqm8loaj\nsXel3YWqPVdHiankE7tz+3ssnQKBgQDdqi4TNdD1MdEpihx19jr0QjUiXW3939FK\nqp30HESPEGDGQzXdmJgif9HhZb+cJSuWaHEbjgBrYahvgCF+y6LbEpOD+D/dmT+s\nDEAQaR84sah6dokwPjV8fjBSrcVFjCS+doxv0d3p/9OUEeyUhFrY03nxtIEYkLIE\n/Zvn37b4RwKBgQCLENVFe9XfsaVhQ5r9dV2iyTlmh7qgMZG5CbTFs12hQGhm8McO\n+Z7s41YSJCFr/yq1WwP4LJDtrBw99vyQr1zRsG35tNLp3gGRNzGQSQyC2uQFVHw2\np+7mNewsfhUK/gbrXNsyFnDz6635rPlhfbII3sWuP2wWXFqkxE9CbMwR7QKBgQC6\nawDMzxmo2/iYArrkyevSuEuPVxvFwpF1RgAI6C0QVCnPE38dmdN4UB7mfHekje4W\nVEercMURidPp0cxZolCYBQtilUjAyL0vqC3In1/Ogjq6oy3FEMxSop1pKxMY5j+Q\nnoqFD+6deLUrddeNH7J3X4LSr4dSbX4JjG+tlgt+yQKBgQCuwTL4hA6KqeInQ0Ta\n9VQX5Qr8hFlqJz1gpymi/k63tW/Ob8yedbg3WWNWyShwRMFYyY9S81ITFWM95uL6\nvF3x9rmRjwElJw9PMwVu6dmf/CO0Z1wzXSp2VVD12gbrUD/0/d7MUoJ9LgC8X8f/\nn0txLHYGHbx+nf95+JUg6lV3hg==\n-----END PRIVATE KEY-----";
25222
+ const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDHo80SecH7FuF2\nhFYnb+l26/VN8UMLXAQFLnxciNTEwkGVFMpdezlH8rU2HtUJL4RETogbAOLVY0XM\njs6sPn8G1nALmh9qeDpUtVqFOVtBHxEZ910TLOtQiunjqJKO5nWdqZ71EC3OFluR\niGQkO84BiIFbv37ub7xl3S8XarbtKoLcyVpkDHi+1wx1pgCAn6gtBUgckPL5NR8j\nLseabl3HAXQfhTCKo4tmOFM2Dxwl1IUMmIJrJg/aIU/U0tj/1Eoo7mG0JcNWX19l\nW3EecCbi0ncCJOrkUdwlBrcjaMayaX/ubEwyUeTGiLdyc4L3GRLHjyK8xgVNXRMH\nbZWJ2a5NAgMBAAECggEASxuE+35zTFO/XydKgmvIGcWL9FbgMlXb7Vcf0nBoG945\nbiz0NVc2paraIhJXc608xbYF3qLmtAE1MVBI0ORyRdBHNxY024l/6H6SH60Ed+uI\nM4ysp5ourY6Vj+DLwpdRiI9YDjqYAQDIUmhNxJP7XPhOMoZI6st+xZQBM34ic/bv\nAMSJm9OZphSp3+qXVkFZztr2mxD2EZSJJLYxi8BCdgM2qhazalbcJ6zDKHCZWVWm\n8RRxDGldyMb/237JxETzP40tAlzOZDmBAbUgEnurDJ93RVDIE3rbZUshwgeQd18a\nem096mWgvB1AIKYgsTAR3pw+V19YWAjq/glP6fz8wQKBgQD/oQq+ukKF0PRgBeM5\ngeTjSwsdGppQLmf5ndujvoiz/TpdjDEPu6R8kigQr1rG2t4K/yfdZoI8RdmJD1al\n3Q7N9hofooSy4rj6E3txzWZCHJjHad2cnCp/O26HiReGAl7wTcfTmNdiFHhZQzm5\nJBkvWAiwuvQMNfEbnXxw6/vIDwKBgQDH7fX8gsc77JLvAWgp1MaQN/sbqVb6JeT1\nFQfR8E/WFCSmzQBtNzd5KgYuCeelwr/8DyYytvN2BzCYZXp73gI1jF3YlW5jVn74\nOY6TwQ095digwo6Z0yuxopdIOApKgAkL9PRKgNrqAf3NAyMua6lOGifzjDojC3KU\nfylQmxMn4wKBgHp2B9O/H0dEBw5JQ8W0+JX6yWQz7mEjGiR2/1W+XXb8hQ1zr709\nw1r6Gb+EghRpnZ3fBpYGGbYOMFx8wKHM+N6qW3F0ReX8v2juFGE8aRSa5oYBrWzt\nU16Idjbv8hj84cZ1PJmdyvDtpYn9rpWHOZl4rxEbPvbqkIsOMyNVqdT5AoGAOSge\nmwIIU2le2FVeohbibXiToWTYKMuMmURZ5/r72AgKMmWJKbAPe+Q3wBG01/7FRBpQ\noU8Ma0HC8s6QJbliiEyIx9JwrJWd1vkdecBHONrtA4ibm/5zD2WcOllLF+FitLhi\n3qnX6+6F0IaFGFBPJrTzlv0P4dTz/OAdv52V7GECgYEA2TttOKBAqWllgOaZOkql\nLVMJVmgR7s6tLi1+cEP8ZcapV9aRbRzTAKXm4f8AEhtlG9F9kCOvHYCYGi6JaiWJ\nZkHjeex3T+eE6Di6y5Bm/Ift5jtVhJ4jCVwHOKTMej79NPUFTJfv8hCo29haBDv6\nRXFrv+T21KCcw8k3sJeJWWQ=\n-----END PRIVATE KEY-----";
24888
25223
  /*
24889
25224
  * The crypto algorithm used for importing key and signing string
24890
25225
  */
@@ -25539,8 +25874,8 @@ const onStoryReactionAdded = (callback) => {
25539
25874
  const onStoryReactionAddedLocal = (callback) => {
25540
25875
  const client = getActiveClient();
25541
25876
  const filter = async (payload) => {
25542
- ingestInCache(payload);
25543
- callback(payload.stories);
25877
+ ingestInCache({ stories: [payload.story] });
25878
+ callback([payload.story]);
25544
25879
  };
25545
25880
  const disposers = [
25546
25881
  createEventSubscriber(client, 'onStoryReactionAdded', 'local.story.reactionAdded', filter),
@@ -25569,8 +25904,8 @@ const onStoryReactionRemoved = (callback) => {
25569
25904
  const onStoryReactionRemovedLocal = (callback) => {
25570
25905
  const client = getActiveClient();
25571
25906
  const filter = async (payload) => {
25572
- ingestInCache(payload);
25573
- callback(payload.stories);
25907
+ ingestInCache({ stories: [payload.story] });
25908
+ callback([payload.story]);
25574
25909
  };
25575
25910
  const disposers = [
25576
25911
  createEventSubscriber(client, 'onStoryReactionRemoved', 'local.story.reactionRemoved', filter),
@@ -26110,12 +26445,12 @@ const updateLocalList = (cacheKey, targetIds) => {
26110
26445
  pushToCache(cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...storyTargets, ...targetIds])] }));
26111
26446
  };
26112
26447
  class GlobalStoryQueryStreamController extends QueryStreamController {
26113
- constructor(query, cacheKey, notifyChange, paginationController) {
26448
+ constructor(query, cacheKey, notifyChange, paginationController, preparePayload) {
26114
26449
  super(query, cacheKey);
26115
26450
  this.notifyChange = notifyChange;
26116
26451
  this.paginationController = paginationController;
26117
26452
  // Fix ESLint, "Expected 'this' to be used by class method"
26118
- this.preparePayload = payload => payload;
26453
+ this.preparePayload = preparePayload;
26119
26454
  }
26120
26455
  saveToMainDB(response) {
26121
26456
  const client = getActiveClient();
@@ -26207,7 +26542,10 @@ class GlobalStoryLiveCollectionController extends LiveCollectionController {
26207
26542
  const paginationController = new GlobalStoryPageController(query);
26208
26543
  super(paginationController, queryStreamId, cacheKey, callback);
26209
26544
  this.query = query;
26210
- this.queryStreamController = new GlobalStoryQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), paginationController);
26545
+ this.queryStreamController = new GlobalStoryQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), paginationController, (data) => {
26546
+ const _a = prepareCommunityPayload(Object.assign(Object.assign({}, data), { feeds: [] })), rest = __rest(_a, ["feeds"]);
26547
+ return Object.assign(Object.assign({}, data), rest);
26548
+ });
26211
26549
  this.paginationController = paginationController;
26212
26550
  this.callback = callback.bind(this);
26213
26551
  this.loadPage({ initial: true });