@amityco/ts-sdk 6.7.1-d808fe1.0 → 6.7.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"markerSyncEngine.d.ts","sourceRoot":"","sources":["../../../src/client/utils/markerSyncEngine.ts"],"names":[],"mappings":"AAoDA;;;GAGG;AACH,eAAO,MAAM,mBAAmB,+BAAe,CAAC;AAEhD;;;GAGG;AACH,eAAO,MAAM,mBAAmB,cAAe,MAAM,eAAe,EAAE,SAErE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,mBAAmB,UAAW,MAAM,eAAe,WAAuB,CAAC;AAExF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,qBA4B7B,CAAC;AAkDF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,qBAiB3B,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,YAK1B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,YAI7B,CAAC"}
1
+ {"version":3,"file":"markerSyncEngine.d.ts","sourceRoot":"","sources":["../../../src/client/utils/markerSyncEngine.ts"],"names":[],"mappings":"AAmDA;;;GAGG;AACH,eAAO,MAAM,mBAAmB,+BAAe,CAAC;AAEhD;;;GAGG;AACH,eAAO,MAAM,mBAAmB,cAAe,MAAM,eAAe,EAAE,SAErE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,mBAAmB,UAAW,MAAM,eAAe,WAAuB,CAAC;AAExF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,qBA4B7B,CAAC;AA2DF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,qBAiB3B,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,YAK1B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,YAI7B,CAAC"}
package/dist/index.cjs.js CHANGED
@@ -96,8 +96,8 @@ const PostContentType = Object.freeze({
96
96
 
97
97
  function getVersion() {
98
98
  try {
99
- // the string ''v6.7.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
100
- return 'v6.7.0-cjs';
99
+ // the string ''v6.7.1-cjs'' should be replaced by actual value by @rollup/plugin-replace
100
+ return 'v6.7.1-cjs';
101
101
  }
102
102
  catch (error) {
103
103
  return '__dev__';
@@ -21001,20 +21001,6 @@ const setIntervalTask = (handler, timeout) => {
21001
21001
  return () => clearInterval(timer);
21002
21002
  };
21003
21003
 
21004
- const onOnline = (callback) => {
21005
- if (typeof window !== 'undefined' && window.addEventListener) {
21006
- window.addEventListener('online', callback);
21007
- return () => window.removeEventListener('online', callback);
21008
- }
21009
- if (typeof document !== 'undefined' && document.addEventListener) {
21010
- document.addEventListener('online', callback);
21011
- return () => document.removeEventListener('online', callback);
21012
- }
21013
- // Handle unsupported environment
21014
- console.error('Unsupported environment');
21015
- return () => console.error('Unsupported environment');
21016
- };
21017
-
21018
21004
  /**
21019
21005
  * ```js
21020
21006
  * import { isInTombstone } from '@amityco/ts-sdk'
@@ -21575,6 +21561,17 @@ const markReadEngineOnLoginHandler = () => {
21575
21561
  stopIntervalTask();
21576
21562
  };
21577
21563
  };
21564
+ /**
21565
+ * the event callback when app is back to online
21566
+ */
21567
+ const onOnline$1 = () => {
21568
+ const callback = () => {
21569
+ // Start reading the reading subChannel again when resume from offline state
21570
+ startReadingFromReadingList();
21571
+ };
21572
+ window.addEventListener('online', callback);
21573
+ return () => window.removeEventListener('online', callback);
21574
+ };
21578
21575
  const getParentChannelId = async (subChannelId) => {
21579
21576
  const cached = getSubChannel$1.locally(subChannelId);
21580
21577
  if (cached) {
@@ -21584,10 +21581,7 @@ const getParentChannelId = async (subChannelId) => {
21584
21581
  return data.channelId;
21585
21582
  };
21586
21583
  const registerEventListeners$1 = () => {
21587
- disposers$1.push(onOnline(() => {
21588
- // Start reading the reading subChannel again when resume from offline state
21589
- startReadingFromReadingList();
21590
- }));
21584
+ disposers$1.push(onOnline$1());
21591
21585
  };
21592
21586
  const registerTopicSubscribers = async (subChannelId) => {
21593
21587
  const channelId = await getParentChannelId(subChannelId);
@@ -24021,11 +24015,6 @@ const onMessageCreated = (callback, local = true) => {
24021
24015
  const message = payload.messages[0];
24022
24016
  // Update in cache
24023
24017
  ingestInCache(payload);
24024
- // Update lastActivity for Channel and SubChannel
24025
- payload.messages.forEach(({ channelId, subChannelId, createdAt }) => {
24026
- upsertInCache(['channel', 'get', channelId], { lastActivity: createdAt });
24027
- upsertInCache(['subChannel', 'get', channelId], { lastActivity: createdAt });
24028
- });
24029
24018
  callback(message);
24030
24019
  };
24031
24020
  const disposers = [
@@ -24409,16 +24398,22 @@ const markerSyncTrigger = async () => {
24409
24398
  // eslint-disable-next-line require-atomic-updates
24410
24399
  isWaitingForResponse = false;
24411
24400
  };
24401
+ /**
24402
+ * the event callback when app is back to online
24403
+ */
24404
+ const onOnline = () => {
24405
+ // should add RESUME to the event to trigger marker syncing again
24406
+ const callback = () => events.push("resume" /* Amity.MarkerSyncEvent.RESUME */);
24407
+ window.addEventListener('online', callback);
24408
+ return () => window.removeEventListener('online', callback);
24409
+ };
24412
24410
  const registerEventListeners = () => {
24413
24411
  // based on the tech spec design, we designed a fetch marker in case of these events
24414
24412
  // - new message
24415
24413
  // - create channel
24416
24414
  // - remove channel
24417
24415
  // - app going to online again after offline
24418
- disposers.push(onOnline(() => {
24419
- // should add RESUME to the event to trigger marker syncing again
24420
- events.push("resume" /* Amity.MarkerSyncEvent.RESUME */);
24421
- }), onMessageCreated(message => {
24416
+ disposers.push(onOnline(), onMessageCreated(message => {
24422
24417
  // only conversation, community and broadcast types can sync
24423
24418
  if (isUnreadCountSupport(message))
24424
24419
  events.push("new message" /* Amity.MarkerSyncEvent.NEW_MESSAGE */);
@@ -29612,7 +29607,16 @@ const getSubChannels = (params, callback, config) => {
29612
29607
  responder(snapshot);
29613
29608
  }, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
29614
29609
  };
29615
- disposers.push(onSubChannelCreated(realtimeRouter('onCreate')), onSubChannelDeleted(realtimeRouter('onDelete')), onSubChannelFetched(realtimeRouter('onFetch')), onSubChannelUpdated(realtimeRouter('onUpdate')), convertEventPayload(onSubChannelMarkerFetched, 'feedId', 'subChannel')(realtimeRouter('onUpdate')));
29610
+ disposers.push(onMessageCreated(message => {
29611
+ const cacheData = pullFromCache([
29612
+ 'subChannel',
29613
+ 'get',
29614
+ message.subChannelId,
29615
+ ]);
29616
+ if (!cacheData)
29617
+ return;
29618
+ realtimeRouter('onUpdate')(Object.assign(Object.assign({}, cacheData.data), { subChannelId: message.subChannelId, lastActivity: message.createdAt }));
29619
+ }), onSubChannelCreated(realtimeRouter('onCreate')), onSubChannelDeleted(realtimeRouter('onDelete')), onSubChannelFetched(realtimeRouter('onFetch')), onSubChannelUpdated(realtimeRouter('onUpdate')), convertEventPayload(onSubChannelMarkerFetched, 'feedId', 'subChannel')(realtimeRouter('onUpdate')));
29616
29620
  onFetch();
29617
29621
  return () => {
29618
29622
  log(`getSubChannels(tmpid: ${timestamp}) > dispose`);
package/dist/index.esm.js CHANGED
@@ -82,8 +82,8 @@ const PostContentType = Object.freeze({
82
82
 
83
83
  function getVersion() {
84
84
  try {
85
- // the string ''v6.7.0-esm'' should be replaced by actual value by @rollup/plugin-replace
86
- return 'v6.7.0-esm';
85
+ // the string ''v6.7.1-esm'' should be replaced by actual value by @rollup/plugin-replace
86
+ return 'v6.7.1-esm';
87
87
  }
88
88
  catch (error) {
89
89
  return '__dev__';
@@ -20987,20 +20987,6 @@ const setIntervalTask = (handler, timeout) => {
20987
20987
  return () => clearInterval(timer);
20988
20988
  };
20989
20989
 
20990
- const onOnline = (callback) => {
20991
- if (typeof window !== 'undefined' && window.addEventListener) {
20992
- window.addEventListener('online', callback);
20993
- return () => window.removeEventListener('online', callback);
20994
- }
20995
- if (typeof document !== 'undefined' && document.addEventListener) {
20996
- document.addEventListener('online', callback);
20997
- return () => document.removeEventListener('online', callback);
20998
- }
20999
- // Handle unsupported environment
21000
- console.error('Unsupported environment');
21001
- return () => console.error('Unsupported environment');
21002
- };
21003
-
21004
20990
  /**
21005
20991
  * ```js
21006
20992
  * import { isInTombstone } from '@amityco/ts-sdk'
@@ -21561,6 +21547,17 @@ const markReadEngineOnLoginHandler = () => {
21561
21547
  stopIntervalTask();
21562
21548
  };
21563
21549
  };
21550
+ /**
21551
+ * the event callback when app is back to online
21552
+ */
21553
+ const onOnline$1 = () => {
21554
+ const callback = () => {
21555
+ // Start reading the reading subChannel again when resume from offline state
21556
+ startReadingFromReadingList();
21557
+ };
21558
+ window.addEventListener('online', callback);
21559
+ return () => window.removeEventListener('online', callback);
21560
+ };
21564
21561
  const getParentChannelId = async (subChannelId) => {
21565
21562
  const cached = getSubChannel$1.locally(subChannelId);
21566
21563
  if (cached) {
@@ -21570,10 +21567,7 @@ const getParentChannelId = async (subChannelId) => {
21570
21567
  return data.channelId;
21571
21568
  };
21572
21569
  const registerEventListeners$1 = () => {
21573
- disposers$1.push(onOnline(() => {
21574
- // Start reading the reading subChannel again when resume from offline state
21575
- startReadingFromReadingList();
21576
- }));
21570
+ disposers$1.push(onOnline$1());
21577
21571
  };
21578
21572
  const registerTopicSubscribers = async (subChannelId) => {
21579
21573
  const channelId = await getParentChannelId(subChannelId);
@@ -24007,11 +24001,6 @@ const onMessageCreated = (callback, local = true) => {
24007
24001
  const message = payload.messages[0];
24008
24002
  // Update in cache
24009
24003
  ingestInCache(payload);
24010
- // Update lastActivity for Channel and SubChannel
24011
- payload.messages.forEach(({ channelId, subChannelId, createdAt }) => {
24012
- upsertInCache(['channel', 'get', channelId], { lastActivity: createdAt });
24013
- upsertInCache(['subChannel', 'get', channelId], { lastActivity: createdAt });
24014
- });
24015
24004
  callback(message);
24016
24005
  };
24017
24006
  const disposers = [
@@ -24395,16 +24384,22 @@ const markerSyncTrigger = async () => {
24395
24384
  // eslint-disable-next-line require-atomic-updates
24396
24385
  isWaitingForResponse = false;
24397
24386
  };
24387
+ /**
24388
+ * the event callback when app is back to online
24389
+ */
24390
+ const onOnline = () => {
24391
+ // should add RESUME to the event to trigger marker syncing again
24392
+ const callback = () => events.push("resume" /* Amity.MarkerSyncEvent.RESUME */);
24393
+ window.addEventListener('online', callback);
24394
+ return () => window.removeEventListener('online', callback);
24395
+ };
24398
24396
  const registerEventListeners = () => {
24399
24397
  // based on the tech spec design, we designed a fetch marker in case of these events
24400
24398
  // - new message
24401
24399
  // - create channel
24402
24400
  // - remove channel
24403
24401
  // - app going to online again after offline
24404
- disposers.push(onOnline(() => {
24405
- // should add RESUME to the event to trigger marker syncing again
24406
- events.push("resume" /* Amity.MarkerSyncEvent.RESUME */);
24407
- }), onMessageCreated(message => {
24402
+ disposers.push(onOnline(), onMessageCreated(message => {
24408
24403
  // only conversation, community and broadcast types can sync
24409
24404
  if (isUnreadCountSupport(message))
24410
24405
  events.push("new message" /* Amity.MarkerSyncEvent.NEW_MESSAGE */);
@@ -29598,7 +29593,16 @@ const getSubChannels = (params, callback, config) => {
29598
29593
  responder(snapshot);
29599
29594
  }, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
29600
29595
  };
29601
- disposers.push(onSubChannelCreated(realtimeRouter('onCreate')), onSubChannelDeleted(realtimeRouter('onDelete')), onSubChannelFetched(realtimeRouter('onFetch')), onSubChannelUpdated(realtimeRouter('onUpdate')), convertEventPayload(onSubChannelMarkerFetched, 'feedId', 'subChannel')(realtimeRouter('onUpdate')));
29596
+ disposers.push(onMessageCreated(message => {
29597
+ const cacheData = pullFromCache([
29598
+ 'subChannel',
29599
+ 'get',
29600
+ message.subChannelId,
29601
+ ]);
29602
+ if (!cacheData)
29603
+ return;
29604
+ realtimeRouter('onUpdate')(Object.assign(Object.assign({}, cacheData.data), { subChannelId: message.subChannelId, lastActivity: message.createdAt }));
29605
+ }), onSubChannelCreated(realtimeRouter('onCreate')), onSubChannelDeleted(realtimeRouter('onDelete')), onSubChannelFetched(realtimeRouter('onFetch')), onSubChannelUpdated(realtimeRouter('onUpdate')), convertEventPayload(onSubChannelMarkerFetched, 'feedId', 'subChannel')(realtimeRouter('onUpdate')));
29602
29606
  onFetch();
29603
29607
  return () => {
29604
29608
  log(`getSubChannels(tmpid: ${timestamp}) > dispose`);