@amityco/ts-sdk 6.11.2-e853528.0 → 6.12.1-06d644c.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.
@@ -1 +1 @@
1
- {"version":3,"file":"markAsRead.d.ts","sourceRoot":"","sources":["../../../src/channelRepsitory/api/markAsRead.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,UAAU,cAAqB,MAAM,OAAO,CAAC,WAAW,CAAC,KAAG,QAAQ,OAAO,CAmCvF,CAAC"}
1
+ {"version":3,"file":"markAsRead.d.ts","sourceRoot":"","sources":["../../../src/channelRepsitory/api/markAsRead.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,UAAU,cAAqB,MAAM,OAAO,CAAC,WAAW,CAAC,KAAG,QAAQ,OAAO,CAuCvF,CAAC"}
package/dist/index.cjs.js CHANGED
@@ -98,8 +98,8 @@ const PostContentType = Object.freeze({
98
98
 
99
99
  function getVersion() {
100
100
  try {
101
- // the string ''v6.11.1-cjs'' should be replaced by actual value by @rollup/plugin-replace
102
- return 'v6.11.1-cjs';
101
+ // the string ''v6.12.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
102
+ return 'v6.12.0-cjs';
103
103
  }
104
104
  catch (error) {
105
105
  return '__dev__';
@@ -4987,7 +4987,7 @@ function shallowClone(obj) {
4987
4987
  }
4988
4988
 
4989
4989
  function updateSubChannelCache(subChannel, params) {
4990
- pushToCache(['channel', 'get', subChannel.subChannelId],
4990
+ pushToCache(['subChannel', 'get', subChannel.subChannelId],
4991
4991
  // eslint-disable-next-line prefer-object-spread
4992
4992
  Object.assign(shallowClone(subChannel), params));
4993
4993
  }
@@ -6976,7 +6976,7 @@ const onSubChannelMarkerFetched = (callback) => {
6976
6976
  const onSubChannelMarkerUpdated = (callback) => {
6977
6977
  const client = getActiveClient();
6978
6978
  const filter = (payload) => {
6979
- callback(payload.userFeedMarkers[0]);
6979
+ callback(payload.userFeedMarkers);
6980
6980
  };
6981
6981
  return createEventSubscriber(client, 'subChannelMarker/onSubChannelMarkerUpdated', 'local.subChannelMarker.updated', filter);
6982
6982
  };
@@ -7630,11 +7630,15 @@ const markAsRead = async (channelId) => {
7630
7630
  const { userMarkers: userMarkersPayload, userEntityMarkers: userEntityMarkersPayload, userFeedMarkers: userFeedMarkersPayload } = data, rest = __rest(data, ["userMarkers", "userEntityMarkers", "userFeedMarkers"]);
7631
7631
  const cachedAt = client.cache && Date.now();
7632
7632
  const channelMarkers = convertChannelMarkerResponse(userEntityMarkersPayload);
7633
+ const subChannelMarkers = convertSubChannelMarkerResponse(userFeedMarkersPayload);
7633
7634
  if (client.cache)
7634
- ingestInCache(Object.assign({ userMarkers: convertUserMarkerResponse(userMarkersPayload), userEntityMarkers: channelMarkers, userFeedMarkers: convertSubChannelMarkerResponse(userFeedMarkersPayload) }, rest), { cachedAt });
7635
+ ingestInCache(Object.assign({ userMarkers: convertUserMarkerResponse(userMarkersPayload), userEntityMarkers: channelMarkers, userFeedMarkers: subChannelMarkers }, rest), { cachedAt });
7635
7636
  fireEvent('local.channelMarker.updated', {
7636
7637
  userEntityMarkers: channelMarkers,
7637
7638
  });
7639
+ fireEvent('local.subChannelMarker.updated', {
7640
+ userFeedMarkers: subChannelMarkers,
7641
+ });
7638
7642
  return true;
7639
7643
  };
7640
7644
 
@@ -10811,7 +10815,7 @@ const unflagUser = async (userId) => {
10811
10815
  /**
10812
10816
  * ```js
10813
10817
  * import { UserRepository } from '@amityco/ts-sdk'
10814
- * const isFlagged = await UserRepository.isUserFlaggedByMe('post', postId)
10818
+ * const isFlagged = await UserRepository.isUserFlaggedByMe(postId)
10815
10819
  * ```
10816
10820
  *
10817
10821
  * @param userId The ID of the thing to check a report to.
@@ -10821,13 +10825,10 @@ const unflagUser = async (userId) => {
10821
10825
  * @async
10822
10826
  * */
10823
10827
  const isUserFlaggedByMe = async (userId) => {
10824
- var _a, _b;
10825
10828
  const client = getActiveClient();
10826
10829
  client.log('user/isUserFlaggedByMe', userId);
10827
- const { result, isFlagByMe } = (_a = (await synchronousWSCall(client, 'user.isFlagByMe', {
10828
- userId,
10829
- }))) !== null && _a !== void 0 ? _a : {};
10830
- return (_b = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _b !== void 0 ? _b : false;
10830
+ const { data: { isFlagByMe }, } = await client.http.get(`/api/v3/users/${userId}/isFlagByMe`);
10831
+ return isFlagByMe;
10831
10832
  };
10832
10833
  /* end_public_function */
10833
10834
 
@@ -14447,6 +14448,22 @@ const getSubChannel = (subChannelId, callback) => {
14447
14448
  },
14448
14449
  onSubChannelDeleted,
14449
14450
  convertEventPayload(onSubChannelMarkerFetched, 'feedId', 'subChannel'),
14451
+ callback => {
14452
+ return onSubChannelMarkerUpdated(subChannelMarkers => {
14453
+ var _a;
14454
+ const isTargetSubChannel = subChannelMarkers.find(({ feedId }) => feedId === subChannelId);
14455
+ if (!isTargetSubChannel)
14456
+ return;
14457
+ const subChannel = (_a = pullFromCache([
14458
+ 'subChannel',
14459
+ 'get',
14460
+ subChannelId,
14461
+ ])) === null || _a === void 0 ? void 0 : _a.data;
14462
+ if (!subChannel)
14463
+ return;
14464
+ callback(subChannel);
14465
+ });
14466
+ },
14450
14467
  convertEventPayload((callback) => {
14451
14468
  const updateMessagePreview = async (message) => {
14452
14469
  var _a;
@@ -14463,8 +14480,9 @@ const getSubChannel = (subChannelId, callback) => {
14463
14480
  ])) === null || _a === void 0 ? void 0 : _a.data;
14464
14481
  if (!subChannel)
14465
14482
  return;
14466
- // TODO: avoid subChannel update cache without getter defined
14467
- pushToCache(['subChannel', 'get', subChannelId], Object.assign(Object.assign({}, subChannel), { messagePreviewId: message.messageId }));
14483
+ updateSubChannelCache(subChannel, {
14484
+ messagePreviewId: message.messageId,
14485
+ });
14468
14486
  callback(message);
14469
14487
  };
14470
14488
  return onMessageCreated(updateMessagePreview);
@@ -14667,18 +14685,29 @@ const getSubChannels = (params, callback, config) => {
14667
14685
  });
14668
14686
  };
14669
14687
  const realtimeRouter = (action) => (subChannel) => {
14670
- if (params.channelId !== subChannel.channelId ||
14671
- !snapshot ||
14672
- !shouldDispatchCollection(snapshot.data, subChannel, action)) {
14673
- return;
14674
- }
14675
- if (action === 'onCreate') {
14676
- snapshot.data = [subChannel, ...snapshot.data];
14688
+ if (!Array.isArray(subChannel)) {
14689
+ if (params.channelId !== subChannel.channelId ||
14690
+ !snapshot ||
14691
+ !shouldDispatchCollection(snapshot.data, subChannel, action)) {
14692
+ return;
14693
+ }
14694
+ if (action === 'onCreate') {
14695
+ snapshot.data = [subChannel, ...snapshot.data];
14696
+ }
14697
+ else {
14698
+ snapshot.data = snapshot.data.map(x => x.subChannelId === subChannel.subChannelId ? subChannel : x);
14699
+ }
14700
+ snapshot.data = snapshot.data.map(convertGetterPropsToStatic);
14677
14701
  }
14678
14702
  else {
14679
- snapshot.data = snapshot.data.map(x => x.subChannelId === subChannel.subChannelId ? subChannel : x);
14703
+ /**
14704
+ * In case of `onUpdate` event with array of subChannel
14705
+ */
14706
+ snapshot.data = snapshot.data.map(x => {
14707
+ const targetSubChannel = subChannel.find(item => item.subChannelId === x.subChannelId);
14708
+ return targetSubChannel !== null && targetSubChannel !== void 0 ? targetSubChannel : x;
14709
+ });
14680
14710
  }
14681
- snapshot.data = snapshot.data.map(convertGetterPropsToStatic);
14682
14711
  responder(snapshot);
14683
14712
  };
14684
14713
  const onFetch = () => {
@@ -14734,7 +14763,16 @@ const getSubChannels = (params, callback, config) => {
14734
14763
  });
14735
14764
  if (!targetSubChannel)
14736
14765
  return;
14737
- }), convertEventPayload(onSubChannelMarkerFetched, 'feedId', 'subChannel')(realtimeRouter('onUpdate')), convertEventPayload(onSubChannelMarkerFetched, 'feedId', 'subChannel')(realtimeRouter('onUpdate')), convertEventPayload((callback) => {
14766
+ }), convertEventPayload(onSubChannelMarkerFetched, 'feedId', 'subChannel')(realtimeRouter('onUpdate')), onSubChannelMarkerUpdated((subChannelMarkers) => {
14767
+ var _a;
14768
+ const subChannelWithMarkerUpdated = (_a = subChannelMarkers
14769
+ .map(({ feedId }) => pullFromCache(['subChannel', 'get', feedId]))
14770
+ .filter(Boolean)
14771
+ .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
14772
+ if (subChannelWithMarkerUpdated.length === 0)
14773
+ return;
14774
+ realtimeRouter('onUpdate')(subChannelWithMarkerUpdated);
14775
+ }), convertEventPayload((callback) => {
14738
14776
  const updateMessagePreview = async (message) => {
14739
14777
  var _a;
14740
14778
  const client = getActiveClient();
package/dist/index.esm.js CHANGED
@@ -83,8 +83,8 @@ const PostContentType = Object.freeze({
83
83
 
84
84
  function getVersion() {
85
85
  try {
86
- // the string ''v6.11.1-esm'' should be replaced by actual value by @rollup/plugin-replace
87
- return 'v6.11.1-esm';
86
+ // the string ''v6.12.0-esm'' should be replaced by actual value by @rollup/plugin-replace
87
+ return 'v6.12.0-esm';
88
88
  }
89
89
  catch (error) {
90
90
  return '__dev__';
@@ -21077,7 +21077,7 @@ function shallowClone(obj) {
21077
21077
  }
21078
21078
 
21079
21079
  function updateSubChannelCache(subChannel, params) {
21080
- pushToCache(['channel', 'get', subChannel.subChannelId],
21080
+ pushToCache(['subChannel', 'get', subChannel.subChannelId],
21081
21081
  // eslint-disable-next-line prefer-object-spread
21082
21082
  Object.assign(shallowClone(subChannel), params));
21083
21083
  }
@@ -23066,7 +23066,7 @@ const onSubChannelMarkerFetched = (callback) => {
23066
23066
  const onSubChannelMarkerUpdated = (callback) => {
23067
23067
  const client = getActiveClient();
23068
23068
  const filter = (payload) => {
23069
- callback(payload.userFeedMarkers[0]);
23069
+ callback(payload.userFeedMarkers);
23070
23070
  };
23071
23071
  return createEventSubscriber(client, 'subChannelMarker/onSubChannelMarkerUpdated', 'local.subChannelMarker.updated', filter);
23072
23072
  };
@@ -23720,11 +23720,15 @@ const markAsRead = async (channelId) => {
23720
23720
  const { userMarkers: userMarkersPayload, userEntityMarkers: userEntityMarkersPayload, userFeedMarkers: userFeedMarkersPayload } = data, rest = __rest(data, ["userMarkers", "userEntityMarkers", "userFeedMarkers"]);
23721
23721
  const cachedAt = client.cache && Date.now();
23722
23722
  const channelMarkers = convertChannelMarkerResponse(userEntityMarkersPayload);
23723
+ const subChannelMarkers = convertSubChannelMarkerResponse(userFeedMarkersPayload);
23723
23724
  if (client.cache)
23724
- ingestInCache(Object.assign({ userMarkers: convertUserMarkerResponse(userMarkersPayload), userEntityMarkers: channelMarkers, userFeedMarkers: convertSubChannelMarkerResponse(userFeedMarkersPayload) }, rest), { cachedAt });
23725
+ ingestInCache(Object.assign({ userMarkers: convertUserMarkerResponse(userMarkersPayload), userEntityMarkers: channelMarkers, userFeedMarkers: subChannelMarkers }, rest), { cachedAt });
23725
23726
  fireEvent('local.channelMarker.updated', {
23726
23727
  userEntityMarkers: channelMarkers,
23727
23728
  });
23729
+ fireEvent('local.subChannelMarker.updated', {
23730
+ userFeedMarkers: subChannelMarkers,
23731
+ });
23728
23732
  return true;
23729
23733
  };
23730
23734
 
@@ -26901,7 +26905,7 @@ const unflagUser = async (userId) => {
26901
26905
  /**
26902
26906
  * ```js
26903
26907
  * import { UserRepository } from '@amityco/ts-sdk'
26904
- * const isFlagged = await UserRepository.isUserFlaggedByMe('post', postId)
26908
+ * const isFlagged = await UserRepository.isUserFlaggedByMe(postId)
26905
26909
  * ```
26906
26910
  *
26907
26911
  * @param userId The ID of the thing to check a report to.
@@ -26911,13 +26915,10 @@ const unflagUser = async (userId) => {
26911
26915
  * @async
26912
26916
  * */
26913
26917
  const isUserFlaggedByMe = async (userId) => {
26914
- var _a, _b;
26915
26918
  const client = getActiveClient();
26916
26919
  client.log('user/isUserFlaggedByMe', userId);
26917
- const { result, isFlagByMe } = (_a = (await synchronousWSCall(client, 'user.isFlagByMe', {
26918
- userId,
26919
- }))) !== null && _a !== void 0 ? _a : {};
26920
- return (_b = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _b !== void 0 ? _b : false;
26920
+ const { data: { isFlagByMe }, } = await client.http.get(`/api/v3/users/${userId}/isFlagByMe`);
26921
+ return isFlagByMe;
26921
26922
  };
26922
26923
  /* end_public_function */
26923
26924
 
@@ -30537,6 +30538,22 @@ const getSubChannel = (subChannelId, callback) => {
30537
30538
  },
30538
30539
  onSubChannelDeleted,
30539
30540
  convertEventPayload(onSubChannelMarkerFetched, 'feedId', 'subChannel'),
30541
+ callback => {
30542
+ return onSubChannelMarkerUpdated(subChannelMarkers => {
30543
+ var _a;
30544
+ const isTargetSubChannel = subChannelMarkers.find(({ feedId }) => feedId === subChannelId);
30545
+ if (!isTargetSubChannel)
30546
+ return;
30547
+ const subChannel = (_a = pullFromCache([
30548
+ 'subChannel',
30549
+ 'get',
30550
+ subChannelId,
30551
+ ])) === null || _a === void 0 ? void 0 : _a.data;
30552
+ if (!subChannel)
30553
+ return;
30554
+ callback(subChannel);
30555
+ });
30556
+ },
30540
30557
  convertEventPayload((callback) => {
30541
30558
  const updateMessagePreview = async (message) => {
30542
30559
  var _a;
@@ -30553,8 +30570,9 @@ const getSubChannel = (subChannelId, callback) => {
30553
30570
  ])) === null || _a === void 0 ? void 0 : _a.data;
30554
30571
  if (!subChannel)
30555
30572
  return;
30556
- // TODO: avoid subChannel update cache without getter defined
30557
- pushToCache(['subChannel', 'get', subChannelId], Object.assign(Object.assign({}, subChannel), { messagePreviewId: message.messageId }));
30573
+ updateSubChannelCache(subChannel, {
30574
+ messagePreviewId: message.messageId,
30575
+ });
30558
30576
  callback(message);
30559
30577
  };
30560
30578
  return onMessageCreated(updateMessagePreview);
@@ -30757,18 +30775,29 @@ const getSubChannels = (params, callback, config) => {
30757
30775
  });
30758
30776
  };
30759
30777
  const realtimeRouter = (action) => (subChannel) => {
30760
- if (params.channelId !== subChannel.channelId ||
30761
- !snapshot ||
30762
- !shouldDispatchCollection(snapshot.data, subChannel, action)) {
30763
- return;
30764
- }
30765
- if (action === 'onCreate') {
30766
- snapshot.data = [subChannel, ...snapshot.data];
30778
+ if (!Array.isArray(subChannel)) {
30779
+ if (params.channelId !== subChannel.channelId ||
30780
+ !snapshot ||
30781
+ !shouldDispatchCollection(snapshot.data, subChannel, action)) {
30782
+ return;
30783
+ }
30784
+ if (action === 'onCreate') {
30785
+ snapshot.data = [subChannel, ...snapshot.data];
30786
+ }
30787
+ else {
30788
+ snapshot.data = snapshot.data.map(x => x.subChannelId === subChannel.subChannelId ? subChannel : x);
30789
+ }
30790
+ snapshot.data = snapshot.data.map(convertGetterPropsToStatic);
30767
30791
  }
30768
30792
  else {
30769
- snapshot.data = snapshot.data.map(x => x.subChannelId === subChannel.subChannelId ? subChannel : x);
30793
+ /**
30794
+ * In case of `onUpdate` event with array of subChannel
30795
+ */
30796
+ snapshot.data = snapshot.data.map(x => {
30797
+ const targetSubChannel = subChannel.find(item => item.subChannelId === x.subChannelId);
30798
+ return targetSubChannel !== null && targetSubChannel !== void 0 ? targetSubChannel : x;
30799
+ });
30770
30800
  }
30771
- snapshot.data = snapshot.data.map(convertGetterPropsToStatic);
30772
30801
  responder(snapshot);
30773
30802
  };
30774
30803
  const onFetch = () => {
@@ -30824,7 +30853,16 @@ const getSubChannels = (params, callback, config) => {
30824
30853
  });
30825
30854
  if (!targetSubChannel)
30826
30855
  return;
30827
- }), convertEventPayload(onSubChannelMarkerFetched, 'feedId', 'subChannel')(realtimeRouter('onUpdate')), convertEventPayload(onSubChannelMarkerFetched, 'feedId', 'subChannel')(realtimeRouter('onUpdate')), convertEventPayload((callback) => {
30856
+ }), convertEventPayload(onSubChannelMarkerFetched, 'feedId', 'subChannel')(realtimeRouter('onUpdate')), onSubChannelMarkerUpdated((subChannelMarkers) => {
30857
+ var _a;
30858
+ const subChannelWithMarkerUpdated = (_a = subChannelMarkers
30859
+ .map(({ feedId }) => pullFromCache(['subChannel', 'get', feedId]))
30860
+ .filter(Boolean)
30861
+ .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
30862
+ if (subChannelWithMarkerUpdated.length === 0)
30863
+ return;
30864
+ realtimeRouter('onUpdate')(subChannelWithMarkerUpdated);
30865
+ }), convertEventPayload((callback) => {
30828
30866
  const updateMessagePreview = async (message) => {
30829
30867
  var _a;
30830
30868
  const client = getActiveClient();