@amityco/ts-sdk-react-native 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 (106) 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/client/utils/onOffline.d.ts.map +1 -1
  29. package/dist/core/events.d.ts +3 -3
  30. package/dist/core/events.d.ts.map +1 -1
  31. package/dist/index.cjs.js +199 -155
  32. package/dist/index.esm.js +199 -155
  33. package/dist/index.umd.js +2 -2
  34. package/dist/marker/events/onUserMessageFeedMarkerResolved.d.ts +12 -0
  35. package/dist/marker/events/onUserMessageFeedMarkerResolved.d.ts.map +1 -0
  36. package/dist/marker/utils/resolveUserMessageFeedMakers.d.ts +2 -0
  37. package/dist/marker/utils/resolveUserMessageFeedMakers.d.ts.map +1 -0
  38. package/dist/messageRepository/utils/prepareMessagePayload.d.ts +1 -1
  39. package/dist/messageRepository/utils/prepareMessagePayload.d.ts.map +1 -1
  40. package/dist/reactionRepository/api/addReaction.d.ts +2 -2
  41. package/dist/reactionRepository/api/addReaction.d.ts.map +1 -1
  42. package/dist/reactionRepository/api/queryReactor.d.ts +3 -3
  43. package/dist/reactionRepository/api/queryReactor.d.ts.map +1 -1
  44. package/dist/reactionRepository/api/removeReaction.d.ts +2 -2
  45. package/dist/reactionRepository/api/removeReaction.d.ts.map +1 -1
  46. package/dist/reactionRepository/events/onReactorAdded.d.ts +2 -2
  47. package/dist/reactionRepository/events/onReactorAdded.d.ts.map +1 -1
  48. package/dist/reactionRepository/events/onReactorRemoved.d.ts +2 -2
  49. package/dist/reactionRepository/events/onReactorRemoved.d.ts.map +1 -1
  50. package/dist/reactionRepository/observers/getReactions.d.ts +1 -1
  51. package/dist/reactionRepository/observers/getReactions.d.ts.map +1 -1
  52. package/dist/reactionRepository/utils/prepareMessagePayloadForCache.d.ts +1 -1
  53. package/dist/reactionRepository/utils/prepareMessagePayloadForCache.d.ts.map +1 -1
  54. package/dist/streamRepository/events/onStreamStopped.d.ts.map +1 -1
  55. package/dist/utils/linkedObject/index.d.ts +1 -0
  56. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  57. package/dist/utils/linkedObject/reactorLinkedObject.d.ts +2 -0
  58. package/dist/utils/linkedObject/reactorLinkedObject.d.ts.map +1 -0
  59. package/dist/utils/tests/dummy/reaction.d.ts +1 -1
  60. package/dist/utils/tests/dummy/reaction.d.ts.map +1 -1
  61. package/package.json +1 -1
  62. package/src/@types/core/events.ts +13 -7
  63. package/src/@types/core/model.ts +3 -3
  64. package/src/@types/core/payload.ts +2 -2
  65. package/src/@types/domains/channel.ts +3 -0
  66. package/src/@types/domains/reaction.ts +10 -4
  67. package/src/analytic/api/queryReachUser.ts +1 -1
  68. package/src/channelRepository/api/getChannel.ts +11 -7
  69. package/src/channelRepository/api/getChannelByIds.ts +13 -7
  70. package/src/channelRepository/events/onChannelResolved.ts +22 -0
  71. package/src/channelRepository/observers/getChannel.ts +2 -0
  72. package/src/channelRepository/observers/getChannels/ChannelLiveCollectionController.ts +14 -10
  73. package/src/channelRepository/observers/getChannels/ChannelQueryStreamController.ts +4 -5
  74. package/src/channelRepository/utils/getChannelIsMentioned.ts +2 -2
  75. package/src/channelRepository/utils/getSubChannelsUnreadCount.ts +3 -2
  76. package/src/channelRepository/utils/prepareChannelPayload.ts +2 -2
  77. package/src/channelRepository/utils/prepateUnreadCountInfo.ts +2 -1
  78. package/src/channelRepository/utils/resolveChannels.ts +8 -0
  79. package/src/client/api/login.ts +1 -3
  80. package/src/client/utils/ObjectResolver/objectResolverEngine.ts +5 -4
  81. package/src/client/utils/hasPermission/checkUserPermission.ts +1 -1
  82. package/src/client/utils/onOffline.ts +17 -0
  83. package/src/commentRepository/events/onCommentReactionAdded.ts +1 -1
  84. package/src/commentRepository/events/onCommentReactionRemoved.ts +1 -1
  85. package/src/commentRepository/observers/tests/getComment.test.ts +2 -2
  86. package/src/core/events.ts +4 -0
  87. package/src/core/model/idResolvers.ts +1 -1
  88. package/src/core/query/filtering.ts +1 -1
  89. package/src/marker/events/onUserMessageFeedMarkerResolved.ts +29 -0
  90. package/src/marker/utils/resolveUserMessageFeedMakers.ts +17 -0
  91. package/src/messageRepository/utils/prepareMessagePayload.ts +2 -2
  92. package/src/postRepository/observers/tests/getPost.test.ts +1 -1
  93. package/src/postRepository/observers/tests/getPosts.test.ts +1 -1
  94. package/src/reactionRepository/api/addReaction.ts +2 -2
  95. package/src/reactionRepository/api/queryReactor.ts +3 -3
  96. package/src/reactionRepository/api/removeReaction.ts +2 -2
  97. package/src/reactionRepository/events/onReactorAdded.ts +5 -5
  98. package/src/reactionRepository/events/onReactorRemoved.ts +5 -5
  99. package/src/reactionRepository/observers/getReactions.ts +18 -16
  100. package/src/reactionRepository/utils/prepareMessagePayloadForCache.ts +1 -1
  101. package/src/streamRepository/events/onStreamRecorded.ts +1 -1
  102. package/src/streamRepository/events/onStreamStarted.ts +1 -1
  103. package/src/streamRepository/events/onStreamStopped.ts +6 -1
  104. package/src/utils/linkedObject/index.ts +2 -0
  105. package/src/utils/linkedObject/reactorLinkedObject.ts +13 -0
  106. package/src/utils/tests/dummy/reaction.ts +1 -1
package/dist/index.esm.js CHANGED
@@ -84,8 +84,8 @@ const PostContentType = Object.freeze({
84
84
 
85
85
  function getVersion() {
86
86
  try {
87
- // the string ''v6.20.1-esm'' should be replaced by actual value by @rollup/plugin-replace
88
- return 'v6.20.1-esm';
87
+ // the string ''v6.21.0-esm'' should be replaced by actual value by @rollup/plugin-replace
88
+ return 'v6.21.0-esm';
89
89
  }
90
90
  catch (error) {
91
91
  return '__dev__';
@@ -490,7 +490,7 @@ const idResolvers = {
490
490
  user: ({ userId }) => userId,
491
491
  file: ({ fileId }) => fileId,
492
492
  role: ({ roleId }) => roleId,
493
- channel: ({ channelId }) => channelId,
493
+ channel: ({ channelInternalId }) => channelInternalId,
494
494
  subChannel: ({ subChannelId }) => subChannelId,
495
495
  channelUsers: ({ channelId, userId }) => `${channelId}#${userId}`,
496
496
  message: ({ messageId }) => messageId,
@@ -1053,7 +1053,7 @@ const filterByChannelMembership = (collection, membership, userId) => {
1053
1053
  return true;
1054
1054
  // get resolver for the channel by user
1055
1055
  const channelUserCacheKey = getResolver('channelUsers')({
1056
- channelId: c.channelId,
1056
+ channelId: c.channelPublicId,
1057
1057
  userId,
1058
1058
  });
1059
1059
  const channelUser = (_a = pullFromCache([
@@ -1294,6 +1294,9 @@ const WS_EVENTS = [
1294
1294
  'sessionStateChange',
1295
1295
  // for internal use by accessTokenExpiryWatcher
1296
1296
  'tokenExpired',
1297
+ 'v3.video-streaming.didRecord',
1298
+ 'v3.video-streaming.didStart',
1299
+ 'v3.video-streaming.didStop',
1297
1300
  ];
1298
1301
  const MQTT_EVENTS = [
1299
1302
  'connect',
@@ -21746,6 +21749,16 @@ const messageLinkedObject = (message) => {
21746
21749
  } });
21747
21750
  };
21748
21751
 
21752
+ const reactorLinkedObject = (reactor) => {
21753
+ return Object.assign(Object.assign({}, reactor), { get user() {
21754
+ var _a;
21755
+ const user = (_a = pullFromCache(['user', 'get', reactor.userId])) === null || _a === void 0 ? void 0 : _a.data;
21756
+ if (!user)
21757
+ return undefined;
21758
+ return userLinkedObject(user);
21759
+ } });
21760
+ };
21761
+
21749
21762
  const LinkedObject = {
21750
21763
  comment: commentLinkedObject,
21751
21764
  post: postLinkedObject,
@@ -21754,6 +21767,7 @@ const LinkedObject = {
21754
21767
  story: storyLinkedObject,
21755
21768
  storyTarget: storyTargetLinkedObject,
21756
21769
  message: messageLinkedObject,
21770
+ reactor: reactorLinkedObject,
21757
21771
  };
21758
21772
 
21759
21773
  const getChannelMessagePreviewWithUser = (channel) => {
@@ -22075,7 +22089,8 @@ const getSubChannelsUnreadCount = (channel, marker) => {
22075
22089
  var _a, _b, _c, _d, _e;
22076
22090
  const client = getActiveClient();
22077
22091
  if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
22078
- return (_b = (_a = getUnreadInfoCached$1(channel.channelId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
22092
+ // Marker service API uses channelInternalId as channelId
22093
+ return (_b = (_a = getUnreadInfoCached$1(channel.channelInternalId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
22079
22094
  }
22080
22095
  if (marker === null || marker === void 0 ? void 0 : marker.isDeleted) {
22081
22096
  // NOTE: This is a temporary solution to handle the channel marker when the user is forced to
@@ -22083,7 +22098,7 @@ const getSubChannelsUnreadCount = (channel, marker) => {
22083
22098
  // from a channel or the channel is deleted the channel's unread count will reset to zero
22084
22099
  return 0;
22085
22100
  }
22086
- 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;
22101
+ 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;
22087
22102
  };
22088
22103
 
22089
22104
  const getCachedMarker = (entityId) => {
@@ -22114,11 +22129,11 @@ const getChannelIsMentioned = (channel, marker) => {
22114
22129
  var _a, _b, _c, _d;
22115
22130
  const client = getActiveClient();
22116
22131
  if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
22117
- return (_b = (_a = getUnreadInfoCached(channel.channelId)) === null || _a === void 0 ? void 0 : _a.isMentioned) !== null && _b !== void 0 ? _b : false;
22132
+ return (_b = (_a = getUnreadInfoCached(channel.channelPublicId)) === null || _a === void 0 ? void 0 : _a.isMentioned) !== null && _b !== void 0 ? _b : false;
22118
22133
  }
22119
22134
  return (marker === null || marker === void 0 ? void 0 : marker.hasMentioned) !== undefined
22120
22135
  ? marker === null || marker === void 0 ? void 0 : marker.hasMentioned
22121
- : (_d = (_c = getCachedMarker(channel.channelId)) === null || _c === void 0 ? void 0 : _c.hasMentioned) !== null && _d !== void 0 ? _d : false;
22136
+ : (_d = (_c = getCachedMarker(channel.channelPublicId)) === null || _c === void 0 ? void 0 : _c.hasMentioned) !== null && _d !== void 0 ? _d : false;
22122
22137
  };
22123
22138
 
22124
22139
  const MARKER_INCLUDED_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
@@ -22145,7 +22160,7 @@ function convertFromRaw$2(channel, options = { isMessagePreviewUpdated: true })
22145
22160
  },
22146
22161
  get subChannelsUnreadCount() {
22147
22162
  return getSubChannelsUnreadCount(channel);
22148
- } }, channel), { defaultSubChannelId: channel._id, isUnreadCountSupport: isUnreadCountSupport$2(channel), messagePreviewId });
22163
+ } }, channel), { defaultSubChannelId: channel.channelInternalId, isUnreadCountSupport: isUnreadCountSupport$2(channel), messagePreviewId });
22149
22164
  }
22150
22165
  const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated: true }) => {
22151
22166
  ingestInCache({
@@ -22164,7 +22179,7 @@ const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpd
22164
22179
  const markerIds = rawPayload.channels
22165
22180
  // filter channel by type. Only conversation, community and broadcast type are included.
22166
22181
  .filter(isUnreadCountSupport$2)
22167
- .map(({ channelId }) => channelId);
22182
+ .map(({ channelInternalId }) => channelInternalId);
22168
22183
  if (markerIds.length > 0) {
22169
22184
  // since the get markers method requires a channel cache to function with the reducer.
22170
22185
  preUpdateChannelCache(rawPayload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated });
@@ -22184,6 +22199,85 @@ const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpd
22184
22199
  channelUsers });
22185
22200
  };
22186
22201
 
22202
+ /**
22203
+ * ```js
22204
+ * import { getSubChannelMarkers } from '@amityco/ts-sdk-react-native'
22205
+ * const subChannelMarkers = await getSubChannelMarkers(['sch1', 'sch2'])
22206
+ * ```
22207
+ *
22208
+ * Fetches a paginable list of {@link Amity.SubChannelMarker} objects
22209
+ *
22210
+ * @param messageFeedIds the feed IDs of the {@link Amity.RawSubChannel} marker to fetch
22211
+ * @param page
22212
+ * @returns A page of {@link Amity.SubChannelMarker} objects
22213
+ *
22214
+ * @category Channel API
22215
+ * @async
22216
+ * @private
22217
+ */
22218
+ const getUserMessageFeedMakers = async (channelIds) => {
22219
+ const client = getActiveClient();
22220
+ client.log('channel/getUserMessageFeedMakers', channelIds);
22221
+ const { data } = await client.http.get(`/api/v1/markers/user-message-feed`, {
22222
+ params: {
22223
+ channelIds,
22224
+ },
22225
+ });
22226
+ fireEvent('local.userMessageFeedMarker.fetched', { userMessageFeedMarker: data });
22227
+ return data;
22228
+ };
22229
+
22230
+ const persistUnreadCountInfo = (payload) => {
22231
+ const { feedMarkers, userFeedMarkers } = payload;
22232
+ // calculate sub channel unread info and channel unread info
22233
+ if (feedMarkers.length > 0 && userFeedMarkers.length > 0) {
22234
+ const channelIds = [];
22235
+ const feedMarkerMap = new Map(feedMarkers.map(fm => [fm.feedId, fm]));
22236
+ userFeedMarkers.forEach(userFeedMarker => {
22237
+ const feedMarker = feedMarkerMap.get(userFeedMarker.feedId);
22238
+ if (!feedMarker)
22239
+ return;
22240
+ if (feedMarker.feedId === userFeedMarker.feedId) {
22241
+ const unreadCount = feedMarker.lastSegment - userFeedMarker.readToSegment;
22242
+ const subChannelUnreadInfo = {
22243
+ subChannelId: feedMarker.feedId,
22244
+ channelId: feedMarker.entityId,
22245
+ readToSegment: userFeedMarker.readToSegment,
22246
+ lastSegment: feedMarker.lastSegment,
22247
+ lastMentionSegment: userFeedMarker.lastMentionSegment,
22248
+ unreadCount: Math.max(0, unreadCount),
22249
+ isMentioned: userFeedMarker.isMentioned,
22250
+ isDeleted: feedMarker.isDeleted,
22251
+ createdAt: userFeedMarker.createdAt,
22252
+ updatedAt: userFeedMarker.updatedAt,
22253
+ };
22254
+ // update sub channel unread info in cache
22255
+ ingestInCache({ subChannelUnreadInfo: [subChannelUnreadInfo] });
22256
+ if (!channelIds.includes(feedMarker.entityId)) {
22257
+ channelIds.push(feedMarker.entityId);
22258
+ }
22259
+ }
22260
+ });
22261
+ // re-calculate channel unread info in cache
22262
+ channelIds.forEach(channelId => {
22263
+ reCalculateChannelUnreadInfo(channelId);
22264
+ });
22265
+ }
22266
+ };
22267
+
22268
+ const prepareUnreadCountInfo = async (rawPayload) => {
22269
+ const client = getActiveClient();
22270
+ // if consistent mode is enabled, persist the unread count info to the cache
22271
+ // Marker service API uses channelInternalId as channelId
22272
+ const queryPayload = await getUserMessageFeedMakers(rawPayload.channels.map(({ channelInternalId }) => channelInternalId));
22273
+ const { feedMarkers, userFeedMarkers } = queryPayload;
22274
+ persistUnreadCountInfo({
22275
+ feedMarkers,
22276
+ userFeedMarkers,
22277
+ });
22278
+ client.log('channel/prepareUnreadCountInfo', rawPayload.channels);
22279
+ };
22280
+
22187
22281
  /**
22188
22282
  * ```js
22189
22283
  * import { getChannelByIds } from '@amityco/ts-sdk-react-native'
@@ -22213,12 +22307,16 @@ const getChannelByIds = async (channelIds) => {
22213
22307
  catch (error) {
22214
22308
  channelIds.forEach(channelId => {
22215
22309
  if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
22310
+ // NOTE: use channelPublicId as tombstone cache key since we cannot get the channelPrivateId that come along with channel data from server
22216
22311
  pushToTombstone('channel', channelId);
22217
22312
  }
22218
22313
  });
22219
22314
  throw error;
22220
22315
  }
22221
22316
  const data = await prepareChannelPayload(payload);
22317
+ if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
22318
+ await prepareUnreadCountInfo(payload);
22319
+ }
22222
22320
  const cachedAt = client.cache && Date.now();
22223
22321
  if (client.cache)
22224
22322
  ingestInCache(data, { cachedAt });
@@ -22242,18 +22340,18 @@ const getChannelByIds = async (channelIds) => {
22242
22340
  * @category Channel API
22243
22341
  */
22244
22342
  getChannelByIds.locally = (channelIds) => {
22245
- var _a;
22343
+ var _a, _b;
22246
22344
  const client = getActiveClient();
22247
22345
  client.log('channel/getChannelByIds.locally', channelIds);
22248
22346
  if (!client.cache)
22249
22347
  return;
22250
- const cached = channelIds
22251
- .map(channelId => pullFromCache(['channel', 'get', channelId]))
22252
- .filter(Boolean);
22253
- if ((cached === null || cached === void 0 ? void 0 : cached.length) < channelIds.length)
22348
+ const cached = (_a = queryCache(['channel', 'get'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
22349
+ return channelIds.includes(data.channelPublicId);
22350
+ });
22351
+ if (!cached || (cached === null || cached === void 0 ? void 0 : cached.length) < channelIds.length)
22254
22352
  return;
22255
22353
  const channels = cached.map(({ data }) => data);
22256
- const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
22354
+ const oldest = (_b = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _b === void 0 ? void 0 : _b[0];
22257
22355
  return {
22258
22356
  data: channels,
22259
22357
  cachedAt: oldest.cachedAt,
@@ -22293,44 +22391,6 @@ const getMessageMarkers = async (messageIds) => {
22293
22391
  return { data: contentMarkers, cachedAt };
22294
22392
  };
22295
22393
 
22296
- const persistUnreadCountInfo = (payload) => {
22297
- const { feedMarkers, userFeedMarkers } = payload;
22298
- // calculate sub channel unread info and channel unread info
22299
- if (feedMarkers.length > 0 && userFeedMarkers.length > 0) {
22300
- const channelIds = [];
22301
- const feedMarkerMap = new Map(feedMarkers.map(fm => [fm.feedId, fm]));
22302
- userFeedMarkers.forEach(userFeedMarker => {
22303
- const feedMarker = feedMarkerMap.get(userFeedMarker.feedId);
22304
- if (!feedMarker)
22305
- return;
22306
- if (feedMarker.feedId === userFeedMarker.feedId) {
22307
- const unreadCount = feedMarker.lastSegment - userFeedMarker.readToSegment;
22308
- const subChannelUnreadInfo = {
22309
- subChannelId: feedMarker.feedId,
22310
- channelId: feedMarker.entityId,
22311
- readToSegment: userFeedMarker.readToSegment,
22312
- lastSegment: feedMarker.lastSegment,
22313
- lastMentionSegment: userFeedMarker.lastMentionSegment,
22314
- unreadCount: Math.max(0, unreadCount),
22315
- isMentioned: userFeedMarker.isMentioned,
22316
- isDeleted: feedMarker.isDeleted,
22317
- createdAt: userFeedMarker.createdAt,
22318
- updatedAt: userFeedMarker.updatedAt,
22319
- };
22320
- // update sub channel unread info in cache
22321
- ingestInCache({ subChannelUnreadInfo: [subChannelUnreadInfo] });
22322
- if (!channelIds.includes(feedMarker.entityId)) {
22323
- channelIds.push(feedMarker.entityId);
22324
- }
22325
- }
22326
- });
22327
- // re-calculate channel unread info in cache
22328
- channelIds.forEach(channelId => {
22329
- reCalculateChannelUnreadInfo(channelId);
22330
- });
22331
- }
22332
- };
22333
-
22334
22394
  /**
22335
22395
  * ```js
22336
22396
  * import { getSubChannelMarkers } from '@amityco/ts-sdk-react-native'
@@ -23259,7 +23319,7 @@ const getSocialSettings = async () => {
23259
23319
 
23260
23320
  const checkUserPermission = (userId, permission) => {
23261
23321
  var _a;
23262
- const user = (_a = pullFromCache(['users', 'get', userId])) === null || _a === void 0 ? void 0 : _a.data;
23322
+ const user = (_a = pullFromCache(['user', 'get', userId])) === null || _a === void 0 ? void 0 : _a.data;
23263
23323
  if (!user)
23264
23324
  return false;
23265
23325
  return user.permissions.some(x => x === permission);
@@ -23630,37 +23690,39 @@ const onOffline = (callback) => {
23630
23690
  document.addEventListener('offline', callback);
23631
23691
  return () => document.removeEventListener('offline', callback);
23632
23692
  }
23693
+ // @TODO: Please update code below to follow our coding conventions and our TS rules
23694
+ if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
23695
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
23696
+ let unsubscribeFn = () => { };
23697
+ import('@react-native-community/netinfo').then(NetInfo => {
23698
+ unsubscribeFn = NetInfo.addEventListener(state => {
23699
+ if (state.isConnected)
23700
+ return;
23701
+ callback();
23702
+ });
23703
+ });
23704
+ return () => {
23705
+ unsubscribeFn();
23706
+ };
23707
+ }
23633
23708
  // Handle unsupported environment
23634
23709
  console.error('Unsupported environment');
23635
23710
  return () => console.error('Unsupported environment');
23636
23711
  };
23637
23712
 
23638
- /**
23639
- * ```js
23640
- * import { getSubChannelMarkers } from '@amityco/ts-sdk-react-native'
23641
- * const subChannelMarkers = await getSubChannelMarkers(['sch1', 'sch2'])
23642
- * ```
23643
- *
23644
- * Fetches a paginable list of {@link Amity.SubChannelMarker} objects
23645
- *
23646
- * @param messageFeedIds the feed IDs of the {@link Amity.RawSubChannel} marker to fetch
23647
- * @param page
23648
- * @returns A page of {@link Amity.SubChannelMarker} objects
23649
- *
23650
- * @category Channel API
23651
- * @async
23652
- * @private
23653
- */
23654
- const getUserMessageFeedMakers = async (channelIds) => {
23655
- const client = getActiveClient();
23656
- client.log('channel/getUserMessageFeedMakers', channelIds);
23657
- const { data } = await client.http.get(`/api/v1/markers/user-message-feed`, {
23658
- params: {
23659
- channelIds,
23660
- },
23713
+ const resolveChannels = async (channelIds) => {
23714
+ const { data: channels } = await getChannelByIds(channelIds);
23715
+ fireEvent('local.channel.resolved', channels);
23716
+ };
23717
+
23718
+ const resolveUserMessageFeedMarkers = async (channelIds) => {
23719
+ const queryPayload = await getUserMessageFeedMakers(channelIds);
23720
+ const { feedMarkers, userFeedMarkers } = queryPayload;
23721
+ persistUnreadCountInfo({
23722
+ feedMarkers,
23723
+ userFeedMarkers,
23661
23724
  });
23662
- fireEvent('local.userMessageFeedMarker.fetched', { userMessageFeedMarker: data });
23663
- return data;
23725
+ fireEvent('local.userMessageFeedMarkers.resolved', { feedMarkers, userFeedMarkers });
23664
23726
  };
23665
23727
 
23666
23728
  class ObjectResolverEngine {
@@ -23727,9 +23789,9 @@ class ObjectResolverEngine {
23727
23789
  // Incase of failure: Ignore
23728
23790
  // Incase of success: Persist in Domain DB & Notify Live collection
23729
23791
  if (channelIds.length > 0)
23730
- getChannelByIds(channelIds);
23792
+ resolveChannels(channelIds);
23731
23793
  if (userMessageFeedMarkerIds.length > 0)
23732
- getUserMessageFeedMakers(userMessageFeedMarkerIds);
23794
+ resolveUserMessageFeedMarkers(userMessageFeedMarkerIds);
23733
23795
  // After sending request
23734
23796
  this.isResolvingTask = false;
23735
23797
  }
@@ -24799,9 +24861,7 @@ const login = async (params, sessionHandler, config) => {
24799
24861
  // FIXME: events are duplicated if connectClient is called few times without disconnectClient
24800
24862
  // wire websocket events to our event emitter
24801
24863
  proxyWebsocketEvents(client.ws, client.emitter);
24802
- client.ws.once('connect', () => {
24803
- client.ws.open();
24804
- });
24864
+ client.ws.open();
24805
24865
  client.userId = user.userId;
24806
24866
  client.sessionHandler = sessionHandler;
24807
24867
  /*
@@ -29217,7 +29277,7 @@ const onReactionRemoved = (referenceType, referenceId, callback) => {
29217
29277
  * })
29218
29278
  * ```
29219
29279
  *
29220
- * Fired when an {@link Amity.Reactor} has been added
29280
+ * Fired when an {@link Amity.InternalReactor} has been added
29221
29281
  *
29222
29282
  * @param {@link Amity.ReactableType} referenceType
29223
29283
  * @param {string} referenceId
@@ -29280,7 +29340,7 @@ const onReactorAdded = (referenceType, referenceId, callback) => {
29280
29340
  * })
29281
29341
  * ```
29282
29342
  *
29283
- * Fired when an {@link Amity.Reactor} has been removed
29343
+ * Fired when an {@link Amity.InternalReactor} has been removed
29284
29344
  *
29285
29345
  * @param {@link Amity.ReactableType} referenceType
29286
29346
  * @param {string} referenceId
@@ -29387,10 +29447,10 @@ const queryReactions = async (query) => {
29387
29447
  * })
29388
29448
  * ```
29389
29449
  *
29390
- * Queries a paginable list of {@link Amity.Reactor} objects
29450
+ * Queries a paginable list of {@link Amity.InternalReactor} objects
29391
29451
  *
29392
29452
  * @param query The query parameters
29393
- * @returns A page of {@link Amity.Reactor} objects
29453
+ * @returns A page of {@link Amity.InternalReactor} objects
29394
29454
  *
29395
29455
  * @reaction Reaction API
29396
29456
  * @async
@@ -29416,7 +29476,7 @@ const queryReactor = async (query) => {
29416
29476
  * }, response => merge(reactions, response.data))
29417
29477
  * ```
29418
29478
  *
29419
- * Observe all mutations on a list of {@link Amity.Reactor} for a given target object
29479
+ * Observe all mutations on a list of {@link Amity.InternalReactor} for a given target object
29420
29480
  *
29421
29481
  * @param params for querying reactions
29422
29482
  * @param callback the function to call when new data are available
@@ -29446,7 +29506,7 @@ const getReactions = (params, callback, config) => {
29446
29506
  const reactions = (_a = data.data
29447
29507
  .map(reactorId => pullFromCache(['reactor', 'get', reactorId]))
29448
29508
  .filter(Boolean)
29449
- .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
29509
+ .map(({ data }) => LinkedObject.reactor(data))) !== null && _a !== void 0 ? _a : [];
29450
29510
  callback({
29451
29511
  onNextPage: onFetch,
29452
29512
  data: reactions,
@@ -29721,18 +29781,6 @@ const updateChannel = async (channelId, patch) => {
29721
29781
  };
29722
29782
  /* end_public_function */
29723
29783
 
29724
- const prepareUnreadCountInfo = async (rawPayload) => {
29725
- const client = getActiveClient();
29726
- // if consistent mode is enabled, persist the unread count info to the cache
29727
- const queryPayload = await getUserMessageFeedMakers(rawPayload.channels.map(({ channelId }) => channelId));
29728
- const { feedMarkers, userFeedMarkers } = queryPayload;
29729
- persistUnreadCountInfo({
29730
- feedMarkers,
29731
- userFeedMarkers,
29732
- });
29733
- client.log('channel/prepareUnreadCountInfo', rawPayload.channels);
29734
- };
29735
-
29736
29784
  /**
29737
29785
  * ```js
29738
29786
  * import { getChannel } from '@amityco/ts-sdk-react-native'
@@ -29761,6 +29809,7 @@ const getChannel$1 = async (channelId) => {
29761
29809
  }
29762
29810
  catch (error) {
29763
29811
  if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
29812
+ // NOTE: use channelPublicId as tombstone cache key since we cannot get the channelPrivateId that come along with channel data from server
29764
29813
  pushToTombstone('channel', channelId);
29765
29814
  }
29766
29815
  throw error;
@@ -29788,16 +29837,20 @@ const getChannel$1 = async (channelId) => {
29788
29837
  * @category Channel API
29789
29838
  */
29790
29839
  getChannel$1.locally = (channelId) => {
29840
+ var _a;
29791
29841
  const client = getActiveClient();
29792
29842
  client.log('channel/getChannel.locally', channelId);
29793
29843
  if (!client.cache)
29794
29844
  return;
29795
- const cached = pullFromCache(['channel', 'get', channelId]);
29796
- if (!cached)
29845
+ // use queryCache to get all channel caches and filter by channelPublicId since we use channelPrivateId as cache key
29846
+ const cached = (_a = queryCache(['channel', 'get'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
29847
+ return data.channelPublicId === channelId;
29848
+ });
29849
+ if (!cached || (cached === null || cached === void 0 ? void 0 : cached.length) === 0)
29797
29850
  return;
29798
29851
  return {
29799
- data: cached.data,
29800
- cachedAt: cached.cachedAt,
29852
+ data: cached[0].data,
29853
+ cachedAt: cached[0].cachedAt,
29801
29854
  };
29802
29855
  };
29803
29856
 
@@ -32441,6 +32494,7 @@ const getChannel = (channelId, callback) => {
32441
32494
  await handleMessageCreated(message);
32442
32495
  if (message.channelId !== channelId)
32443
32496
  return;
32497
+ // channelId from message is channelInternalId
32444
32498
  const channel = (_a = pullFromCache(['channel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
32445
32499
  if (!channel)
32446
32500
  return;
@@ -32460,6 +32514,7 @@ const getChannel = (channelId, callback) => {
32460
32514
  await handleMessageCreated(message);
32461
32515
  if (message.channelId !== channelId)
32462
32516
  return;
32517
+ // channelId from message is channelInternalId
32463
32518
  const channel = (_a = pullFromCache(['channel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
32464
32519
  if (!channel)
32465
32520
  return;
@@ -32623,15 +32678,15 @@ class ChannelQueryStreamController extends QueryStreamController {
32623
32678
  if ([
32624
32679
  "onCreate" /* Amity.ChannelActionType.OnCreate */,
32625
32680
  "onJoin" /* Amity.ChannelActionType.OnJoin */,
32626
- "onFetch" /* Amity.ChannelActionType.OnFetch */,
32627
- "onUserMessageFeedMarkerFetch" /* Amity.ChannelActionType.OnUserMessageFeedMarkerFetch */,
32681
+ "onResolve" /* Amity.ChannelActionType.OnResolve */,
32628
32682
  ].includes(action)) {
32629
- if (Array.isArray(payload))
32683
+ if (Array.isArray(payload)) {
32630
32684
  collection.data = [
32631
- ...new Set([...payload.map(({ channelId }) => channelId), ...collection.data]),
32685
+ ...new Set([...payload.map(getResolver('channel')), ...collection.data]),
32632
32686
  ];
32687
+ }
32633
32688
  else
32634
- collection.data = [...new Set([payload.channelId, ...collection.data])];
32689
+ collection.data = [...new Set([payload.channelInternalId, ...collection.data])];
32635
32690
  }
32636
32691
  pushToCache(this.cacheKey, collection);
32637
32692
  this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
@@ -32642,62 +32697,50 @@ class ChannelQueryStreamController extends QueryStreamController {
32642
32697
  }
32643
32698
  }
32644
32699
 
32700
+ const resolveUnreadInfoOnChannelEvent = (channel, callback) => {
32701
+ const client = getActiveClient();
32702
+ if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
32703
+ const objectResolverEngine = ObjectResolverEngine$1.getInstance();
32704
+ objectResolverEngine.resolve(channel.channelId, "userMessageFeedMarker" /* Amity.ReferenceType.USER_MESSAGE_FEED_MARKER */);
32705
+ }
32706
+ else
32707
+ callback(channel);
32708
+ };
32709
+
32645
32710
  /**
32646
- * ```js
32647
- * import { onChannelFetched } from '@amityco/ts-sdk-react-native'
32648
- * const dispose = onChannelFetched(channel => {
32649
- * // ...
32650
- * })
32651
- * ```
32711
+ * Internal used only
32652
32712
  *
32653
- * Fired when any {@link Amity.Channel} list have been fetched
32713
+ * Fired when any {@link Amity.Channel} have been resolved by Object resolver
32654
32714
  *
32655
32715
  * @param callback The function to call when the event was fired
32656
32716
  * @returns an {@link Amity.Unsubscriber} function to stop listening
32657
32717
  *
32658
32718
  * @category Channel Events
32659
32719
  */
32660
- const onChannelFetched = (callback) => {
32720
+ const onChannelResolved = (callback) => {
32661
32721
  const client = getActiveClient();
32662
32722
  const filter = async (payload) => {
32663
32723
  callback(payload);
32664
32724
  };
32665
- return createEventSubscriber(client, 'onChannelFetched', 'local.channel.fetched', filter);
32725
+ return createEventSubscriber(client, 'onChannelResolved', 'local.channel.resolved', filter);
32666
32726
  };
32667
32727
 
32668
32728
  /**
32669
- * ```js
32670
- * import { onFeedMarkerUpdated } from '@amityco/ts-sdk-react-native'
32671
- * const dispose = onFeedMarkerUpdated(feedMarker => {
32672
- * // ...
32673
- * })
32674
- * ```
32729
+ * Internal used only
32675
32730
  *
32676
- * Fired when an {@link Amity.UserMessageFeedMarkerPayload} has been updated
32731
+ * Fired when an {@link Amity.userMessageFeedMarkers} has been resolved by Object Rsesolver
32677
32732
  *
32678
32733
  * @param callback The function to call when the event was fired
32679
32734
  * @returns an {@link Amity.Unsubscriber} function to stop listening
32680
32735
  *
32681
- * @category FeedMarker Events
32736
+ * @category MessageMarker Events
32682
32737
  */
32683
- const onUserFeedMarkerFetched = (callback) => {
32738
+ const onUserMessageFeedMarkerResolved = (callback) => {
32684
32739
  const client = getActiveClient();
32685
32740
  const filter = (payload) => {
32686
- // update sub channel unread info and channel unread info in cache
32687
- persistUnreadCountInfo(payload.userMessageFeedMarker);
32688
- callback(payload.userMessageFeedMarker);
32741
+ callback(payload);
32689
32742
  };
32690
- return createEventSubscriber(client, 'feedMarker/onUserFeedMarkerFetched', 'local.userMessageFeedMarker.fetched', filter);
32691
- };
32692
-
32693
- const resolveUnreadInfoOnChannelEvent = (channel, callback) => {
32694
- const client = getActiveClient();
32695
- if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
32696
- const objectResolverEngine = ObjectResolverEngine$1.getInstance();
32697
- objectResolverEngine.resolve(channel.channelId, "userMessageFeedMarker" /* Amity.ReferenceType.USER_MESSAGE_FEED_MARKER */);
32698
- }
32699
- else
32700
- callback(channel);
32743
+ return createEventSubscriber(client, 'userMessageFeedMarker/onUserMessageFeedMarkerResolved', 'local.userMessageFeedMarkers.resolved', filter);
32701
32744
  };
32702
32745
 
32703
32746
  /* eslint-disable no-use-before-define */
@@ -32834,7 +32877,6 @@ class ChannelLiveCollectionController extends LiveCollectionController {
32834
32877
  getSubscriptions() {
32835
32878
  const subscriptions = [
32836
32879
  {
32837
- // TODO: merge this code to another onMessageCreated in this file
32838
32880
  fn: convertEventPayload((callback) => {
32839
32881
  return onMessageCreatedMqtt(message => {
32840
32882
  var _a;
@@ -32845,6 +32887,7 @@ class ChannelLiveCollectionController extends LiveCollectionController {
32845
32887
  ])) === null || _a === void 0 ? void 0 : _a.data;
32846
32888
  if (!cacheData) {
32847
32889
  const objectResolverEngine = ObjectResolverEngine$1.getInstance();
32890
+ // channelId from message event payload is channelInternalId
32848
32891
  objectResolverEngine.resolve(message.channelId, "channel" /* Amity.ReferenceType.CHANNEL */);
32849
32892
  }
32850
32893
  else {
@@ -32858,7 +32901,6 @@ class ChannelLiveCollectionController extends LiveCollectionController {
32858
32901
  action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
32859
32902
  },
32860
32903
  {
32861
- // TODO: merge this code to another onMessageCreated in this file
32862
32904
  fn: convertEventPayload((callback) => {
32863
32905
  return onMessageCreatedLocal(message => {
32864
32906
  var _a;
@@ -33050,23 +33092,25 @@ class ChannelLiveCollectionController extends LiveCollectionController {
33050
33092
  action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
33051
33093
  },
33052
33094
  {
33053
- fn: onChannelFetched,
33054
- action: "onFetch" /* Amity.ChannelActionType.OnFetch */,
33095
+ fn: onChannelResolved,
33096
+ action: "onResolve" /* Amity.ChannelActionType.OnResolve */,
33055
33097
  },
33056
33098
  {
33057
33099
  fn: (callback) => {
33058
- const handleUserFeedMarkerFetch = async (marker) => {
33100
+ const handleUserFeedMarkerResolved = async (marker) => {
33059
33101
  if (marker.feedMarkers) {
33060
- const channelIds = marker.feedMarkers.map(feedMarker => feedMarker.entityId);
33102
+ const channelIds = [
33103
+ ...new Set(marker.feedMarkers.map(feedMarker => feedMarker.entityId)),
33104
+ ];
33061
33105
  const channels = channelIds
33062
33106
  .map(channelId => { var _a; return (_a = pullFromCache(['channel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data; })
33063
33107
  .filter(Boolean);
33064
33108
  callback(channels);
33065
33109
  }
33066
33110
  };
33067
- return onUserFeedMarkerFetched(handleUserFeedMarkerFetch);
33111
+ return onUserMessageFeedMarkerResolved(handleUserFeedMarkerResolved);
33068
33112
  },
33069
- action: "onUserMessageFeedMarkerFetch" /* Amity.ChannelActionType.OnUserMessageFeedMarkerFetch */,
33113
+ action: "onResolve" /* Amity.ChannelActionType.OnResolve */,
33070
33114
  },
33071
33115
  ];
33072
33116
  if (this.paginationController instanceof PaginationController) {
@@ -37690,7 +37734,7 @@ const onStreamStarted = (callback) => {
37690
37734
  ingestInCache(payload);
37691
37735
  callback(payload.videoStreamings[0]);
37692
37736
  };
37693
- return createEventSubscriber(client, 'stream/onStreamStarted', 'video-streaming.didStart', filter);
37737
+ return createEventSubscriber(client, 'stream/onStreamStarted', 'v3.video-streaming.didStart', filter);
37694
37738
  };
37695
37739
 
37696
37740
  /**
@@ -37714,7 +37758,7 @@ const onStreamStopped = (callback) => {
37714
37758
  ingestInCache(payload);
37715
37759
  callback(payload.videoStreamings[0]);
37716
37760
  };
37717
- return createEventSubscriber(client, 'stream/onStreamStarted', 'video-streaming.didStop', filter);
37761
+ return createEventSubscriber(client, 'stream/onStreamStropped', 'v3.video-streaming.didStop', filter);
37718
37762
  };
37719
37763
 
37720
37764
  /**
@@ -37738,7 +37782,7 @@ const onStreamRecorded = (callback) => {
37738
37782
  ingestInCache(payload);
37739
37783
  callback(payload.videoStreamings[0]);
37740
37784
  };
37741
- return createEventSubscriber(client, 'stream/onStreamRecorded', 'video-streaming.didRecord', filter);
37785
+ return createEventSubscriber(client, 'stream/onStreamRecorded', 'v3.video-streaming.didRecord', filter);
37742
37786
  };
37743
37787
 
37744
37788
  /* eslint-disable no-use-before-define */