@amityco/ts-sdk 6.7.3-cbeeb97.0 → 6.7.3-ceeb20b.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.
@@ -17,6 +17,7 @@ declare global {
17
17
  };
18
18
  type ContentDataImage = {
19
19
  fileId: Amity.File<'image'>['fileId'];
20
+ caption?: string;
20
21
  };
21
22
  type Attachment = {
22
23
  type: 'image' | 'link';
@@ -1 +1 @@
1
- {"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../../../src/@types/domains/content.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe;;;;;;EAM1B,CAAC;AAEH,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK,CAAC;QACd,KAAK,WAAW,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;QAElF,KAAK,eAAe,GAAG,OAAO,CAAC,OAAO,eAAe,CAAC,CAAC;QAEvD,KAAK,eAAe,GAAG;YACrB,IAAI,EAAE,MAAM,CAAC;SACd,CAAC;QAEF,KAAK,eAAe,GAAG;YACrB,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC;SACtC,CAAC;QAEF,KAAK,gBAAgB,GAAG;YACtB,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC;SACvC,CAAC;QAEF,KAAK,UAAU,GAAG;YAChB,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC;YACvB,GAAG,CAAC,EAAE,MAAM,CAAC;YACb,MAAM,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC;SACxC,CAAC;QAEF,KAAK,gBAAgB,GAAG;YACtB,eAAe,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC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- {"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":"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;AAqDF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,qBAK3B,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,YAI1B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,YAI7B,CAAC"}
package/dist/index.cjs.js CHANGED
@@ -5238,8 +5238,11 @@ const prepareMessagePayload = async (payload, event) => {
5238
5238
  return Object.assign(Object.assign({}, payload), { messages: payload.messages.map(m => convertFromRaw$1(m, payload.reactions, event)) });
5239
5239
  };
5240
5240
  function convertParams(_a) {
5241
- var { subChannelId, mentionees } = _a, rest = __rest(_a, ["subChannelId", "mentionees"]);
5242
- return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees }, rest);
5241
+ var { subChannelId, mentionees, dataType, data } = _a, rest = __rest(_a, ["subChannelId", "mentionees", "dataType", "data"]);
5242
+ if (dataType === MessageContentType.IMAGE || dataType === MessageContentType.FILE) {
5243
+ return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees, dataType, data: Object.assign({ caption: '' }, data) }, rest);
5244
+ }
5245
+ return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees, dataType, data }, rest);
5243
5246
  }
5244
5247
  function convertQueryParams$1(_a) {
5245
5248
  var { page, sortBy, subChannelId, tags, includeDeleted } = _a, rest = __rest(_a, ["page", "sortBy", "subChannelId", "tags", "includeDeleted"]);
@@ -5513,7 +5516,7 @@ const stopReadingAPI = async (messageFeedId) => {
5513
5516
  };
5514
5517
 
5515
5518
  const START_READING_INTERVAL_TIME = 30000;
5516
- let clearIntervalTask = null;
5519
+ let isSyncRunning$1 = false;
5517
5520
  let disposers$1 = [];
5518
5521
  /**
5519
5522
  * map contains subChannelId and isReading flag to determine which subChannel is on reading state
@@ -5536,13 +5539,10 @@ const startReadingFromReadingList = async () => {
5536
5539
  return readingAPI(isReadingSubChannelIds);
5537
5540
  };
5538
5541
  const startIntervalTask = () => {
5539
- if (clearIntervalTask === null) {
5540
- clearIntervalTask = setIntervalTask(startReadingFromReadingList, START_READING_INTERVAL_TIME);
5541
- }
5542
+ isSyncRunning$1 = true;
5542
5543
  };
5543
5544
  const stopIntervalTask = () => {
5544
- clearIntervalTask === null || clearIntervalTask === void 0 ? void 0 : clearIntervalTask();
5545
- clearIntervalTask = null;
5545
+ isSyncRunning$1 = false;
5546
5546
  };
5547
5547
  /**
5548
5548
  * global task for mark read engines runs when the client is authenticated.
@@ -5570,6 +5570,9 @@ const getParentChannelId = async (subChannelId) => {
5570
5570
  return data.channelId;
5571
5571
  };
5572
5572
  const registerEventListeners$1 = () => {
5573
+ if (disposers$1.length > 0) {
5574
+ return;
5575
+ }
5573
5576
  disposers$1.push(onOnline(() => {
5574
5577
  // Start reading the reading subChannel again when resume from offline state
5575
5578
  startReadingFromReadingList();
@@ -5640,7 +5643,12 @@ const stopReading = (subChannelId) => {
5640
5643
  disposeAll();
5641
5644
  return stopReadingAPI(subChannelId);
5642
5645
  };
5643
- /* end_public_function */
5646
+ /* end_public_function */
5647
+ setIntervalTask(async () => {
5648
+ if (!isSyncRunning$1)
5649
+ return;
5650
+ await startReadingFromReadingList();
5651
+ }, START_READING_INTERVAL_TIME);
5644
5652
 
5645
5653
  const createUserEventSubscriber = (event, callback) => {
5646
5654
  const client = getActiveClient();
@@ -6425,23 +6433,28 @@ const convertGetterPropsToStatic = (obj) => {
6425
6433
  const onMessageMarked = (callback) => {
6426
6434
  const client = getActiveClient();
6427
6435
  const filter = (payload) => {
6436
+ var _a, _b;
6428
6437
  ingestInCache(payload);
6429
6438
  const cacheCollection = queryCache(['message', 'collection']);
6430
- if (cacheCollection) {
6439
+ if (cacheCollection && (cacheCollection === null || cacheCollection === void 0 ? void 0 : cacheCollection.length) > 0) {
6440
+ const contentMarker = payload.contentMarkers[0];
6431
6441
  const currentMessageCollection = cacheCollection.filter(currentMessage => {
6432
6442
  if (!isObject(currentMessage.key[2]))
6433
6443
  return false;
6434
- return currentMessage.key[2].subChannelId === payload.contentMarkers[0].feedId;
6444
+ return currentMessage.key[2].subChannelId === contentMarker.feedId;
6435
6445
  });
6436
- if (currentMessageCollection) {
6437
- const currentMessages = currentMessageCollection[0].data.data.map(messageId => {
6446
+ if (currentMessageCollection.length > 0) {
6447
+ const currentMessages = ((_b = (_a = currentMessageCollection[0].data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.map(messageId => {
6438
6448
  return pullFromCache(['message', 'get', messageId]);
6439
- });
6449
+ })) || [];
6440
6450
  currentMessages.forEach(message => {
6441
- const isSameSubChannelId = payload.contentMarkers[0].feedId === (message === null || message === void 0 ? void 0 : message.data.subChannelId);
6442
- const isReadCountLatest = payload.contentMarkers[0].readCount > (message === null || message === void 0 ? void 0 : message.data.readCount);
6443
- if (isSameSubChannelId && isReadCountLatest) {
6444
- pushToCache(['message', 'get', message.data.messageId], Object.assign(Object.assign({}, message.data), { readCount: payload.contentMarkers[0].readCount }));
6451
+ const isSameSubChannelId = contentMarker.feedId === (message === null || message === void 0 ? void 0 : message.data.subChannelId);
6452
+ const isReadCountLatest = contentMarker.readCount > (message === null || message === void 0 ? void 0 : message.data.readCount);
6453
+ const isDeliveredCountLatest = contentMarker.deliveredCount > (message === null || message === void 0 ? void 0 : message.data.deliveredCount);
6454
+ if (isSameSubChannelId) {
6455
+ pushToCache(['message', 'get', message.data.messageId], Object.assign(Object.assign({}, message.data), { readCount: isReadCountLatest ? contentMarker.readCount : message === null || message === void 0 ? void 0 : message.data.readCount, deliveredCount: isDeliveredCountLatest
6456
+ ? contentMarker.deliveredCount
6457
+ : message === null || message === void 0 ? void 0 : message.data.deliveredCount }));
6445
6458
  }
6446
6459
  });
6447
6460
  }
@@ -8389,7 +8402,7 @@ const onSubChannelDeleted = (callback) => {
8389
8402
 
8390
8403
  const SYNC_TRIGGER_INTERVAL_TIME = 2000;
8391
8404
  const ON_SUB_CHANNEL_DELETE_SYNC_TRIGGER_DELAY = 2000;
8392
- let clearSyncTrigger;
8405
+ let isSyncRunning = false;
8393
8406
  let disposers = [];
8394
8407
  let isWaitingForResponse = false;
8395
8408
  let deviceLastSyncAt = null;
@@ -8458,6 +8471,9 @@ const markerSyncTrigger = async () => {
8458
8471
  isWaitingForResponse = false;
8459
8472
  };
8460
8473
  const registerEventListeners = () => {
8474
+ if (disposers.length > 0) {
8475
+ return;
8476
+ }
8461
8477
  // based on the tech spec design, we designed a fetch marker in case of these events
8462
8478
  // - new message
8463
8479
  // - create channel
@@ -8499,17 +8515,7 @@ const unRegisterEventListeners = () => {
8499
8515
  const startUnreadSync = async () => {
8500
8516
  await fetchDeviceLastSyncAt();
8501
8517
  pushMarkerSyncEvent("start syncing" /* Amity.MarkerSyncEvent.START_SYNCING */);
8502
- if (!clearSyncTrigger) {
8503
- // it is possible to repeatedly call the API when multiple events occur at the same time.
8504
- // This is very burdensome to the BE Server, so we have an interval loop for
8505
- // grouping every event that occurs within 2 seconds into a single API call.
8506
- //
8507
- // interval loop is also useful for fetching large results. Because if the result
8508
- // is more than 20 records, the API will split the result into multiple pages
8509
- // and the SDK will need to fetch it repeatedly until all the results are available.
8510
- // So we need an interval loop for repeat fetch.
8511
- clearSyncTrigger = setIntervalTask(markerSyncTrigger, SYNC_TRIGGER_INTERVAL_TIME);
8512
- }
8518
+ isSyncRunning = true;
8513
8519
  registerEventListeners();
8514
8520
  };
8515
8521
  /**
@@ -8523,8 +8529,7 @@ const startUnreadSync = async () => {
8523
8529
  * @category Marker API
8524
8530
  */
8525
8531
  const stopUnreadSync = () => {
8526
- clearSyncTrigger === null || clearSyncTrigger === void 0 ? void 0 : clearSyncTrigger();
8527
- clearSyncTrigger = undefined;
8532
+ isSyncRunning = false;
8528
8533
  setMarkerSyncEvents([]);
8529
8534
  unRegisterEventListeners();
8530
8535
  };
@@ -8534,7 +8539,12 @@ const stopUnreadSync = () => {
8534
8539
  const stopUnreadSyncing = () => {
8535
8540
  console.warn('`stopUnreadSyncing` has been deprecated, please use `stopUnreadSync` instead');
8536
8541
  return stopUnreadSync();
8537
- };
8542
+ };
8543
+ setIntervalTask(async () => {
8544
+ if (!isSyncRunning)
8545
+ return;
8546
+ await markerSyncTrigger();
8547
+ }, SYNC_TRIGGER_INTERVAL_TIME);
8538
8548
 
8539
8549
  var index$f = /*#__PURE__*/Object.freeze({
8540
8550
  __proto__: null,
@@ -13077,12 +13087,22 @@ const getMessages = (params, callback, config) => {
13077
13087
  const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
13078
13088
  const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
13079
13089
  const disposers = [];
13080
- const cacheKey = ['message', 'collection', params];
13090
+ const cacheKey = ['message', 'collection', params, uuid()];
13081
13091
  const responder = (data) => {
13082
13092
  var _a, _b;
13083
13093
  let messages = (_a = data.data
13084
13094
  .map(messageId => pullFromCache(['message', 'get', messageId]))
13085
13095
  .filter(Boolean)
13096
+ .filter(item => {
13097
+ if (!params.tags)
13098
+ return true;
13099
+ return params.tags.find(value => {
13100
+ var _a;
13101
+ if (!((_a = item.data) === null || _a === void 0 ? void 0 : _a.tags))
13102
+ return false;
13103
+ return item.data.tags.includes(value);
13104
+ });
13105
+ })
13086
13106
  .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
13087
13107
  /*
13088
13108
  * for cases when message is deleted via RTE, this flag is used to get
@@ -13099,14 +13119,11 @@ const getMessages = (params, callback, config) => {
13099
13119
  error: data.error,
13100
13120
  });
13101
13121
  };
13102
- const realtimeRouter = (_) => (message) => {
13122
+ const realtimeRouter = (action) => (message) => {
13103
13123
  var _a;
13104
13124
  const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
13105
13125
  if (params.subChannelId !== (message === null || message === void 0 ? void 0 : message.subChannelId) || !collection)
13106
13126
  return;
13107
- if (!collection.data.includes(message.messageId)) {
13108
- collection.data = [...new Set([message.messageId, ...collection.data])];
13109
- }
13110
13127
  pushToCache(cacheKey, collection);
13111
13128
  responder(collection);
13112
13129
  };
package/dist/index.esm.js CHANGED
@@ -21329,8 +21329,11 @@ const prepareMessagePayload = async (payload, event) => {
21329
21329
  return Object.assign(Object.assign({}, payload), { messages: payload.messages.map(m => convertFromRaw$1(m, payload.reactions, event)) });
21330
21330
  };
21331
21331
  function convertParams(_a) {
21332
- var { subChannelId, mentionees } = _a, rest = __rest(_a, ["subChannelId", "mentionees"]);
21333
- return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees }, rest);
21332
+ var { subChannelId, mentionees, dataType, data } = _a, rest = __rest(_a, ["subChannelId", "mentionees", "dataType", "data"]);
21333
+ if (dataType === MessageContentType.IMAGE || dataType === MessageContentType.FILE) {
21334
+ return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees, dataType, data: Object.assign({ caption: '' }, data) }, rest);
21335
+ }
21336
+ return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees, dataType, data }, rest);
21334
21337
  }
21335
21338
  function convertQueryParams$1(_a) {
21336
21339
  var { page, sortBy, subChannelId, tags, includeDeleted } = _a, rest = __rest(_a, ["page", "sortBy", "subChannelId", "tags", "includeDeleted"]);
@@ -21604,7 +21607,7 @@ const stopReadingAPI = async (messageFeedId) => {
21604
21607
  };
21605
21608
 
21606
21609
  const START_READING_INTERVAL_TIME = 30000;
21607
- let clearIntervalTask = null;
21610
+ let isSyncRunning$1 = false;
21608
21611
  let disposers$1 = [];
21609
21612
  /**
21610
21613
  * map contains subChannelId and isReading flag to determine which subChannel is on reading state
@@ -21627,13 +21630,10 @@ const startReadingFromReadingList = async () => {
21627
21630
  return readingAPI(isReadingSubChannelIds);
21628
21631
  };
21629
21632
  const startIntervalTask = () => {
21630
- if (clearIntervalTask === null) {
21631
- clearIntervalTask = setIntervalTask(startReadingFromReadingList, START_READING_INTERVAL_TIME);
21632
- }
21633
+ isSyncRunning$1 = true;
21633
21634
  };
21634
21635
  const stopIntervalTask = () => {
21635
- clearIntervalTask === null || clearIntervalTask === void 0 ? void 0 : clearIntervalTask();
21636
- clearIntervalTask = null;
21636
+ isSyncRunning$1 = false;
21637
21637
  };
21638
21638
  /**
21639
21639
  * global task for mark read engines runs when the client is authenticated.
@@ -21661,6 +21661,9 @@ const getParentChannelId = async (subChannelId) => {
21661
21661
  return data.channelId;
21662
21662
  };
21663
21663
  const registerEventListeners$1 = () => {
21664
+ if (disposers$1.length > 0) {
21665
+ return;
21666
+ }
21664
21667
  disposers$1.push(onOnline(() => {
21665
21668
  // Start reading the reading subChannel again when resume from offline state
21666
21669
  startReadingFromReadingList();
@@ -21731,7 +21734,12 @@ const stopReading = (subChannelId) => {
21731
21734
  disposeAll();
21732
21735
  return stopReadingAPI(subChannelId);
21733
21736
  };
21734
- /* end_public_function */
21737
+ /* end_public_function */
21738
+ setIntervalTask(async () => {
21739
+ if (!isSyncRunning$1)
21740
+ return;
21741
+ await startReadingFromReadingList();
21742
+ }, START_READING_INTERVAL_TIME);
21735
21743
 
21736
21744
  const createUserEventSubscriber = (event, callback) => {
21737
21745
  const client = getActiveClient();
@@ -22516,23 +22524,28 @@ const convertGetterPropsToStatic = (obj) => {
22516
22524
  const onMessageMarked = (callback) => {
22517
22525
  const client = getActiveClient();
22518
22526
  const filter = (payload) => {
22527
+ var _a, _b;
22519
22528
  ingestInCache(payload);
22520
22529
  const cacheCollection = queryCache(['message', 'collection']);
22521
- if (cacheCollection) {
22530
+ if (cacheCollection && (cacheCollection === null || cacheCollection === void 0 ? void 0 : cacheCollection.length) > 0) {
22531
+ const contentMarker = payload.contentMarkers[0];
22522
22532
  const currentMessageCollection = cacheCollection.filter(currentMessage => {
22523
22533
  if (!isObject(currentMessage.key[2]))
22524
22534
  return false;
22525
- return currentMessage.key[2].subChannelId === payload.contentMarkers[0].feedId;
22535
+ return currentMessage.key[2].subChannelId === contentMarker.feedId;
22526
22536
  });
22527
- if (currentMessageCollection) {
22528
- const currentMessages = currentMessageCollection[0].data.data.map(messageId => {
22537
+ if (currentMessageCollection.length > 0) {
22538
+ const currentMessages = ((_b = (_a = currentMessageCollection[0].data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.map(messageId => {
22529
22539
  return pullFromCache(['message', 'get', messageId]);
22530
- });
22540
+ })) || [];
22531
22541
  currentMessages.forEach(message => {
22532
- const isSameSubChannelId = payload.contentMarkers[0].feedId === (message === null || message === void 0 ? void 0 : message.data.subChannelId);
22533
- const isReadCountLatest = payload.contentMarkers[0].readCount > (message === null || message === void 0 ? void 0 : message.data.readCount);
22534
- if (isSameSubChannelId && isReadCountLatest) {
22535
- pushToCache(['message', 'get', message.data.messageId], Object.assign(Object.assign({}, message.data), { readCount: payload.contentMarkers[0].readCount }));
22542
+ const isSameSubChannelId = contentMarker.feedId === (message === null || message === void 0 ? void 0 : message.data.subChannelId);
22543
+ const isReadCountLatest = contentMarker.readCount > (message === null || message === void 0 ? void 0 : message.data.readCount);
22544
+ const isDeliveredCountLatest = contentMarker.deliveredCount > (message === null || message === void 0 ? void 0 : message.data.deliveredCount);
22545
+ if (isSameSubChannelId) {
22546
+ pushToCache(['message', 'get', message.data.messageId], Object.assign(Object.assign({}, message.data), { readCount: isReadCountLatest ? contentMarker.readCount : message === null || message === void 0 ? void 0 : message.data.readCount, deliveredCount: isDeliveredCountLatest
22547
+ ? contentMarker.deliveredCount
22548
+ : message === null || message === void 0 ? void 0 : message.data.deliveredCount }));
22536
22549
  }
22537
22550
  });
22538
22551
  }
@@ -24480,7 +24493,7 @@ const onSubChannelDeleted = (callback) => {
24480
24493
 
24481
24494
  const SYNC_TRIGGER_INTERVAL_TIME = 2000;
24482
24495
  const ON_SUB_CHANNEL_DELETE_SYNC_TRIGGER_DELAY = 2000;
24483
- let clearSyncTrigger;
24496
+ let isSyncRunning = false;
24484
24497
  let disposers = [];
24485
24498
  let isWaitingForResponse = false;
24486
24499
  let deviceLastSyncAt = null;
@@ -24549,6 +24562,9 @@ const markerSyncTrigger = async () => {
24549
24562
  isWaitingForResponse = false;
24550
24563
  };
24551
24564
  const registerEventListeners = () => {
24565
+ if (disposers.length > 0) {
24566
+ return;
24567
+ }
24552
24568
  // based on the tech spec design, we designed a fetch marker in case of these events
24553
24569
  // - new message
24554
24570
  // - create channel
@@ -24590,17 +24606,7 @@ const unRegisterEventListeners = () => {
24590
24606
  const startUnreadSync = async () => {
24591
24607
  await fetchDeviceLastSyncAt();
24592
24608
  pushMarkerSyncEvent("start syncing" /* Amity.MarkerSyncEvent.START_SYNCING */);
24593
- if (!clearSyncTrigger) {
24594
- // it is possible to repeatedly call the API when multiple events occur at the same time.
24595
- // This is very burdensome to the BE Server, so we have an interval loop for
24596
- // grouping every event that occurs within 2 seconds into a single API call.
24597
- //
24598
- // interval loop is also useful for fetching large results. Because if the result
24599
- // is more than 20 records, the API will split the result into multiple pages
24600
- // and the SDK will need to fetch it repeatedly until all the results are available.
24601
- // So we need an interval loop for repeat fetch.
24602
- clearSyncTrigger = setIntervalTask(markerSyncTrigger, SYNC_TRIGGER_INTERVAL_TIME);
24603
- }
24609
+ isSyncRunning = true;
24604
24610
  registerEventListeners();
24605
24611
  };
24606
24612
  /**
@@ -24614,8 +24620,7 @@ const startUnreadSync = async () => {
24614
24620
  * @category Marker API
24615
24621
  */
24616
24622
  const stopUnreadSync = () => {
24617
- clearSyncTrigger === null || clearSyncTrigger === void 0 ? void 0 : clearSyncTrigger();
24618
- clearSyncTrigger = undefined;
24623
+ isSyncRunning = false;
24619
24624
  setMarkerSyncEvents([]);
24620
24625
  unRegisterEventListeners();
24621
24626
  };
@@ -24625,7 +24630,12 @@ const stopUnreadSync = () => {
24625
24630
  const stopUnreadSyncing = () => {
24626
24631
  console.warn('`stopUnreadSyncing` has been deprecated, please use `stopUnreadSync` instead');
24627
24632
  return stopUnreadSync();
24628
- };
24633
+ };
24634
+ setIntervalTask(async () => {
24635
+ if (!isSyncRunning)
24636
+ return;
24637
+ await markerSyncTrigger();
24638
+ }, SYNC_TRIGGER_INTERVAL_TIME);
24629
24639
 
24630
24640
  var index$f = /*#__PURE__*/Object.freeze({
24631
24641
  __proto__: null,
@@ -29168,12 +29178,22 @@ const getMessages = (params, callback, config) => {
29168
29178
  const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
29169
29179
  const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
29170
29180
  const disposers = [];
29171
- const cacheKey = ['message', 'collection', params];
29181
+ const cacheKey = ['message', 'collection', params, uuid()];
29172
29182
  const responder = (data) => {
29173
29183
  var _a, _b;
29174
29184
  let messages = (_a = data.data
29175
29185
  .map(messageId => pullFromCache(['message', 'get', messageId]))
29176
29186
  .filter(Boolean)
29187
+ .filter(item => {
29188
+ if (!params.tags)
29189
+ return true;
29190
+ return params.tags.find(value => {
29191
+ var _a;
29192
+ if (!((_a = item.data) === null || _a === void 0 ? void 0 : _a.tags))
29193
+ return false;
29194
+ return item.data.tags.includes(value);
29195
+ });
29196
+ })
29177
29197
  .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
29178
29198
  /*
29179
29199
  * for cases when message is deleted via RTE, this flag is used to get
@@ -29190,14 +29210,11 @@ const getMessages = (params, callback, config) => {
29190
29210
  error: data.error,
29191
29211
  });
29192
29212
  };
29193
- const realtimeRouter = (_) => (message) => {
29213
+ const realtimeRouter = (action) => (message) => {
29194
29214
  var _a;
29195
29215
  const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
29196
29216
  if (params.subChannelId !== (message === null || message === void 0 ? void 0 : message.subChannelId) || !collection)
29197
29217
  return;
29198
- if (!collection.data.includes(message.messageId)) {
29199
- collection.data = [...new Set([message.messageId, ...collection.data])];
29200
- }
29201
29218
  pushToCache(cacheKey, collection);
29202
29219
  responder(collection);
29203
29220
  };