@amityco/ts-sdk 6.20.1 → 6.21.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 (103) hide show
  1. package/dist/@types/core/events.d.ts +12 -7
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/model.d.ts +3 -3
  4. package/dist/@types/core/model.d.ts.map +1 -1
  5. package/dist/@types/core/payload.d.ts +2 -2
  6. package/dist/@types/core/payload.d.ts.map +1 -1
  7. package/dist/@types/domains/channel.d.ts +3 -0
  8. package/dist/@types/domains/channel.d.ts.map +1 -1
  9. package/dist/@types/domains/reaction.d.ts +8 -4
  10. package/dist/@types/domains/reaction.d.ts.map +1 -1
  11. package/dist/channelRepository/api/getChannel.d.ts +2 -2
  12. package/dist/channelRepository/api/getChannel.d.ts.map +1 -1
  13. package/dist/channelRepository/api/getChannelByIds.d.ts +2 -2
  14. package/dist/channelRepository/api/getChannelByIds.d.ts.map +1 -1
  15. package/dist/channelRepository/events/onChannelResolved.d.ts +12 -0
  16. package/dist/channelRepository/events/onChannelResolved.d.ts.map +1 -0
  17. package/dist/channelRepository/observers/getChannel.d.ts.map +1 -1
  18. package/dist/channelRepository/observers/getChannels/ChannelLiveCollectionController.d.ts.map +1 -1
  19. package/dist/channelRepository/observers/getChannels/ChannelQueryStreamController.d.ts.map +1 -1
  20. package/dist/channelRepository/observers/observeChannel.d.ts +1 -1
  21. package/dist/channelRepository/observers/observeChannel.d.ts.map +1 -1
  22. package/dist/channelRepository/utils/getSubChannelsUnreadCount.d.ts.map +1 -1
  23. package/dist/channelRepository/utils/prepateUnreadCountInfo.d.ts.map +1 -1
  24. package/dist/channelRepository/utils/resolveChannels.d.ts +2 -0
  25. package/dist/channelRepository/utils/resolveChannels.d.ts.map +1 -0
  26. package/dist/client/api/login.d.ts.map +1 -1
  27. package/dist/client/utils/ObjectResolver/objectResolverEngine.d.ts.map +1 -1
  28. package/dist/core/events.d.ts +3 -3
  29. package/dist/core/events.d.ts.map +1 -1
  30. package/dist/index.cjs.js +184 -155
  31. package/dist/index.esm.js +184 -155
  32. package/dist/index.umd.js +2 -2
  33. package/dist/marker/events/onUserMessageFeedMarkerResolved.d.ts +12 -0
  34. package/dist/marker/events/onUserMessageFeedMarkerResolved.d.ts.map +1 -0
  35. package/dist/marker/utils/resolveUserMessageFeedMakers.d.ts +2 -0
  36. package/dist/marker/utils/resolveUserMessageFeedMakers.d.ts.map +1 -0
  37. package/dist/messageRepository/utils/prepareMessagePayload.d.ts +1 -1
  38. package/dist/messageRepository/utils/prepareMessagePayload.d.ts.map +1 -1
  39. package/dist/reactionRepository/api/addReaction.d.ts +2 -2
  40. package/dist/reactionRepository/api/addReaction.d.ts.map +1 -1
  41. package/dist/reactionRepository/api/queryReactor.d.ts +3 -3
  42. package/dist/reactionRepository/api/queryReactor.d.ts.map +1 -1
  43. package/dist/reactionRepository/api/removeReaction.d.ts +2 -2
  44. package/dist/reactionRepository/api/removeReaction.d.ts.map +1 -1
  45. package/dist/reactionRepository/events/onReactorAdded.d.ts +2 -2
  46. package/dist/reactionRepository/events/onReactorAdded.d.ts.map +1 -1
  47. package/dist/reactionRepository/events/onReactorRemoved.d.ts +2 -2
  48. package/dist/reactionRepository/events/onReactorRemoved.d.ts.map +1 -1
  49. package/dist/reactionRepository/observers/getReactions.d.ts +1 -1
  50. package/dist/reactionRepository/observers/getReactions.d.ts.map +1 -1
  51. package/dist/reactionRepository/utils/prepareMessagePayloadForCache.d.ts +1 -1
  52. package/dist/reactionRepository/utils/prepareMessagePayloadForCache.d.ts.map +1 -1
  53. package/dist/streamRepository/events/onStreamStopped.d.ts.map +1 -1
  54. package/dist/utils/linkedObject/index.d.ts +1 -0
  55. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  56. package/dist/utils/linkedObject/reactorLinkedObject.d.ts +2 -0
  57. package/dist/utils/linkedObject/reactorLinkedObject.d.ts.map +1 -0
  58. package/dist/utils/tests/dummy/reaction.d.ts +1 -1
  59. package/dist/utils/tests/dummy/reaction.d.ts.map +1 -1
  60. package/package.json +1 -1
  61. package/src/@types/core/events.ts +13 -7
  62. package/src/@types/core/model.ts +3 -3
  63. package/src/@types/core/payload.ts +2 -2
  64. package/src/@types/domains/channel.ts +3 -0
  65. package/src/@types/domains/reaction.ts +10 -4
  66. package/src/channelRepository/api/getChannel.ts +11 -7
  67. package/src/channelRepository/api/getChannelByIds.ts +13 -7
  68. package/src/channelRepository/events/onChannelResolved.ts +22 -0
  69. package/src/channelRepository/observers/getChannel.ts +2 -0
  70. package/src/channelRepository/observers/getChannels/ChannelLiveCollectionController.ts +14 -10
  71. package/src/channelRepository/observers/getChannels/ChannelQueryStreamController.ts +4 -5
  72. package/src/channelRepository/utils/getChannelIsMentioned.ts +2 -2
  73. package/src/channelRepository/utils/getSubChannelsUnreadCount.ts +3 -2
  74. package/src/channelRepository/utils/prepareChannelPayload.ts +2 -2
  75. package/src/channelRepository/utils/prepateUnreadCountInfo.ts +2 -1
  76. package/src/channelRepository/utils/resolveChannels.ts +8 -0
  77. package/src/client/api/login.ts +1 -3
  78. package/src/client/utils/ObjectResolver/objectResolverEngine.ts +5 -4
  79. package/src/client/utils/hasPermission/checkUserPermission.ts +1 -1
  80. package/src/commentRepository/events/onCommentReactionAdded.ts +1 -1
  81. package/src/commentRepository/events/onCommentReactionRemoved.ts +1 -1
  82. package/src/commentRepository/observers/tests/getComment.test.ts +2 -2
  83. package/src/core/events.ts +4 -0
  84. package/src/core/model/idResolvers.ts +1 -1
  85. package/src/core/query/filtering.ts +1 -1
  86. package/src/marker/events/onUserMessageFeedMarkerResolved.ts +29 -0
  87. package/src/marker/utils/resolveUserMessageFeedMakers.ts +17 -0
  88. package/src/messageRepository/utils/prepareMessagePayload.ts +2 -2
  89. package/src/postRepository/observers/tests/getPost.test.ts +1 -1
  90. package/src/postRepository/observers/tests/getPosts.test.ts +1 -1
  91. package/src/reactionRepository/api/addReaction.ts +2 -2
  92. package/src/reactionRepository/api/queryReactor.ts +3 -3
  93. package/src/reactionRepository/api/removeReaction.ts +2 -2
  94. package/src/reactionRepository/events/onReactorAdded.ts +5 -5
  95. package/src/reactionRepository/events/onReactorRemoved.ts +5 -5
  96. package/src/reactionRepository/observers/getReactions.ts +18 -16
  97. package/src/reactionRepository/utils/prepareMessagePayloadForCache.ts +1 -1
  98. package/src/streamRepository/events/onStreamRecorded.ts +1 -1
  99. package/src/streamRepository/events/onStreamStarted.ts +1 -1
  100. package/src/streamRepository/events/onStreamStopped.ts +6 -1
  101. package/src/utils/linkedObject/index.ts +2 -0
  102. package/src/utils/linkedObject/reactorLinkedObject.ts +13 -0
  103. package/src/utils/tests/dummy/reaction.ts +1 -1
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.20.1-cjs'' should be replaced by actual value by @rollup/plugin-replace
102
- return 'v6.20.1-cjs';
101
+ // the string ''v6.21.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
102
+ return 'v6.21.0-cjs';
103
103
  }
104
104
  catch (error) {
105
105
  return '__dev__';
@@ -504,7 +504,7 @@ const idResolvers = {
504
504
  user: ({ userId }) => userId,
505
505
  file: ({ fileId }) => fileId,
506
506
  role: ({ roleId }) => roleId,
507
- channel: ({ channelId }) => channelId,
507
+ channel: ({ channelInternalId }) => channelInternalId,
508
508
  subChannel: ({ subChannelId }) => subChannelId,
509
509
  channelUsers: ({ channelId, userId }) => `${channelId}#${userId}`,
510
510
  message: ({ messageId }) => messageId,
@@ -1067,7 +1067,7 @@ const filterByChannelMembership = (collection, membership, userId) => {
1067
1067
  return true;
1068
1068
  // get resolver for the channel by user
1069
1069
  const channelUserCacheKey = getResolver('channelUsers')({
1070
- channelId: c.channelId,
1070
+ channelId: c.channelPublicId,
1071
1071
  userId,
1072
1072
  });
1073
1073
  const channelUser = (_a = pullFromCache([
@@ -1308,6 +1308,9 @@ const WS_EVENTS = [
1308
1308
  'sessionStateChange',
1309
1309
  // for internal use by accessTokenExpiryWatcher
1310
1310
  'tokenExpired',
1311
+ 'v3.video-streaming.didRecord',
1312
+ 'v3.video-streaming.didStart',
1313
+ 'v3.video-streaming.didStop',
1311
1314
  ];
1312
1315
  const MQTT_EVENTS = [
1313
1316
  'connect',
@@ -5647,6 +5650,16 @@ const messageLinkedObject = (message) => {
5647
5650
  } });
5648
5651
  };
5649
5652
 
5653
+ const reactorLinkedObject = (reactor) => {
5654
+ return Object.assign(Object.assign({}, reactor), { get user() {
5655
+ var _a;
5656
+ const user = (_a = pullFromCache(['user', 'get', reactor.userId])) === null || _a === void 0 ? void 0 : _a.data;
5657
+ if (!user)
5658
+ return undefined;
5659
+ return userLinkedObject(user);
5660
+ } });
5661
+ };
5662
+
5650
5663
  const LinkedObject = {
5651
5664
  comment: commentLinkedObject,
5652
5665
  post: postLinkedObject,
@@ -5655,6 +5668,7 @@ const LinkedObject = {
5655
5668
  story: storyLinkedObject,
5656
5669
  storyTarget: storyTargetLinkedObject,
5657
5670
  message: messageLinkedObject,
5671
+ reactor: reactorLinkedObject,
5658
5672
  };
5659
5673
 
5660
5674
  const getChannelMessagePreviewWithUser = (channel) => {
@@ -5976,7 +5990,8 @@ const getSubChannelsUnreadCount = (channel, marker) => {
5976
5990
  var _a, _b, _c, _d, _e;
5977
5991
  const client = getActiveClient();
5978
5992
  if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
5979
- return (_b = (_a = getUnreadInfoCached$1(channel.channelId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
5993
+ // Marker service API uses channelInternalId as channelId
5994
+ return (_b = (_a = getUnreadInfoCached$1(channel.channelInternalId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
5980
5995
  }
5981
5996
  if (marker === null || marker === void 0 ? void 0 : marker.isDeleted) {
5982
5997
  // NOTE: This is a temporary solution to handle the channel marker when the user is forced to
@@ -5984,7 +5999,7 @@ const getSubChannelsUnreadCount = (channel, marker) => {
5984
5999
  // from a channel or the channel is deleted the channel's unread count will reset to zero
5985
6000
  return 0;
5986
6001
  }
5987
- return (_e = (_c = marker === null || marker === void 0 ? void 0 : marker.unreadCount) !== null && _c !== void 0 ? _c : (_d = getCachedMarker$1(channel.channelId)) === null || _d === void 0 ? void 0 : _d.unreadCount) !== null && _e !== void 0 ? _e : 0;
6002
+ return (_e = (_c = marker === null || marker === void 0 ? void 0 : marker.unreadCount) !== null && _c !== void 0 ? _c : (_d = getCachedMarker$1(channel.channelInternalId)) === null || _d === void 0 ? void 0 : _d.unreadCount) !== null && _e !== void 0 ? _e : 0;
5988
6003
  };
5989
6004
 
5990
6005
  const getCachedMarker = (entityId) => {
@@ -6015,11 +6030,11 @@ const getChannelIsMentioned = (channel, marker) => {
6015
6030
  var _a, _b, _c, _d;
6016
6031
  const client = getActiveClient();
6017
6032
  if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
6018
- return (_b = (_a = getUnreadInfoCached(channel.channelId)) === null || _a === void 0 ? void 0 : _a.isMentioned) !== null && _b !== void 0 ? _b : false;
6033
+ return (_b = (_a = getUnreadInfoCached(channel.channelPublicId)) === null || _a === void 0 ? void 0 : _a.isMentioned) !== null && _b !== void 0 ? _b : false;
6019
6034
  }
6020
6035
  return (marker === null || marker === void 0 ? void 0 : marker.hasMentioned) !== undefined
6021
6036
  ? marker === null || marker === void 0 ? void 0 : marker.hasMentioned
6022
- : (_d = (_c = getCachedMarker(channel.channelId)) === null || _c === void 0 ? void 0 : _c.hasMentioned) !== null && _d !== void 0 ? _d : false;
6037
+ : (_d = (_c = getCachedMarker(channel.channelPublicId)) === null || _c === void 0 ? void 0 : _c.hasMentioned) !== null && _d !== void 0 ? _d : false;
6023
6038
  };
6024
6039
 
6025
6040
  const MARKER_INCLUDED_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
@@ -6046,7 +6061,7 @@ function convertFromRaw$2(channel, options = { isMessagePreviewUpdated: true })
6046
6061
  },
6047
6062
  get subChannelsUnreadCount() {
6048
6063
  return getSubChannelsUnreadCount(channel);
6049
- } }, channel), { defaultSubChannelId: channel._id, isUnreadCountSupport: isUnreadCountSupport$2(channel), messagePreviewId });
6064
+ } }, channel), { defaultSubChannelId: channel.channelInternalId, isUnreadCountSupport: isUnreadCountSupport$2(channel), messagePreviewId });
6050
6065
  }
6051
6066
  const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated: true }) => {
6052
6067
  ingestInCache({
@@ -6065,7 +6080,7 @@ const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpd
6065
6080
  const markerIds = rawPayload.channels
6066
6081
  // filter channel by type. Only conversation, community and broadcast type are included.
6067
6082
  .filter(isUnreadCountSupport$2)
6068
- .map(({ channelId }) => channelId);
6083
+ .map(({ channelInternalId }) => channelInternalId);
6069
6084
  if (markerIds.length > 0) {
6070
6085
  // since the get markers method requires a channel cache to function with the reducer.
6071
6086
  preUpdateChannelCache(rawPayload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated });
@@ -6085,6 +6100,85 @@ const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpd
6085
6100
  channelUsers });
6086
6101
  };
6087
6102
 
6103
+ /**
6104
+ * ```js
6105
+ * import { getSubChannelMarkers } from '@amityco/ts-sdk'
6106
+ * const subChannelMarkers = await getSubChannelMarkers(['sch1', 'sch2'])
6107
+ * ```
6108
+ *
6109
+ * Fetches a paginable list of {@link Amity.SubChannelMarker} objects
6110
+ *
6111
+ * @param messageFeedIds the feed IDs of the {@link Amity.RawSubChannel} marker to fetch
6112
+ * @param page
6113
+ * @returns A page of {@link Amity.SubChannelMarker} objects
6114
+ *
6115
+ * @category Channel API
6116
+ * @async
6117
+ * @private
6118
+ */
6119
+ const getUserMessageFeedMakers = async (channelIds) => {
6120
+ const client = getActiveClient();
6121
+ client.log('channel/getUserMessageFeedMakers', channelIds);
6122
+ const { data } = await client.http.get(`/api/v1/markers/user-message-feed`, {
6123
+ params: {
6124
+ channelIds,
6125
+ },
6126
+ });
6127
+ fireEvent('local.userMessageFeedMarker.fetched', { userMessageFeedMarker: data });
6128
+ return data;
6129
+ };
6130
+
6131
+ const persistUnreadCountInfo = (payload) => {
6132
+ const { feedMarkers, userFeedMarkers } = payload;
6133
+ // calculate sub channel unread info and channel unread info
6134
+ if (feedMarkers.length > 0 && userFeedMarkers.length > 0) {
6135
+ const channelIds = [];
6136
+ const feedMarkerMap = new Map(feedMarkers.map(fm => [fm.feedId, fm]));
6137
+ userFeedMarkers.forEach(userFeedMarker => {
6138
+ const feedMarker = feedMarkerMap.get(userFeedMarker.feedId);
6139
+ if (!feedMarker)
6140
+ return;
6141
+ if (feedMarker.feedId === userFeedMarker.feedId) {
6142
+ const unreadCount = feedMarker.lastSegment - userFeedMarker.readToSegment;
6143
+ const subChannelUnreadInfo = {
6144
+ subChannelId: feedMarker.feedId,
6145
+ channelId: feedMarker.entityId,
6146
+ readToSegment: userFeedMarker.readToSegment,
6147
+ lastSegment: feedMarker.lastSegment,
6148
+ lastMentionSegment: userFeedMarker.lastMentionSegment,
6149
+ unreadCount: Math.max(0, unreadCount),
6150
+ isMentioned: userFeedMarker.isMentioned,
6151
+ isDeleted: feedMarker.isDeleted,
6152
+ createdAt: userFeedMarker.createdAt,
6153
+ updatedAt: userFeedMarker.updatedAt,
6154
+ };
6155
+ // update sub channel unread info in cache
6156
+ ingestInCache({ subChannelUnreadInfo: [subChannelUnreadInfo] });
6157
+ if (!channelIds.includes(feedMarker.entityId)) {
6158
+ channelIds.push(feedMarker.entityId);
6159
+ }
6160
+ }
6161
+ });
6162
+ // re-calculate channel unread info in cache
6163
+ channelIds.forEach(channelId => {
6164
+ reCalculateChannelUnreadInfo(channelId);
6165
+ });
6166
+ }
6167
+ };
6168
+
6169
+ const prepareUnreadCountInfo = async (rawPayload) => {
6170
+ const client = getActiveClient();
6171
+ // if consistent mode is enabled, persist the unread count info to the cache
6172
+ // Marker service API uses channelInternalId as channelId
6173
+ const queryPayload = await getUserMessageFeedMakers(rawPayload.channels.map(({ channelInternalId }) => channelInternalId));
6174
+ const { feedMarkers, userFeedMarkers } = queryPayload;
6175
+ persistUnreadCountInfo({
6176
+ feedMarkers,
6177
+ userFeedMarkers,
6178
+ });
6179
+ client.log('channel/prepareUnreadCountInfo', rawPayload.channels);
6180
+ };
6181
+
6088
6182
  /**
6089
6183
  * ```js
6090
6184
  * import { getChannelByIds } from '@amityco/ts-sdk'
@@ -6114,12 +6208,16 @@ const getChannelByIds = async (channelIds) => {
6114
6208
  catch (error) {
6115
6209
  channelIds.forEach(channelId => {
6116
6210
  if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
6211
+ // NOTE: use channelPublicId as tombstone cache key since we cannot get the channelPrivateId that come along with channel data from server
6117
6212
  pushToTombstone('channel', channelId);
6118
6213
  }
6119
6214
  });
6120
6215
  throw error;
6121
6216
  }
6122
6217
  const data = await prepareChannelPayload(payload);
6218
+ if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
6219
+ await prepareUnreadCountInfo(payload);
6220
+ }
6123
6221
  const cachedAt = client.cache && Date.now();
6124
6222
  if (client.cache)
6125
6223
  ingestInCache(data, { cachedAt });
@@ -6143,18 +6241,18 @@ const getChannelByIds = async (channelIds) => {
6143
6241
  * @category Channel API
6144
6242
  */
6145
6243
  getChannelByIds.locally = (channelIds) => {
6146
- var _a;
6244
+ var _a, _b;
6147
6245
  const client = getActiveClient();
6148
6246
  client.log('channel/getChannelByIds.locally', channelIds);
6149
6247
  if (!client.cache)
6150
6248
  return;
6151
- const cached = channelIds
6152
- .map(channelId => pullFromCache(['channel', 'get', channelId]))
6153
- .filter(Boolean);
6154
- if ((cached === null || cached === void 0 ? void 0 : cached.length) < channelIds.length)
6249
+ const cached = (_a = queryCache(['channel', 'get'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
6250
+ return channelIds.includes(data.channelPublicId);
6251
+ });
6252
+ if (!cached || (cached === null || cached === void 0 ? void 0 : cached.length) < channelIds.length)
6155
6253
  return;
6156
6254
  const channels = cached.map(({ data }) => data);
6157
- const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
6255
+ const oldest = (_b = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _b === void 0 ? void 0 : _b[0];
6158
6256
  return {
6159
6257
  data: channels,
6160
6258
  cachedAt: oldest.cachedAt,
@@ -6194,44 +6292,6 @@ const getMessageMarkers = async (messageIds) => {
6194
6292
  return { data: contentMarkers, cachedAt };
6195
6293
  };
6196
6294
 
6197
- const persistUnreadCountInfo = (payload) => {
6198
- const { feedMarkers, userFeedMarkers } = payload;
6199
- // calculate sub channel unread info and channel unread info
6200
- if (feedMarkers.length > 0 && userFeedMarkers.length > 0) {
6201
- const channelIds = [];
6202
- const feedMarkerMap = new Map(feedMarkers.map(fm => [fm.feedId, fm]));
6203
- userFeedMarkers.forEach(userFeedMarker => {
6204
- const feedMarker = feedMarkerMap.get(userFeedMarker.feedId);
6205
- if (!feedMarker)
6206
- return;
6207
- if (feedMarker.feedId === userFeedMarker.feedId) {
6208
- const unreadCount = feedMarker.lastSegment - userFeedMarker.readToSegment;
6209
- const subChannelUnreadInfo = {
6210
- subChannelId: feedMarker.feedId,
6211
- channelId: feedMarker.entityId,
6212
- readToSegment: userFeedMarker.readToSegment,
6213
- lastSegment: feedMarker.lastSegment,
6214
- lastMentionSegment: userFeedMarker.lastMentionSegment,
6215
- unreadCount: Math.max(0, unreadCount),
6216
- isMentioned: userFeedMarker.isMentioned,
6217
- isDeleted: feedMarker.isDeleted,
6218
- createdAt: userFeedMarker.createdAt,
6219
- updatedAt: userFeedMarker.updatedAt,
6220
- };
6221
- // update sub channel unread info in cache
6222
- ingestInCache({ subChannelUnreadInfo: [subChannelUnreadInfo] });
6223
- if (!channelIds.includes(feedMarker.entityId)) {
6224
- channelIds.push(feedMarker.entityId);
6225
- }
6226
- }
6227
- });
6228
- // re-calculate channel unread info in cache
6229
- channelIds.forEach(channelId => {
6230
- reCalculateChannelUnreadInfo(channelId);
6231
- });
6232
- }
6233
- };
6234
-
6235
6295
  /**
6236
6296
  * ```js
6237
6297
  * import { getSubChannelMarkers } from '@amityco/ts-sdk'
@@ -7145,7 +7205,7 @@ const getSocialSettings = async () => {
7145
7205
 
7146
7206
  const checkUserPermission = (userId, permission) => {
7147
7207
  var _a;
7148
- const user = (_a = pullFromCache(['users', 'get', userId])) === null || _a === void 0 ? void 0 : _a.data;
7208
+ const user = (_a = pullFromCache(['user', 'get', userId])) === null || _a === void 0 ? void 0 : _a.data;
7149
7209
  if (!user)
7150
7210
  return false;
7151
7211
  return user.permissions.some(x => x === permission);
@@ -7521,32 +7581,19 @@ const onOffline = (callback) => {
7521
7581
  return () => console.error('Unsupported environment');
7522
7582
  };
7523
7583
 
7524
- /**
7525
- * ```js
7526
- * import { getSubChannelMarkers } from '@amityco/ts-sdk'
7527
- * const subChannelMarkers = await getSubChannelMarkers(['sch1', 'sch2'])
7528
- * ```
7529
- *
7530
- * Fetches a paginable list of {@link Amity.SubChannelMarker} objects
7531
- *
7532
- * @param messageFeedIds the feed IDs of the {@link Amity.RawSubChannel} marker to fetch
7533
- * @param page
7534
- * @returns A page of {@link Amity.SubChannelMarker} objects
7535
- *
7536
- * @category Channel API
7537
- * @async
7538
- * @private
7539
- */
7540
- const getUserMessageFeedMakers = async (channelIds) => {
7541
- const client = getActiveClient();
7542
- client.log('channel/getUserMessageFeedMakers', channelIds);
7543
- const { data } = await client.http.get(`/api/v1/markers/user-message-feed`, {
7544
- params: {
7545
- channelIds,
7546
- },
7584
+ const resolveChannels = async (channelIds) => {
7585
+ const { data: channels } = await getChannelByIds(channelIds);
7586
+ fireEvent('local.channel.resolved', channels);
7587
+ };
7588
+
7589
+ const resolveUserMessageFeedMarkers = async (channelIds) => {
7590
+ const queryPayload = await getUserMessageFeedMakers(channelIds);
7591
+ const { feedMarkers, userFeedMarkers } = queryPayload;
7592
+ persistUnreadCountInfo({
7593
+ feedMarkers,
7594
+ userFeedMarkers,
7547
7595
  });
7548
- fireEvent('local.userMessageFeedMarker.fetched', { userMessageFeedMarker: data });
7549
- return data;
7596
+ fireEvent('local.userMessageFeedMarkers.resolved', { feedMarkers, userFeedMarkers });
7550
7597
  };
7551
7598
 
7552
7599
  class ObjectResolverEngine {
@@ -7613,9 +7660,9 @@ class ObjectResolverEngine {
7613
7660
  // Incase of failure: Ignore
7614
7661
  // Incase of success: Persist in Domain DB & Notify Live collection
7615
7662
  if (channelIds.length > 0)
7616
- getChannelByIds(channelIds);
7663
+ resolveChannels(channelIds);
7617
7664
  if (userMessageFeedMarkerIds.length > 0)
7618
- getUserMessageFeedMakers(userMessageFeedMarkerIds);
7665
+ resolveUserMessageFeedMarkers(userMessageFeedMarkerIds);
7619
7666
  // After sending request
7620
7667
  this.isResolvingTask = false;
7621
7668
  }
@@ -8685,9 +8732,7 @@ const login = async (params, sessionHandler, config) => {
8685
8732
  // FIXME: events are duplicated if connectClient is called few times without disconnectClient
8686
8733
  // wire websocket events to our event emitter
8687
8734
  proxyWebsocketEvents(client.ws, client.emitter);
8688
- client.ws.once('connect', () => {
8689
- client.ws.open();
8690
- });
8735
+ client.ws.open();
8691
8736
  client.userId = user.userId;
8692
8737
  client.sessionHandler = sessionHandler;
8693
8738
  /*
@@ -13103,7 +13148,7 @@ const onReactionRemoved = (referenceType, referenceId, callback) => {
13103
13148
  * })
13104
13149
  * ```
13105
13150
  *
13106
- * Fired when an {@link Amity.Reactor} has been added
13151
+ * Fired when an {@link Amity.InternalReactor} has been added
13107
13152
  *
13108
13153
  * @param {@link Amity.ReactableType} referenceType
13109
13154
  * @param {string} referenceId
@@ -13166,7 +13211,7 @@ const onReactorAdded = (referenceType, referenceId, callback) => {
13166
13211
  * })
13167
13212
  * ```
13168
13213
  *
13169
- * Fired when an {@link Amity.Reactor} has been removed
13214
+ * Fired when an {@link Amity.InternalReactor} has been removed
13170
13215
  *
13171
13216
  * @param {@link Amity.ReactableType} referenceType
13172
13217
  * @param {string} referenceId
@@ -13273,10 +13318,10 @@ const queryReactions = async (query) => {
13273
13318
  * })
13274
13319
  * ```
13275
13320
  *
13276
- * Queries a paginable list of {@link Amity.Reactor} objects
13321
+ * Queries a paginable list of {@link Amity.InternalReactor} objects
13277
13322
  *
13278
13323
  * @param query The query parameters
13279
- * @returns A page of {@link Amity.Reactor} objects
13324
+ * @returns A page of {@link Amity.InternalReactor} objects
13280
13325
  *
13281
13326
  * @reaction Reaction API
13282
13327
  * @async
@@ -13302,7 +13347,7 @@ const queryReactor = async (query) => {
13302
13347
  * }, response => merge(reactions, response.data))
13303
13348
  * ```
13304
13349
  *
13305
- * Observe all mutations on a list of {@link Amity.Reactor} for a given target object
13350
+ * Observe all mutations on a list of {@link Amity.InternalReactor} for a given target object
13306
13351
  *
13307
13352
  * @param params for querying reactions
13308
13353
  * @param callback the function to call when new data are available
@@ -13332,7 +13377,7 @@ const getReactions = (params, callback, config) => {
13332
13377
  const reactions = (_a = data.data
13333
13378
  .map(reactorId => pullFromCache(['reactor', 'get', reactorId]))
13334
13379
  .filter(Boolean)
13335
- .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
13380
+ .map(({ data }) => LinkedObject.reactor(data))) !== null && _a !== void 0 ? _a : [];
13336
13381
  callback({
13337
13382
  onNextPage: onFetch,
13338
13383
  data: reactions,
@@ -13607,18 +13652,6 @@ const updateChannel = async (channelId, patch) => {
13607
13652
  };
13608
13653
  /* end_public_function */
13609
13654
 
13610
- const prepareUnreadCountInfo = async (rawPayload) => {
13611
- const client = getActiveClient();
13612
- // if consistent mode is enabled, persist the unread count info to the cache
13613
- const queryPayload = await getUserMessageFeedMakers(rawPayload.channels.map(({ channelId }) => channelId));
13614
- const { feedMarkers, userFeedMarkers } = queryPayload;
13615
- persistUnreadCountInfo({
13616
- feedMarkers,
13617
- userFeedMarkers,
13618
- });
13619
- client.log('channel/prepareUnreadCountInfo', rawPayload.channels);
13620
- };
13621
-
13622
13655
  /**
13623
13656
  * ```js
13624
13657
  * import { getChannel } from '@amityco/ts-sdk'
@@ -13647,6 +13680,7 @@ const getChannel$1 = async (channelId) => {
13647
13680
  }
13648
13681
  catch (error) {
13649
13682
  if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
13683
+ // NOTE: use channelPublicId as tombstone cache key since we cannot get the channelPrivateId that come along with channel data from server
13650
13684
  pushToTombstone('channel', channelId);
13651
13685
  }
13652
13686
  throw error;
@@ -13674,16 +13708,20 @@ const getChannel$1 = async (channelId) => {
13674
13708
  * @category Channel API
13675
13709
  */
13676
13710
  getChannel$1.locally = (channelId) => {
13711
+ var _a;
13677
13712
  const client = getActiveClient();
13678
13713
  client.log('channel/getChannel.locally', channelId);
13679
13714
  if (!client.cache)
13680
13715
  return;
13681
- const cached = pullFromCache(['channel', 'get', channelId]);
13682
- if (!cached)
13716
+ // use queryCache to get all channel caches and filter by channelPublicId since we use channelPrivateId as cache key
13717
+ const cached = (_a = queryCache(['channel', 'get'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
13718
+ return data.channelPublicId === channelId;
13719
+ });
13720
+ if (!cached || (cached === null || cached === void 0 ? void 0 : cached.length) === 0)
13683
13721
  return;
13684
13722
  return {
13685
- data: cached.data,
13686
- cachedAt: cached.cachedAt,
13723
+ data: cached[0].data,
13724
+ cachedAt: cached[0].cachedAt,
13687
13725
  };
13688
13726
  };
13689
13727
 
@@ -16327,6 +16365,7 @@ const getChannel = (channelId, callback) => {
16327
16365
  await handleMessageCreated(message);
16328
16366
  if (message.channelId !== channelId)
16329
16367
  return;
16368
+ // channelId from message is channelInternalId
16330
16369
  const channel = (_a = pullFromCache(['channel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
16331
16370
  if (!channel)
16332
16371
  return;
@@ -16346,6 +16385,7 @@ const getChannel = (channelId, callback) => {
16346
16385
  await handleMessageCreated(message);
16347
16386
  if (message.channelId !== channelId)
16348
16387
  return;
16388
+ // channelId from message is channelInternalId
16349
16389
  const channel = (_a = pullFromCache(['channel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
16350
16390
  if (!channel)
16351
16391
  return;
@@ -16509,15 +16549,15 @@ class ChannelQueryStreamController extends QueryStreamController {
16509
16549
  if ([
16510
16550
  "onCreate" /* Amity.ChannelActionType.OnCreate */,
16511
16551
  "onJoin" /* Amity.ChannelActionType.OnJoin */,
16512
- "onFetch" /* Amity.ChannelActionType.OnFetch */,
16513
- "onUserMessageFeedMarkerFetch" /* Amity.ChannelActionType.OnUserMessageFeedMarkerFetch */,
16552
+ "onResolve" /* Amity.ChannelActionType.OnResolve */,
16514
16553
  ].includes(action)) {
16515
- if (Array.isArray(payload))
16554
+ if (Array.isArray(payload)) {
16516
16555
  collection.data = [
16517
- ...new Set([...payload.map(({ channelId }) => channelId), ...collection.data]),
16556
+ ...new Set([...payload.map(getResolver('channel')), ...collection.data]),
16518
16557
  ];
16558
+ }
16519
16559
  else
16520
- collection.data = [...new Set([payload.channelId, ...collection.data])];
16560
+ collection.data = [...new Set([payload.channelInternalId, ...collection.data])];
16521
16561
  }
16522
16562
  pushToCache(this.cacheKey, collection);
16523
16563
  this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
@@ -16528,62 +16568,50 @@ class ChannelQueryStreamController extends QueryStreamController {
16528
16568
  }
16529
16569
  }
16530
16570
 
16571
+ const resolveUnreadInfoOnChannelEvent = (channel, callback) => {
16572
+ const client = getActiveClient();
16573
+ if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
16574
+ const objectResolverEngine = ObjectResolverEngine$1.getInstance();
16575
+ objectResolverEngine.resolve(channel.channelId, "userMessageFeedMarker" /* Amity.ReferenceType.USER_MESSAGE_FEED_MARKER */);
16576
+ }
16577
+ else
16578
+ callback(channel);
16579
+ };
16580
+
16531
16581
  /**
16532
- * ```js
16533
- * import { onChannelFetched } from '@amityco/ts-sdk'
16534
- * const dispose = onChannelFetched(channel => {
16535
- * // ...
16536
- * })
16537
- * ```
16582
+ * Internal used only
16538
16583
  *
16539
- * Fired when any {@link Amity.Channel} list have been fetched
16584
+ * Fired when any {@link Amity.Channel} have been resolved by Object resolver
16540
16585
  *
16541
16586
  * @param callback The function to call when the event was fired
16542
16587
  * @returns an {@link Amity.Unsubscriber} function to stop listening
16543
16588
  *
16544
16589
  * @category Channel Events
16545
16590
  */
16546
- const onChannelFetched = (callback) => {
16591
+ const onChannelResolved = (callback) => {
16547
16592
  const client = getActiveClient();
16548
16593
  const filter = async (payload) => {
16549
16594
  callback(payload);
16550
16595
  };
16551
- return createEventSubscriber(client, 'onChannelFetched', 'local.channel.fetched', filter);
16596
+ return createEventSubscriber(client, 'onChannelResolved', 'local.channel.resolved', filter);
16552
16597
  };
16553
16598
 
16554
16599
  /**
16555
- * ```js
16556
- * import { onFeedMarkerUpdated } from '@amityco/ts-sdk'
16557
- * const dispose = onFeedMarkerUpdated(feedMarker => {
16558
- * // ...
16559
- * })
16560
- * ```
16600
+ * Internal used only
16561
16601
  *
16562
- * Fired when an {@link Amity.UserMessageFeedMarkerPayload} has been updated
16602
+ * Fired when an {@link Amity.userMessageFeedMarkers} has been resolved by Object Rsesolver
16563
16603
  *
16564
16604
  * @param callback The function to call when the event was fired
16565
16605
  * @returns an {@link Amity.Unsubscriber} function to stop listening
16566
16606
  *
16567
- * @category FeedMarker Events
16607
+ * @category MessageMarker Events
16568
16608
  */
16569
- const onUserFeedMarkerFetched = (callback) => {
16609
+ const onUserMessageFeedMarkerResolved = (callback) => {
16570
16610
  const client = getActiveClient();
16571
16611
  const filter = (payload) => {
16572
- // update sub channel unread info and channel unread info in cache
16573
- persistUnreadCountInfo(payload.userMessageFeedMarker);
16574
- callback(payload.userMessageFeedMarker);
16612
+ callback(payload);
16575
16613
  };
16576
- return createEventSubscriber(client, 'feedMarker/onUserFeedMarkerFetched', 'local.userMessageFeedMarker.fetched', filter);
16577
- };
16578
-
16579
- const resolveUnreadInfoOnChannelEvent = (channel, callback) => {
16580
- const client = getActiveClient();
16581
- if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
16582
- const objectResolverEngine = ObjectResolverEngine$1.getInstance();
16583
- objectResolverEngine.resolve(channel.channelId, "userMessageFeedMarker" /* Amity.ReferenceType.USER_MESSAGE_FEED_MARKER */);
16584
- }
16585
- else
16586
- callback(channel);
16614
+ return createEventSubscriber(client, 'userMessageFeedMarker/onUserMessageFeedMarkerResolved', 'local.userMessageFeedMarkers.resolved', filter);
16587
16615
  };
16588
16616
 
16589
16617
  /* eslint-disable no-use-before-define */
@@ -16720,7 +16748,6 @@ class ChannelLiveCollectionController extends LiveCollectionController {
16720
16748
  getSubscriptions() {
16721
16749
  const subscriptions = [
16722
16750
  {
16723
- // TODO: merge this code to another onMessageCreated in this file
16724
16751
  fn: convertEventPayload((callback) => {
16725
16752
  return onMessageCreatedMqtt(message => {
16726
16753
  var _a;
@@ -16731,6 +16758,7 @@ class ChannelLiveCollectionController extends LiveCollectionController {
16731
16758
  ])) === null || _a === void 0 ? void 0 : _a.data;
16732
16759
  if (!cacheData) {
16733
16760
  const objectResolverEngine = ObjectResolverEngine$1.getInstance();
16761
+ // channelId from message event payload is channelInternalId
16734
16762
  objectResolverEngine.resolve(message.channelId, "channel" /* Amity.ReferenceType.CHANNEL */);
16735
16763
  }
16736
16764
  else {
@@ -16744,7 +16772,6 @@ class ChannelLiveCollectionController extends LiveCollectionController {
16744
16772
  action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
16745
16773
  },
16746
16774
  {
16747
- // TODO: merge this code to another onMessageCreated in this file
16748
16775
  fn: convertEventPayload((callback) => {
16749
16776
  return onMessageCreatedLocal(message => {
16750
16777
  var _a;
@@ -16936,23 +16963,25 @@ class ChannelLiveCollectionController extends LiveCollectionController {
16936
16963
  action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
16937
16964
  },
16938
16965
  {
16939
- fn: onChannelFetched,
16940
- action: "onFetch" /* Amity.ChannelActionType.OnFetch */,
16966
+ fn: onChannelResolved,
16967
+ action: "onResolve" /* Amity.ChannelActionType.OnResolve */,
16941
16968
  },
16942
16969
  {
16943
16970
  fn: (callback) => {
16944
- const handleUserFeedMarkerFetch = async (marker) => {
16971
+ const handleUserFeedMarkerResolved = async (marker) => {
16945
16972
  if (marker.feedMarkers) {
16946
- const channelIds = marker.feedMarkers.map(feedMarker => feedMarker.entityId);
16973
+ const channelIds = [
16974
+ ...new Set(marker.feedMarkers.map(feedMarker => feedMarker.entityId)),
16975
+ ];
16947
16976
  const channels = channelIds
16948
16977
  .map(channelId => { var _a; return (_a = pullFromCache(['channel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data; })
16949
16978
  .filter(Boolean);
16950
16979
  callback(channels);
16951
16980
  }
16952
16981
  };
16953
- return onUserFeedMarkerFetched(handleUserFeedMarkerFetch);
16982
+ return onUserMessageFeedMarkerResolved(handleUserFeedMarkerResolved);
16954
16983
  },
16955
- action: "onUserMessageFeedMarkerFetch" /* Amity.ChannelActionType.OnUserMessageFeedMarkerFetch */,
16984
+ action: "onResolve" /* Amity.ChannelActionType.OnResolve */,
16956
16985
  },
16957
16986
  ];
16958
16987
  if (this.paginationController instanceof PaginationController) {
@@ -21576,7 +21605,7 @@ const onStreamStarted = (callback) => {
21576
21605
  ingestInCache(payload);
21577
21606
  callback(payload.videoStreamings[0]);
21578
21607
  };
21579
- return createEventSubscriber(client, 'stream/onStreamStarted', 'video-streaming.didStart', filter);
21608
+ return createEventSubscriber(client, 'stream/onStreamStarted', 'v3.video-streaming.didStart', filter);
21580
21609
  };
21581
21610
 
21582
21611
  /**
@@ -21600,7 +21629,7 @@ const onStreamStopped = (callback) => {
21600
21629
  ingestInCache(payload);
21601
21630
  callback(payload.videoStreamings[0]);
21602
21631
  };
21603
- return createEventSubscriber(client, 'stream/onStreamStarted', 'video-streaming.didStop', filter);
21632
+ return createEventSubscriber(client, 'stream/onStreamStropped', 'v3.video-streaming.didStop', filter);
21604
21633
  };
21605
21634
 
21606
21635
  /**
@@ -21624,7 +21653,7 @@ const onStreamRecorded = (callback) => {
21624
21653
  ingestInCache(payload);
21625
21654
  callback(payload.videoStreamings[0]);
21626
21655
  };
21627
- return createEventSubscriber(client, 'stream/onStreamRecorded', 'video-streaming.didRecord', filter);
21656
+ return createEventSubscriber(client, 'stream/onStreamRecorded', 'v3.video-streaming.didRecord', filter);
21628
21657
  };
21629
21658
 
21630
21659
  /* eslint-disable no-use-before-define */