@amityco/ts-sdk-react-native 6.8.2-d546836.0 → 6.8.3-6df654f.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.
package/dist/index.esm.js CHANGED
@@ -82,8 +82,8 @@ const PostContentType = Object.freeze({
82
82
 
83
83
  function getVersion() {
84
84
  try {
85
- // the string ''v6.8.0-esm'' should be replaced by actual value by @rollup/plugin-replace
86
- return 'v6.8.0-esm';
85
+ // the string ''v6.8.2-esm'' should be replaced by actual value by @rollup/plugin-replace
86
+ return 'v6.8.2-esm';
87
87
  }
88
88
  catch (error) {
89
89
  return '__dev__';
@@ -22088,7 +22088,10 @@ const removeChannelMarkerCache = (channel) => {
22088
22088
  * than the one already connected, in which case the existing subscriptions need
22089
22089
  * to be cleared
22090
22090
  */
22091
- const subscriptions = [];
22091
+ let subscriptions = [];
22092
+ async function runMqtt() {
22093
+ await modifyMqttConnection();
22094
+ }
22092
22095
  /* begin_public_function
22093
22096
  id: client.login
22094
22097
  */
@@ -22122,6 +22125,7 @@ const login = async (params, sessionHandler, config) => {
22122
22125
  await logout();
22123
22126
  // Remove subscription to ban and delete
22124
22127
  subscriptions.forEach(fn => fn());
22128
+ subscriptions = [];
22125
22129
  }
22126
22130
  // default values
22127
22131
  (_a = params.deviceId) !== null && _a !== void 0 ? _a : (params.deviceId = await getDeviceId());
@@ -22132,10 +22136,7 @@ const login = async (params, sessionHandler, config) => {
22132
22136
  // FIXME: events are duplicated if connectClient is called few times without disconnectClient
22133
22137
  // wire websocket events to our event emitter
22134
22138
  proxyWebsocketEvents(client.ws, client.emitter);
22135
- // TODO: in phase 2, this should not be necessary. we should have WS
22136
- // to be connected "on demand" rather than "by default"
22137
- await new Promise(resolve => {
22138
- client.ws.once('connect', resolve);
22139
+ client.ws.once('connect', () => {
22139
22140
  client.ws.open();
22140
22141
  });
22141
22142
  client.userId = params.userId;
@@ -22157,34 +22158,36 @@ const login = async (params, sessionHandler, config) => {
22157
22158
  throw error;
22158
22159
  }
22159
22160
  if ((config === null || config === void 0 ? void 0 : config.disableRTE) !== true) {
22160
- await modifyMqttConnection();
22161
+ runMqtt();
22161
22162
  }
22162
- subscriptions.push(
22163
- // GLOBAL_BAN
22164
- onClientBanned((_) => {
22165
- terminateClient("globalBan" /* Amity.TokenTerminationReason.GLOBAL_BAN */);
22166
- subscriptions.forEach(fn => fn());
22167
- unsubWatcher();
22168
- }), onTokenTerminated(_ => {
22169
- terminateClient();
22170
- subscriptions.forEach(fn => fn());
22171
- unsubWatcher();
22172
- }), onUserDeleted((user) => {
22173
- if (user.userId === client.userId) {
22174
- terminateClient("userDeleted" /* Amity.TokenTerminationReason.USER_DELETED */);
22163
+ if (subscriptions.length === 0) {
22164
+ subscriptions.push(
22165
+ // GLOBAL_BAN
22166
+ onClientBanned((_) => {
22167
+ terminateClient("globalBan" /* Amity.TokenTerminationReason.GLOBAL_BAN */);
22175
22168
  subscriptions.forEach(fn => fn());
22176
22169
  unsubWatcher();
22177
- }
22178
- }), onTokenExpired(state => {
22179
- setSessionState(state);
22180
- logout();
22181
- subscriptions.forEach(fn => fn());
22182
- }),
22183
- // NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
22184
- // the channel because currently backend can't handle this, so every time a user is banned from
22185
- // a channel or the channel is deleted the channel's unread count will not be reset to zero
22186
- onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler());
22187
- return client.ws.connected;
22170
+ }), onTokenTerminated(_ => {
22171
+ terminateClient();
22172
+ subscriptions.forEach(fn => fn());
22173
+ unsubWatcher();
22174
+ }), onUserDeleted((user) => {
22175
+ if (user.userId === client.userId) {
22176
+ terminateClient("userDeleted" /* Amity.TokenTerminationReason.USER_DELETED */);
22177
+ subscriptions.forEach(fn => fn());
22178
+ unsubWatcher();
22179
+ }
22180
+ }), onTokenExpired(state => {
22181
+ setSessionState(state);
22182
+ logout();
22183
+ subscriptions.forEach(fn => fn());
22184
+ }),
22185
+ // NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
22186
+ // the channel because currently backend can't handle this, so every time a user is banned from
22187
+ // a channel or the channel is deleted the channel's unread count will not be reset to zero
22188
+ onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler());
22189
+ }
22190
+ return true;
22188
22191
  };
22189
22192
  /* end_public_function */
22190
22193
 
@@ -22645,24 +22648,31 @@ const onMessageMarked = (callback) => {
22645
22648
  var _a, _b;
22646
22649
  ingestInCache(payload);
22647
22650
  const cacheCollection = queryCache(['message', 'collection']);
22648
- if (cacheCollection && (cacheCollection === null || cacheCollection === void 0 ? void 0 : cacheCollection.length) > 0) {
22649
- const contentMarker = payload.contentMarkers[0];
22651
+ const { contentMarkers, feedMarkers } = payload;
22652
+ if (cacheCollection && (cacheCollection === null || cacheCollection === void 0 ? void 0 : cacheCollection.length) > 0 && (feedMarkers === null || feedMarkers === void 0 ? void 0 : feedMarkers.length) > 0) {
22653
+ /**
22654
+ * in case of read the message collection,
22655
+ * use feedId of the feedMarkers to check if it equal to subChannelId.
22656
+ */
22650
22657
  const currentMessageCollection = cacheCollection.filter(currentMessage => {
22651
- if (!isObject(currentMessage.key[2]))
22658
+ const cacheKey = currentMessage.key;
22659
+ if (!isObject(cacheKey[2]))
22652
22660
  return false;
22653
- return currentMessage.key[2].subChannelId === contentMarker.feedId;
22661
+ const queryParams = cacheKey[2];
22662
+ return queryParams.subChannelId === feedMarkers[0].feedId;
22654
22663
  });
22655
- if (currentMessageCollection.length > 0) {
22664
+ if (currentMessageCollection.length > 0 && (contentMarkers === null || contentMarkers === void 0 ? void 0 : contentMarkers.length) > 0) {
22656
22665
  const currentMessages = ((_b = (_a = currentMessageCollection[0].data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.map(messageId => {
22657
22666
  return pullFromCache(['message', 'get', messageId]);
22658
22667
  })) || [];
22659
22668
  currentMessages.forEach(message => {
22660
- const isSameSubChannelId = contentMarker.feedId === (message === null || message === void 0 ? void 0 : message.data.subChannelId);
22661
- const isReadCountLatest = contentMarker.readCount > (message === null || message === void 0 ? void 0 : message.data.readCount);
22662
- const isDeliveredCountLatest = contentMarker.deliveredCount > (message === null || message === void 0 ? void 0 : message.data.deliveredCount);
22669
+ var _a;
22670
+ const isSameSubChannelId = contentMarkers[0].feedId === (message === null || message === void 0 ? void 0 : message.data.subChannelId);
22671
+ const isReadCountLatest = contentMarkers[0].readCount > (message === null || message === void 0 ? void 0 : message.data.readCount);
22672
+ const isDeliveredCountLatest = ((_a = contentMarkers[0]) === null || _a === void 0 ? void 0 : _a.deliveredCount) > (message === null || message === void 0 ? void 0 : message.data.deliveredCount);
22663
22673
  if (isSameSubChannelId) {
22664
- pushToCache(['message', 'get', message.data.messageId], Object.assign(Object.assign({}, message.data), { readCount: isReadCountLatest ? contentMarker.readCount : message === null || message === void 0 ? void 0 : message.data.readCount, deliveredCount: isDeliveredCountLatest
22665
- ? contentMarker.deliveredCount
22674
+ pushToCache(['message', 'get', message.data.messageId], Object.assign(Object.assign({}, message.data), { readCount: isReadCountLatest ? contentMarkers[0].readCount : message === null || message === void 0 ? void 0 : message.data.readCount, deliveredCount: isDeliveredCountLatest
22675
+ ? contentMarkers[0].deliveredCount
22666
22676
  : message === null || message === void 0 ? void 0 : message.data.deliveredCount }));
22667
22677
  }
22668
22678
  });
@@ -23900,7 +23910,7 @@ queryChannelMembers.locally = (query) => {
23900
23910
  * Exported for testing
23901
23911
  * @hidden
23902
23912
  */
23903
- const applyFilter$2 = (data, params) => {
23913
+ const applyFilter$3 = (data, params) => {
23904
23914
  let channelMembers = filterByPropIntersection(data, 'roles', params.roles);
23905
23915
  if (params.memberships) {
23906
23916
  /*
@@ -23975,7 +23985,7 @@ const getMembers$1 = (params, callback, config) => {
23975
23985
  /*
23976
23986
  * Only apply filter to RTE Model
23977
23987
  */
23978
- data: isEventModel ? applyFilter$2(channelMembers, params) : channelMembers,
23988
+ data: isEventModel ? applyFilter$3(channelMembers, params) : channelMembers,
23979
23989
  hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
23980
23990
  loading: data.loading,
23981
23991
  error: data.error,
@@ -24065,7 +24075,7 @@ var index$i = /*#__PURE__*/Object.freeze({
24065
24075
  __proto__: null,
24066
24076
  addMembers: addMembers$1,
24067
24077
  removeMembers: removeMembers$1,
24068
- applyFilter: applyFilter$2,
24078
+ applyFilter: applyFilter$3,
24069
24079
  getMembers: getMembers$1,
24070
24080
  searchMembers: searchMembers
24071
24081
  });
@@ -26390,7 +26400,7 @@ queryUsers.locally = (query = {}) => {
26390
26400
  * Exported for testing
26391
26401
  * @hidden
26392
26402
  */
26393
- const applyFilter$1 = (data, params) => {
26403
+ const applyFilter$2 = (data, params) => {
26394
26404
  let users = filterByStringComparePartially(data, 'displayName', params.displayName);
26395
26405
  switch (params.sortBy) {
26396
26406
  case 'firstCreated':
@@ -26439,7 +26449,7 @@ const getUsers = (params, callback, config) => {
26439
26449
  const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
26440
26450
  const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
26441
26451
  const disposers = [];
26442
- const cacheKey = ['user', 'collection', queryParams];
26452
+ const cacheKey = ['user', 'collection', uuid()];
26443
26453
  const responder = (data, isEventModel = false) => {
26444
26454
  var _a, _b;
26445
26455
  const users = (_a = data.data
@@ -26451,7 +26461,7 @@ const getUsers = (params, callback, config) => {
26451
26461
  /*
26452
26462
  * Only apply filter to RTE Model
26453
26463
  */
26454
- data: isEventModel ? applyFilter$1(users, params) : users,
26464
+ data: isEventModel ? applyFilter$2(users, params) : users,
26455
26465
  hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
26456
26466
  loading: data.loading,
26457
26467
  error: data.error,
@@ -29261,6 +29271,50 @@ const queryMessages = async (query) => {
29261
29271
  };
29262
29272
  /* end_public_function */
29263
29273
 
29274
+ /*
29275
+ * Exported for testing
29276
+ * @hidden
29277
+ */
29278
+ const applyFilter$1 = (data, params) => {
29279
+ let messages = data;
29280
+ messages = messages.filter(m => {
29281
+ if (params.tags) {
29282
+ return params.tags.find(value => {
29283
+ if (!m.tags)
29284
+ return false;
29285
+ return m.tags.includes(value);
29286
+ });
29287
+ }
29288
+ return true;
29289
+ });
29290
+ messages = messages.filter(m => {
29291
+ if (params.excludeTags) {
29292
+ return (params.excludeTags || []).find(value => {
29293
+ if (!m.tags)
29294
+ return true;
29295
+ return !m.tags.includes(value);
29296
+ });
29297
+ }
29298
+ return true;
29299
+ });
29300
+ /*
29301
+ * for cases when message is deleted via RTE, this flag is used to get
29302
+ * items from cache that are !deleted
29303
+ */
29304
+ if (!params.includeDeleted) {
29305
+ messages = filterByPropEquality(messages, 'isDeleted', false);
29306
+ }
29307
+ messages = messages.sort((message1, message2) => {
29308
+ if (params.sortBy === 'segmentAsc') {
29309
+ return message1.channelSegment - message2.channelSegment;
29310
+ }
29311
+ if (params.sortBy === 'segmentDesc') {
29312
+ return message2.channelSegment - message1.channelSegment;
29313
+ }
29314
+ return 0;
29315
+ });
29316
+ return messages;
29317
+ };
29264
29318
  /* begin_public_function
29265
29319
  id: message.query
29266
29320
  */
@@ -29294,30 +29348,14 @@ const getMessages = (params, callback, config) => {
29294
29348
  const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
29295
29349
  const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
29296
29350
  const disposers = [];
29297
- const cacheKey = ['message', 'collection', params, uuid()];
29351
+ const uniqueId = uuid();
29352
+ const cacheKey = ['message', 'collection', params, uniqueId];
29298
29353
  const responder = (data) => {
29299
29354
  var _a, _b;
29300
- let messages = (_a = data.data
29355
+ const messages = applyFilter$1((_a = data.data
29301
29356
  .map(messageId => pullFromCache(['message', 'get', messageId]))
29302
29357
  .filter(Boolean)
29303
- .filter(item => {
29304
- if (!params.tags)
29305
- return true;
29306
- return params.tags.find(value => {
29307
- var _a;
29308
- if (!((_a = item.data) === null || _a === void 0 ? void 0 : _a.tags))
29309
- return false;
29310
- return item.data.tags.includes(value);
29311
- });
29312
- })
29313
- .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
29314
- /*
29315
- * for cases when message is deleted via RTE, this flag is used to get
29316
- * items from cache that are !deleted
29317
- */
29318
- if (!params.includeDeleted) {
29319
- messages = filterByPropEquality(messages, 'isDeleted', false);
29320
- }
29358
+ .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [], params);
29321
29359
  callback({
29322
29360
  onNextPage: onFetch,
29323
29361
  data: messages,
@@ -29327,10 +29365,28 @@ const getMessages = (params, callback, config) => {
29327
29365
  });
29328
29366
  };
29329
29367
  const realtimeRouter = (action) => (message) => {
29330
- var _a;
29368
+ var _a, _b, _c;
29331
29369
  const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
29332
29370
  if (params.subChannelId !== (message === null || message === void 0 ? void 0 : message.subChannelId) || !collection)
29333
29371
  return;
29372
+ // /*
29373
+ // * check if RTE message event payload is with the params in order to update in the colleciton cache
29374
+ // */
29375
+ if (params.dataType && params.dataType !== message.dataType)
29376
+ return;
29377
+ if (params.excludeTags && ((_b = params.excludeTags) === null || _b === void 0 ? void 0 : _b.some(value => { var _a; return (_a = message.tags) === null || _a === void 0 ? void 0 : _a.includes(value); })))
29378
+ return;
29379
+ if (!!params.hasFlags !== !!message.flagCount)
29380
+ return;
29381
+ if (params.parentId && params.parentId !== message.parentId)
29382
+ return;
29383
+ if (params.hasOwnProperty('includeDeleted') && !params.includeDeleted && message.isDeleted)
29384
+ return;
29385
+ if (params.tags && !((_c = params.tags) === null || _c === void 0 ? void 0 : _c.some(value => { var _a; return (_a = message.tags) === null || _a === void 0 ? void 0 : _a.includes(value); })))
29386
+ return;
29387
+ if (!collection.data.includes(message.messageId) && action === 'onCreate') {
29388
+ collection.data = [...new Set([message.messageId, ...collection.data])];
29389
+ }
29334
29390
  pushToCache(cacheKey, collection);
29335
29391
  responder(collection);
29336
29392
  };
@@ -29355,7 +29411,7 @@ const getMessages = (params, callback, config) => {
29355
29411
  responder(data);
29356
29412
  }, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
29357
29413
  };
29358
- disposers.push(onMessageFetched(realtimeRouter()), onMessageCreated(realtimeRouter()), onMessageUpdated(realtimeRouter()), onMessageDeleted(realtimeRouter()), onMessageFlagged(realtimeRouter()), onMessageUnflagged(realtimeRouter()), onMessageFlagCleared(realtimeRouter()), onMessageReactionAdded(realtimeRouter()), onMessageReactionRemoved(realtimeRouter()), convertEventPayload(onMessageMarkerFetched, 'contentId', 'message')(realtimeRouter()), convertEventPayload(onMessageMarked, 'contentId', 'message')(realtimeRouter()));
29414
+ disposers.push(onMessageFetched(realtimeRouter('onFetch')), onMessageCreated(realtimeRouter('onCreate')), onMessageUpdated(realtimeRouter('onUpdate')), onMessageDeleted(realtimeRouter('onDelete')), onMessageFlagged(realtimeRouter('onFlagged')), onMessageUnflagged(realtimeRouter('onUnflagged')), onMessageFlagCleared(realtimeRouter('onFlagCleared')), onMessageReactionAdded(realtimeRouter('onReactionAdded')), onMessageReactionRemoved(realtimeRouter('onReactionRemoved')), convertEventPayload(onMessageMarkerFetched, 'contentId', 'message')(realtimeRouter('onUpdate')), convertEventPayload(onMessageMarked, 'contentId', 'message')(realtimeRouter('onUpdate')));
29359
29415
  onFetch(true);
29360
29416
  disposers.push(() => dropFromCache(cacheKey));
29361
29417
  return () => {
@@ -33379,8 +33435,10 @@ const getComments = (params, callback, config) => {
33379
33435
  const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
33380
33436
  if (params.referenceId !== comment.referenceId ||
33381
33437
  params.referenceType !== comment.referenceType ||
33382
- !collection)
33438
+ params.parentId !== comment.parentId ||
33439
+ !collection) {
33383
33440
  return;
33441
+ }
33384
33442
  if (action === 'onCreate') {
33385
33443
  collection.data = [...new Set([comment.commentId, ...collection.data])];
33386
33444
  }
@@ -34253,4 +34311,4 @@ const createUserToken = async (apiKey, apiRegion, params) => {
34253
34311
  return { accessToken: data.accessToken };
34254
34312
  };
34255
34313
 
34256
- export { API_REGIONS, index$5 as CategoryRepository, index$g as ChannelRepository, index$f as Client, index$2 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$6 as CommunityRepository, ContentFeedType, DefaultCommunityPostSetting, index$4 as FeedRepository, index$c as FileRepository, FileType, MessageContentType, index$a as MessageRepository, index as PollRepository, PostContentType, index$3 as PostRepository, index$b as ReactionRepository, index$1 as StreamRepository, index$9 as SubChannelRepository, SubscriptionLevels, index$d as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelMarkers, getChannelTopic, getCommentTopic, getCommunityTopic, getDeviceId, getDeviceInfo, getDeviceModel, getMQTTClientId, getMarkedMessageTopic, getMessageMarkers, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getSubChannelMarkers, getSubChannelTopic, getUserMarker, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByLastActivity, sortByLastCreated, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
34314
+ export { API_REGIONS, index$5 as CategoryRepository, index$g as ChannelRepository, index$f as Client, index$2 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$6 as CommunityRepository, ContentFeedType, DefaultCommunityPostSetting, index$4 as FeedRepository, index$c as FileRepository, FileType, MessageContentType, index$a as MessageRepository, index as PollRepository, PostContentType, index$3 as PostRepository, index$b as ReactionRepository, index$1 as StreamRepository, index$9 as SubChannelRepository, SubscriptionLevels, index$d as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelMarkers, getChannelTopic, getCommentTopic, getCommunityTopic, getMarkedMessageTopic, getMessageMarkers, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getSubChannelMarkers, getSubChannelTopic, getUserMarker, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByLastActivity, sortByLastCreated, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };