@stream-io/feeds-client 0.3.33 → 0.3.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +3 -2
  3. package/dist/cjs/index.js +1 -1
  4. package/dist/cjs/index.js.map +1 -1
  5. package/dist/cjs/react-bindings.js +2 -4
  6. package/dist/cjs/react-bindings.js.map +1 -1
  7. package/dist/es/index.mjs +2 -2
  8. package/dist/es/index.mjs.map +1 -1
  9. package/dist/es/react-bindings.mjs +2 -4
  10. package/dist/es/react-bindings.mjs.map +1 -1
  11. package/dist/{feeds-client-C-6NrDBy.mjs → feeds-client-BRK49aQb.mjs} +40 -34
  12. package/dist/{feeds-client-C-6NrDBy.mjs.map → feeds-client-BRK49aQb.mjs.map} +1 -1
  13. package/dist/{feeds-client-CyaHg6lu.js → feeds-client-F087iP6p.js} +40 -34
  14. package/dist/{feeds-client-CyaHg6lu.js.map → feeds-client-F087iP6p.js.map} +1 -1
  15. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  16. package/dist/types/activity-with-state-updates/activity-with-state-updates.d.ts +3 -1
  17. package/dist/types/activity-with-state-updates/activity-with-state-updates.d.ts.map +1 -1
  18. package/dist/types/bindings/react/hooks/useCreateFeedsClient.d.ts.map +1 -1
  19. package/dist/types/feed/event-handlers/activity-updater.d.ts +1 -0
  20. package/dist/types/feed/event-handlers/activity-updater.d.ts.map +1 -1
  21. package/dist/types/feed/feed.d.ts.map +1 -1
  22. package/dist/types/feeds-client/active-activity.d.ts +2 -1
  23. package/dist/types/feeds-client/active-activity.d.ts.map +1 -1
  24. package/dist/types/feeds-client/feeds-client.d.ts +7 -3
  25. package/dist/types/feeds-client/feeds-client.d.ts.map +1 -1
  26. package/dist/types/gen/models/index.d.ts +1 -0
  27. package/dist/types/gen/models/index.d.ts.map +1 -1
  28. package/package.json +1 -1
  29. package/src/activity-with-state-updates/activity-with-state-updates.ts +10 -1
  30. package/src/bindings/react/hooks/useCreateFeedsClient.ts +1 -3
  31. package/src/feed/feed.ts +7 -5
  32. package/src/feeds-client/active-activity.ts +8 -4
  33. package/src/feeds-client/feeds-client.ts +22 -23
  34. package/src/gen/models/index.ts +2 -0
@@ -3941,7 +3941,7 @@ const getRateLimitFromResponseHeader = (response_headers) => {
3941
3941
  };
3942
3942
  return result;
3943
3943
  };
3944
- const version = "0.3.33";
3944
+ const version = "0.3.35";
3945
3945
  const axios = axiosImport.default ?? axiosImport;
3946
3946
  class ApiClient {
3947
3947
  constructor(apiKey, tokenManager, connectionIdManager, options) {
@@ -6932,11 +6932,13 @@ const _Feed = class _Feed extends FeedApi {
6932
6932
  const newFeeds = Array.from(feedsToGetOrCreate.values());
6933
6933
  const fieldsToUpdate = [];
6934
6934
  if (!options.fromWebSocket) {
6935
- fieldsToUpdate.push(
6936
- "own_capabilities",
6937
- "own_follows",
6938
- "own_membership"
6939
- );
6935
+ fieldsToUpdate.push("own_membership");
6936
+ if (!enrichmentOptions?.skip_own_capabilities) {
6937
+ fieldsToUpdate.push("own_capabilities");
6938
+ }
6939
+ if (!enrichmentOptions?.skip_own_follows) {
6940
+ fieldsToUpdate.push("own_follows");
6941
+ }
6940
6942
  if (enrichmentOptions?.enrich_own_followings) {
6941
6943
  fieldsToUpdate.push("own_followings");
6942
6944
  }
@@ -7044,14 +7046,14 @@ function isAnyFeedWatched(fids) {
7044
7046
  }
7045
7047
  return false;
7046
7048
  }
7047
- function disconnectActivityFromFeed(id) {
7048
- const activeFeed = this.activeActivities[id];
7049
- if (activeFeed) {
7050
- delete this.activeActivities[id];
7049
+ function disconnectActivityFromFeed(activity) {
7050
+ const index = this.activeActivities.indexOf(activity);
7051
+ if (index !== -1) {
7052
+ this.activeActivities.splice(index, 1);
7051
7053
  }
7052
7054
  }
7053
7055
  class ActivityWithStateUpdates {
7054
- constructor(id, feedsClient) {
7056
+ constructor(id, feedsClient, { fromResponse } = { fromResponse: void 0 }) {
7055
7057
  this.id = id;
7056
7058
  this.feedsClient = feedsClient;
7057
7059
  this.state = new stateStore.StateStore({
@@ -7059,6 +7061,13 @@ class ActivityWithStateUpdates {
7059
7061
  comments_by_entity_id: {},
7060
7062
  is_loading: false
7061
7063
  });
7064
+ if (fromResponse) {
7065
+ this.setFeed({
7066
+ fid: fromResponse.feeds[0],
7067
+ initialState: fromResponse
7068
+ });
7069
+ this.subscribeToFeedState();
7070
+ }
7062
7071
  }
7063
7072
  get currentState() {
7064
7073
  return this.state.getLatestValue();
@@ -7127,7 +7136,7 @@ class ActivityWithStateUpdates {
7127
7136
  }
7128
7137
  dispose() {
7129
7138
  this.unsubscribeFromFeedState?.();
7130
- disconnectActivityFromFeed.call(this.feedsClient, this.id);
7139
+ disconnectActivityFromFeed.call(this.feedsClient, this);
7131
7140
  }
7132
7141
  /**
7133
7142
  * @internal
@@ -7224,7 +7233,7 @@ class FeedsClient extends FeedsApi {
7224
7233
  );
7225
7234
  super(apiClient);
7226
7235
  this.eventDispatcher = new EventDispatcher();
7227
- this.activeActivities = {};
7236
+ this.activeActivities = [];
7228
7237
  this.activeFeeds = {};
7229
7238
  this.healthyConnectionChangedEventCount = 0;
7230
7239
  this.setGetBatchOwnFieldsThrottlingInterval = (throttlingMs) => {
@@ -7251,16 +7260,15 @@ class FeedsClient extends FeedsApi {
7251
7260
  this.healthyConnectionChangedEventCount++;
7252
7261
  if (this.healthyConnectionChangedEventCount > 1) {
7253
7262
  const feedEntries = Object.entries(this.activeFeeds);
7254
- const activityEntries = Object.entries(this.activeActivities);
7255
7263
  const results = await Promise.allSettled([
7256
7264
  ...feedEntries.map(([, feed]) => feed.synchronize()),
7257
- ...activityEntries.map(([, activity]) => activity.synchronize())
7265
+ ...this.activeActivities.map((activity) => activity.synchronize())
7258
7266
  ]);
7259
7267
  const failures = results.flatMap((result, index) => {
7260
7268
  if (result.status === "fulfilled") {
7261
7269
  return [];
7262
7270
  }
7263
- const activity = activityEntries[index - feedEntries.length]?.[1];
7271
+ const activity = this.activeActivities[index - feedEntries.length];
7264
7272
  const feed = feedEntries[index]?.[0] ?? (activity && getFeed.call(activity)?.feed);
7265
7273
  return [{ feed, reason: result.reason, activity_id: activity?.id }];
7266
7274
  });
@@ -7446,7 +7454,7 @@ class FeedsClient extends FeedsApi {
7446
7454
  this.connectionIdManager.reset();
7447
7455
  this.tokenManager.reset();
7448
7456
  this.polls_by_id.clear();
7449
- this.activeActivities = {};
7457
+ this.activeActivities = [];
7450
7458
  this.activeFeeds = {};
7451
7459
  this.state.partialNext({
7452
7460
  connected_user: void 0,
@@ -7465,12 +7473,11 @@ class FeedsClient extends FeedsApi {
7465
7473
  fieldsToUpdate: []
7466
7474
  });
7467
7475
  };
7468
- this.activityWithStateUpdates = (id) => {
7469
- let activity = this.activeActivities[id];
7470
- if (!activity) {
7471
- activity = new ActivityWithStateUpdates(id, this);
7472
- this.activeActivities[id] = activity;
7473
- }
7476
+ this.activityWithStateUpdates = (id, { fromResponse } = {
7477
+ fromResponse: void 0
7478
+ }) => {
7479
+ const activity = new ActivityWithStateUpdates(id, this, { fromResponse });
7480
+ this.activeActivities.push(activity);
7474
7481
  return activity;
7475
7482
  };
7476
7483
  this.updateNetworkConnectionStatus = (event) => {
@@ -7584,12 +7591,9 @@ class FeedsClient extends FeedsApi {
7584
7591
  feeds.forEach((f) => f.handleWSEvent(event));
7585
7592
  if (typeof fid === "string") {
7586
7593
  delete this.activeFeeds[fid];
7587
- Object.keys(this.activeActivities).forEach((activityId) => {
7588
- const activity = this.activeActivities[activityId];
7589
- if (getFeed.call(activity)?.feed === fid) {
7590
- delete this.activeActivities[activityId];
7591
- }
7592
- });
7594
+ this.activeActivities = this.activeActivities.filter(
7595
+ (activity) => getFeed.call(activity)?.feed !== fid
7596
+ );
7593
7597
  }
7594
7598
  break;
7595
7599
  }
@@ -7667,7 +7671,9 @@ class FeedsClient extends FeedsApi {
7667
7671
  default: {
7668
7672
  feeds.forEach((f) => f.handleWSEvent(event));
7669
7673
  if (event.type === "feeds.activity.deleted") {
7670
- delete this.activeActivities[event.activity.id];
7674
+ this.activeActivities = this.activeActivities.filter(
7675
+ (activity) => activity.id !== event.activity.id
7676
+ );
7671
7677
  }
7672
7678
  }
7673
7679
  }
@@ -7795,8 +7801,8 @@ class FeedsClient extends FeedsApi {
7795
7801
  }
7796
7802
  async getFollowSuggestions(...params) {
7797
7803
  const response = await super.getFollowSuggestions(...params);
7798
- response.suggestions.forEach((suggestion) => {
7799
- this.getOrCreateActiveFeed({
7804
+ const feeds = response.suggestions.map((suggestion) => {
7805
+ return this.getOrCreateActiveFeed({
7800
7806
  group: suggestion.group_id,
7801
7807
  id: suggestion.id,
7802
7808
  data: suggestion,
@@ -7808,7 +7814,7 @@ class FeedsClient extends FeedsApi {
7808
7814
  ]
7809
7815
  });
7810
7816
  });
7811
- return response;
7817
+ return { ...response, feeds };
7812
7818
  }
7813
7819
  findAllActiveFeedsByActivityId(activityId) {
7814
7820
  return [
@@ -7889,4 +7895,4 @@ exports.replaceUniqueArrayMerge = replaceUniqueArrayMerge;
7889
7895
  exports.shouldUpdateState = shouldUpdateState;
7890
7896
  exports.uniqueArrayMerge = uniqueArrayMerge;
7891
7897
  exports.updateEntityInArray = updateEntityInArray;
7892
- //# sourceMappingURL=feeds-client-CyaHg6lu.js.map
7898
+ //# sourceMappingURL=feeds-client-F087iP6p.js.map