@amityco/ts-sdk 6.4.1 → 6.4.2-66daf4a.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 (34) hide show
  1. package/.eslintrc.json +2 -1
  2. package/dist/@types/core/live.d.ts +5 -0
  3. package/dist/@types/core/live.d.ts.map +1 -1
  4. package/dist/cache/api/mergeInCache.d.ts.map +1 -1
  5. package/dist/client/observers/getTotalUnreadCount.d.ts.map +1 -1
  6. package/dist/client/utils/markerSyncEngine.d.ts +4 -0
  7. package/dist/client/utils/markerSyncEngine.d.ts.map +1 -1
  8. package/dist/core/model/index.d.ts +1 -1
  9. package/dist/core/model/index.d.ts.map +1 -1
  10. package/dist/core/transports/mqtt.d.ts.map +1 -1
  11. package/dist/index.cjs.js +49 -35
  12. package/dist/index.esm.js +49 -35
  13. package/dist/index.umd.js +4 -4
  14. package/dist/subChannelRepository/utils/markReadEngine.d.ts +1 -1
  15. package/dist/subChannelRepository/utils/markReadEngine.d.ts.map +1 -1
  16. package/dist/userRepository/relationship/follow/observers/getFollowInfo.d.ts.map +1 -1
  17. package/dist/utils/index.d.ts +1 -1
  18. package/dist/utils/index.d.ts.map +1 -1
  19. package/dist/utils/liveObject.d.ts +1 -1
  20. package/dist/utils/liveObject.d.ts.map +1 -1
  21. package/package.json +1 -1
  22. package/src/@types/core/live.ts +6 -0
  23. package/src/cache/api/mergeInCache.ts +5 -0
  24. package/src/client/observers/getTotalUnreadCount.ts +4 -9
  25. package/src/client/utils/markerSyncEngine.ts +9 -0
  26. package/src/core/model/index.ts +6 -2
  27. package/src/core/transports/mqtt.ts +4 -2
  28. package/src/subChannelRepository/observers/getSubChannels.ts +2 -2
  29. package/src/subChannelRepository/utils/markReadEngine.ts +9 -4
  30. package/src/userRepository/relationship/follow/observers/getFollowInfo.ts +3 -1
  31. package/src/userRepository/relationship/follow/observers/tests/getFollowInfo.test.ts +5 -6
  32. package/src/utils/index.ts +4 -3
  33. package/src/utils/liveObject.ts +13 -22
  34. package/src/utils/tests/liveObject.test.ts +0 -17
package/.eslintrc.json CHANGED
@@ -28,7 +28,8 @@
28
28
  "import/no-extraneous-dependencies": ["error", { "devDependencies": true }],
29
29
  "import/no-unresolved": "off",
30
30
  "no-shadow": "off",
31
- "no-unused-vars": "off"
31
+ "no-unused-vars": "off",
32
+ "no-console": ["error", { "allow": ["warn", "error"] }]
32
33
  },
33
34
  "settings": {
34
35
  "import/resolver": {
@@ -8,6 +8,11 @@ declare global {
8
8
  origin?: 'local' | 'server' | 'event';
9
9
  };
10
10
  type LiveObjectCallback<T extends any> = Amity.Listener<LiveObject<T>>;
11
+ type LiveObjectOptions<T extends Amity.Models[Amity.Domain], CallbackData extends any = any> = {
12
+ forceDispatch?: boolean;
13
+ callbackDataSelector?: (data: T) => CallbackData;
14
+ callbackFilter?: (currentModel: T, previousModel: T) => boolean;
15
+ };
11
16
  type LiveCollection<T extends any> = LiveObject<T[]> & {
12
17
  onNextPage: () => void;
13
18
  hasNextPage: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"live.d.ts","sourceRoot":"","sources":["../../../src/@types/core/live.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC;AAEV,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK,CAAC;QACd,KAAK,UAAU,CAAC,CAAC,SAAS,GAAG,IAAI;YAC/B,IAAI,EAAE,CAAC,CAAC;YACR,KAAK,CAAC,EAAE,GAAG,CAAC;YACZ,OAAO,EAAE,OAAO,CAAC;YACjB,MAAM,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;SACvC,CAAC;QAEF,KAAK,kBAAkB,CAAC,CAAC,SAAS,GAAG,IAAI,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;QAEvE,KAAK,cAAc,CAAC,CAAC,SAAS,GAAG,IAAI,UAAU,CAAC,CAAC,EAAE,CAAC,GAAG;YACrD,UAAU,EAAE,MAAM,IAAI,CAAC;YACvB,WAAW,EAAE,OAAO,CAAC;SACtB,CAAC;QAEF,KAAK,sBAAsB,CAAC,CAAC,SAAS,GAAG,IAAI,KAAK,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;QAE/E,KAAK,oBAAoB,GAAG;YAC1B,MAAM,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;SACjD,CAAC;QAEF,KAAK,oBAAoB,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG;YAC7C,KAAK,CAAC,EAAE,MAAM,CAAC;SAChB,CAAC;QAEF,KAAK,mBAAmB,CAAC,CAAC,SAAS,GAAG,EAAE,CAAC,SAAS,GAAG,IAAI,IAAI,CAC3D,cAAc,CAAC,CAAC,CAAC,EACjB,MAAM,GAAG,OAAO,GAAG,SAAS,CAC7B,GAAG;YAAE,MAAM,EAAE,CAAC,CAAA;SAAE,CAAC;KACnB;CACF"}
1
+ {"version":3,"file":"live.d.ts","sourceRoot":"","sources":["../../../src/@types/core/live.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC;AAEV,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK,CAAC;QACd,KAAK,UAAU,CAAC,CAAC,SAAS,GAAG,IAAI;YAC/B,IAAI,EAAE,CAAC,CAAC;YACR,KAAK,CAAC,EAAE,GAAG,CAAC;YACZ,OAAO,EAAE,OAAO,CAAC;YACjB,MAAM,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;SACvC,CAAC;QAEF,KAAK,kBAAkB,CAAC,CAAC,SAAS,GAAG,IAAI,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;QAEvE,KAAK,iBAAiB,CAAC,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,YAAY,SAAS,GAAG,GAAG,GAAG,IAAI;YAC7F,aAAa,CAAC,EAAE,OAAO,CAAC;YACxB,oBAAoB,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,YAAY,CAAC;YACjD,cAAc,CAAC,EAAE,CAAC,YAAY,EAAE,CAAC,EAAE,aAAa,EAAE,CAAC,KAAK,OAAO,CAAC;SACjE,CAAC;QAEF,KAAK,cAAc,CAAC,CAAC,SAAS,GAAG,IAAI,UAAU,CAAC,CAAC,EAAE,CAAC,GAAG;YACrD,UAAU,EAAE,MAAM,IAAI,CAAC;YACvB,WAAW,EAAE,OAAO,CAAC;SACtB,CAAC;QAEF,KAAK,sBAAsB,CAAC,CAAC,SAAS,GAAG,IAAI,KAAK,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;QAE/E,KAAK,oBAAoB,GAAG;YAC1B,MAAM,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;SACjD,CAAC;QAEF,KAAK,oBAAoB,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG;YAC7C,KAAK,CAAC,EAAE,MAAM,CAAC;SAChB,CAAC;QAEF,KAAK,mBAAmB,CAAC,CAAC,SAAS,GAAG,EAAE,CAAC,SAAS,GAAG,IAAI,IAAI,CAC3D,cAAc,CAAC,CAAC,CAAC,EACjB,MAAM,GAAG,OAAO,GAAG,SAAS,CAC7B,GAAG;YAAE,MAAM,EAAE,CAAC,CAAA;SAAE,CAAC;KACnB;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"mergeInCache.d.ts","sourceRoot":"","sources":["../../../src/cache/api/mergeInCache.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,YAAY,gHAGb,MAAM,YAAY,KAC3B,OAeF,CAAC"}
1
+ {"version":3,"file":"mergeInCache.d.ts","sourceRoot":"","sources":["../../../src/cache/api/mergeInCache.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,YAAY,gHAGb,MAAM,YAAY,KAC3B,OAmBF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getTotalUnreadCount.d.ts","sourceRoot":"","sources":["../../../src/client/observers/getTotalUnreadCount.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,mBAAmB,aACpB,MAAM,kBAAkB,CAAC,MAAM,CAAC,KACzC,MAAM,YA0BR,CAAC"}
1
+ {"version":3,"file":"getTotalUnreadCount.d.ts","sourceRoot":"","sources":["../../../src/client/observers/getTotalUnreadCount.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,mBAAmB,aACpB,MAAM,kBAAkB,CAAC,MAAM,CAAC,KACzC,MAAM,YAqBR,CAAC"}
@@ -41,4 +41,8 @@ export declare const startUnreadSync: () => Promise<void>;
41
41
  * @category Marker API
42
42
  */
43
43
  export declare const stopUnreadSync: () => void;
44
+ /**
45
+ * @deprecated Please use `startUnreadSync` instead
46
+ */
47
+ export declare const stopUnreadSyncing: () => void;
44
48
  //# sourceMappingURL=markerSyncEngine.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"markerSyncEngine.d.ts","sourceRoot":"","sources":["../../../src/client/utils/markerSyncEngine.ts"],"names":[],"mappings":"AAiDA;;;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;AAgDF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,qBAiB3B,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,YAK1B,CAAC"}
1
+ {"version":3,"file":"markerSyncEngine.d.ts","sourceRoot":"","sources":["../../../src/client/utils/markerSyncEngine.ts"],"names":[],"mappings":"AAiDA;;;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;AAgDF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,qBAiB3B,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,YAK1B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,YAI7B,CAAC"}
@@ -6,7 +6,7 @@ export * from './identifyModel';
6
6
  */
7
7
  export declare const PAYLOAD2MODEL: Record<string, Amity.Domain>;
8
8
  /** hidden */
9
- export declare const hasUpdates: <T extends Amity.UpdatedAt>(prevData: T, nextData: T) => boolean;
9
+ export declare const isOutdated: <T extends Amity.UpdatedAt>(prevData: T, nextData: T) => boolean;
10
10
  /** hidden */
11
11
  export declare function getFutureDate(date?: string | undefined): string;
12
12
  /** hidden */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/model/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAEhC;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CA+BtD,CAAC;AAEF,aAAa;AACb,eAAO,MAAM,UAAU,2DAA0D,OAEhF,CAAC;AAEF,aAAa;AACb,wBAAgB,aAAa,CAAC,IAAI,GAAE,MAAM,GAAG,SAAoC,GAAG,MAAM,CAEzF;AAED,aAAa;AACb,wBAAgB,WAAW,CAAC,IAAI,GAAE,MAAM,GAAG,SAAoC,GAAG,MAAM,CAEvF"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/model/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAEhC;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CA+BtD,CAAC;AAEF,aAAa;AACb,eAAO,MAAM,UAAU,2DAA0D,OAMhF,CAAC;AAEF,aAAa;AACb,wBAAgB,aAAa,CAAC,IAAI,GAAE,MAAM,GAAG,SAAoC,GAAG,MAAM,CAEzF;AAED,aAAa;AACb,wBAAgB,WAAW,CAAC,IAAI,GAAE,MAAM,GAAG,SAAoC,GAAG,MAAM,CAEvF"}
@@ -1 +1 @@
1
- {"version":3,"file":"mqtt.d.ts","sourceRoot":"","sources":["../../../src/core/transports/mqtt.ts"],"names":[],"mappings":"AAEA,OAAa,EAAE,cAAc,EAAsB,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAetF,wBAAgB,cAAc,CAAC,MAAM,EAAE;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GAAG,cAAc,CAiBjB;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,aAAc,MAAM,KAAG,gBAyGtD,CAAC"}
1
+ {"version":3,"file":"mqtt.d.ts","sourceRoot":"","sources":["../../../src/core/transports/mqtt.ts"],"names":[],"mappings":"AAEA,OAAa,EAAE,cAAc,EAAsB,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAetF,wBAAgB,cAAc,CAAC,MAAM,EAAE;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GAAG,cAAc,CAiBjB;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,aAAc,MAAM,KAAG,gBA2GtD,CAAC"}
package/dist/index.cjs.js CHANGED
@@ -637,8 +637,11 @@ const PAYLOAD2MODEL = {
637
637
  feeds: 'feed',
638
638
  };
639
639
  /** hidden */
640
- const hasUpdates = (prevData, nextData) => {
641
- return new Date(prevData.updatedAt) < new Date(nextData.updatedAt);
640
+ const isOutdated = (prevData, nextData) => {
641
+ if ('updatedAt' in nextData && 'updatedAt' in nextData) {
642
+ return new Date(nextData.updatedAt) < new Date(prevData.updatedAt);
643
+ }
644
+ return false;
642
645
  };
643
646
  /** hidden */
644
647
  function getFutureDate(date = new Date().toISOString()) {
@@ -995,6 +998,9 @@ const mergeInCache = (key, mutation, options) => {
995
998
  if (!oldVal)
996
999
  return false;
997
1000
  const newVal = typeof mutation === 'function' ? mutation(oldVal.data) : Object.assign(Object.assign({}, oldVal.data), mutation);
1001
+ if (isOutdated(oldVal.data, newVal)) {
1002
+ return false;
1003
+ }
998
1004
  pushToCache(key, newVal, options);
999
1005
  return true;
1000
1006
  };
@@ -20505,7 +20511,10 @@ const createMqttTransport = (endpoint) => {
20505
20511
  },
20506
20512
  subscribe(topic, callback) {
20507
20513
  const callbackWrapper = (error, granted) => {
20508
- if (error || granted[0].qos === QOS_FAILURE_CODE) {
20514
+ var _a;
20515
+ // In MQTT.js, when you subscribe to a topic with QoS 0, the granted parameter
20516
+ // in the callback will typically be empty or undefined
20517
+ if (error || ((_a = granted[0]) === null || _a === void 0 ? void 0 : _a.qos) === QOS_FAILURE_CODE) {
20509
20518
  const ascError = error
20510
20519
  ? new ASCError(error.message, 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */)
20511
20520
  : // TODO throw the actual error, once BE can tell us the actual error code
@@ -20515,7 +20524,7 @@ const createMqttTransport = (endpoint) => {
20515
20524
  callback === null || callback === void 0 ? void 0 : callback(ascError);
20516
20525
  }
20517
20526
  else {
20518
- console.log(`Subscribed to topic ${granted[0].topic}`);
20527
+ console.log(`Subscribed to topic ${topic}`);
20519
20528
  callback === null || callback === void 0 ? void 0 : callback();
20520
20529
  }
20521
20530
  };
@@ -21459,11 +21468,11 @@ const getReadingSubChannels = () => {
21459
21468
  /**
21460
21469
  * call start reading API with reading list
21461
21470
  */
21462
- const startReadingFromReadingList = () => {
21471
+ const startReadingFromReadingList = async () => {
21463
21472
  const isReadingSubChannelIds = getReadingSubChannels();
21464
21473
  if (isReadingSubChannelIds.length === 0) {
21465
21474
  // no subChannel that require to call start reading API
21466
- return;
21475
+ return false;
21467
21476
  }
21468
21477
  return startReadingAPI(isReadingSubChannelIds);
21469
21478
  };
@@ -21542,13 +21551,19 @@ const disposeAll = () => {
21542
21551
  * @category Channel API
21543
21552
  * @async
21544
21553
  */
21545
- const startReading = (subChannelId) => {
21554
+ const startReading = async (subChannelId) => {
21546
21555
  isReadingMap[subChannelId] = true;
21547
21556
  if (disposers$1.length === 0) {
21548
21557
  registerEventListeners$1();
21549
21558
  registerTopicSubscribers(subChannelId);
21550
21559
  }
21551
- return startReadingFromReadingList();
21560
+ try {
21561
+ return await startReadingFromReadingList();
21562
+ }
21563
+ catch (e) {
21564
+ isReadingMap[subChannelId] = false;
21565
+ return false;
21566
+ }
21552
21567
  };
21553
21568
  /* end_public_function */
21554
21569
  /* begin_public_function
@@ -22399,7 +22414,8 @@ function isEqual(x, y) {
22399
22414
  }));
22400
22415
  }
22401
22416
 
22402
- const liveObject = (id, callback, key, fetcher, eventHandlers, callbackDataSelector = data => data, callbackFilter) => {
22417
+ const liveObject = (id, callback, key, fetcher, eventHandlers, options) => {
22418
+ const { forceDispatch, callbackDataSelector, callbackFilter } = Object.assign({ forceDispatch: false, callbackDataSelector: (data) => data }, options);
22403
22419
  const { cache } = getActiveClient();
22404
22420
  if (!cache) {
22405
22421
  console.log(LIVE_OBJECT_ENABLE_CACHE_MESSAGE);
@@ -22414,28 +22430,13 @@ const liveObject = (id, callback, key, fetcher, eventHandlers, callbackDataSelec
22414
22430
  }
22415
22431
  model = newModel;
22416
22432
  };
22417
- const realtimeRouter = (eventModel) => {
22433
+ const realtimeRouter = (eventModel, forceDispatch = false) => {
22418
22434
  if (id !== eventModel[key]) {
22419
22435
  return;
22420
22436
  }
22421
22437
  if (model) {
22422
- /*
22423
- * This test is required as follow does not extend Amity.Timestamps
22424
- * Also, follow can have an event where the paylod is not updated i.e.
22425
- * when a request is declined
22426
- */
22427
- if ('updatedAt' in model && 'updatedAt' in eventModel) {
22428
- /*
22429
- * NOTE: the isEqual is added as a fail safe as the server does not update
22430
- * the updatedAt when the model updates rather when the data in the data of
22431
- * the model (if any) updates.
22432
- *
22433
- * Ex: post.addReaction | post.removeReaction does not update the updatedAt
22434
- * of the post
22435
- */
22436
- if (!hasUpdates(model, eventModel) || isEqual(model, eventModel)) {
22437
- return;
22438
- }
22438
+ if (!forceDispatch && isEqual(model, eventModel)) {
22439
+ return;
22439
22440
  }
22440
22441
  }
22441
22442
  dispatcher({ loading: false, data: eventModel, origin: 'event' });
@@ -22464,7 +22465,7 @@ const liveObject = (id, callback, key, fetcher, eventHandlers, callbackDataSelec
22464
22465
  }
22465
22466
  });
22466
22467
  };
22467
- disposers.push(...eventHandlers.map(fn => fn(realtimeRouter)));
22468
+ disposers.push(...eventHandlers.map(fn => fn(eventModel => realtimeRouter(eventModel, forceDispatch))));
22468
22469
  onFetch();
22469
22470
  return () => {
22470
22471
  disposers.forEach(fn => fn());
@@ -22491,11 +22492,14 @@ const getTotalUnreadCount = (callback) => {
22491
22492
  const { _id: userId } = getActiveUser();
22492
22493
  if (!userId)
22493
22494
  throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
22494
- const callbackPayloadSelector = (data) => { var _a; return (_a = data === null || data === void 0 ? void 0 : data.unreadCount) !== null && _a !== void 0 ? _a : 0; };
22495
+ const callbackDataSelector = (data) => { var _a; return (_a = data === null || data === void 0 ? void 0 : data.unreadCount) !== null && _a !== void 0 ? _a : 0; };
22495
22496
  // based on the mobile specs, unreadCount will not trigger observer when userMarker
22496
22497
  // is re-fetched, so apply this filter to ensure the behavior is the same.
22497
22498
  const callbackFilter = (newModel, oldModel) => (newModel === null || newModel === void 0 ? void 0 : newModel.unreadCount) !== (oldModel === null || oldModel === void 0 ? void 0 : oldModel.unreadCount);
22498
- return liveObject(userId, callback, 'userId', getUserMarker, [onUserMarkerFetched], callbackPayloadSelector, callbackFilter);
22499
+ return liveObject(userId, callback, 'userId', getUserMarker, [onUserMarkerFetched], {
22500
+ callbackDataSelector,
22501
+ callbackFilter,
22502
+ });
22499
22503
  };
22500
22504
 
22501
22505
  /**
@@ -24464,6 +24468,13 @@ const stopUnreadSync = () => {
24464
24468
  clearSyncTrigger = undefined;
24465
24469
  setMarkerSyncEvents([]);
24466
24470
  unRegisterEventListeners();
24471
+ };
24472
+ /**
24473
+ * @deprecated Please use `startUnreadSync` instead
24474
+ */
24475
+ const stopUnreadSyncing = () => {
24476
+ console.warn('`stopUnreadSyncing` has been deprecated, please use `stopUnreadSync` instead');
24477
+ return stopUnreadSync();
24467
24478
  };
24468
24479
 
24469
24480
  var index$f = /*#__PURE__*/Object.freeze({
@@ -24488,7 +24499,8 @@ var index$f = /*#__PURE__*/Object.freeze({
24488
24499
  pushMarkerSyncEvent: pushMarkerSyncEvent,
24489
24500
  markerSyncTrigger: markerSyncTrigger,
24490
24501
  startUnreadSync: startUnreadSync,
24491
- stopUnreadSync: stopUnreadSync
24502
+ stopUnreadSync: stopUnreadSync,
24503
+ stopUnreadSyncing: stopUnreadSyncing
24492
24504
  });
24493
24505
 
24494
24506
  const blockUser = async (userId) => {
@@ -25478,7 +25490,9 @@ const getFollowings = (params, callback, config) => {
25478
25490
  * @category FollowInfo Live Object
25479
25491
  */
25480
25492
  const getFollowInfo = (userId, callback) => {
25481
- return liveObject(userId, callback, 'userId', getFollowInfo$1, [onFollowInfoUpdated]);
25493
+ return liveObject(userId, callback, 'userId', getFollowInfo$1, [onFollowInfoUpdated], {
25494
+ forceDispatch: true,
25495
+ });
25482
25496
  };
25483
25497
  /* end_public_function */
25484
25498
 
@@ -29218,12 +29232,12 @@ const getSubChannel = (subChannelId, callback) => {
29218
29232
  };
29219
29233
  /* end_public_function */
29220
29234
 
29221
- function isCollectionOutdated(collection, newItem, action) {
29235
+ function shouldDispatchCollection(collection, newItem, action) {
29222
29236
  const key = identifyModelKey(newItem);
29223
29237
  // @ts-ignore
29224
29238
  const item = collection.find(x => x[key] === newItem[key]);
29225
29239
  if (item) {
29226
- return hasUpdates(item, newItem);
29240
+ return !isEqual(item, newItem);
29227
29241
  }
29228
29242
  return action === 'onCreate';
29229
29243
  }
@@ -29370,7 +29384,7 @@ const getSubChannels = (params, callback, config) => {
29370
29384
  const realtimeRouter = (action) => (subChannel) => {
29371
29385
  if (params.channelId !== subChannel.channelId ||
29372
29386
  !snapshot ||
29373
- !isCollectionOutdated(snapshot.data, subChannel, action)) {
29387
+ !shouldDispatchCollection(snapshot.data, subChannel, action)) {
29374
29388
  return;
29375
29389
  }
29376
29390
  if (action === 'onCreate') {
package/dist/index.esm.js CHANGED
@@ -623,8 +623,11 @@ const PAYLOAD2MODEL = {
623
623
  feeds: 'feed',
624
624
  };
625
625
  /** hidden */
626
- const hasUpdates = (prevData, nextData) => {
627
- return new Date(prevData.updatedAt) < new Date(nextData.updatedAt);
626
+ const isOutdated = (prevData, nextData) => {
627
+ if ('updatedAt' in nextData && 'updatedAt' in nextData) {
628
+ return new Date(nextData.updatedAt) < new Date(prevData.updatedAt);
629
+ }
630
+ return false;
628
631
  };
629
632
  /** hidden */
630
633
  function getFutureDate(date = new Date().toISOString()) {
@@ -981,6 +984,9 @@ const mergeInCache = (key, mutation, options) => {
981
984
  if (!oldVal)
982
985
  return false;
983
986
  const newVal = typeof mutation === 'function' ? mutation(oldVal.data) : Object.assign(Object.assign({}, oldVal.data), mutation);
987
+ if (isOutdated(oldVal.data, newVal)) {
988
+ return false;
989
+ }
984
990
  pushToCache(key, newVal, options);
985
991
  return true;
986
992
  };
@@ -20491,7 +20497,10 @@ const createMqttTransport = (endpoint) => {
20491
20497
  },
20492
20498
  subscribe(topic, callback) {
20493
20499
  const callbackWrapper = (error, granted) => {
20494
- if (error || granted[0].qos === QOS_FAILURE_CODE) {
20500
+ var _a;
20501
+ // In MQTT.js, when you subscribe to a topic with QoS 0, the granted parameter
20502
+ // in the callback will typically be empty or undefined
20503
+ if (error || ((_a = granted[0]) === null || _a === void 0 ? void 0 : _a.qos) === QOS_FAILURE_CODE) {
20495
20504
  const ascError = error
20496
20505
  ? new ASCError(error.message, 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */)
20497
20506
  : // TODO throw the actual error, once BE can tell us the actual error code
@@ -20501,7 +20510,7 @@ const createMqttTransport = (endpoint) => {
20501
20510
  callback === null || callback === void 0 ? void 0 : callback(ascError);
20502
20511
  }
20503
20512
  else {
20504
- console.log(`Subscribed to topic ${granted[0].topic}`);
20513
+ console.log(`Subscribed to topic ${topic}`);
20505
20514
  callback === null || callback === void 0 ? void 0 : callback();
20506
20515
  }
20507
20516
  };
@@ -21445,11 +21454,11 @@ const getReadingSubChannels = () => {
21445
21454
  /**
21446
21455
  * call start reading API with reading list
21447
21456
  */
21448
- const startReadingFromReadingList = () => {
21457
+ const startReadingFromReadingList = async () => {
21449
21458
  const isReadingSubChannelIds = getReadingSubChannels();
21450
21459
  if (isReadingSubChannelIds.length === 0) {
21451
21460
  // no subChannel that require to call start reading API
21452
- return;
21461
+ return false;
21453
21462
  }
21454
21463
  return startReadingAPI(isReadingSubChannelIds);
21455
21464
  };
@@ -21528,13 +21537,19 @@ const disposeAll = () => {
21528
21537
  * @category Channel API
21529
21538
  * @async
21530
21539
  */
21531
- const startReading = (subChannelId) => {
21540
+ const startReading = async (subChannelId) => {
21532
21541
  isReadingMap[subChannelId] = true;
21533
21542
  if (disposers$1.length === 0) {
21534
21543
  registerEventListeners$1();
21535
21544
  registerTopicSubscribers(subChannelId);
21536
21545
  }
21537
- return startReadingFromReadingList();
21546
+ try {
21547
+ return await startReadingFromReadingList();
21548
+ }
21549
+ catch (e) {
21550
+ isReadingMap[subChannelId] = false;
21551
+ return false;
21552
+ }
21538
21553
  };
21539
21554
  /* end_public_function */
21540
21555
  /* begin_public_function
@@ -22385,7 +22400,8 @@ function isEqual(x, y) {
22385
22400
  }));
22386
22401
  }
22387
22402
 
22388
- const liveObject = (id, callback, key, fetcher, eventHandlers, callbackDataSelector = data => data, callbackFilter) => {
22403
+ const liveObject = (id, callback, key, fetcher, eventHandlers, options) => {
22404
+ const { forceDispatch, callbackDataSelector, callbackFilter } = Object.assign({ forceDispatch: false, callbackDataSelector: (data) => data }, options);
22389
22405
  const { cache } = getActiveClient();
22390
22406
  if (!cache) {
22391
22407
  console.log(LIVE_OBJECT_ENABLE_CACHE_MESSAGE);
@@ -22400,28 +22416,13 @@ const liveObject = (id, callback, key, fetcher, eventHandlers, callbackDataSelec
22400
22416
  }
22401
22417
  model = newModel;
22402
22418
  };
22403
- const realtimeRouter = (eventModel) => {
22419
+ const realtimeRouter = (eventModel, forceDispatch = false) => {
22404
22420
  if (id !== eventModel[key]) {
22405
22421
  return;
22406
22422
  }
22407
22423
  if (model) {
22408
- /*
22409
- * This test is required as follow does not extend Amity.Timestamps
22410
- * Also, follow can have an event where the paylod is not updated i.e.
22411
- * when a request is declined
22412
- */
22413
- if ('updatedAt' in model && 'updatedAt' in eventModel) {
22414
- /*
22415
- * NOTE: the isEqual is added as a fail safe as the server does not update
22416
- * the updatedAt when the model updates rather when the data in the data of
22417
- * the model (if any) updates.
22418
- *
22419
- * Ex: post.addReaction | post.removeReaction does not update the updatedAt
22420
- * of the post
22421
- */
22422
- if (!hasUpdates(model, eventModel) || isEqual(model, eventModel)) {
22423
- return;
22424
- }
22424
+ if (!forceDispatch && isEqual(model, eventModel)) {
22425
+ return;
22425
22426
  }
22426
22427
  }
22427
22428
  dispatcher({ loading: false, data: eventModel, origin: 'event' });
@@ -22450,7 +22451,7 @@ const liveObject = (id, callback, key, fetcher, eventHandlers, callbackDataSelec
22450
22451
  }
22451
22452
  });
22452
22453
  };
22453
- disposers.push(...eventHandlers.map(fn => fn(realtimeRouter)));
22454
+ disposers.push(...eventHandlers.map(fn => fn(eventModel => realtimeRouter(eventModel, forceDispatch))));
22454
22455
  onFetch();
22455
22456
  return () => {
22456
22457
  disposers.forEach(fn => fn());
@@ -22477,11 +22478,14 @@ const getTotalUnreadCount = (callback) => {
22477
22478
  const { _id: userId } = getActiveUser();
22478
22479
  if (!userId)
22479
22480
  throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
22480
- const callbackPayloadSelector = (data) => { var _a; return (_a = data === null || data === void 0 ? void 0 : data.unreadCount) !== null && _a !== void 0 ? _a : 0; };
22481
+ const callbackDataSelector = (data) => { var _a; return (_a = data === null || data === void 0 ? void 0 : data.unreadCount) !== null && _a !== void 0 ? _a : 0; };
22481
22482
  // based on the mobile specs, unreadCount will not trigger observer when userMarker
22482
22483
  // is re-fetched, so apply this filter to ensure the behavior is the same.
22483
22484
  const callbackFilter = (newModel, oldModel) => (newModel === null || newModel === void 0 ? void 0 : newModel.unreadCount) !== (oldModel === null || oldModel === void 0 ? void 0 : oldModel.unreadCount);
22484
- return liveObject(userId, callback, 'userId', getUserMarker, [onUserMarkerFetched], callbackPayloadSelector, callbackFilter);
22485
+ return liveObject(userId, callback, 'userId', getUserMarker, [onUserMarkerFetched], {
22486
+ callbackDataSelector,
22487
+ callbackFilter,
22488
+ });
22485
22489
  };
22486
22490
 
22487
22491
  /**
@@ -24450,6 +24454,13 @@ const stopUnreadSync = () => {
24450
24454
  clearSyncTrigger = undefined;
24451
24455
  setMarkerSyncEvents([]);
24452
24456
  unRegisterEventListeners();
24457
+ };
24458
+ /**
24459
+ * @deprecated Please use `startUnreadSync` instead
24460
+ */
24461
+ const stopUnreadSyncing = () => {
24462
+ console.warn('`stopUnreadSyncing` has been deprecated, please use `stopUnreadSync` instead');
24463
+ return stopUnreadSync();
24453
24464
  };
24454
24465
 
24455
24466
  var index$f = /*#__PURE__*/Object.freeze({
@@ -24474,7 +24485,8 @@ var index$f = /*#__PURE__*/Object.freeze({
24474
24485
  pushMarkerSyncEvent: pushMarkerSyncEvent,
24475
24486
  markerSyncTrigger: markerSyncTrigger,
24476
24487
  startUnreadSync: startUnreadSync,
24477
- stopUnreadSync: stopUnreadSync
24488
+ stopUnreadSync: stopUnreadSync,
24489
+ stopUnreadSyncing: stopUnreadSyncing
24478
24490
  });
24479
24491
 
24480
24492
  const blockUser = async (userId) => {
@@ -25464,7 +25476,9 @@ const getFollowings = (params, callback, config) => {
25464
25476
  * @category FollowInfo Live Object
25465
25477
  */
25466
25478
  const getFollowInfo = (userId, callback) => {
25467
- return liveObject(userId, callback, 'userId', getFollowInfo$1, [onFollowInfoUpdated]);
25479
+ return liveObject(userId, callback, 'userId', getFollowInfo$1, [onFollowInfoUpdated], {
25480
+ forceDispatch: true,
25481
+ });
25468
25482
  };
25469
25483
  /* end_public_function */
25470
25484
 
@@ -29204,12 +29218,12 @@ const getSubChannel = (subChannelId, callback) => {
29204
29218
  };
29205
29219
  /* end_public_function */
29206
29220
 
29207
- function isCollectionOutdated(collection, newItem, action) {
29221
+ function shouldDispatchCollection(collection, newItem, action) {
29208
29222
  const key = identifyModelKey(newItem);
29209
29223
  // @ts-ignore
29210
29224
  const item = collection.find(x => x[key] === newItem[key]);
29211
29225
  if (item) {
29212
- return hasUpdates(item, newItem);
29226
+ return !isEqual(item, newItem);
29213
29227
  }
29214
29228
  return action === 'onCreate';
29215
29229
  }
@@ -29356,7 +29370,7 @@ const getSubChannels = (params, callback, config) => {
29356
29370
  const realtimeRouter = (action) => (subChannel) => {
29357
29371
  if (params.channelId !== subChannel.channelId ||
29358
29372
  !snapshot ||
29359
- !isCollectionOutdated(snapshot.data, subChannel, action)) {
29373
+ !shouldDispatchCollection(snapshot.data, subChannel, action)) {
29360
29374
  return;
29361
29375
  }
29362
29376
  if (action === 'onCreate') {