@amityco/ts-sdk-react-native 6.30.3 → 6.30.4

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 (77) hide show
  1. package/dist/@types/core/events.d.ts +2 -0
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/payload.d.ts +2 -0
  4. package/dist/@types/core/payload.d.ts.map +1 -1
  5. package/dist/@types/domains/community.d.ts +8 -0
  6. package/dist/@types/domains/community.d.ts.map +1 -1
  7. package/dist/client/api/index.d.ts +2 -0
  8. package/dist/client/api/index.d.ts.map +1 -1
  9. package/dist/communityRepository/communityMembership/events/index.d.ts +2 -0
  10. package/dist/communityRepository/communityMembership/events/index.d.ts.map +1 -1
  11. package/dist/communityRepository/communityMembership/events/onLocalCommunityJoined.d.ts +2 -0
  12. package/dist/communityRepository/communityMembership/events/onLocalCommunityJoined.d.ts.map +1 -0
  13. package/dist/communityRepository/communityMembership/events/onLocalCommunityLeft.d.ts +2 -0
  14. package/dist/communityRepository/communityMembership/events/onLocalCommunityLeft.d.ts.map +1 -0
  15. package/dist/communityRepository/communityMembership/events/utils.d.ts.map +1 -1
  16. package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.d.ts.map +1 -1
  17. package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.d.ts.map +1 -1
  18. package/dist/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.d.ts.map +1 -1
  19. package/dist/communityRepository/observers/getCommunity.d.ts.map +1 -1
  20. package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesLiveCollectionController.d.ts +13 -0
  21. package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesLiveCollectionController.d.ts.map +1 -0
  22. package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesPaginationController.d.ts +9 -0
  23. package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesPaginationController.d.ts.map +1 -0
  24. package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesQueryStreamController.d.ts +16 -0
  25. package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesQueryStreamController.d.ts.map +1 -0
  26. package/dist/communityRepository/observers/getRecommendedCommunities/enums.d.ts +5 -0
  27. package/dist/communityRepository/observers/getRecommendedCommunities/enums.d.ts.map +1 -0
  28. package/dist/communityRepository/observers/getRecommendedCommunities.d.ts +1 -1
  29. package/dist/communityRepository/observers/getRecommendedCommunities.d.ts.map +1 -1
  30. package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesLiveCollectionController.d.ts +13 -0
  31. package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesLiveCollectionController.d.ts.map +1 -0
  32. package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesPaginationController.d.ts +9 -0
  33. package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesPaginationController.d.ts.map +1 -0
  34. package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesQueryStreamController.d.ts +16 -0
  35. package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesQueryStreamController.d.ts.map +1 -0
  36. package/dist/communityRepository/observers/getTrendingCommunities/enums.d.ts +5 -0
  37. package/dist/communityRepository/observers/getTrendingCommunities/enums.d.ts.map +1 -0
  38. package/dist/communityRepository/observers/getTrendingCommunities.d.ts +1 -1
  39. package/dist/communityRepository/observers/getTrendingCommunities.d.ts.map +1 -1
  40. package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesLiveCollectionController.d.ts.map +1 -1
  41. package/dist/communityRepository/utils/communityWithMembership.d.ts.map +1 -1
  42. package/dist/core/events.d.ts +3 -3
  43. package/dist/core/events.d.ts.map +1 -1
  44. package/dist/index.cjs.js +334 -221
  45. package/dist/index.esm.js +334 -221
  46. package/dist/index.umd.js +3 -3
  47. package/dist/report/api/isReportedByMe.d.ts.map +1 -1
  48. package/package.json +1 -1
  49. package/src/@types/core/events.ts +2 -0
  50. package/src/@types/core/payload.ts +3 -0
  51. package/src/@types/domains/community.ts +6 -0
  52. package/src/client/api/index.ts +3 -0
  53. package/src/communityRepository/api/joinCommunity.ts +1 -1
  54. package/src/communityRepository/api/leaveCommunity.ts +1 -1
  55. package/src/communityRepository/communityMembership/events/index.ts +2 -0
  56. package/src/communityRepository/communityMembership/events/onLocalCommunityJoined.ts +5 -0
  57. package/src/communityRepository/communityMembership/events/onLocalCommunityLeft.ts +5 -0
  58. package/src/communityRepository/communityMembership/events/utils.ts +0 -2
  59. package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.ts +4 -0
  60. package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.ts +4 -0
  61. package/src/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.ts +7 -2
  62. package/src/communityRepository/observers/getCommunity.ts +4 -0
  63. package/src/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesLiveCollectionController.ts +109 -0
  64. package/src/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesPaginationController.ts +31 -0
  65. package/src/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesQueryStreamController.ts +88 -0
  66. package/src/communityRepository/observers/getRecommendedCommunities/enums.ts +4 -0
  67. package/src/communityRepository/observers/getRecommendedCommunities.ts +9 -81
  68. package/src/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesLiveCollectionController.ts +109 -0
  69. package/src/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesPaginationController.ts +28 -0
  70. package/src/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesQueryStreamController.ts +86 -0
  71. package/src/communityRepository/observers/getTrendingCommunities/enums.ts +4 -0
  72. package/src/communityRepository/observers/getTrendingCommunities.ts +10 -82
  73. package/src/communityRepository/observers/searchCommunities/SearchCommunitiesLiveCollectionController.ts +7 -2
  74. package/src/communityRepository/utils/communityWithMembership.ts +7 -4
  75. package/src/report/api/createReport.ts +2 -2
  76. package/src/report/api/deleteReport.ts +2 -2
  77. package/src/report/api/isReportedByMe.ts +5 -3
package/dist/index.cjs.js CHANGED
@@ -10,6 +10,7 @@ var HttpAgent = require('agentkeepalive');
10
10
  var io = require('socket.io-client');
11
11
  var AsyncStorage = require('@react-native-async-storage/async-storage');
12
12
  var uuid$1 = require('react-native-uuid');
13
+ var reactNative = require('react-native');
13
14
  var hash = require('object-hash');
14
15
  var Hls = require('hls.js');
15
16
 
@@ -122,8 +123,8 @@ const PostContentType = Object.freeze({
122
123
 
123
124
  function getVersion() {
124
125
  try {
125
- // the string ''v6.30.3-cjs'' should be replaced by actual value by @rollup/plugin-replace
126
- return 'v6.30.3-cjs';
126
+ // the string ''v6.30.4-cjs'' should be replaced by actual value by @rollup/plugin-replace
127
+ return 'v6.30.4-cjs';
127
128
  }
128
129
  catch (error) {
129
130
  return '__dev__';
@@ -688,6 +689,18 @@ class ASCConnectionError extends ASCError {
688
689
  : 800210 /* Amity.ClientError.CONNECTION_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
689
690
  this.event = event;
690
691
  }
692
+ }
693
+ /**
694
+ * Input sanitization related error
695
+ * @category Errors
696
+ */
697
+ class ASCInvalidParameterError extends ASCError {
698
+ /**
699
+ * @param message A custom error message
700
+ */
701
+ constructor(message) {
702
+ super(message, 800110 /* Amity.ClientError.INVALID_PARAMETERS */, "error" /* Amity.ErrorLevel.ERROR */);
703
+ }
691
704
  }
692
705
 
693
706
  let activeClient = null;
@@ -9465,6 +9478,43 @@ function setUploadedFileAccessType(accessType) {
9465
9478
  GlobalFileAccessType$1.getInstance().setFileAccessType(accessType);
9466
9479
  }
9467
9480
 
9481
+ const registerPushNotification = async (deviceToken) => {
9482
+ const client = getActiveClient();
9483
+ let platform;
9484
+ if (reactNative.Platform.OS === 'ios' || reactNative.Platform.OS === 'android') {
9485
+ platform = reactNative.Platform.OS;
9486
+ }
9487
+ else {
9488
+ throw new ASCInvalidParameterError('Unsupported platform');
9489
+ }
9490
+ const deviceId = await getDeviceId();
9491
+ const { data: { status, error }, } = await client.http.post('/v1/notification', {
9492
+ userId: client.userId,
9493
+ deviceId,
9494
+ platform,
9495
+ token: deviceToken,
9496
+ }, { headers: { 'X-API-Key': client.apiKey } });
9497
+ if (error) {
9498
+ throw new ASCApiError(error, 500000 /* Amity.ServerError.BUSINESS_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
9499
+ }
9500
+ return status === 'success';
9501
+ };
9502
+
9503
+ const unregisterPushNotification = async () => {
9504
+ const client = getActiveClient();
9505
+ const deviceId = getDeviceId();
9506
+ const { data: { status, error }, } = await client.http.delete('/v1/notification', {
9507
+ data: {
9508
+ deviceId,
9509
+ },
9510
+ headers: { 'X-API-Key': client.apiKey },
9511
+ });
9512
+ if (error) {
9513
+ throw new ASCApiError(error, 500000 /* Amity.ServerError.BUSINESS_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
9514
+ }
9515
+ return status === 'success';
9516
+ };
9517
+
9468
9518
  /**
9469
9519
  * ```js
9470
9520
  * import { onChannelMarkerFetched } from '@amityco/ts-sdk-react-native'
@@ -9926,6 +9976,8 @@ var index$l = /*#__PURE__*/Object.freeze({
9926
9976
  markerSync: markerSync,
9927
9977
  enableUnreadCount: enableUnreadCount,
9928
9978
  setUploadedFileAccessType: setUploadedFileAccessType,
9979
+ registerPushNotification: registerPushNotification,
9980
+ unregisterPushNotification: unregisterPushNotification,
9929
9981
  onConnectionError: onConnectionError,
9930
9982
  onClientDisconnected: onClientDisconnected,
9931
9983
  onClientBanned: onClientBanned,
@@ -13204,8 +13256,11 @@ function isCurrentUserPartOfCommunity(c, m) {
13204
13256
  */
13205
13257
  function updateMembershipStatus(communities, communityUsers) {
13206
13258
  return communities.map(c => {
13207
- const isJoined = communityUsers.some(m => isCurrentUserPartOfCommunity(c, m) && isMember(m.communityMembership));
13208
- return Object.assign(Object.assign({}, c), { isJoined });
13259
+ if (c.isJoined == null) {
13260
+ const isJoined = communityUsers.some(m => isCurrentUserPartOfCommunity(c, m) && isMember(m.communityMembership));
13261
+ return Object.assign(Object.assign({}, c), { isJoined });
13262
+ }
13263
+ return c;
13209
13264
  });
13210
13265
  }
13211
13266
 
@@ -14484,7 +14539,7 @@ const createMessageReport = async ({ client, referenceId, }) => {
14484
14539
  return !!payload;
14485
14540
  };
14486
14541
  const createPostReport = async ({ client, referenceId, }) => {
14487
- const { data: payload } = await client.http.post(`/api/v3/post/${encodeURIComponent(referenceId)}/flag`);
14542
+ const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(referenceId)}/flag`);
14488
14543
  if (client.cache) {
14489
14544
  const postPayload = await preparePostPayload(payload);
14490
14545
  ingestInCache(postPayload);
@@ -14502,7 +14557,7 @@ const createUserReport = async ({ client, referenceId, }) => {
14502
14557
  return !!payload;
14503
14558
  };
14504
14559
  const createCommentReport = async ({ client, referenceId, }) => {
14505
- const { data: payload } = await client.http.post(`/api/v3/comment/${encodeURIComponent(referenceId)}/flag`);
14560
+ const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(referenceId)}/flag`);
14506
14561
  if (client.cache) {
14507
14562
  const commentPayload = await prepareCommentPayload(payload);
14508
14563
  ingestInCache(commentPayload);
@@ -14551,7 +14606,7 @@ const deleteMessageReport = async ({ client, referenceId, }) => {
14551
14606
  return !!payload;
14552
14607
  };
14553
14608
  const deletePostReport = async ({ client, referenceId, }) => {
14554
- const { data: payload } = await client.http.delete(`/api/v3/post/${encodeURIComponent(referenceId)}/flag`);
14609
+ const { data: payload } = await client.http.delete(`/api/v3/posts/${encodeURIComponent(referenceId)}/unflag`);
14555
14610
  if (client.cache) {
14556
14611
  const postPayload = await preparePostPayload(payload);
14557
14612
  ingestInCache(postPayload);
@@ -14569,7 +14624,7 @@ const deleteUserReport = async ({ client, referenceId, }) => {
14569
14624
  return !!payload;
14570
14625
  };
14571
14626
  const deleteCommentReport = async ({ client, referenceId, }) => {
14572
- const { data: payload } = await client.http.delete(`/api/v3/comment/${encodeURIComponent(referenceId)}/flag`);
14627
+ const { data: payload } = await client.http.delete(`/api/v3/comments/${encodeURIComponent(referenceId)}/unflag`);
14573
14628
  if (client.cache) {
14574
14629
  const commentPayload = await prepareCommentPayload(payload);
14575
14630
  ingestInCache(commentPayload);
@@ -14616,19 +14671,19 @@ const getMessageReport = async ({ client, referenceId, }) => {
14616
14671
  };
14617
14672
  const getPostReport = async ({ client, referenceId, }) => {
14618
14673
  var _a;
14619
- const { data } = await client.http.get(`/api/v3/user/${referenceId}/isflagbyme`);
14674
+ const { data } = await client.http.get(`/api/v3/posts/${referenceId}/isflagbyme`);
14620
14675
  const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
14621
14676
  return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
14622
14677
  };
14623
14678
  const getUserReport = async ({ client, referenceId, }) => {
14624
14679
  var _a;
14625
- const { data } = await client.http.get(`/api/v3/user/${referenceId}/isflagbyme`);
14680
+ const { data } = await client.http.get(`/api/v3/users/${referenceId}/isflagbyme`);
14626
14681
  const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
14627
14682
  return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
14628
14683
  };
14629
14684
  const getCommentReport = async ({ client, referenceId, }) => {
14630
14685
  var _a;
14631
- const { data } = await client.http.get(`/api/v3/comment/${referenceId}/isflagbyme`);
14686
+ const { data } = await client.http.get(`/api/v3/comments/${referenceId}/isflagbyme`);
14632
14687
  const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
14633
14688
  return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
14634
14689
  };
@@ -18867,7 +18922,7 @@ const joinCommunity = async (communityId) => {
18867
18922
  const client = getActiveClient();
18868
18923
  client.log('community/joinCommunity', communityId);
18869
18924
  const { data: payload } = await client.http.post(`/api/v3/communities/${communityId}/join`);
18870
- fireEvent('community.joined', payload);
18925
+ fireEvent('local.community.joined', payload);
18871
18926
  const data = prepareCommunityPayload(payload);
18872
18927
  const cachedAt = client.cache && Date.now();
18873
18928
  if (client.cache)
@@ -18898,7 +18953,7 @@ const leaveCommunity = async (communityId) => {
18898
18953
  const client = getActiveClient();
18899
18954
  client.log('community/leaveCommunity', communityId);
18900
18955
  const { data: payload } = await client.http.delete(`/api/v3/communities/${communityId}/leave`);
18901
- fireEvent('community.left', payload);
18956
+ fireEvent('local.community.left', payload);
18902
18957
  const data = prepareCommunityPayload(payload);
18903
18958
  const cachedAt = client.cache && Date.now();
18904
18959
  if (client.cache)
@@ -19063,8 +19118,6 @@ function getEventRelatedMember(event, payload) {
19063
19118
  if (event === 'community.joined' || event === 'community.left') {
19064
19119
  return payload.communityUsers;
19065
19120
  }
19066
- // NOTE: backend returns the one who took the action and the one on whom
19067
- // the action was taken. We need the 2nd one
19068
19121
  if (event === 'community.userRemoved' || event === 'local.community.userRemoved') {
19069
19122
  return payload.communityUsers.filter(x => x.communityMembership === 'none');
19070
19123
  }
@@ -19339,6 +19392,10 @@ const onCommunityJoined = (callback) => createCommunityMemberEventSubscriber('co
19339
19392
  */
19340
19393
  const onCommunityLeft = (callback) => createCommunityMemberEventSubscriber('community.left', callback);
19341
19394
 
19395
+ const onLocalCommunityJoined = (callback) => createLocalCommunityMemberEventSubscriber('local.community.joined', callback);
19396
+
19397
+ const onLocalCommunityLeft = (callback) => createLocalCommunityMemberEventSubscriber('local.community.left', callback);
19398
+
19342
19399
  /**
19343
19400
  * ```js
19344
19401
  * import { observeCommunity } from '@amityco/ts-sdk-react-native'
@@ -19440,12 +19497,12 @@ class CommunitiesQueryStreamController$1 extends QueryStreamController {
19440
19497
  }
19441
19498
  }
19442
19499
 
19443
- var EnumCommunityActions$1;
19500
+ var EnumCommunityActions$3;
19444
19501
  (function (EnumCommunityActions) {
19445
19502
  EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
19446
19503
  EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
19447
19504
  EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
19448
- })(EnumCommunityActions$1 || (EnumCommunityActions$1 = {}));
19505
+ })(EnumCommunityActions$3 || (EnumCommunityActions$3 = {}));
19449
19506
 
19450
19507
  var EnumCommunityMemberActions$1;
19451
19508
  (function (EnumCommunityMemberActions) {
@@ -19724,7 +19781,9 @@ class CommunityMembersLiveCollectionController extends LiveCollectionController
19724
19781
  startSubscription() {
19725
19782
  return this.queryStreamController.subscribeRTE([
19726
19783
  { fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
19784
+ { fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
19727
19785
  { fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
19786
+ { fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
19728
19787
  { fn: onCommunityUserBanned, action: EnumCommunityMemberActions$1.OnCommunityUserBanned },
19729
19788
  { fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnCommunityUserChanged },
19730
19789
  { fn: onCommunityUserRoleAdded, action: EnumCommunityMemberActions$1.OnCommunityUserRoleAdded },
@@ -19984,7 +20043,9 @@ class SearchCommunityMembersLiveCollectionController extends LiveCollectionContr
19984
20043
  startSubscription() {
19985
20044
  return this.queryStreamController.subscribeRTE([
19986
20045
  { fn: onCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
20046
+ { fn: onLocalCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
19987
20047
  { fn: onCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
20048
+ { fn: onLocalCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
19988
20049
  { fn: onCommunityUserBanned, action: EnumCommunityMemberActions.OnCommunityUserBanned },
19989
20050
  { fn: onCommunityUserChanged, action: EnumCommunityMemberActions.OnCommunityUserChanged },
19990
20051
  {
@@ -20099,7 +20160,9 @@ var index$b = /*#__PURE__*/Object.freeze({
20099
20160
  onLocalCommunityUserAdded: onLocalCommunityUserAdded,
20100
20161
  onLocalCommunityUserRemoved: onLocalCommunityUserRemoved,
20101
20162
  onCommunityJoined: onCommunityJoined,
20102
- onCommunityLeft: onCommunityLeft
20163
+ onCommunityLeft: onCommunityLeft,
20164
+ onLocalCommunityJoined: onLocalCommunityJoined,
20165
+ onLocalCommunityLeft: onLocalCommunityLeft
20103
20166
  });
20104
20167
 
20105
20168
  class SearchCommunityLiveCollectionController extends LiveCollectionController {
@@ -20131,11 +20194,13 @@ class SearchCommunityLiveCollectionController extends LiveCollectionController {
20131
20194
  }
20132
20195
  startSubscription() {
20133
20196
  return this.queryStreamController.subscribeRTE([
20134
- { fn: onCommunityDeleted, action: EnumCommunityActions$1.OnCommunityDeleted },
20135
- { fn: onCommunityUpdated, action: EnumCommunityActions$1.OnCommunityUpdated },
20197
+ { fn: onCommunityDeleted, action: EnumCommunityActions$3.OnCommunityDeleted },
20198
+ { fn: onCommunityUpdated, action: EnumCommunityActions$3.OnCommunityUpdated },
20136
20199
  { fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
20137
20200
  { fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
20138
20201
  { fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
20202
+ { fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
20203
+ { fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
20139
20204
  ]);
20140
20205
  }
20141
20206
  notifyChange({ origin, loading, error }) {
@@ -20145,7 +20210,7 @@ class SearchCommunityLiveCollectionController extends LiveCollectionController {
20145
20210
  return;
20146
20211
  const data = this.applyFilter((_b = collection.data
20147
20212
  .map(id => pullFromCache(['community', 'get', id]))
20148
- .filter(Boolean)
20213
+ .filter(isNonNullable)
20149
20214
  .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
20150
20215
  if (!this.shouldNotify(data) && origin === 'event')
20151
20216
  return;
@@ -20230,12 +20295,12 @@ class CommunitiesPaginationController extends PaginationController {
20230
20295
  }
20231
20296
  }
20232
20297
 
20233
- var EnumCommunityActions;
20298
+ var EnumCommunityActions$2;
20234
20299
  (function (EnumCommunityActions) {
20235
20300
  EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
20236
20301
  EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
20237
20302
  EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
20238
- })(EnumCommunityActions || (EnumCommunityActions = {}));
20303
+ })(EnumCommunityActions$2 || (EnumCommunityActions$2 = {}));
20239
20304
 
20240
20305
  class CommunitiesQueryStreamController extends QueryStreamController {
20241
20306
  constructor(query, cacheKey, notifyChange, preparePayload) {
@@ -20271,7 +20336,7 @@ class CommunitiesQueryStreamController extends QueryStreamController {
20271
20336
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
20272
20337
  if (!collection)
20273
20338
  return;
20274
- if (this.query.displayName && action === EnumCommunityActions.OnCommunityCreated) {
20339
+ if (this.query.displayName && action === EnumCommunityActions$2.OnCommunityCreated) {
20275
20340
  return;
20276
20341
  }
20277
20342
  /*
@@ -20316,12 +20381,14 @@ class CommunityLiveCollectionController extends LiveCollectionController {
20316
20381
  }
20317
20382
  startSubscription() {
20318
20383
  return this.queryStreamController.subscribeRTE([
20319
- { fn: onCommunityCreated, action: EnumCommunityActions.OnCommunityCreated },
20320
- { fn: onCommunityDeleted, action: EnumCommunityActions.OnCommunityDeleted },
20321
- { fn: onCommunityUpdated, action: EnumCommunityActions.OnCommunityUpdated },
20384
+ { fn: onCommunityCreated, action: EnumCommunityActions$2.OnCommunityCreated },
20385
+ { fn: onCommunityDeleted, action: EnumCommunityActions$2.OnCommunityDeleted },
20386
+ { fn: onCommunityUpdated, action: EnumCommunityActions$2.OnCommunityUpdated },
20322
20387
  { fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
20323
20388
  { fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
20324
20389
  { fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
20390
+ { fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
20391
+ { fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
20325
20392
  ]);
20326
20393
  }
20327
20394
  notifyChange({ origin, loading, error }) {
@@ -20331,7 +20398,7 @@ class CommunityLiveCollectionController extends LiveCollectionController {
20331
20398
  return;
20332
20399
  const data = this.applyFilter((_b = collection.data
20333
20400
  .map(id => pullFromCache(['community', 'get', id]))
20334
- .filter(Boolean)
20401
+ .filter(isNonNullable)
20335
20402
  .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
20336
20403
  if (!this.shouldNotify(data) && origin === 'event')
20337
20404
  return;
@@ -20444,6 +20511,8 @@ const getCommunity = (communityId, callback) => {
20444
20511
  onCommunityDeleted,
20445
20512
  onCommunityJoined,
20446
20513
  onCommunityLeft,
20514
+ onLocalCommunityJoined,
20515
+ onLocalCommunityLeft,
20447
20516
  onCommunityUserBanned,
20448
20517
  onCommunityUserUnbanned,
20449
20518
  onCommunityUserChanged,
@@ -20452,71 +20521,128 @@ const getCommunity = (communityId, callback) => {
20452
20521
  /* end_public_function */
20453
20522
 
20454
20523
  /**
20455
- * ```js
20456
- * import { CommunityRepository } from '@amityco/ts-sdk-react-native'
20457
- * const trendingCommunities = await CommunityRepository.getTrendingCommunities()
20458
- * ```
20459
- *
20460
- * Gets a list of top trending {@link Amity.Community} objects
20461
- *
20462
- * @param query The query parameters
20463
- * @returns A list of {@link Amity.Community} objects
20464
- *
20465
- * @category Community API
20466
- * @async
20467
- * @private
20524
+ * TODO: handle cache receive cache option, and cache policy
20525
+ * TODO: check if querybyIds is supported
20468
20526
  */
20469
- const getTrendingCommunities$1 = async (query) => {
20470
- const client = getActiveClient();
20471
- client.log('community/getTrendingCommunities', query);
20472
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = query !== null && query !== void 0 ? query : {};
20473
- // API-FIX: backend doesnt answer Amity.Response
20474
- // const { data } = await client.http.get<Amity.Response<CommunityPayload>>(
20475
- const { data: payload } = await client.http.get(`/api/v3/communities/top-trending`, { params: { options: { limit } } });
20476
- const data = prepareCommunityPayload(payload);
20477
- const { communities } = data;
20478
- const cachedAt = client.cache && Date.now();
20479
- if (client.cache) {
20480
- ingestInCache(data, { cachedAt });
20527
+ class TrendingCommunitiesPaginationController extends PaginationController {
20528
+ async getRequest(queryParams, token) {
20529
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
20530
+ const options = token ? { token } : { limit };
20531
+ const { data: queryResponse } = await this.http.get(`/api/v3/communities/top-trending`, {
20532
+ params: Object.assign(Object.assign({}, params), { options }),
20533
+ });
20534
+ return queryResponse;
20481
20535
  }
20482
- return { data: communities, cachedAt };
20483
- };
20536
+ }
20484
20537
 
20485
- const communityQueryFilter = (data, params, userId) => {
20486
- let communities = data;
20487
- communities = filterByPropEquality(communities, 'displayName', params.displayName);
20488
- if (!params.includeDeleted) {
20489
- communities = filterByPropEquality(communities, 'isDeleted', false);
20538
+ class TrendingCommunitiesQueryStreamController extends QueryStreamController {
20539
+ constructor(query, cacheKey, notifyChange, preparePayload) {
20540
+ super(query, cacheKey);
20541
+ this.notifyChange = notifyChange;
20542
+ this.preparePayload = preparePayload;
20490
20543
  }
20491
- if (params.categoryId) {
20492
- communities = communities.filter(c => { var _a; return (_a = c.categoryIds) === null || _a === void 0 ? void 0 : _a.includes(params.categoryId); });
20544
+ async saveToMainDB(response) {
20545
+ const processedPayload = await this.preparePayload(response);
20546
+ const client = getActiveClient();
20547
+ const cachedAt = client.cache && Date.now();
20548
+ if (client.cache) {
20549
+ ingestInCache(processedPayload, { cachedAt });
20550
+ saveCommunityUsers(response.communities, response.communityUsers);
20551
+ }
20493
20552
  }
20494
- if (params.tags) {
20495
- communities = communities.filter(c => { var _a; return (_a = c.tags) === null || _a === void 0 ? void 0 : _a.some(t => { var _a; return (_a = params.tags) === null || _a === void 0 ? void 0 : _a.includes(t); }); });
20553
+ appendToQueryStream(response, direction, refresh = false) {
20554
+ var _a, _b;
20555
+ if (refresh) {
20556
+ pushToCache(this.cacheKey, {
20557
+ data: response.communities.map(getResolver('community')),
20558
+ });
20559
+ }
20560
+ else {
20561
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
20562
+ const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
20563
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...response.communities.map(getResolver('community'))])] }));
20564
+ }
20496
20565
  }
20497
- if (params.membership && userId) {
20498
- communities = filterByCommunityMembership(communities, params.membership, userId);
20566
+ reactor(action) {
20567
+ return (community) => {
20568
+ var _a;
20569
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
20570
+ if (!collection)
20571
+ return;
20572
+ pushToCache(this.cacheKey, collection);
20573
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
20574
+ };
20499
20575
  }
20500
- const sortBy = params.sortBy || 'lastCreated';
20501
- if (sortBy === 'lastCreated' || sortBy === 'firstCreated') {
20502
- communities = communities.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
20576
+ subscribeRTE(createSubscriber) {
20577
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
20503
20578
  }
20504
- /*
20505
- * The server returns communities with empty | null displayName's first before
20506
- * returning sorted list of communities with displayNames
20507
- *
20508
- * This section needs to be updated as displayNames can be null as well
20509
- */
20510
- if (sortBy === 'displayName') {
20511
- communities = communities
20512
- // this needs to be aligned with the backend data type
20513
- .map(c => (c.displayName ? c : Object.assign(Object.assign({}, c), { displayName: '' })))
20514
- .sort(sortByDisplayName);
20579
+ }
20580
+
20581
+ var EnumCommunityActions$1;
20582
+ (function (EnumCommunityActions) {
20583
+ EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
20584
+ EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
20585
+ })(EnumCommunityActions$1 || (EnumCommunityActions$1 = {}));
20586
+
20587
+ class TrendingCommunityLiveCollectionController extends LiveCollectionController {
20588
+ constructor(query, callback) {
20589
+ const queryStreamId = hash__default["default"](query);
20590
+ const cacheKey = ['trendingCommunity', 'collection', queryStreamId];
20591
+ const paginationController = new TrendingCommunitiesPaginationController(query);
20592
+ super(paginationController, queryStreamId, cacheKey, callback);
20593
+ this.query = query;
20594
+ this.queryStreamController = new TrendingCommunitiesQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
20595
+ this.callback = callback.bind(this);
20596
+ this.loadPage({ initial: true });
20515
20597
  }
20516
- return communities;
20517
- };
20598
+ setup() {
20599
+ var _a;
20600
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
20601
+ if (!collection) {
20602
+ pushToCache(this.cacheKey, {
20603
+ data: [],
20604
+ params: {},
20605
+ });
20606
+ }
20607
+ }
20608
+ async persistModel(queryPayload) {
20609
+ await this.queryStreamController.saveToMainDB(queryPayload);
20610
+ }
20611
+ persistQueryStream({ response, direction, refresh, }) {
20612
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
20613
+ }
20614
+ startSubscription() {
20615
+ return this.queryStreamController.subscribeRTE([
20616
+ { fn: onCommunityDeleted, action: EnumCommunityActions$1.OnCommunityDeleted },
20617
+ { fn: onCommunityUpdated, action: EnumCommunityActions$1.OnCommunityUpdated },
20618
+ { fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
20619
+ { fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
20620
+ { fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
20621
+ { fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
20622
+ { fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
20623
+ ]);
20624
+ }
20625
+ notifyChange({ origin, loading, error }) {
20626
+ var _a, _b;
20627
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
20628
+ if (!collection)
20629
+ return;
20630
+ const data = (_b = collection.data
20631
+ .map(id => pullFromCache(['community', 'get', id]))
20632
+ .filter(isNonNullable)
20633
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
20634
+ if (!this.shouldNotify(data) && origin === 'event')
20635
+ return;
20636
+ this.callback({
20637
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
20638
+ data,
20639
+ hasNextPage: !!this.paginationController.getNextToken(),
20640
+ loading,
20641
+ error,
20642
+ });
20643
+ }
20644
+ }
20518
20645
 
20519
- /* eslint-disable no-use-before-define */
20520
20646
  /* begin_public_function
20521
20647
  id: community.query.trending_communities
20522
20648
  */
@@ -20545,60 +20671,9 @@ const getTrendingCommunities = (params, callback, config) => {
20545
20671
  }
20546
20672
  const timestamp = Date.now();
20547
20673
  log(`getTrendingCommunities(tmpid: ${timestamp}) > listen`);
20548
- const { limit: queryLimit } = params;
20549
- const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
20550
- const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
20551
- const disposers = [];
20552
- const cacheKey = ['community', 'top-trending', { params: { options: { limit } } }];
20553
- const responder = (data, isEventModel = false) => {
20554
- var _a, _b;
20555
- const communities = (_a = data.data
20556
- .map(communityId => pullFromCache(['community', 'get', communityId]))
20557
- .filter(Boolean)
20558
- .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
20559
- callback({
20560
- onNextPage: onFetch,
20561
- data: isEventModel ? communityQueryFilter(communities, params, userId) : communities,
20562
- hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
20563
- loading: data.loading,
20564
- error: data.error,
20565
- });
20566
- };
20567
- const realtimeRouter = (_) => (community) => {
20568
- var _a;
20569
- const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
20570
- if (!collection)
20571
- return;
20572
- /*
20573
- * Simply update collection and let responder decide what to do with data
20574
- */
20575
- collection.data = [...new Set([community.communityId, ...collection.data])];
20576
- pushToCache(cacheKey, collection);
20577
- responder(collection);
20578
- };
20579
- const onFetch = (initial = false) => {
20580
- var _a, _b;
20581
- const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
20582
- const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
20583
- if (!initial && communities.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
20584
- return;
20585
- const query = createQuery(getTrendingCommunities$1, params);
20586
- runQuery(query, ({ data: result, error, loading }) => {
20587
- const data = {
20588
- loading,
20589
- error,
20590
- params,
20591
- data: communities,
20592
- };
20593
- if (result) {
20594
- data.data = [...new Set([...communities, ...result.map(getResolver('community'))])];
20595
- }
20596
- pushToCache(cacheKey, data);
20597
- responder(data);
20598
- }, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
20599
- };
20600
- disposers.push(onCommunityUserChanged(realtimeRouter()));
20601
- onFetch(true);
20674
+ const trendingCommunitiesLiveCollection = new TrendingCommunityLiveCollectionController(params, callback);
20675
+ const disposers = trendingCommunitiesLiveCollection.startSubscription();
20676
+ const cacheKey = trendingCommunitiesLiveCollection.getCacheKey();
20602
20677
  disposers.push(() => dropFromCache(cacheKey));
20603
20678
  return () => {
20604
20679
  log(`getTrendingCommunities(tmpid: ${timestamp}) > dispose`);
@@ -20607,39 +20682,128 @@ const getTrendingCommunities = (params, callback, config) => {
20607
20682
  };
20608
20683
  /* end_public_function */
20609
20684
 
20610
- /* begin_public_function
20611
- id: community.query.recommended_communities
20612
- */
20613
20685
  /**
20614
- * ```js
20615
- * import { CommunityRepository } from '@amityco/ts-sdk-react-native'
20616
- * const communities = await CommunityRepository.getRecommendedCommunities()
20617
- * ```
20618
- *
20619
- * Gets a list of recommended {@link Amity.Community} objects
20620
- *
20621
- * @param query The query parameters
20622
- * @returns A list of {@link Amity.Community} objects
20623
- *
20624
- * @category Community API
20625
- * @async
20626
- * @private
20686
+ * TODO: handle cache receive cache option, and cache policy
20687
+ * TODO: check if querybyIds is supported
20627
20688
  */
20628
- const getRecommendedCommunities$1 = async (query) => {
20629
- const client = getActiveClient();
20630
- client.log('community/getRecommendedCommunities', query);
20631
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = query !== null && query !== void 0 ? query : {};
20632
- // API-FIX: backend doesnt answer Amity.Response
20633
- // const { data: payload } = await client.http.get<Amity.Response<CommunityPayload>>(
20634
- const { data: payload } = await client.http.get(`/api/v3/communities/recommended`, { params: { options: { limit } } });
20635
- const data = prepareCommunityPayload(payload);
20636
- const { communities } = data;
20637
- const cachedAt = client.cache && Date.now();
20638
- if (client.cache) {
20639
- ingestInCache(data, { cachedAt });
20689
+ class RecommendedCommunitiesPaginationController extends PaginationController {
20690
+ async getRequest(queryParams, token) {
20691
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
20692
+ const options = token ? { token } : { limit };
20693
+ const { data: queryResponse } = await this.http.get(`/api/v3/communities/recommended`, {
20694
+ params: Object.assign(Object.assign({}, params), { options }),
20695
+ });
20696
+ return queryResponse;
20640
20697
  }
20641
- return { data: communities, cachedAt };
20642
- };
20698
+ }
20699
+
20700
+ class RecommendedCommunitiesQueryStreamController extends QueryStreamController {
20701
+ constructor(query, cacheKey, notifyChange, preparePayload) {
20702
+ super(query, cacheKey);
20703
+ this.notifyChange = notifyChange;
20704
+ this.preparePayload = preparePayload;
20705
+ }
20706
+ async saveToMainDB(response) {
20707
+ const processedPayload = await this.preparePayload(response);
20708
+ const client = getActiveClient();
20709
+ const cachedAt = client.cache && Date.now();
20710
+ if (client.cache) {
20711
+ ingestInCache(processedPayload, { cachedAt });
20712
+ saveCommunityUsers(response.communities, response.communityUsers);
20713
+ }
20714
+ }
20715
+ appendToQueryStream(response, direction, refresh = false) {
20716
+ var _a, _b;
20717
+ if (refresh) {
20718
+ pushToCache(this.cacheKey, {
20719
+ data: response.communities.map(getResolver('community')),
20720
+ });
20721
+ }
20722
+ else {
20723
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
20724
+ const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
20725
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...response.communities.map(getResolver('community'))])] }));
20726
+ }
20727
+ }
20728
+ reactor(action) {
20729
+ return (community) => {
20730
+ var _a;
20731
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
20732
+ if (!collection)
20733
+ return;
20734
+ pushToCache(this.cacheKey, collection);
20735
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
20736
+ };
20737
+ }
20738
+ subscribeRTE(createSubscriber) {
20739
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
20740
+ }
20741
+ }
20742
+
20743
+ var EnumCommunityActions;
20744
+ (function (EnumCommunityActions) {
20745
+ EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
20746
+ EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
20747
+ })(EnumCommunityActions || (EnumCommunityActions = {}));
20748
+
20749
+ class RecommendedCommunityLiveCollectionController extends LiveCollectionController {
20750
+ constructor(query, callback) {
20751
+ const queryStreamId = hash__default["default"](query);
20752
+ const cacheKey = ['community', 'collection', queryStreamId];
20753
+ const paginationController = new RecommendedCommunitiesPaginationController(query);
20754
+ super(paginationController, queryStreamId, cacheKey, callback);
20755
+ this.query = query;
20756
+ this.queryStreamController = new RecommendedCommunitiesQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
20757
+ this.callback = callback.bind(this);
20758
+ this.loadPage({ initial: true });
20759
+ }
20760
+ setup() {
20761
+ var _a;
20762
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
20763
+ if (!collection) {
20764
+ pushToCache(this.cacheKey, {
20765
+ data: [],
20766
+ params: {},
20767
+ });
20768
+ }
20769
+ }
20770
+ async persistModel(queryPayload) {
20771
+ await this.queryStreamController.saveToMainDB(queryPayload);
20772
+ }
20773
+ persistQueryStream({ response, direction, refresh, }) {
20774
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
20775
+ }
20776
+ startSubscription() {
20777
+ return this.queryStreamController.subscribeRTE([
20778
+ { fn: onCommunityDeleted, action: EnumCommunityActions.OnCommunityDeleted },
20779
+ { fn: onCommunityUpdated, action: EnumCommunityActions.OnCommunityUpdated },
20780
+ { fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
20781
+ { fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
20782
+ { fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
20783
+ { fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
20784
+ { fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
20785
+ ]);
20786
+ }
20787
+ notifyChange({ origin, loading, error }) {
20788
+ var _a, _b;
20789
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
20790
+ if (!collection)
20791
+ return;
20792
+ const data = (_b = collection.data
20793
+ .map(id => pullFromCache(['community', 'get', id]))
20794
+ .filter(isNonNullable)
20795
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
20796
+ if (!this.shouldNotify(data) && origin === 'event')
20797
+ return;
20798
+ this.callback({
20799
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
20800
+ data,
20801
+ hasNextPage: !!this.paginationController.getNextToken(),
20802
+ loading,
20803
+ error,
20804
+ });
20805
+ }
20806
+ }
20643
20807
 
20644
20808
  /* begin_public_function
20645
20809
  id: community.query.recommended_communities
@@ -20669,60 +20833,9 @@ const getRecommendedCommunities = (params, callback, config) => {
20669
20833
  }
20670
20834
  const timestamp = Date.now();
20671
20835
  log(`getRecommendedCommunities(tmpid: ${timestamp}) > listen`);
20672
- const { limit: queryLimit } = params; __rest(params, ["limit"]);
20673
- const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
20674
- const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
20675
- const disposers = [];
20676
- const cacheKey = ['community', 'recommended', { params: { options: { limit } } }];
20677
- const responder = (data, isEventModel = false) => {
20678
- var _a, _b;
20679
- const communities = (_a = data.data
20680
- .map(communityId => pullFromCache(['community', 'get', communityId]))
20681
- .filter(Boolean)
20682
- .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
20683
- callback({
20684
- onNextPage: onFetch,
20685
- data: isEventModel ? communityQueryFilter(communities, params, userId) : communities,
20686
- hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
20687
- loading: data.loading,
20688
- error: data.error,
20689
- });
20690
- };
20691
- const realtimeRouter = (_) => (community) => {
20692
- var _a;
20693
- const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
20694
- if (!collection)
20695
- return;
20696
- /*
20697
- * Simply update collection and let responder decide what to do with data
20698
- */
20699
- collection.data = [...new Set([community.communityId, ...collection.data])];
20700
- pushToCache(cacheKey, collection);
20701
- responder(collection);
20702
- };
20703
- const onFetch = (initial = false) => {
20704
- var _a, _b;
20705
- const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
20706
- const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
20707
- if (!initial && communities.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
20708
- return;
20709
- const query = createQuery(getRecommendedCommunities$1, params);
20710
- runQuery(query, ({ data: result, error, loading }) => {
20711
- const data = {
20712
- loading,
20713
- error,
20714
- params,
20715
- data: communities,
20716
- };
20717
- if (result) {
20718
- data.data = [...new Set([...communities, ...result.map(getResolver('community'))])];
20719
- }
20720
- pushToCache(cacheKey, data);
20721
- responder(data);
20722
- }, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
20723
- };
20724
- disposers.push(onCommunityUserChanged(realtimeRouter()));
20725
- onFetch(true);
20836
+ const recommendedCommunitiesLiveCollection = new RecommendedCommunityLiveCollectionController(params, callback);
20837
+ const disposers = recommendedCommunitiesLiveCollection.startSubscription();
20838
+ const cacheKey = recommendedCommunitiesLiveCollection.getCacheKey();
20726
20839
  disposers.push(() => dropFromCache(cacheKey));
20727
20840
  return () => {
20728
20841
  log(`getRecommendedCommunities(tmpid: ${timestamp}) > dispose`);