@amityco/ts-sdk-react-native 6.25.2-843ba7e.0 → 6.26.1-4e1acd6.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 (68) hide show
  1. package/dist/@types/core/model.d.ts +4 -0
  2. package/dist/@types/core/model.d.ts.map +1 -1
  3. package/dist/@types/core/payload.d.ts +7 -0
  4. package/dist/@types/core/payload.d.ts.map +1 -1
  5. package/dist/@types/domains/ad.d.ts +74 -0
  6. package/dist/@types/domains/ad.d.ts.map +1 -0
  7. package/dist/@types/domains/analytics.d.ts +3 -1
  8. package/dist/@types/domains/analytics.d.ts.map +1 -1
  9. package/dist/@types/index.d.ts +2 -0
  10. package/dist/@types/index.d.ts.map +1 -1
  11. package/dist/adRepository/api/getNetworkAds.d.ts +2 -0
  12. package/dist/adRepository/api/getNetworkAds.d.ts.map +1 -0
  13. package/dist/adRepository/api/index.d.ts +2 -0
  14. package/dist/adRepository/api/index.d.ts.map +1 -0
  15. package/dist/adRepository/index.d.ts +2 -0
  16. package/dist/adRepository/index.d.ts.map +1 -0
  17. package/dist/analytic/service/analytic/AnalyticsEngine.d.ts +2 -0
  18. package/dist/analytic/service/analytic/AnalyticsEngine.d.ts.map +1 -1
  19. package/dist/analytic/service/analytic/AnalyticsEventCapturer.d.ts +3 -0
  20. package/dist/analytic/service/analytic/AnalyticsEventCapturer.d.ts.map +1 -1
  21. package/dist/client/api/getToken.d.ts +1 -1
  22. package/dist/client/api/getToken.d.ts.map +1 -1
  23. package/dist/commentRepository/observers/getComments/CommentLiveCollectionController.d.ts +14 -0
  24. package/dist/commentRepository/observers/getComments/CommentLiveCollectionController.d.ts.map +1 -0
  25. package/dist/commentRepository/observers/getComments/CommentPaginationController.d.ts +5 -0
  26. package/dist/commentRepository/observers/getComments/CommentPaginationController.d.ts.map +1 -0
  27. package/dist/commentRepository/observers/getComments/CommentQueryStreamController.d.ts +15 -0
  28. package/dist/commentRepository/observers/getComments/CommentQueryStreamController.d.ts.map +1 -0
  29. package/dist/commentRepository/observers/getComments/enums.d.ts +10 -0
  30. package/dist/commentRepository/observers/getComments/enums.d.ts.map +1 -0
  31. package/dist/commentRepository/observers/getComments.d.ts.map +1 -1
  32. package/dist/commentRepository/utils/payload.d.ts +2 -0
  33. package/dist/commentRepository/utils/payload.d.ts.map +1 -0
  34. package/dist/core/model/idResolvers.d.ts.map +1 -1
  35. package/dist/core/model/index.d.ts.map +1 -1
  36. package/dist/index.cjs.js +309 -169
  37. package/dist/index.d.ts +1 -0
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.esm.js +293 -154
  40. package/dist/index.umd.js +3 -3
  41. package/dist/utils/linkedObject/adLinkedObject.d.ts +2 -0
  42. package/dist/utils/linkedObject/adLinkedObject.d.ts.map +1 -0
  43. package/dist/utils/linkedObject/index.d.ts +1 -0
  44. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  45. package/package.json +1 -1
  46. package/src/@types/core/model.ts +6 -0
  47. package/src/@types/core/payload.ts +12 -0
  48. package/src/@types/domains/ad.ts +88 -0
  49. package/src/@types/domains/analytics.ts +2 -0
  50. package/src/@types/index.ts +2 -0
  51. package/src/adRepository/api/getNetworkAds.ts +24 -0
  52. package/src/adRepository/api/index.ts +1 -0
  53. package/src/adRepository/index.ts +1 -0
  54. package/src/analytic/service/analytic/AnalyticsEngine.ts +18 -0
  55. package/src/analytic/service/analytic/AnalyticsEventCapturer.ts +49 -8
  56. package/src/client/api/getToken.ts +1 -1
  57. package/src/client/api/login.ts +1 -1
  58. package/src/commentRepository/observers/getComments/CommentLiveCollectionController.ts +132 -0
  59. package/src/commentRepository/observers/getComments/CommentPaginationController.ts +25 -0
  60. package/src/commentRepository/observers/getComments/CommentQueryStreamController.ts +90 -0
  61. package/src/commentRepository/observers/getComments/enums.ts +9 -0
  62. package/src/commentRepository/observers/getComments.ts +5 -141
  63. package/src/commentRepository/utils/payload.ts +5 -0
  64. package/src/core/model/idResolvers.ts +3 -0
  65. package/src/core/model/index.ts +2 -0
  66. package/src/index.ts +3 -0
  67. package/src/utils/linkedObject/adLinkedObject.ts +50 -0
  68. package/src/utils/linkedObject/index.ts +2 -0
package/dist/index.esm.js CHANGED
@@ -84,8 +84,8 @@ const PostContentType = Object.freeze({
84
84
 
85
85
  function getVersion() {
86
86
  try {
87
- // the string ''v6.25.0-esm'' should be replaced by actual value by @rollup/plugin-replace
88
- return 'v6.25.0-esm';
87
+ // the string ''v6.26.0-esm'' should be replaced by actual value by @rollup/plugin-replace
88
+ return 'v6.26.0-esm';
89
89
  }
90
90
  catch (error) {
91
91
  return '__dev__';
@@ -520,6 +520,8 @@ const idResolvers = {
520
520
  feed: ({ targetId, feedId }) => `${targetId}#${feedId}`,
521
521
  story: ({ referenceId }) => referenceId,
522
522
  storyTarget: ({ targetId }) => targetId,
523
+ ad: ({ adId }) => adId,
524
+ advertiser: ({ advertiserId }) => advertiserId,
523
525
  };
524
526
  /**
525
527
  * Retrieve the id resolver matching a domain name
@@ -567,6 +569,8 @@ const PAYLOAD2MODEL = {
567
569
  follows: 'follow',
568
570
  followCounts: 'followCount',
569
571
  feeds: 'feed',
572
+ ads: 'ad',
573
+ advertisers: 'advertiser',
570
574
  };
571
575
  /** hidden */
572
576
  const isOutdated = (prevData, nextData) => {
@@ -20981,8 +20985,8 @@ class AnalyticsEventCapturer {
20981
20985
  }
20982
20986
  return true;
20983
20987
  }
20984
- markPostAsViewed(postId) {
20985
- if (!this.isAbleToEnqueue({ itemId: postId, expireTime: this._expireTime }))
20988
+ markAs(itemId, contentType, activityType, metadata = undefined) {
20989
+ if (!this.isAbleToEnqueue({ itemId, expireTime: this._expireTime }))
20986
20990
  return;
20987
20991
  const now = new Date();
20988
20992
  const currentData = { event: [] };
@@ -20995,14 +20999,21 @@ class AnalyticsEventCapturer {
20995
20999
  // Remove oldest data
20996
21000
  currentData.event.shift();
20997
21001
  }
20998
- currentData.event.push({
20999
- contentId: postId,
21000
- contentType: "post" /* Amity.AnalyticEventContentType.Post */,
21001
- activityType: "view" /* Amity.AnalyticEventActivityType.View */,
21002
+ const analyticItem = {
21003
+ contentId: itemId,
21004
+ contentType,
21005
+ activityType,
21002
21006
  timestamp: now.toISOString(),
21003
- });
21007
+ };
21008
+ if (metadata) {
21009
+ analyticItem.metadata = metadata;
21010
+ }
21011
+ currentData.event.push(analyticItem);
21004
21012
  upsertInCache(ANALYTIC_CACHE_KEY, currentData);
21005
- this._recentViewed[postId] = now;
21013
+ this._recentViewed[itemId] = now;
21014
+ }
21015
+ markPostAsViewed(postId) {
21016
+ this.markAs(postId, "post" /* Amity.AnalyticEventContentType.Post */, "view" /* Amity.AnalyticEventActivityType.View */);
21006
21017
  }
21007
21018
  markStory(story, activityType) {
21008
21019
  if (!story.expiresAt)
@@ -21072,6 +21083,18 @@ class AnalyticsEventCapturer {
21072
21083
  markStoryAsClicked(story) {
21073
21084
  this.markStory(story, "linkClicked" /* Amity.AnalyticEventActivityType.Click */);
21074
21085
  }
21086
+ markAdAsViewed(ad, placement) {
21087
+ const metadata = {
21088
+ placement,
21089
+ };
21090
+ this.markAs(`${ad.adId}.${"view" /* Amity.AnalyticEventActivityType.View */}.${placement}`, "ad" /* Amity.AnalyticEventContentType.Ad */, "view" /* Amity.AnalyticEventActivityType.View */, metadata);
21091
+ }
21092
+ markAdAsClicked(ad, placement) {
21093
+ const metadata = {
21094
+ placement,
21095
+ };
21096
+ this.markAs(`${ad.adId}.${"view" /* Amity.AnalyticEventActivityType.View */}.${placement}`, "ad" /* Amity.AnalyticEventContentType.Ad */, "linkClicked" /* Amity.AnalyticEventActivityType.Click */, metadata);
21097
+ }
21075
21098
  }
21076
21099
 
21077
21100
  class AnalyticsEngine {
@@ -21094,6 +21117,18 @@ class AnalyticsEngine {
21094
21117
  this._eventCapturer.markStoryAsViewed(story);
21095
21118
  }
21096
21119
  }
21120
+ markAdAsViewed(ad, placement) {
21121
+ if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
21122
+ this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
21123
+ this._eventCapturer.markAdAsViewed(ad, placement);
21124
+ }
21125
+ }
21126
+ markAdAsClicked(ad, placement) {
21127
+ if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
21128
+ this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
21129
+ this._eventCapturer.markAdAsClicked(ad, placement);
21130
+ }
21131
+ }
21097
21132
  markStoryAsClicked(story) {
21098
21133
  if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
21099
21134
  this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
@@ -21825,7 +21860,51 @@ const channelLinkedObject = (channel) => {
21825
21860
  return Object.assign(Object.assign({}, channel), { markAsRead: () => markAsRead(channel.channelInternalId) });
21826
21861
  };
21827
21862
 
21863
+ // import AnalyticsEngine from '~/analytic/service/analytic/AnalyticsEngine';
21864
+ const adLinkedObject = (ad) => {
21865
+ // const analyticsEngineInstance = AnalyticsEngine.getInstance();
21866
+ const { image9_16: image916, image1_1: image11 } = ad, restAds = __rest(ad, ["image9_16", "image1_1"]);
21867
+ return Object.assign(Object.assign({}, restAds), {
21868
+ // analytics: {
21869
+ // markAsSeen: (placement: Amity.AdPlacement) => {
21870
+ // analyticsEngineInstance.markAdAsViewed(ad, placement);
21871
+ // },
21872
+ // markLinkAsClicked: (placement: Amity.AdPlacement) => {
21873
+ // analyticsEngineInstance.markAdAsClicked(ad, placement);
21874
+ // },
21875
+ // },
21876
+ get advertiser() {
21877
+ var _a, _b;
21878
+ const advertiserData = (_a = pullFromCache([
21879
+ 'advertiser',
21880
+ 'get',
21881
+ ad.advertiserId,
21882
+ ])) === null || _a === void 0 ? void 0 : _a.data;
21883
+ if (!advertiserData)
21884
+ return;
21885
+ const avatarFile = (_b = pullFromCache([
21886
+ 'file',
21887
+ 'get',
21888
+ advertiserData.avatarFileId,
21889
+ ])) === null || _b === void 0 ? void 0 : _b.data;
21890
+ return Object.assign(Object.assign({}, advertiserData), { avatar: avatarFile });
21891
+ },
21892
+ get image1_1() {
21893
+ const cacheData = pullFromCache(['file', 'get', image11]);
21894
+ if (!cacheData)
21895
+ return undefined;
21896
+ return cacheData.data || undefined;
21897
+ },
21898
+ get image9_16() {
21899
+ const cacheData = pullFromCache(['file', 'get', image916]);
21900
+ if (!cacheData)
21901
+ return undefined;
21902
+ return cacheData.data || undefined;
21903
+ } });
21904
+ };
21905
+
21828
21906
  const LinkedObject = {
21907
+ ad: adLinkedObject,
21829
21908
  comment: commentLinkedObject,
21830
21909
  post: postLinkedObject,
21831
21910
  user: userLinkedObject,
@@ -24917,7 +24996,7 @@ const login = async (params, sessionHandler, config) => {
24917
24996
  // default values
24918
24997
  const defaultDeviceId = await getDeviceId();
24919
24998
  try {
24920
- const { users } = await setClientToken(Object.assign(Object.assign({}, params), { displayName: (params === null || params === void 0 ? void 0 : params.displayName) || params.userId, deviceId: (params === null || params === void 0 ? void 0 : params.deviceId) || defaultDeviceId }));
24999
+ const { users } = await setClientToken(Object.assign(Object.assign({}, params), { displayName: params === null || params === void 0 ? void 0 : params.displayName, deviceId: (params === null || params === void 0 ? void 0 : params.deviceId) || defaultDeviceId }));
24921
25000
  const user = users.find(u => u.userId === params.userId);
24922
25001
  if (user == null) {
24923
25002
  throw new ASCError(`${params.userId} has not been founded`, 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
@@ -25797,7 +25876,7 @@ const getUserUnread = (callback) => {
25797
25876
  };
25798
25877
  };
25799
25878
 
25800
- var index$k = /*#__PURE__*/Object.freeze({
25879
+ var index$l = /*#__PURE__*/Object.freeze({
25801
25880
  __proto__: null,
25802
25881
  getActiveClient: getActiveClient,
25803
25882
  getActiveUser: getActiveUser,
@@ -26960,7 +27039,7 @@ const getMyFollowInfo = (callback) => {
26960
27039
  };
26961
27040
  /* end_public_function */
26962
27041
 
26963
- var index$j = /*#__PURE__*/Object.freeze({
27042
+ var index$k = /*#__PURE__*/Object.freeze({
26964
27043
  __proto__: null,
26965
27044
  blockUser: blockUser,
26966
27045
  unBlockUser: unBlockUser,
@@ -27847,9 +27926,9 @@ const getReachedUsers = (params, callback) => {
27847
27926
  };
27848
27927
  };
27849
27928
 
27850
- var index$i = /*#__PURE__*/Object.freeze({
27929
+ var index$j = /*#__PURE__*/Object.freeze({
27851
27930
  __proto__: null,
27852
- Relationship: index$j,
27931
+ Relationship: index$k,
27853
27932
  getUserByIds: getUserByIds,
27854
27933
  updateUser: updateUser,
27855
27934
  flagUser: flagUser,
@@ -28277,7 +28356,7 @@ const observeFile = (fileId, callback) => {
28277
28356
  };
28278
28357
  };
28279
28358
 
28280
- var index$h = /*#__PURE__*/Object.freeze({
28359
+ var index$i = /*#__PURE__*/Object.freeze({
28281
28360
  __proto__: null,
28282
28361
  getFile: getFile,
28283
28362
  uploadFile: uploadFile,
@@ -29729,7 +29808,7 @@ const getReactions = (params, callback, config) => {
29729
29808
  };
29730
29809
  /* end_public_function */
29731
29810
 
29732
- var index$g = /*#__PURE__*/Object.freeze({
29811
+ var index$h = /*#__PURE__*/Object.freeze({
29733
29812
  __proto__: null,
29734
29813
  addReaction: addReaction,
29735
29814
  removeReaction: removeReaction,
@@ -31967,7 +32046,7 @@ const observeMessages = (subChannelId, callback) => {
31967
32046
  };
31968
32047
  };
31969
32048
 
31970
- var index$f = /*#__PURE__*/Object.freeze({
32049
+ var index$g = /*#__PURE__*/Object.freeze({
31971
32050
  __proto__: null,
31972
32051
  getMessageByIds: getMessages$1,
31973
32052
  createMessage: createMessage,
@@ -32576,7 +32655,7 @@ const stopMessageReceiptSync = (subChannelId) => {
32576
32655
  };
32577
32656
  /* end_public_function */
32578
32657
 
32579
- var index$e = /*#__PURE__*/Object.freeze({
32658
+ var index$f = /*#__PURE__*/Object.freeze({
32580
32659
  __proto__: null,
32581
32660
  getSubChannelByIds: getSubChannels$1,
32582
32661
  createSubChannel: createSubChannel,
@@ -33694,7 +33773,7 @@ const searchMembers$1 = (params, callback, config) => {
33694
33773
  };
33695
33774
  /* end_public_function */
33696
33775
 
33697
- var index$d = /*#__PURE__*/Object.freeze({
33776
+ var index$e = /*#__PURE__*/Object.freeze({
33698
33777
  __proto__: null,
33699
33778
  addMembers: addMembers$1,
33700
33779
  removeMembers: removeMembers$1,
@@ -33897,7 +33976,7 @@ const unmuteMembers = async (channelId, userIds) => {
33897
33976
  };
33898
33977
  /* end_public_function */
33899
33978
 
33900
- var index$c = /*#__PURE__*/Object.freeze({
33979
+ var index$d = /*#__PURE__*/Object.freeze({
33901
33980
  __proto__: null,
33902
33981
  addRole: addRole,
33903
33982
  removeRole: removeRole,
@@ -33907,10 +33986,10 @@ var index$c = /*#__PURE__*/Object.freeze({
33907
33986
  unmuteMembers: unmuteMembers
33908
33987
  });
33909
33988
 
33910
- var index$b = /*#__PURE__*/Object.freeze({
33989
+ var index$c = /*#__PURE__*/Object.freeze({
33911
33990
  __proto__: null,
33912
- Membership: index$d,
33913
- Moderation: index$c,
33991
+ Membership: index$e,
33992
+ Moderation: index$d,
33914
33993
  getChannelByIds: getChannelByIds,
33915
33994
  createChannel: createChannel,
33916
33995
  updateChannel: updateChannel,
@@ -35270,7 +35349,7 @@ const searchMembers = (params, callback, config) => {
35270
35349
  };
35271
35350
  /* end_public_function */
35272
35351
 
35273
- var index$a = /*#__PURE__*/Object.freeze({
35352
+ var index$b = /*#__PURE__*/Object.freeze({
35274
35353
  __proto__: null,
35275
35354
  addMembers: addMembers,
35276
35355
  removeMembers: removeMembers,
@@ -36051,7 +36130,7 @@ const unbanMembers = async (communityId, userIds) => {
36051
36130
  };
36052
36131
  /* end_public_function */
36053
36132
 
36054
- var index$9 = /*#__PURE__*/Object.freeze({
36133
+ var index$a = /*#__PURE__*/Object.freeze({
36055
36134
  __proto__: null,
36056
36135
  addRoles: addRoles,
36057
36136
  removeRoles: removeRoles,
@@ -36059,10 +36138,10 @@ var index$9 = /*#__PURE__*/Object.freeze({
36059
36138
  unbanMembers: unbanMembers
36060
36139
  });
36061
36140
 
36062
- var index$8 = /*#__PURE__*/Object.freeze({
36141
+ var index$9 = /*#__PURE__*/Object.freeze({
36063
36142
  __proto__: null,
36064
- Moderation: index$9,
36065
- Membership: index$a,
36143
+ Moderation: index$a,
36144
+ Membership: index$b,
36066
36145
  getCommunityByIds: getCommunities$1,
36067
36146
  createCommunity: createCommunity,
36068
36147
  updateCommunity: updateCommunity,
@@ -36295,7 +36374,7 @@ const getCategories = (params, callback, config) => {
36295
36374
  };
36296
36375
  /* end_public_function */
36297
36376
 
36298
- var index$7 = /*#__PURE__*/Object.freeze({
36377
+ var index$8 = /*#__PURE__*/Object.freeze({
36299
36378
  __proto__: null,
36300
36379
  getCategory: getCategory,
36301
36380
  getCategories: getCategories
@@ -36505,7 +36584,7 @@ getCustomRankingGlobalFeed.locally = (query) => {
36505
36584
  : undefined;
36506
36585
  };
36507
36586
 
36508
- var index$6 = /*#__PURE__*/Object.freeze({
36587
+ var index$7 = /*#__PURE__*/Object.freeze({
36509
36588
  __proto__: null,
36510
36589
  queryGlobalFeed: queryGlobalFeed,
36511
36590
  getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
@@ -37697,48 +37776,160 @@ const getComment = (commentId, callback) => {
37697
37776
  };
37698
37777
  /* end_public_function */
37699
37778
 
37700
- const convertToInternalComment = (commentPayload) => {
37701
- const { comments } = commentPayload;
37702
- return Object.assign(Object.assign({}, commentPayload), { comments: comments.map(comment => {
37703
- if (comment.hasOwnProperty('myReactions'))
37704
- return comment;
37705
- // Sometimes `myReactions` field will not come with BE response because that field is empty
37706
- // We need to put it with an empty array manually to make it show up in client side
37707
- return Object.assign({ myReactions: [] }, comment);
37708
- }) });
37709
- };
37779
+ class CommentPaginationController extends PaginationController {
37780
+ async getRequest(queryParams, token) {
37781
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
37782
+ const options = token ? { token } : { limit };
37783
+ const { data: queryResponse } = await this.http.get(`/api/v3/comments`, {
37784
+ params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
37785
+ });
37786
+ return queryResponse;
37787
+ }
37788
+ }
37710
37789
 
37711
- const queryComments = async (query) => {
37712
- const client = getActiveClient();
37713
- client.log('comment/queryComments', query);
37714
- const { limit = 10, includeDeleted } = query, params = __rest(query, ["limit", "includeDeleted"]);
37715
- const options = {
37716
- type: params.sortBy || query.limit ? 'pagination' : undefined,
37717
- limit: query.limit,
37718
- token: query.page,
37719
- };
37720
- // const filterByParentId = query.parentId !== undefined
37721
- // API-FIX: parameters should be querystring. (1)
37722
- // API-FIX: backend should answer Amity.Response (2)
37723
- // const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.CommentPayload>>>(
37724
- const { data } = await client.http.get(`/api/v3/comments`, {
37725
- params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted),
37726
- // filterByParentId, API-FIX: backend does not support this boolean LOL. what the hell seriously.
37727
- options }),
37728
- });
37729
- // API-FIX: backend should answer Amity.Response (2)
37730
- // const { paging, comments } = unwrapPayload(data)
37731
- const { paging } = data, payload = __rest(data, ["paging"]);
37732
- const processedData = convertToInternalComment(payload);
37733
- const { comments } = processedData;
37734
- const cachedAt = client.cache && Date.now();
37735
- if (client.cache) {
37736
- ingestInCache(processedData, { cachedAt });
37737
- const cacheKey = ['comment', 'query', Object.assign(Object.assign({}, params), { options: { limit } })];
37738
- pushToCache(cacheKey, { comments: comments.map(getResolver('comment')), paging });
37790
+ var EnumCommentActions;
37791
+ (function (EnumCommentActions) {
37792
+ EnumCommentActions["OnCommentCreated"] = "onCommentCreated";
37793
+ EnumCommentActions["OnCommentUpdated"] = "onCommentUpdated";
37794
+ EnumCommentActions["OnCommentDeleted"] = "onCommentDeleted";
37795
+ EnumCommentActions["OnCommentFlagged"] = "onCommentFlagged";
37796
+ EnumCommentActions["OnCommentUnflagged"] = "onCommentUnflagged";
37797
+ EnumCommentActions["OnCommentReactionAdded"] = "onCommentReactionAdded";
37798
+ EnumCommentActions["OnCommentReactionRemoved"] = "onCommentReactionRemoved";
37799
+ })(EnumCommentActions || (EnumCommentActions = {}));
37800
+
37801
+ class CommentQueryStreamController extends QueryStreamController {
37802
+ constructor(query, cacheKey, notifyChange, preparePayload) {
37803
+ super(query, cacheKey);
37804
+ this.notifyChange = notifyChange;
37805
+ this.preparePayload = preparePayload;
37739
37806
  }
37740
- return { data: comments, cachedAt, paging };
37741
- };
37807
+ async saveToMainDB(response) {
37808
+ const processedPayload = await this.preparePayload(response);
37809
+ const client = getActiveClient();
37810
+ const cachedAt = client.cache && Date.now();
37811
+ if (client.cache) {
37812
+ ingestInCache(processedPayload, { cachedAt });
37813
+ }
37814
+ }
37815
+ appendToQueryStream(response, direction, refresh = false) {
37816
+ var _a, _b;
37817
+ if (refresh) {
37818
+ pushToCache(this.cacheKey, {
37819
+ data: response.comments.map(getResolver('comment')),
37820
+ });
37821
+ }
37822
+ else {
37823
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
37824
+ const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
37825
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...response.comments.map(getResolver('comment'))])] }));
37826
+ }
37827
+ }
37828
+ reactor(action) {
37829
+ return (comment) => {
37830
+ var _a;
37831
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
37832
+ if (this.query.referenceId !== comment.referenceId ||
37833
+ this.query.referenceType !== comment.referenceType ||
37834
+ !collection) {
37835
+ return;
37836
+ }
37837
+ if (action === EnumCommentActions.OnCommentCreated) {
37838
+ collection.data = [...new Set([comment.commentId, ...collection.data])];
37839
+ }
37840
+ else if (action === EnumCommentActions.OnCommentDeleted) {
37841
+ collection.data = collection.data.filter(p => p !== comment.commentId);
37842
+ }
37843
+ pushToCache(this.cacheKey, collection);
37844
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
37845
+ };
37846
+ }
37847
+ subscribeRTE(createSubscriber) {
37848
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
37849
+ }
37850
+ }
37851
+
37852
+ function prepareCommentPayload(comment) {
37853
+ return comment;
37854
+ }
37855
+
37856
+ class CommentLiveCollectionController extends LiveCollectionController {
37857
+ constructor(query, callback) {
37858
+ const queryStreamId = hash(query);
37859
+ const cacheKey = ['comments', 'collection', queryStreamId];
37860
+ const paginationController = new CommentPaginationController(query);
37861
+ super(paginationController, queryStreamId, cacheKey, callback);
37862
+ this.query = query;
37863
+ this.queryStreamController = new CommentQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommentPayload);
37864
+ this.callback = callback.bind(this);
37865
+ this.loadPage({ initial: true });
37866
+ }
37867
+ setup() {
37868
+ var _a;
37869
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
37870
+ if (!collection) {
37871
+ pushToCache(this.cacheKey, {
37872
+ data: [],
37873
+ params: {},
37874
+ });
37875
+ }
37876
+ }
37877
+ async persistModel(queryPayload) {
37878
+ await this.queryStreamController.saveToMainDB(queryPayload);
37879
+ }
37880
+ persistQueryStream({ response, direction, refresh, }) {
37881
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
37882
+ }
37883
+ startSubscription() {
37884
+ return this.queryStreamController.subscribeRTE([
37885
+ { fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
37886
+ { fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
37887
+ { fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
37888
+ { fn: onCommentFlagged, action: EnumCommentActions.OnCommentFlagged },
37889
+ { fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
37890
+ { fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
37891
+ { fn: onCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
37892
+ ]);
37893
+ }
37894
+ notifyChange({ origin, loading, error }) {
37895
+ var _a, _b;
37896
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
37897
+ if (!collection)
37898
+ return;
37899
+ const data = this.applyFilter((_b = collection.data
37900
+ .map(id => pullFromCache(['comments', 'get', id]))
37901
+ .filter(isNonNullable)
37902
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.comment);
37903
+ if (!this.shouldNotify(data) && origin === 'event')
37904
+ return;
37905
+ this.callback({
37906
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
37907
+ data,
37908
+ hasNextPage: !!this.paginationController.getNextToken(),
37909
+ loading,
37910
+ error,
37911
+ });
37912
+ }
37913
+ applyFilter(data) {
37914
+ let comments = data;
37915
+ if (this.query.includeDeleted) {
37916
+ comments = filterByPropEquality(comments, 'isDeleted', false);
37917
+ }
37918
+ if (this.query.parentId) {
37919
+ comments = comments.filter(comment => comment.parentId === this.query.parentId);
37920
+ }
37921
+ switch (this.query.sortBy) {
37922
+ case 'firstCreated':
37923
+ comments = comments.sort(sortByFirstCreated);
37924
+ break;
37925
+ case 'lastCreated':
37926
+ default:
37927
+ comments = comments.sort(sortByLastCreated);
37928
+ break;
37929
+ }
37930
+ return comments;
37931
+ }
37932
+ }
37742
37933
 
37743
37934
  /* begin_public_function
37744
37935
  id: comment.query
@@ -37770,82 +37961,9 @@ const getComments = (params, callback, config) => {
37770
37961
  }
37771
37962
  const timestamp = Date.now();
37772
37963
  log(`getComments(tmpid: ${timestamp}) > listen`);
37773
- const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
37774
- const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
37775
- const disposers = [];
37776
- const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
37777
- const cacheKey = [
37778
- 'comment',
37779
- 'collection',
37780
- {
37781
- referenceId: params.referenceType,
37782
- referenceType: params.referenceId,
37783
- parentId: (params === null || params === void 0 ? void 0 : params.parentId) || '',
37784
- sortBy,
37785
- },
37786
- ];
37787
- const responder = (data) => {
37788
- var _a, _b;
37789
- let comments = (_a = data.data
37790
- .map(commentId => pullFromCache(['comment', 'get', commentId]))
37791
- .filter(({ data }) => data.parentId === (params === null || params === void 0 ? void 0 : params.parentId))
37792
- .filter(Boolean)
37793
- .map(({ data }) => LinkedObject.comment(data))) !== null && _a !== void 0 ? _a : [];
37794
- if (!params.includeDeleted) {
37795
- comments = filterByPropEquality(comments, 'isDeleted', false);
37796
- }
37797
- comments = comments.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
37798
- callback({
37799
- onNextPage: onFetch,
37800
- data: comments,
37801
- hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
37802
- loading: data.loading,
37803
- error: data.error,
37804
- });
37805
- };
37806
- const realtimeRouter = (action) => (comment) => {
37807
- var _a;
37808
- const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
37809
- if (params.referenceId !== comment.referenceId ||
37810
- params.referenceType !== comment.referenceType ||
37811
- !collection) {
37812
- return;
37813
- }
37814
- if (action === 'onCreate') {
37815
- collection.data = [...new Set([comment.commentId, ...collection.data])];
37816
- }
37817
- else if (action === 'onDelete') {
37818
- collection.data = collection.data.filter(p => p !== comment.commentId);
37819
- }
37820
- pushToCache(cacheKey, collection);
37821
- responder(collection);
37822
- };
37823
- const onFetch = (initial = false) => {
37824
- var _a, _b, _c;
37825
- const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
37826
- const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
37827
- if (!initial && comments.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
37828
- return;
37829
- const query = createQuery(queryComments, Object.assign(Object.assign({}, queryParams), { limit: queryLimit, page: !initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined }));
37830
- runQuery(query, ({ data: result, error, loading, paging }) => {
37831
- const page = paging === null || paging === void 0 ? void 0 : paging.next;
37832
- const data = {
37833
- loading,
37834
- error,
37835
- params: { page },
37836
- data: comments,
37837
- };
37838
- if (result) {
37839
- data.data = initial
37840
- ? result.map(getResolver('comment')) // Replace a collection list with new data from BE
37841
- : [...new Set([...comments, ...result.map(getResolver('comment'))])];
37842
- }
37843
- pushToCache(cacheKey, data);
37844
- responder(data);
37845
- }, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
37846
- };
37847
- disposers.push(onCommentCreated(realtimeRouter('onCreate')), onCommentUpdated(realtimeRouter('onUpdate')), onCommentDeleted(realtimeRouter('onDelete')), onCommentFlagged(realtimeRouter('onFlagged')), onCommentUnflagged(realtimeRouter('onUnflagged')), onCommentReactionAdded(realtimeRouter('onReactionAdded')), onCommentReactionRemoved(realtimeRouter('onReactionRemoved')));
37848
- onFetch(true);
37964
+ const commentsLiveCollection = new CommentLiveCollectionController(params, callback);
37965
+ const disposers = commentsLiveCollection.startSubscription();
37966
+ const cacheKey = commentsLiveCollection.getCacheKey();
37849
37967
  disposers.push(() => dropFromCache(cacheKey));
37850
37968
  return () => {
37851
37969
  log(`getComments(tmpid: ${timestamp}) > dispose`);
@@ -37854,7 +37972,7 @@ const getComments = (params, callback, config) => {
37854
37972
  };
37855
37973
  /* end_public_function */
37856
37974
 
37857
- var index$5 = /*#__PURE__*/Object.freeze({
37975
+ var index$6 = /*#__PURE__*/Object.freeze({
37858
37976
  __proto__: null,
37859
37977
  getCommentByIds: getCommentByIds,
37860
37978
  createComment: createComment,
@@ -38167,7 +38285,7 @@ const getPosts = (params, callback, config) => {
38167
38285
  };
38168
38286
  /* end_public_function */
38169
38287
 
38170
- var index$4 = /*#__PURE__*/Object.freeze({
38288
+ var index$5 = /*#__PURE__*/Object.freeze({
38171
38289
  __proto__: null,
38172
38290
  getPostByIds: getPostByIds,
38173
38291
  createPost: createPost,
@@ -38737,7 +38855,7 @@ const getStreams = (params, callback, config) => {
38737
38855
  };
38738
38856
  /* end_public_function */
38739
38857
 
38740
- var index$3 = /*#__PURE__*/Object.freeze({
38858
+ var index$4 = /*#__PURE__*/Object.freeze({
38741
38859
  __proto__: null,
38742
38860
  createStream: createStream,
38743
38861
  updateStream: updateStream,
@@ -39070,7 +39188,7 @@ const getPoll = (pollId, callback) => {
39070
39188
  };
39071
39189
  /* end_public_function */
39072
39190
 
39073
- var index$2 = /*#__PURE__*/Object.freeze({
39191
+ var index$3 = /*#__PURE__*/Object.freeze({
39074
39192
  __proto__: null,
39075
39193
  createPoll: createPoll,
39076
39194
  closePoll: closePoll,
@@ -39442,7 +39560,7 @@ const getPlayer = async (parameters) => {
39442
39560
  return video;
39443
39561
  };
39444
39562
 
39445
- var index$1 = /*#__PURE__*/Object.freeze({
39563
+ var index$2 = /*#__PURE__*/Object.freeze({
39446
39564
  __proto__: null,
39447
39565
  getPlayer: getPlayer
39448
39566
  });
@@ -40515,7 +40633,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
40515
40633
  };
40516
40634
  };
40517
40635
 
40518
- var index = /*#__PURE__*/Object.freeze({
40636
+ var index$1 = /*#__PURE__*/Object.freeze({
40519
40637
  __proto__: null,
40520
40638
  createImageStory: createImageStory,
40521
40639
  createVideoStory: createVideoStory,
@@ -40529,6 +40647,27 @@ var index = /*#__PURE__*/Object.freeze({
40529
40647
  getGlobalStoryTargets: getGlobalStoryTargets
40530
40648
  });
40531
40649
 
40650
+ const convertToNetworkAds = (data) => {
40651
+ const { ads, settings } = data;
40652
+ return {
40653
+ ads: ads.map(LinkedObject.ad),
40654
+ settings,
40655
+ };
40656
+ };
40657
+ const getNetworkAds = async () => {
40658
+ const client = getActiveClient();
40659
+ const { data } = await client.http.get('/api/v1/ads/me');
40660
+ const { settings } = data, rest = __rest(data, ["settings"]);
40661
+ ingestInCache(rest);
40662
+ pushToCache(['ad', 'setting'], settings);
40663
+ return convertToNetworkAds(data);
40664
+ };
40665
+
40666
+ var index = /*#__PURE__*/Object.freeze({
40667
+ __proto__: null,
40668
+ getNetworkAds: getNetworkAds
40669
+ });
40670
+
40532
40671
  /**
40533
40672
  * Retrieves accessToken info to use in Beta services
40534
40673
  *
@@ -40551,4 +40690,4 @@ const createUserToken = async (apiKey, apiRegion, params) => {
40551
40690
  return { accessToken: data.accessToken };
40552
40691
  };
40553
40692
 
40554
- export { API_REGIONS, index$7 as CategoryRepository, index$b as ChannelRepository, index$k as Client, index$5 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$8 as CommunityRepository, ContentFeedType, DefaultCommunityPostSetting, index$6 as FeedRepository, index$h as FileRepository, FileType, index$1 as LiveStreamPlayer, MessageContentType, index$f as MessageRepository, index$2 as PollRepository, PostContentType, index$4 as PostRepository, index$g as ReactionRepository, index as StoryRepository, index$3 as StreamRepository, index$e as SubChannelRepository, SubscriptionLevels, index$i as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
40693
+ export { API_REGIONS, index as AdRepository, index$8 as CategoryRepository, index$c as ChannelRepository, index$l as Client, index$6 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$9 as CommunityRepository, ContentFeedType, DefaultCommunityPostSetting, index$7 as FeedRepository, index$i as FileRepository, FileType, index$2 as LiveStreamPlayer, MessageContentType, index$g as MessageRepository, index$3 as PollRepository, PostContentType, index$5 as PostRepository, index$h as ReactionRepository, index$1 as StoryRepository, index$4 as StreamRepository, index$f as SubChannelRepository, SubscriptionLevels, index$j as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };