@amityco/ts-sdk-react-native 6.26.4-2eb3673.0 → 6.27.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 (42) hide show
  1. package/.env +26 -26
  2. package/dist/@types/core/model.d.ts +5 -5
  3. package/dist/@types/core/model.d.ts.map +1 -1
  4. package/dist/@types/domains/ad.d.ts +14 -2
  5. package/dist/@types/domains/ad.d.ts.map +1 -1
  6. package/dist/@types/domains/message.d.ts +4 -1
  7. package/dist/@types/domains/message.d.ts.map +1 -1
  8. package/dist/adRepository/api/getNetworkAds.d.ts.map +1 -1
  9. package/dist/analytic/service/analytic/AnalyticsEngine.d.ts +2 -2
  10. package/dist/analytic/service/analytic/AnalyticsEngine.d.ts.map +1 -1
  11. package/dist/analytic/service/analytic/AnalyticsEventCapturer.d.ts +11 -5
  12. package/dist/analytic/service/analytic/AnalyticsEventCapturer.d.ts.map +1 -1
  13. package/dist/index.cjs.js +284 -265
  14. package/dist/index.esm.js +284 -265
  15. package/dist/index.umd.js +2 -2
  16. package/dist/messageRepository/api/createMessage.d.ts +7 -25
  17. package/dist/messageRepository/api/createMessage.d.ts.map +1 -1
  18. package/dist/messageRepository/events/onMessageCreated.d.ts.map +1 -1
  19. package/dist/messageRepository/observers/getMessages/MessageLiveCollectionController.d.ts +4 -4
  20. package/dist/messageRepository/observers/getMessages/MessageLiveCollectionController.d.ts.map +1 -1
  21. package/dist/messageRepository/observers/getMessages/MessageQueryStreamController.d.ts.map +1 -1
  22. package/dist/messageRepository/utils/prepareMessagePayload.d.ts.map +1 -1
  23. package/dist/postRepository/observers/getPost.d.ts.map +1 -1
  24. package/dist/utils/linkedObject/adLinkedObject.d.ts +1 -1
  25. package/dist/utils/linkedObject/adLinkedObject.d.ts.map +1 -1
  26. package/dist/utils/linkedObject/index.d.ts +1 -1
  27. package/package.json +1 -1
  28. package/src/@types/core/model.ts +5 -5
  29. package/src/@types/domains/ad.ts +17 -6
  30. package/src/@types/domains/message.ts +6 -1
  31. package/src/adRepository/api/getNetworkAds.ts +22 -8
  32. package/src/analytic/service/analytic/AnalyticsEngine.ts +2 -2
  33. package/src/analytic/service/analytic/AnalyticsEventCapturer.ts +45 -27
  34. package/src/core/model/idResolvers.ts +1 -1
  35. package/src/messageRepository/api/createMessage.ts +83 -98
  36. package/src/messageRepository/events/onMessageCreated.ts +12 -6
  37. package/src/messageRepository/observers/getMessages/MessageLiveCollectionController.ts +26 -24
  38. package/src/messageRepository/observers/getMessages/MessageQueryStreamController.ts +3 -2
  39. package/src/messageRepository/observers/observeMessages.ts +3 -3
  40. package/src/messageRepository/utils/prepareMessagePayload.ts +1 -1
  41. package/src/postRepository/observers/getPost.ts +8 -1
  42. package/src/utils/linkedObject/adLinkedObject.ts +11 -11
package/dist/index.cjs.js CHANGED
@@ -118,8 +118,8 @@ const PostContentType = Object.freeze({
118
118
 
119
119
  function getVersion() {
120
120
  try {
121
- // the string ''v6.26.3-cjs'' should be replaced by actual value by @rollup/plugin-replace
122
- return 'v6.26.3-cjs';
121
+ // the string ''v6.27.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
122
+ return 'v6.27.0-cjs';
123
123
  }
124
124
  catch (error) {
125
125
  return '__dev__';
@@ -527,7 +527,7 @@ const idResolvers = {
527
527
  channel: ({ channelInternalId }) => channelInternalId,
528
528
  subChannel: ({ subChannelId }) => subChannelId,
529
529
  channelUsers: ({ channelId, userId }) => `${channelId}#${userId}`,
530
- message: ({ messageId }) => messageId,
530
+ message: ({ messageId, referenceId }) => referenceId !== null && referenceId !== void 0 ? referenceId : messageId,
531
531
  messagePreviewChannel: ({ channelId }) => `${channelId}`,
532
532
  messagePreviewSubChannel: ({ subChannelId }) => `${subChannelId}`,
533
533
  channelUnreadInfo: ({ channelId }) => channelId,
@@ -4899,12 +4899,12 @@ class AnalyticsEventCapturer {
4899
4899
  this._throttleStoryTimer = undefined;
4900
4900
  this._bufferNewSeenStoryReferenceIds = [];
4901
4901
  }
4902
- isAbleToEnqueue({ itemId, expireTime, isHighPriority = false, }) {
4902
+ isAbleToEnqueue({ uniqueId, expireTime, isHighPriority = false, }) {
4903
4903
  const now = new Date();
4904
4904
  const getRecentViewedDate = () => {
4905
4905
  if (isHighPriority)
4906
- return this._recentHighPriorityViewed[itemId];
4907
- return this._recentViewed[itemId];
4906
+ return this._recentHighPriorityViewed[uniqueId];
4907
+ return this._recentViewed[uniqueId];
4908
4908
  };
4909
4909
  const recentViewedDate = getRecentViewedDate() || new Date(DAY * -1);
4910
4910
  const timeDiff = now.getTime() - recentViewedDate.getTime();
@@ -4914,8 +4914,8 @@ class AnalyticsEventCapturer {
4914
4914
  }
4915
4915
  return true;
4916
4916
  }
4917
- markAs(itemId, contentType, activityType, metadata = undefined) {
4918
- if (!this.isAbleToEnqueue({ itemId, expireTime: this._expireTime }))
4917
+ markAs({ uniqueId, contentId, contentType, activityType, metadata, }) {
4918
+ if (!this.isAbleToEnqueue({ uniqueId, expireTime: this._expireTime }))
4919
4919
  return;
4920
4920
  const now = new Date();
4921
4921
  const currentData = { event: [] };
@@ -4929,7 +4929,7 @@ class AnalyticsEventCapturer {
4929
4929
  currentData.event.shift();
4930
4930
  }
4931
4931
  const analyticItem = {
4932
- contentId: itemId,
4932
+ contentId,
4933
4933
  contentType,
4934
4934
  activityType,
4935
4935
  timestamp: now.toISOString(),
@@ -4939,10 +4939,15 @@ class AnalyticsEventCapturer {
4939
4939
  }
4940
4940
  currentData.event.push(analyticItem);
4941
4941
  upsertInCache(ANALYTIC_CACHE_KEY, currentData);
4942
- this._recentViewed[itemId] = now;
4942
+ this._recentViewed[uniqueId] = now;
4943
4943
  }
4944
4944
  markPostAsViewed(postId) {
4945
- this.markAs(postId, "post" /* Amity.AnalyticEventContentType.Post */, "view" /* Amity.AnalyticEventActivityType.View */);
4945
+ this.markAs({
4946
+ uniqueId: postId,
4947
+ contentId: postId,
4948
+ contentType: "post" /* Amity.AnalyticEventContentType.Post */,
4949
+ activityType: "view" /* Amity.AnalyticEventActivityType.View */,
4950
+ });
4946
4951
  }
4947
4952
  markStory(story, activityType) {
4948
4953
  if (!story.expiresAt)
@@ -4950,7 +4955,7 @@ class AnalyticsEventCapturer {
4950
4955
  const now = new Date();
4951
4956
  const expireTime = new Date(story.expiresAt);
4952
4957
  if (!this.isAbleToEnqueue({
4953
- itemId: story.storyId,
4958
+ uniqueId: story.storyId,
4954
4959
  expireTime: expireTime.getTime(),
4955
4960
  isHighPriority: true,
4956
4961
  }))
@@ -5016,13 +5021,27 @@ class AnalyticsEventCapturer {
5016
5021
  const metadata = {
5017
5022
  placement,
5018
5023
  };
5019
- this.markAs(`${ad.adId}.${"view" /* Amity.AnalyticEventActivityType.View */}.${placement}`, "ad" /* Amity.AnalyticEventContentType.Ad */, "view" /* Amity.AnalyticEventActivityType.View */, metadata);
5024
+ const activityType = "view" /* Amity.AnalyticEventActivityType.View */;
5025
+ this.markAs({
5026
+ uniqueId: `${ad.adId}.${activityType}.${placement}`,
5027
+ contentId: ad.adId,
5028
+ contentType: "ad" /* Amity.AnalyticEventContentType.Ad */,
5029
+ activityType,
5030
+ metadata,
5031
+ });
5020
5032
  }
5021
5033
  markAdAsClicked(ad, placement) {
5022
5034
  const metadata = {
5023
5035
  placement,
5024
5036
  };
5025
- this.markAs(`${ad.adId}.${"view" /* Amity.AnalyticEventActivityType.View */}.${placement}`, "ad" /* Amity.AnalyticEventContentType.Ad */, "linkClicked" /* Amity.AnalyticEventActivityType.Click */, metadata);
5037
+ const activityType = "linkClicked" /* Amity.AnalyticEventActivityType.Click */;
5038
+ this.markAs({
5039
+ uniqueId: `${ad.adId}.${activityType}.${placement}`,
5040
+ contentId: ad.adId,
5041
+ contentType: "ad" /* Amity.AnalyticEventContentType.Ad */,
5042
+ activityType,
5043
+ metadata,
5044
+ });
5026
5045
  }
5027
5046
  }
5028
5047
 
@@ -5789,20 +5808,17 @@ const channelLinkedObject = (channel) => {
5789
5808
  return Object.assign(Object.assign({}, channel), { markAsRead: () => markAsRead(channel.channelInternalId) });
5790
5809
  };
5791
5810
 
5792
- // import AnalyticsEngine from '~/analytic/service/analytic/AnalyticsEngine';
5793
5811
  const adLinkedObject = (ad) => {
5794
- // const analyticsEngineInstance = AnalyticsEngine.getInstance();
5812
+ const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
5795
5813
  const { image9_16: image916, image1_1: image11 } = ad, restAds = __rest(ad, ["image9_16", "image1_1"]);
5796
- return Object.assign(Object.assign({}, restAds), {
5797
- // analytics: {
5798
- // markAsSeen: (placement: Amity.AdPlacement) => {
5799
- // analyticsEngineInstance.markAdAsViewed(ad, placement);
5800
- // },
5801
- // markLinkAsClicked: (placement: Amity.AdPlacement) => {
5802
- // analyticsEngineInstance.markAdAsClicked(ad, placement);
5803
- // },
5804
- // },
5805
- get advertiser() {
5814
+ return Object.assign(Object.assign({}, restAds), { analytics: {
5815
+ markAsSeen: (placement) => {
5816
+ analyticsEngineInstance.markAdAsViewed(ad, placement);
5817
+ },
5818
+ markLinkAsClicked: (placement) => {
5819
+ analyticsEngineInstance.markAdAsClicked(ad, placement);
5820
+ },
5821
+ }, get advertiser() {
5806
5822
  var _a, _b;
5807
5823
  const advertiserData = (_a = pullFromCache([
5808
5824
  'advertiser',
@@ -6690,7 +6706,7 @@ function convertFromRaw(message, reactors, event) {
6690
6706
  *
6691
6707
  * Check git blame for previous iteration
6692
6708
  */
6693
- myReactions: myReactions || ((_a = cache === null || cache === void 0 ? void 0 : cache.data.myReactions) !== null && _a !== void 0 ? _a : []), reactionsCount: reactionCount, subChannelId: messageFeedId, uniqueId: cache ? cache.data.uniqueId : messageId, referenceId });
6709
+ myReactions: myReactions || ((_a = cache === null || cache === void 0 ? void 0 : cache.data.myReactions) !== null && _a !== void 0 ? _a : []), reactionsCount: reactionCount, subChannelId: messageFeedId, uniqueId: cache ? cache.data.uniqueId : messageId, referenceId, syncState: "synced" /* Amity.SyncState.Synced */ });
6694
6710
  if (mentionedUsers) {
6695
6711
  out.mentionees = mentionedUsers.map(mention => {
6696
6712
  if (mention.type === 'channel') {
@@ -8520,9 +8536,12 @@ const onMessageCreatedMqtt = (callback) => {
8520
8536
  const onMessageCreatedLocal = (callback) => {
8521
8537
  const client = getActiveClient();
8522
8538
  const disposers = [
8523
- createEventSubscriber(client, 'message/onMessageCreated', 'local.message.created', payload => payload.messages.forEach(message => {
8524
- callback(message);
8525
- })),
8539
+ createEventSubscriber(client, 'message/onMessageCreated', 'local.message.created', async (payload) => {
8540
+ ingestInCache(payload);
8541
+ return payload.messages.forEach(message => {
8542
+ callback(message);
8543
+ });
8544
+ }),
8526
8545
  ];
8527
8546
  return () => {
8528
8547
  disposers.forEach(fn => fn());
@@ -14605,9 +14624,40 @@ getMessages$1.locally = (messageIds) => {
14605
14624
  const getLocalId = () => `LOCAL_${uuid()}`;
14606
14625
  // FIXME: temp solution
14607
14626
  let uniqueId;
14608
- /* begin_public_function
14609
- id: message.create.text_message, message.create.image_message, message.create.file_message, message.create.video_message, message.create.audio_message, message.create.custom_message
14610
- */
14627
+ const createMessageOptimistic = (bundle) => {
14628
+ var _a, _b;
14629
+ const client = getActiveClient();
14630
+ if (!client.cache)
14631
+ return;
14632
+ /*
14633
+ * When creating messages optimistically a messageId needs to be added by the
14634
+ * client, created a new variable to allow backward compatibility of API
14635
+ *
14636
+ * Updated to handle client requirement to add messageId while uploading
14637
+ * a message with image.
14638
+ * Temporary!
14639
+ */
14640
+ uniqueId = bundle.referenceId || getLocalId();
14641
+ const bundleWithMessageId = Object.assign({ messageId: uniqueId, uniqueId }, bundle);
14642
+ client.log('message/createMessage.optimistically', bundleWithMessageId);
14643
+ const subChannel = pullFromCache(['subChannel', 'get', bundle.subChannelId]);
14644
+ if (subChannel) {
14645
+ upsertInCache(['subChannel', 'get', bundle.subChannelId], Object.assign(Object.assign({}, subChannel.data), { messageCount: subChannel.data.messageCount + 1 }));
14646
+ if (subChannel.data.channelId === subChannel.data.subChannelId) {
14647
+ const channel = pullFromCache(['channel', 'get', subChannel.data.channelId]);
14648
+ if (channel === null || channel === void 0 ? void 0 : channel.data) {
14649
+ upsertInCache(['channel', 'get', subChannel.data.channelId], Object.assign(Object.assign({}, channel.data), { messageCount: ((_a = channel.data.messageCount) !== null && _a !== void 0 ? _a : 0) + 1 }));
14650
+ }
14651
+ }
14652
+ }
14653
+ // as reused to update created and updated time, which should be the same
14654
+ const createdTime = new Date().toISOString();
14655
+ const message = Object.assign({ creatorId: client.userId, creatorPrivateId: getActiveUser()._id, channelSegment: ((_b = subChannel === null || subChannel === void 0 ? void 0 : subChannel.data.messageCount) !== null && _b !== void 0 ? _b : 0) + 1, childrenNumber: 0, createdAt: createdTime, updatedAt: createdTime, syncState: "syncing" /* Amity.SyncState.Syncing */, isDeleted: false }, bundleWithMessageId);
14656
+ const cachedAt = UNSYNCED_OBJECT_CACHED_AT_VALUE;
14657
+ pushToCache(['message', 'get', message.messageId], message, { cachedAt });
14658
+ fireEvent('local.message.created', { messages: [message] });
14659
+ return message;
14660
+ };
14611
14661
  /**
14612
14662
  * ```js
14613
14663
  * import { createMessage, createQuery, runQuery } from '@amityco/ts-sdk-react-native'
@@ -14633,75 +14683,31 @@ let uniqueId;
14633
14683
  const createMessage = async (bundle) => {
14634
14684
  const client = getActiveClient();
14635
14685
  client.log('message/createMessage', bundle);
14686
+ const optimisticData = createMessageOptimistic(bundle);
14636
14687
  const referenceId = bundle.referenceId || uniqueId || getLocalId();
14637
14688
  uniqueId = undefined;
14638
- const { data: payload } = await client.http.post('/api/v5/messages', Object.assign(Object.assign({}, convertParams(bundle)), { referenceId }));
14639
- const data = await prepareMessagePayload(payload);
14640
- const { messages } = data;
14641
- const cachedAt = client.cache && Date.now();
14642
- if (client.cache) {
14643
- dropFromCache(['message', 'get', referenceId]);
14644
- ingestInCache(data, { cachedAt });
14645
- }
14646
- fireEvent('local.message.created', { messages });
14647
- return {
14648
- data: LinkedObject.message(messages[0]),
14649
- cachedAt,
14650
- };
14651
- };
14652
- /**
14653
- * ```js
14654
- * import { createMessage } from '@amityco/ts-sdk-react-native'
14655
- *
14656
- * const created = createMessage.optimistically({
14657
- * channelId: 'foobar',
14658
- * data: { text: 'hello world' }
14659
- * })
14660
- * ```
14661
- *
14662
- * Creates an {@link Amity.Message} in cache
14663
- *
14664
- * @param bundle The data necessary to create a new {@link Amity.Message}
14665
- * @returns The newly created {@link Amity.Message}
14666
- *
14667
- * @category Message API
14668
- */
14669
- createMessage.optimistically = (_a) => {
14670
- var _b, _c;
14671
- var { referenceId } = _a, bundle = __rest(_a, ["referenceId"]);
14672
- const client = getActiveClient();
14673
- if (!client.cache)
14674
- return;
14675
- /*
14676
- * when creating messages optimistically a messageId needs to be added by the
14677
- * client, created a new variable so as to allow backward compatibility of API
14678
- *
14679
- * Updated to handle client requirement to add messageId while uploading
14680
- * message with image. Temporary!
14681
- */
14682
- uniqueId = referenceId || getLocalId();
14683
- const bundleWithMessageId = Object.assign({ messageId: uniqueId, uniqueId }, bundle);
14684
- client.log('message/createMessage.optimistically', bundleWithMessageId);
14685
- const subChannel = pullFromCache(['subChannel', 'get', bundle.subChannelId]);
14686
- if (subChannel) {
14687
- upsertInCache(['subChannel', 'get', bundle.subChannelId], Object.assign(Object.assign({}, subChannel.data), { messageCount: subChannel.data.messageCount + 1 }));
14688
- if (subChannel.data.channelId === subChannel.data.subChannelId) {
14689
- const channel = pullFromCache(['channel', 'get', subChannel.data.channelId]);
14690
- if (channel === null || channel === void 0 ? void 0 : channel.data) {
14691
- upsertInCache(['channel', 'get', subChannel.data.channelId], Object.assign(Object.assign({}, channel.data), { messageCount: ((_b = channel.data.messageCount) !== null && _b !== void 0 ? _b : 0) + 1 }));
14692
- }
14689
+ try {
14690
+ const { data: payload } = await client.http.post('/api/v5/messages', Object.assign(Object.assign({}, convertParams(bundle)), { referenceId }));
14691
+ const data = await prepareMessagePayload(payload);
14692
+ const { messages } = data;
14693
+ const cachedAt = client.cache && Date.now();
14694
+ if (client.cache) {
14695
+ ingestInCache(data, { cachedAt });
14693
14696
  }
14697
+ fireEvent('local.message.created', {
14698
+ messages: [Object.assign(Object.assign({}, messages[0]), { syncState: "synced" /* Amity.SyncState.Synced */ })],
14699
+ });
14700
+ return {
14701
+ data: LinkedObject.message(messages[0]),
14702
+ cachedAt,
14703
+ };
14704
+ }
14705
+ catch (e) {
14706
+ fireEvent('local.message.created', {
14707
+ messages: [Object.assign(Object.assign({}, optimisticData), { syncState: "error" /* Amity.SyncState.Error */ })],
14708
+ });
14709
+ throw e;
14694
14710
  }
14695
- // as reused to update created and updated time, which should be the same
14696
- const createdTime = new Date().toISOString();
14697
- const message = Object.assign({ creatorId: client.userId, creatorPrivateId: getActiveUser()._id, channelSegment: ((_c = subChannel === null || subChannel === void 0 ? void 0 : subChannel.data.messageCount) !== null && _c !== void 0 ? _c : 0) + 1, childrenNumber: 0, createdAt: createdTime, updatedAt: createdTime }, bundleWithMessageId);
14698
- const cachedAt = UNSYNCED_OBJECT_CACHED_AT_VALUE;
14699
- pushToCache(['message', 'get', message.messageId], message, { cachedAt });
14700
- fireEvent('local.message.created', { messages: [message] });
14701
- return {
14702
- cachedAt,
14703
- data: LinkedObject.message(message),
14704
- };
14705
14711
  };
14706
14712
  /* end_public_function */
14707
14713
 
@@ -15414,67 +15420,106 @@ const getMessage$1 = (messageId, callback) => {
15414
15420
  };
15415
15421
  /* end_public_function */
15416
15422
 
15417
- class PaginationController {
15423
+ class PaginationNoPageController {
15418
15424
  constructor(queryParams) {
15419
15425
  const { http } = getActiveClient();
15420
15426
  this.queryParams = queryParams;
15421
15427
  this.http = http;
15422
15428
  }
15423
- loadFirstPage() {
15424
- return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
15429
+ async onFetch() {
15430
+ const queryResponse = await this.getRequest(this.queryParams);
15431
+ return queryResponse;
15425
15432
  }
15426
- loadNextPage() {
15427
- return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
15433
+ }
15434
+
15435
+ class LiveCollectionController {
15436
+ constructor(paginationController, queryStreamId, cacheKey, callback) {
15437
+ this.paginationController = paginationController;
15438
+ this.queryStreamId = queryStreamId;
15439
+ this.cacheKey = cacheKey;
15440
+ this.callback = callback;
15428
15441
  }
15429
- loadPreviousPage() {
15430
- return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
15442
+ async refresh() {
15443
+ try {
15444
+ let result;
15445
+ if (this.paginationController instanceof PaginationNoPageController) {
15446
+ result = await this.paginationController.onFetch();
15447
+ }
15448
+ else {
15449
+ result = await this.paginationController.loadFirstPage();
15450
+ }
15451
+ if (!result)
15452
+ return;
15453
+ await this.persistModel(result);
15454
+ this.persistQueryStream({
15455
+ response: result,
15456
+ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
15457
+ refresh: true,
15458
+ });
15459
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
15460
+ }
15461
+ catch (e) {
15462
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
15463
+ }
15431
15464
  }
15432
- async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
15433
- var _a, _b, _c, _d;
15434
- if (direction === 'prev' && !this.previousToken)
15435
- return;
15436
- if (direction === 'next' && !this.nextToken)
15437
- return;
15438
- let token;
15439
- if (direction === 'prev')
15440
- token = this.previousToken;
15441
- if (direction === 'next')
15442
- token = this.nextToken;
15443
- const queryResponse = await this.getRequest(this.queryParams, token);
15444
- if (direction === 'first') {
15445
- this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
15446
- this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
15465
+ loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
15466
+ this.setup();
15467
+ this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
15468
+ if (initial) {
15469
+ this.refresh();
15470
+ }
15471
+ else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
15472
+ this.loadPrevPage();
15473
+ }
15474
+ else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
15475
+ this.loadNextPage();
15447
15476
  }
15448
- if (direction === 'prev')
15449
- this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
15450
- if (direction === 'next')
15451
- this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
15452
- return queryResponse;
15453
15477
  }
15454
- getNextToken() {
15455
- return this.nextToken;
15478
+ async loadNextPage() {
15479
+ try {
15480
+ if (this.paginationController instanceof PaginationNoPageController)
15481
+ return;
15482
+ const result = await this.paginationController.loadNextPage();
15483
+ if (!result)
15484
+ return;
15485
+ await this.persistModel(result);
15486
+ this.persistQueryStream({
15487
+ response: result,
15488
+ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
15489
+ });
15490
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
15491
+ }
15492
+ catch (e) {
15493
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
15494
+ }
15456
15495
  }
15457
- getPrevToken() {
15458
- return this.previousToken;
15496
+ async loadPrevPage() {
15497
+ try {
15498
+ if (this.paginationController instanceof PaginationNoPageController)
15499
+ return;
15500
+ const result = await this.paginationController.loadPreviousPage();
15501
+ if (!result)
15502
+ return;
15503
+ await this.persistModel(result);
15504
+ this.persistQueryStream({
15505
+ response: result,
15506
+ direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
15507
+ });
15508
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
15509
+ }
15510
+ catch (e) {
15511
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
15512
+ }
15459
15513
  }
15460
- }
15461
-
15462
- /* eslint-disable no-use-before-define */
15463
- /**
15464
- * TODO: handle cache receive cache option, and cache policy
15465
- * TODO: check if querybyIds is supported
15466
- */
15467
- class MessagePaginationController extends PaginationController {
15468
- async getRequest(queryParams, token) {
15469
- const processedQueryParams = convertQueryParams$1(queryParams);
15470
- const { data: queryResponse } = await this.http.get(`/api/v5/messages`, {
15471
- params: Object.assign(Object.assign({}, processedQueryParams), { options: token
15472
- ? {
15473
- token,
15474
- }
15475
- : Object.assign({}, processedQueryParams.options) }),
15476
- });
15477
- return queryResponse;
15514
+ shouldNotify(data) {
15515
+ const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
15516
+ if (isEqual(this.snapshot, newData))
15517
+ return false;
15518
+ this.snapshot = newData;
15519
+ return true;
15520
+ }
15521
+ getCacheKey() {
15522
+ return this.cacheKey;
15478
15523
  }
15479
15524
  }
15480
15525
 
@@ -15522,6 +15567,7 @@ class MessageQueryStreamController extends QueryStreamController {
15522
15567
  var _a, _b, _c, _d, _e;
15523
15568
  if (action === 'onCreate') {
15524
15569
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
15570
+ const { referenceId } = payload;
15525
15571
  if (!collection)
15526
15572
  return;
15527
15573
  if (this.query.subChannelId !== (payload === null || payload === void 0 ? void 0 : payload.subChannelId) || !collection)
@@ -15551,10 +15597,10 @@ class MessageQueryStreamController extends QueryStreamController {
15551
15597
  return;
15552
15598
  if ((!this.query.sortBy || this.query.sortBy === 'segmentDesc') &&
15553
15599
  !this.paginationController.getPrevToken()) {
15554
- collection.data = [...new Set([payload.messageId, ...collection.data])];
15600
+ collection.data = [...new Set([referenceId !== null && referenceId !== void 0 ? referenceId : payload.messageId, ...collection.data])];
15555
15601
  }
15556
15602
  if (this.query.sortBy === 'segmentAsc' && !this.paginationController.getNextToken()) {
15557
- collection.data = [...new Set([...collection.data, payload.messageId])];
15603
+ collection.data = [...new Set([...collection.data, referenceId !== null && referenceId !== void 0 ? referenceId : payload.messageId])];
15558
15604
  }
15559
15605
  pushToCache(this.cacheKey, collection);
15560
15606
  }
@@ -15566,106 +15612,67 @@ class MessageQueryStreamController extends QueryStreamController {
15566
15612
  }
15567
15613
  }
15568
15614
 
15569
- class PaginationNoPageController {
15615
+ class PaginationController {
15570
15616
  constructor(queryParams) {
15571
15617
  const { http } = getActiveClient();
15572
15618
  this.queryParams = queryParams;
15573
15619
  this.http = http;
15574
15620
  }
15575
- async onFetch() {
15576
- const queryResponse = await this.getRequest(this.queryParams);
15577
- return queryResponse;
15578
- }
15579
- }
15580
-
15581
- class LiveCollectionController {
15582
- constructor(paginationController, queryStreamId, cacheKey, callback) {
15583
- this.paginationController = paginationController;
15584
- this.queryStreamId = queryStreamId;
15585
- this.cacheKey = cacheKey;
15586
- this.callback = callback;
15621
+ loadFirstPage() {
15622
+ return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
15587
15623
  }
15588
- async refresh() {
15589
- try {
15590
- let result;
15591
- if (this.paginationController instanceof PaginationNoPageController) {
15592
- result = await this.paginationController.onFetch();
15593
- }
15594
- else {
15595
- result = await this.paginationController.loadFirstPage();
15596
- }
15597
- if (!result)
15598
- return;
15599
- await this.persistModel(result);
15600
- this.persistQueryStream({
15601
- response: result,
15602
- direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
15603
- refresh: true,
15604
- });
15605
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
15606
- }
15607
- catch (e) {
15608
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
15609
- }
15624
+ loadNextPage() {
15625
+ return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
15610
15626
  }
15611
- loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
15612
- this.setup();
15613
- this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
15614
- if (initial) {
15615
- this.refresh();
15616
- }
15617
- else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
15618
- this.loadPrevPage();
15619
- }
15620
- else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
15621
- this.loadNextPage();
15622
- }
15627
+ loadPreviousPage() {
15628
+ return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
15623
15629
  }
15624
- async loadNextPage() {
15625
- try {
15626
- if (this.paginationController instanceof PaginationNoPageController)
15627
- return;
15628
- const result = await this.paginationController.loadNextPage();
15629
- if (!result)
15630
- return;
15631
- await this.persistModel(result);
15632
- this.persistQueryStream({
15633
- response: result,
15634
- direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
15635
- });
15636
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
15637
- }
15638
- catch (e) {
15639
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
15630
+ async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
15631
+ var _a, _b, _c, _d;
15632
+ if (direction === 'prev' && !this.previousToken)
15633
+ return;
15634
+ if (direction === 'next' && !this.nextToken)
15635
+ return;
15636
+ let token;
15637
+ if (direction === 'prev')
15638
+ token = this.previousToken;
15639
+ if (direction === 'next')
15640
+ token = this.nextToken;
15641
+ const queryResponse = await this.getRequest(this.queryParams, token);
15642
+ if (direction === 'first') {
15643
+ this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
15644
+ this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
15640
15645
  }
15646
+ if (direction === 'prev')
15647
+ this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
15648
+ if (direction === 'next')
15649
+ this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
15650
+ return queryResponse;
15641
15651
  }
15642
- async loadPrevPage() {
15643
- try {
15644
- if (this.paginationController instanceof PaginationNoPageController)
15645
- return;
15646
- const result = await this.paginationController.loadPreviousPage();
15647
- if (!result)
15648
- return;
15649
- await this.persistModel(result);
15650
- this.persistQueryStream({
15651
- response: result,
15652
- direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
15653
- });
15654
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
15655
- }
15656
- catch (e) {
15657
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
15658
- }
15652
+ getNextToken() {
15653
+ return this.nextToken;
15659
15654
  }
15660
- shouldNotify(data) {
15661
- const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
15662
- if (isEqual(this.snapshot, newData))
15663
- return false;
15664
- this.snapshot = newData;
15665
- return true;
15655
+ getPrevToken() {
15656
+ return this.previousToken;
15666
15657
  }
15667
- getCacheKey() {
15668
- return this.cacheKey;
15658
+ }
15659
+
15660
+ /* eslint-disable no-use-before-define */
15661
+ /**
15662
+ * TODO: handle cache receive cache option, and cache policy
15663
+ * TODO: check if querybyIds is supported
15664
+ */
15665
+ class MessagePaginationController extends PaginationController {
15666
+ async getRequest(queryParams, token) {
15667
+ const processedQueryParams = convertQueryParams$1(queryParams);
15668
+ const { data: queryResponse } = await this.http.get(`/api/v5/messages`, {
15669
+ params: Object.assign(Object.assign({}, processedQueryParams), { options: token
15670
+ ? {
15671
+ token,
15672
+ }
15673
+ : Object.assign({}, processedQueryParams.options) }),
15674
+ });
15675
+ return queryResponse;
15669
15676
  }
15670
15677
  }
15671
15678
 
@@ -15680,25 +15687,10 @@ class MessageLiveCollectionController extends LiveCollectionController {
15680
15687
  this.callback = callback.bind(this);
15681
15688
  this.loadPage({ initial: true });
15682
15689
  }
15683
- setup() {
15684
- var _a;
15685
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
15686
- if (!collection) {
15687
- pushToCache(this.cacheKey, {
15688
- data: [],
15689
- query: this.query,
15690
- });
15691
- }
15692
- }
15693
- async persistModel(response) {
15694
- await this.queryStreamController.saveToMainDB(response);
15695
- }
15696
- persistQueryStream({ response, direction, refresh, }) {
15697
- this.queryStreamController.appendToQueryStream(response, direction, refresh);
15698
- }
15699
15690
  startSubscription() {
15700
15691
  return this.queryStreamController.subscribeRTE([
15701
15692
  { fn: onMessageCreatedMqtt, action: 'onCreate' },
15693
+ { fn: onMessageCreatedLocal, action: 'onCreate' },
15702
15694
  { fn: onMessageDeleted, action: 'onDelete' },
15703
15695
  { fn: onMessageUpdated, action: 'onUpdate' },
15704
15696
  { fn: onMessageFlagged, action: 'onFlagged' },
@@ -15775,6 +15767,22 @@ class MessageLiveCollectionController extends LiveCollectionController {
15775
15767
  });
15776
15768
  return messages;
15777
15769
  }
15770
+ setup() {
15771
+ var _a;
15772
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
15773
+ if (!collection) {
15774
+ pushToCache(this.cacheKey, {
15775
+ data: [],
15776
+ query: this.query,
15777
+ });
15778
+ }
15779
+ }
15780
+ async persistModel(response) {
15781
+ await this.queryStreamController.saveToMainDB(response);
15782
+ }
15783
+ persistQueryStream({ response, direction, refresh, }) {
15784
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
15785
+ }
15778
15786
  }
15779
15787
 
15780
15788
  /* eslint-disable no-use-before-define */
@@ -21984,7 +21992,11 @@ var index$6 = /*#__PURE__*/Object.freeze({
21984
21992
  * @category Post Live Object
21985
21993
  */
21986
21994
  const getPost = (postId, callback) => {
21987
- return liveObject(postId, callback, 'postId', getPost$1, [
21995
+ const responder = (snapshot) => {
21996
+ const { data } = snapshot;
21997
+ callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.post(snapshot.data) : data }));
21998
+ };
21999
+ return liveObject(postId, responder, 'postId', getPost$1, [
21988
22000
  onPostApproved,
21989
22001
  onPostDeclined,
21990
22002
  (callback) => {
@@ -23165,7 +23177,7 @@ var index$3 = /*#__PURE__*/Object.freeze({
23165
23177
  getPoll: getPoll
23166
23178
  });
23167
23179
 
23168
- const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvwI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ZcapV9aRbRzTAKXm4f8AEhtlG9F9kCOvHYCYGi6JaiWJ\nZkHjeex3T+eE6Di6y5Bm/Ift5jtVhJ4jCVwHOKTMej79NPUFTJfv8hCo29haBDv6\nRXFrv+T21KCcw8k3sJeJWWQ=\n-----END PRIVATE KEY-----";
23169
23181
  /*
23170
23182
  * The crypto algorithm used for importing key and signing string
23171
23183
  */
@@ -24612,20 +24624,27 @@ var index$1 = /*#__PURE__*/Object.freeze({
24612
24624
  getGlobalStoryTargets: getGlobalStoryTargets
24613
24625
  });
24614
24626
 
24615
- const convertToNetworkAds = (data) => {
24616
- const { ads, settings } = data;
24617
- return {
24618
- ads: ads.map(LinkedObject.ad),
24619
- settings,
24620
- };
24627
+ const convertToInternalAd = (ad) => {
24628
+ return Object.assign(Object.assign({}, ad), { endAt: ad.endAt ? ad.endAt : null });
24629
+ };
24630
+ const convertToInternalAdvertiser = (advertiser) => {
24631
+ return Object.assign({}, advertiser);
24621
24632
  };
24622
24633
  const getNetworkAds = async () => {
24623
24634
  const client = getActiveClient();
24624
24635
  const { data } = await client.http.get('/api/v1/ads/me');
24625
- const { settings } = data, rest = __rest(data, ["settings"]);
24626
- ingestInCache(rest);
24627
- pushToCache(['ad', 'setting'], settings);
24628
- return convertToNetworkAds(data);
24636
+ const internalAds = data.ads.map(convertToInternalAd);
24637
+ const internalAdvertisers = data.advertisers.map(convertToInternalAdvertiser);
24638
+ ingestInCache({
24639
+ ads: internalAds,
24640
+ advertisers: internalAdvertisers,
24641
+ files: data.files,
24642
+ });
24643
+ pushToCache(['ad', 'setting'], data.settings);
24644
+ return {
24645
+ ads: internalAds.map(LinkedObject.ad),
24646
+ settings: data.settings,
24647
+ };
24629
24648
  };
24630
24649
 
24631
24650
  var index = /*#__PURE__*/Object.freeze({