@amityco/ts-sdk-react-native 6.26.4-2eb3673.0 → 6.26.4-b4d0c1f.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 (41) hide show
  1. package/dist/@types/core/model.d.ts +5 -5
  2. package/dist/@types/core/model.d.ts.map +1 -1
  3. package/dist/@types/domains/ad.d.ts +14 -2
  4. package/dist/@types/domains/ad.d.ts.map +1 -1
  5. package/dist/@types/domains/message.d.ts +4 -1
  6. package/dist/@types/domains/message.d.ts.map +1 -1
  7. package/dist/adRepository/api/getNetworkAds.d.ts.map +1 -1
  8. package/dist/analytic/service/analytic/AnalyticsEngine.d.ts +2 -2
  9. package/dist/analytic/service/analytic/AnalyticsEngine.d.ts.map +1 -1
  10. package/dist/analytic/service/analytic/AnalyticsEventCapturer.d.ts +11 -5
  11. package/dist/analytic/service/analytic/AnalyticsEventCapturer.d.ts.map +1 -1
  12. package/dist/index.cjs.js +281 -262
  13. package/dist/index.esm.js +281 -262
  14. package/dist/index.umd.js +3 -3
  15. package/dist/messageRepository/api/createMessage.d.ts +7 -25
  16. package/dist/messageRepository/api/createMessage.d.ts.map +1 -1
  17. package/dist/messageRepository/events/onMessageCreated.d.ts.map +1 -1
  18. package/dist/messageRepository/observers/getMessages/MessageLiveCollectionController.d.ts +4 -4
  19. package/dist/messageRepository/observers/getMessages/MessageLiveCollectionController.d.ts.map +1 -1
  20. package/dist/messageRepository/observers/getMessages/MessageQueryStreamController.d.ts.map +1 -1
  21. package/dist/messageRepository/utils/prepareMessagePayload.d.ts.map +1 -1
  22. package/dist/postRepository/observers/getPost.d.ts.map +1 -1
  23. package/dist/utils/linkedObject/adLinkedObject.d.ts +1 -1
  24. package/dist/utils/linkedObject/adLinkedObject.d.ts.map +1 -1
  25. package/dist/utils/linkedObject/index.d.ts +1 -1
  26. package/package.json +1 -1
  27. package/src/@types/core/model.ts +5 -5
  28. package/src/@types/domains/ad.ts +17 -6
  29. package/src/@types/domains/message.ts +6 -1
  30. package/src/adRepository/api/getNetworkAds.ts +22 -8
  31. package/src/analytic/service/analytic/AnalyticsEngine.ts +2 -2
  32. package/src/analytic/service/analytic/AnalyticsEventCapturer.ts +45 -27
  33. package/src/core/model/idResolvers.ts +1 -1
  34. package/src/messageRepository/api/createMessage.ts +83 -98
  35. package/src/messageRepository/events/onMessageCreated.ts +12 -6
  36. package/src/messageRepository/observers/getMessages/MessageLiveCollectionController.ts +26 -24
  37. package/src/messageRepository/observers/getMessages/MessageQueryStreamController.ts +3 -2
  38. package/src/messageRepository/observers/observeMessages.ts +3 -3
  39. package/src/messageRepository/utils/prepareMessagePayload.ts +1 -1
  40. package/src/postRepository/observers/getPost.ts +8 -1
  41. package/src/utils/linkedObject/adLinkedObject.ts +11 -11
package/dist/index.esm.js CHANGED
@@ -493,7 +493,7 @@ const idResolvers = {
493
493
  channel: ({ channelInternalId }) => channelInternalId,
494
494
  subChannel: ({ subChannelId }) => subChannelId,
495
495
  channelUsers: ({ channelId, userId }) => `${channelId}#${userId}`,
496
- message: ({ messageId }) => messageId,
496
+ message: ({ messageId, referenceId }) => referenceId !== null && referenceId !== void 0 ? referenceId : messageId,
497
497
  messagePreviewChannel: ({ channelId }) => `${channelId}`,
498
498
  messagePreviewSubChannel: ({ subChannelId }) => `${subChannelId}`,
499
499
  channelUnreadInfo: ({ channelId }) => channelId,
@@ -20970,12 +20970,12 @@ class AnalyticsEventCapturer {
20970
20970
  this._throttleStoryTimer = undefined;
20971
20971
  this._bufferNewSeenStoryReferenceIds = [];
20972
20972
  }
20973
- isAbleToEnqueue({ itemId, expireTime, isHighPriority = false, }) {
20973
+ isAbleToEnqueue({ uniqueId, expireTime, isHighPriority = false, }) {
20974
20974
  const now = new Date();
20975
20975
  const getRecentViewedDate = () => {
20976
20976
  if (isHighPriority)
20977
- return this._recentHighPriorityViewed[itemId];
20978
- return this._recentViewed[itemId];
20977
+ return this._recentHighPriorityViewed[uniqueId];
20978
+ return this._recentViewed[uniqueId];
20979
20979
  };
20980
20980
  const recentViewedDate = getRecentViewedDate() || new Date(DAY * -1);
20981
20981
  const timeDiff = now.getTime() - recentViewedDate.getTime();
@@ -20985,8 +20985,8 @@ class AnalyticsEventCapturer {
20985
20985
  }
20986
20986
  return true;
20987
20987
  }
20988
- markAs(itemId, contentType, activityType, metadata = undefined) {
20989
- if (!this.isAbleToEnqueue({ itemId, expireTime: this._expireTime }))
20988
+ markAs({ uniqueId, contentId, contentType, activityType, metadata, }) {
20989
+ if (!this.isAbleToEnqueue({ uniqueId, expireTime: this._expireTime }))
20990
20990
  return;
20991
20991
  const now = new Date();
20992
20992
  const currentData = { event: [] };
@@ -21000,7 +21000,7 @@ class AnalyticsEventCapturer {
21000
21000
  currentData.event.shift();
21001
21001
  }
21002
21002
  const analyticItem = {
21003
- contentId: itemId,
21003
+ contentId,
21004
21004
  contentType,
21005
21005
  activityType,
21006
21006
  timestamp: now.toISOString(),
@@ -21010,10 +21010,15 @@ class AnalyticsEventCapturer {
21010
21010
  }
21011
21011
  currentData.event.push(analyticItem);
21012
21012
  upsertInCache(ANALYTIC_CACHE_KEY, currentData);
21013
- this._recentViewed[itemId] = now;
21013
+ this._recentViewed[uniqueId] = now;
21014
21014
  }
21015
21015
  markPostAsViewed(postId) {
21016
- this.markAs(postId, "post" /* Amity.AnalyticEventContentType.Post */, "view" /* Amity.AnalyticEventActivityType.View */);
21016
+ this.markAs({
21017
+ uniqueId: postId,
21018
+ contentId: postId,
21019
+ contentType: "post" /* Amity.AnalyticEventContentType.Post */,
21020
+ activityType: "view" /* Amity.AnalyticEventActivityType.View */,
21021
+ });
21017
21022
  }
21018
21023
  markStory(story, activityType) {
21019
21024
  if (!story.expiresAt)
@@ -21021,7 +21026,7 @@ class AnalyticsEventCapturer {
21021
21026
  const now = new Date();
21022
21027
  const expireTime = new Date(story.expiresAt);
21023
21028
  if (!this.isAbleToEnqueue({
21024
- itemId: story.storyId,
21029
+ uniqueId: story.storyId,
21025
21030
  expireTime: expireTime.getTime(),
21026
21031
  isHighPriority: true,
21027
21032
  }))
@@ -21087,13 +21092,27 @@ class AnalyticsEventCapturer {
21087
21092
  const metadata = {
21088
21093
  placement,
21089
21094
  };
21090
- this.markAs(`${ad.adId}.${"view" /* Amity.AnalyticEventActivityType.View */}.${placement}`, "ad" /* Amity.AnalyticEventContentType.Ad */, "view" /* Amity.AnalyticEventActivityType.View */, metadata);
21095
+ const activityType = "view" /* Amity.AnalyticEventActivityType.View */;
21096
+ this.markAs({
21097
+ uniqueId: `${ad.adId}.${activityType}.${placement}`,
21098
+ contentId: ad.adId,
21099
+ contentType: "ad" /* Amity.AnalyticEventContentType.Ad */,
21100
+ activityType,
21101
+ metadata,
21102
+ });
21091
21103
  }
21092
21104
  markAdAsClicked(ad, placement) {
21093
21105
  const metadata = {
21094
21106
  placement,
21095
21107
  };
21096
- this.markAs(`${ad.adId}.${"view" /* Amity.AnalyticEventActivityType.View */}.${placement}`, "ad" /* Amity.AnalyticEventContentType.Ad */, "linkClicked" /* Amity.AnalyticEventActivityType.Click */, metadata);
21108
+ const activityType = "linkClicked" /* Amity.AnalyticEventActivityType.Click */;
21109
+ this.markAs({
21110
+ uniqueId: `${ad.adId}.${activityType}.${placement}`,
21111
+ contentId: ad.adId,
21112
+ contentType: "ad" /* Amity.AnalyticEventContentType.Ad */,
21113
+ activityType,
21114
+ metadata,
21115
+ });
21097
21116
  }
21098
21117
  }
21099
21118
 
@@ -21860,20 +21879,17 @@ const channelLinkedObject = (channel) => {
21860
21879
  return Object.assign(Object.assign({}, channel), { markAsRead: () => markAsRead(channel.channelInternalId) });
21861
21880
  };
21862
21881
 
21863
- // import AnalyticsEngine from '~/analytic/service/analytic/AnalyticsEngine';
21864
21882
  const adLinkedObject = (ad) => {
21865
- // const analyticsEngineInstance = AnalyticsEngine.getInstance();
21883
+ const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
21866
21884
  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() {
21885
+ return Object.assign(Object.assign({}, restAds), { analytics: {
21886
+ markAsSeen: (placement) => {
21887
+ analyticsEngineInstance.markAdAsViewed(ad, placement);
21888
+ },
21889
+ markLinkAsClicked: (placement) => {
21890
+ analyticsEngineInstance.markAdAsClicked(ad, placement);
21891
+ },
21892
+ }, get advertiser() {
21877
21893
  var _a, _b;
21878
21894
  const advertiserData = (_a = pullFromCache([
21879
21895
  'advertiser',
@@ -22761,7 +22777,7 @@ function convertFromRaw(message, reactors, event) {
22761
22777
  *
22762
22778
  * Check git blame for previous iteration
22763
22779
  */
22764
- 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 });
22780
+ 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 */ });
22765
22781
  if (mentionedUsers) {
22766
22782
  out.mentionees = mentionedUsers.map(mention => {
22767
22783
  if (mention.type === 'channel') {
@@ -24591,9 +24607,12 @@ const onMessageCreatedMqtt = (callback) => {
24591
24607
  const onMessageCreatedLocal = (callback) => {
24592
24608
  const client = getActiveClient();
24593
24609
  const disposers = [
24594
- createEventSubscriber(client, 'message/onMessageCreated', 'local.message.created', payload => payload.messages.forEach(message => {
24595
- callback(message);
24596
- })),
24610
+ createEventSubscriber(client, 'message/onMessageCreated', 'local.message.created', async (payload) => {
24611
+ ingestInCache(payload);
24612
+ return payload.messages.forEach(message => {
24613
+ callback(message);
24614
+ });
24615
+ }),
24597
24616
  ];
24598
24617
  return () => {
24599
24618
  disposers.forEach(fn => fn());
@@ -30676,9 +30695,40 @@ getMessages$1.locally = (messageIds) => {
30676
30695
  const getLocalId = () => `LOCAL_${uuid()}`;
30677
30696
  // FIXME: temp solution
30678
30697
  let uniqueId;
30679
- /* begin_public_function
30680
- 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
30681
- */
30698
+ const createMessageOptimistic = (bundle) => {
30699
+ var _a, _b;
30700
+ const client = getActiveClient();
30701
+ if (!client.cache)
30702
+ return;
30703
+ /*
30704
+ * When creating messages optimistically a messageId needs to be added by the
30705
+ * client, created a new variable to allow backward compatibility of API
30706
+ *
30707
+ * Updated to handle client requirement to add messageId while uploading
30708
+ * a message with image.
30709
+ * Temporary!
30710
+ */
30711
+ uniqueId = bundle.referenceId || getLocalId();
30712
+ const bundleWithMessageId = Object.assign({ messageId: uniqueId, uniqueId }, bundle);
30713
+ client.log('message/createMessage.optimistically', bundleWithMessageId);
30714
+ const subChannel = pullFromCache(['subChannel', 'get', bundle.subChannelId]);
30715
+ if (subChannel) {
30716
+ upsertInCache(['subChannel', 'get', bundle.subChannelId], Object.assign(Object.assign({}, subChannel.data), { messageCount: subChannel.data.messageCount + 1 }));
30717
+ if (subChannel.data.channelId === subChannel.data.subChannelId) {
30718
+ const channel = pullFromCache(['channel', 'get', subChannel.data.channelId]);
30719
+ if (channel === null || channel === void 0 ? void 0 : channel.data) {
30720
+ upsertInCache(['channel', 'get', subChannel.data.channelId], Object.assign(Object.assign({}, channel.data), { messageCount: ((_a = channel.data.messageCount) !== null && _a !== void 0 ? _a : 0) + 1 }));
30721
+ }
30722
+ }
30723
+ }
30724
+ // as reused to update created and updated time, which should be the same
30725
+ const createdTime = new Date().toISOString();
30726
+ 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);
30727
+ const cachedAt = UNSYNCED_OBJECT_CACHED_AT_VALUE;
30728
+ pushToCache(['message', 'get', message.messageId], message, { cachedAt });
30729
+ fireEvent('local.message.created', { messages: [message] });
30730
+ return message;
30731
+ };
30682
30732
  /**
30683
30733
  * ```js
30684
30734
  * import { createMessage, createQuery, runQuery } from '@amityco/ts-sdk-react-native'
@@ -30704,75 +30754,31 @@ let uniqueId;
30704
30754
  const createMessage = async (bundle) => {
30705
30755
  const client = getActiveClient();
30706
30756
  client.log('message/createMessage', bundle);
30757
+ const optimisticData = createMessageOptimistic(bundle);
30707
30758
  const referenceId = bundle.referenceId || uniqueId || getLocalId();
30708
30759
  uniqueId = undefined;
30709
- const { data: payload } = await client.http.post('/api/v5/messages', Object.assign(Object.assign({}, convertParams(bundle)), { referenceId }));
30710
- const data = await prepareMessagePayload(payload);
30711
- const { messages } = data;
30712
- const cachedAt = client.cache && Date.now();
30713
- if (client.cache) {
30714
- dropFromCache(['message', 'get', referenceId]);
30715
- ingestInCache(data, { cachedAt });
30716
- }
30717
- fireEvent('local.message.created', { messages });
30718
- return {
30719
- data: LinkedObject.message(messages[0]),
30720
- cachedAt,
30721
- };
30722
- };
30723
- /**
30724
- * ```js
30725
- * import { createMessage } from '@amityco/ts-sdk-react-native'
30726
- *
30727
- * const created = createMessage.optimistically({
30728
- * channelId: 'foobar',
30729
- * data: { text: 'hello world' }
30730
- * })
30731
- * ```
30732
- *
30733
- * Creates an {@link Amity.Message} in cache
30734
- *
30735
- * @param bundle The data necessary to create a new {@link Amity.Message}
30736
- * @returns The newly created {@link Amity.Message}
30737
- *
30738
- * @category Message API
30739
- */
30740
- createMessage.optimistically = (_a) => {
30741
- var _b, _c;
30742
- var { referenceId } = _a, bundle = __rest(_a, ["referenceId"]);
30743
- const client = getActiveClient();
30744
- if (!client.cache)
30745
- return;
30746
- /*
30747
- * when creating messages optimistically a messageId needs to be added by the
30748
- * client, created a new variable so as to allow backward compatibility of API
30749
- *
30750
- * Updated to handle client requirement to add messageId while uploading
30751
- * message with image. Temporary!
30752
- */
30753
- uniqueId = referenceId || getLocalId();
30754
- const bundleWithMessageId = Object.assign({ messageId: uniqueId, uniqueId }, bundle);
30755
- client.log('message/createMessage.optimistically', bundleWithMessageId);
30756
- const subChannel = pullFromCache(['subChannel', 'get', bundle.subChannelId]);
30757
- if (subChannel) {
30758
- upsertInCache(['subChannel', 'get', bundle.subChannelId], Object.assign(Object.assign({}, subChannel.data), { messageCount: subChannel.data.messageCount + 1 }));
30759
- if (subChannel.data.channelId === subChannel.data.subChannelId) {
30760
- const channel = pullFromCache(['channel', 'get', subChannel.data.channelId]);
30761
- if (channel === null || channel === void 0 ? void 0 : channel.data) {
30762
- upsertInCache(['channel', 'get', subChannel.data.channelId], Object.assign(Object.assign({}, channel.data), { messageCount: ((_b = channel.data.messageCount) !== null && _b !== void 0 ? _b : 0) + 1 }));
30763
- }
30760
+ try {
30761
+ const { data: payload } = await client.http.post('/api/v5/messages', Object.assign(Object.assign({}, convertParams(bundle)), { referenceId }));
30762
+ const data = await prepareMessagePayload(payload);
30763
+ const { messages } = data;
30764
+ const cachedAt = client.cache && Date.now();
30765
+ if (client.cache) {
30766
+ ingestInCache(data, { cachedAt });
30764
30767
  }
30768
+ fireEvent('local.message.created', {
30769
+ messages: [Object.assign(Object.assign({}, messages[0]), { syncState: "synced" /* Amity.SyncState.Synced */ })],
30770
+ });
30771
+ return {
30772
+ data: LinkedObject.message(messages[0]),
30773
+ cachedAt,
30774
+ };
30775
+ }
30776
+ catch (e) {
30777
+ fireEvent('local.message.created', {
30778
+ messages: [Object.assign(Object.assign({}, optimisticData), { syncState: "error" /* Amity.SyncState.Error */ })],
30779
+ });
30780
+ throw e;
30765
30781
  }
30766
- // as reused to update created and updated time, which should be the same
30767
- const createdTime = new Date().toISOString();
30768
- 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);
30769
- const cachedAt = UNSYNCED_OBJECT_CACHED_AT_VALUE;
30770
- pushToCache(['message', 'get', message.messageId], message, { cachedAt });
30771
- fireEvent('local.message.created', { messages: [message] });
30772
- return {
30773
- cachedAt,
30774
- data: LinkedObject.message(message),
30775
- };
30776
30782
  };
30777
30783
  /* end_public_function */
30778
30784
 
@@ -31485,67 +31491,106 @@ const getMessage$1 = (messageId, callback) => {
31485
31491
  };
31486
31492
  /* end_public_function */
31487
31493
 
31488
- class PaginationController {
31494
+ class PaginationNoPageController {
31489
31495
  constructor(queryParams) {
31490
31496
  const { http } = getActiveClient();
31491
31497
  this.queryParams = queryParams;
31492
31498
  this.http = http;
31493
31499
  }
31494
- loadFirstPage() {
31495
- return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
31500
+ async onFetch() {
31501
+ const queryResponse = await this.getRequest(this.queryParams);
31502
+ return queryResponse;
31496
31503
  }
31497
- loadNextPage() {
31498
- return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
31504
+ }
31505
+
31506
+ class LiveCollectionController {
31507
+ constructor(paginationController, queryStreamId, cacheKey, callback) {
31508
+ this.paginationController = paginationController;
31509
+ this.queryStreamId = queryStreamId;
31510
+ this.cacheKey = cacheKey;
31511
+ this.callback = callback;
31499
31512
  }
31500
- loadPreviousPage() {
31501
- return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
31513
+ async refresh() {
31514
+ try {
31515
+ let result;
31516
+ if (this.paginationController instanceof PaginationNoPageController) {
31517
+ result = await this.paginationController.onFetch();
31518
+ }
31519
+ else {
31520
+ result = await this.paginationController.loadFirstPage();
31521
+ }
31522
+ if (!result)
31523
+ return;
31524
+ await this.persistModel(result);
31525
+ this.persistQueryStream({
31526
+ response: result,
31527
+ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
31528
+ refresh: true,
31529
+ });
31530
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
31531
+ }
31532
+ catch (e) {
31533
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
31534
+ }
31502
31535
  }
31503
- async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
31504
- var _a, _b, _c, _d;
31505
- if (direction === 'prev' && !this.previousToken)
31506
- return;
31507
- if (direction === 'next' && !this.nextToken)
31508
- return;
31509
- let token;
31510
- if (direction === 'prev')
31511
- token = this.previousToken;
31512
- if (direction === 'next')
31513
- token = this.nextToken;
31514
- const queryResponse = await this.getRequest(this.queryParams, token);
31515
- if (direction === 'first') {
31516
- this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
31517
- this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
31536
+ loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
31537
+ this.setup();
31538
+ this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
31539
+ if (initial) {
31540
+ this.refresh();
31541
+ }
31542
+ else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
31543
+ this.loadPrevPage();
31544
+ }
31545
+ else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
31546
+ this.loadNextPage();
31518
31547
  }
31519
- if (direction === 'prev')
31520
- this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
31521
- if (direction === 'next')
31522
- this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
31523
- return queryResponse;
31524
31548
  }
31525
- getNextToken() {
31526
- return this.nextToken;
31549
+ async loadNextPage() {
31550
+ try {
31551
+ if (this.paginationController instanceof PaginationNoPageController)
31552
+ return;
31553
+ const result = await this.paginationController.loadNextPage();
31554
+ if (!result)
31555
+ return;
31556
+ await this.persistModel(result);
31557
+ this.persistQueryStream({
31558
+ response: result,
31559
+ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
31560
+ });
31561
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
31562
+ }
31563
+ catch (e) {
31564
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
31565
+ }
31527
31566
  }
31528
- getPrevToken() {
31529
- return this.previousToken;
31567
+ async loadPrevPage() {
31568
+ try {
31569
+ if (this.paginationController instanceof PaginationNoPageController)
31570
+ return;
31571
+ const result = await this.paginationController.loadPreviousPage();
31572
+ if (!result)
31573
+ return;
31574
+ await this.persistModel(result);
31575
+ this.persistQueryStream({
31576
+ response: result,
31577
+ direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
31578
+ });
31579
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
31580
+ }
31581
+ catch (e) {
31582
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
31583
+ }
31530
31584
  }
31531
- }
31532
-
31533
- /* eslint-disable no-use-before-define */
31534
- /**
31535
- * TODO: handle cache receive cache option, and cache policy
31536
- * TODO: check if querybyIds is supported
31537
- */
31538
- class MessagePaginationController extends PaginationController {
31539
- async getRequest(queryParams, token) {
31540
- const processedQueryParams = convertQueryParams$1(queryParams);
31541
- const { data: queryResponse } = await this.http.get(`/api/v5/messages`, {
31542
- params: Object.assign(Object.assign({}, processedQueryParams), { options: token
31543
- ? {
31544
- token,
31545
- }
31546
- : Object.assign({}, processedQueryParams.options) }),
31547
- });
31548
- return queryResponse;
31585
+ shouldNotify(data) {
31586
+ const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
31587
+ if (isEqual(this.snapshot, newData))
31588
+ return false;
31589
+ this.snapshot = newData;
31590
+ return true;
31591
+ }
31592
+ getCacheKey() {
31593
+ return this.cacheKey;
31549
31594
  }
31550
31595
  }
31551
31596
 
@@ -31593,6 +31638,7 @@ class MessageQueryStreamController extends QueryStreamController {
31593
31638
  var _a, _b, _c, _d, _e;
31594
31639
  if (action === 'onCreate') {
31595
31640
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
31641
+ const { referenceId } = payload;
31596
31642
  if (!collection)
31597
31643
  return;
31598
31644
  if (this.query.subChannelId !== (payload === null || payload === void 0 ? void 0 : payload.subChannelId) || !collection)
@@ -31622,10 +31668,10 @@ class MessageQueryStreamController extends QueryStreamController {
31622
31668
  return;
31623
31669
  if ((!this.query.sortBy || this.query.sortBy === 'segmentDesc') &&
31624
31670
  !this.paginationController.getPrevToken()) {
31625
- collection.data = [...new Set([payload.messageId, ...collection.data])];
31671
+ collection.data = [...new Set([referenceId !== null && referenceId !== void 0 ? referenceId : payload.messageId, ...collection.data])];
31626
31672
  }
31627
31673
  if (this.query.sortBy === 'segmentAsc' && !this.paginationController.getNextToken()) {
31628
- collection.data = [...new Set([...collection.data, payload.messageId])];
31674
+ collection.data = [...new Set([...collection.data, referenceId !== null && referenceId !== void 0 ? referenceId : payload.messageId])];
31629
31675
  }
31630
31676
  pushToCache(this.cacheKey, collection);
31631
31677
  }
@@ -31637,106 +31683,67 @@ class MessageQueryStreamController extends QueryStreamController {
31637
31683
  }
31638
31684
  }
31639
31685
 
31640
- class PaginationNoPageController {
31686
+ class PaginationController {
31641
31687
  constructor(queryParams) {
31642
31688
  const { http } = getActiveClient();
31643
31689
  this.queryParams = queryParams;
31644
31690
  this.http = http;
31645
31691
  }
31646
- async onFetch() {
31647
- const queryResponse = await this.getRequest(this.queryParams);
31648
- return queryResponse;
31649
- }
31650
- }
31651
-
31652
- class LiveCollectionController {
31653
- constructor(paginationController, queryStreamId, cacheKey, callback) {
31654
- this.paginationController = paginationController;
31655
- this.queryStreamId = queryStreamId;
31656
- this.cacheKey = cacheKey;
31657
- this.callback = callback;
31692
+ loadFirstPage() {
31693
+ return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
31658
31694
  }
31659
- async refresh() {
31660
- try {
31661
- let result;
31662
- if (this.paginationController instanceof PaginationNoPageController) {
31663
- result = await this.paginationController.onFetch();
31664
- }
31665
- else {
31666
- result = await this.paginationController.loadFirstPage();
31667
- }
31668
- if (!result)
31669
- return;
31670
- await this.persistModel(result);
31671
- this.persistQueryStream({
31672
- response: result,
31673
- direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
31674
- refresh: true,
31675
- });
31676
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
31677
- }
31678
- catch (e) {
31679
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
31680
- }
31695
+ loadNextPage() {
31696
+ return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
31681
31697
  }
31682
- loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
31683
- this.setup();
31684
- this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
31685
- if (initial) {
31686
- this.refresh();
31687
- }
31688
- else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
31689
- this.loadPrevPage();
31690
- }
31691
- else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
31692
- this.loadNextPage();
31693
- }
31698
+ loadPreviousPage() {
31699
+ return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
31694
31700
  }
31695
- async loadNextPage() {
31696
- try {
31697
- if (this.paginationController instanceof PaginationNoPageController)
31698
- return;
31699
- const result = await this.paginationController.loadNextPage();
31700
- if (!result)
31701
- return;
31702
- await this.persistModel(result);
31703
- this.persistQueryStream({
31704
- response: result,
31705
- direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
31706
- });
31707
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
31708
- }
31709
- catch (e) {
31710
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
31701
+ async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
31702
+ var _a, _b, _c, _d;
31703
+ if (direction === 'prev' && !this.previousToken)
31704
+ return;
31705
+ if (direction === 'next' && !this.nextToken)
31706
+ return;
31707
+ let token;
31708
+ if (direction === 'prev')
31709
+ token = this.previousToken;
31710
+ if (direction === 'next')
31711
+ token = this.nextToken;
31712
+ const queryResponse = await this.getRequest(this.queryParams, token);
31713
+ if (direction === 'first') {
31714
+ this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
31715
+ this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
31711
31716
  }
31717
+ if (direction === 'prev')
31718
+ this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
31719
+ if (direction === 'next')
31720
+ this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
31721
+ return queryResponse;
31712
31722
  }
31713
- async loadPrevPage() {
31714
- try {
31715
- if (this.paginationController instanceof PaginationNoPageController)
31716
- return;
31717
- const result = await this.paginationController.loadPreviousPage();
31718
- if (!result)
31719
- return;
31720
- await this.persistModel(result);
31721
- this.persistQueryStream({
31722
- response: result,
31723
- direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
31724
- });
31725
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
31726
- }
31727
- catch (e) {
31728
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
31729
- }
31723
+ getNextToken() {
31724
+ return this.nextToken;
31730
31725
  }
31731
- shouldNotify(data) {
31732
- const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
31733
- if (isEqual(this.snapshot, newData))
31734
- return false;
31735
- this.snapshot = newData;
31736
- return true;
31726
+ getPrevToken() {
31727
+ return this.previousToken;
31737
31728
  }
31738
- getCacheKey() {
31739
- return this.cacheKey;
31729
+ }
31730
+
31731
+ /* eslint-disable no-use-before-define */
31732
+ /**
31733
+ * TODO: handle cache receive cache option, and cache policy
31734
+ * TODO: check if querybyIds is supported
31735
+ */
31736
+ class MessagePaginationController extends PaginationController {
31737
+ async getRequest(queryParams, token) {
31738
+ const processedQueryParams = convertQueryParams$1(queryParams);
31739
+ const { data: queryResponse } = await this.http.get(`/api/v5/messages`, {
31740
+ params: Object.assign(Object.assign({}, processedQueryParams), { options: token
31741
+ ? {
31742
+ token,
31743
+ }
31744
+ : Object.assign({}, processedQueryParams.options) }),
31745
+ });
31746
+ return queryResponse;
31740
31747
  }
31741
31748
  }
31742
31749
 
@@ -31751,25 +31758,10 @@ class MessageLiveCollectionController extends LiveCollectionController {
31751
31758
  this.callback = callback.bind(this);
31752
31759
  this.loadPage({ initial: true });
31753
31760
  }
31754
- setup() {
31755
- var _a;
31756
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
31757
- if (!collection) {
31758
- pushToCache(this.cacheKey, {
31759
- data: [],
31760
- query: this.query,
31761
- });
31762
- }
31763
- }
31764
- async persistModel(response) {
31765
- await this.queryStreamController.saveToMainDB(response);
31766
- }
31767
- persistQueryStream({ response, direction, refresh, }) {
31768
- this.queryStreamController.appendToQueryStream(response, direction, refresh);
31769
- }
31770
31761
  startSubscription() {
31771
31762
  return this.queryStreamController.subscribeRTE([
31772
31763
  { fn: onMessageCreatedMqtt, action: 'onCreate' },
31764
+ { fn: onMessageCreatedLocal, action: 'onCreate' },
31773
31765
  { fn: onMessageDeleted, action: 'onDelete' },
31774
31766
  { fn: onMessageUpdated, action: 'onUpdate' },
31775
31767
  { fn: onMessageFlagged, action: 'onFlagged' },
@@ -31846,6 +31838,22 @@ class MessageLiveCollectionController extends LiveCollectionController {
31846
31838
  });
31847
31839
  return messages;
31848
31840
  }
31841
+ setup() {
31842
+ var _a;
31843
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
31844
+ if (!collection) {
31845
+ pushToCache(this.cacheKey, {
31846
+ data: [],
31847
+ query: this.query,
31848
+ });
31849
+ }
31850
+ }
31851
+ async persistModel(response) {
31852
+ await this.queryStreamController.saveToMainDB(response);
31853
+ }
31854
+ persistQueryStream({ response, direction, refresh, }) {
31855
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
31856
+ }
31849
31857
  }
31850
31858
 
31851
31859
  /* eslint-disable no-use-before-define */
@@ -38055,7 +38063,11 @@ var index$6 = /*#__PURE__*/Object.freeze({
38055
38063
  * @category Post Live Object
38056
38064
  */
38057
38065
  const getPost = (postId, callback) => {
38058
- return liveObject(postId, callback, 'postId', getPost$1, [
38066
+ const responder = (snapshot) => {
38067
+ const { data } = snapshot;
38068
+ callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.post(snapshot.data) : data }));
38069
+ };
38070
+ return liveObject(postId, responder, 'postId', getPost$1, [
38059
38071
  onPostApproved,
38060
38072
  onPostDeclined,
38061
38073
  (callback) => {
@@ -40683,20 +40695,27 @@ var index$1 = /*#__PURE__*/Object.freeze({
40683
40695
  getGlobalStoryTargets: getGlobalStoryTargets
40684
40696
  });
40685
40697
 
40686
- const convertToNetworkAds = (data) => {
40687
- const { ads, settings } = data;
40688
- return {
40689
- ads: ads.map(LinkedObject.ad),
40690
- settings,
40691
- };
40698
+ const convertToInternalAd = (ad) => {
40699
+ return Object.assign(Object.assign({}, ad), { endAt: ad.endAt ? ad.endAt : null });
40700
+ };
40701
+ const convertToInternalAdvertiser = (advertiser) => {
40702
+ return Object.assign({}, advertiser);
40692
40703
  };
40693
40704
  const getNetworkAds = async () => {
40694
40705
  const client = getActiveClient();
40695
40706
  const { data } = await client.http.get('/api/v1/ads/me');
40696
- const { settings } = data, rest = __rest(data, ["settings"]);
40697
- ingestInCache(rest);
40698
- pushToCache(['ad', 'setting'], settings);
40699
- return convertToNetworkAds(data);
40707
+ const internalAds = data.ads.map(convertToInternalAd);
40708
+ const internalAdvertisers = data.advertisers.map(convertToInternalAdvertiser);
40709
+ ingestInCache({
40710
+ ads: internalAds,
40711
+ advertisers: internalAdvertisers,
40712
+ files: data.files,
40713
+ });
40714
+ pushToCache(['ad', 'setting'], data.settings);
40715
+ return {
40716
+ ads: internalAds.map(LinkedObject.ad),
40717
+ settings: data.settings,
40718
+ };
40700
40719
  };
40701
40720
 
40702
40721
  var index = /*#__PURE__*/Object.freeze({