@stream-io/feeds-client 0.3.18 → 0.3.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  const stateStore = require("@stream-io/state-store");
3
3
  const loggerInternal = require("@stream-io/logger");
4
- const axios = require("axios");
4
+ const axiosImport = require("axios");
5
5
  function _interopNamespaceDefault(e) {
6
6
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
7
7
  if (e) {
@@ -3932,7 +3932,8 @@ const getRateLimitFromResponseHeader = (response_headers) => {
3932
3932
  };
3933
3933
  return result;
3934
3934
  };
3935
- const version = "0.3.18";
3935
+ const version = "0.3.20";
3936
+ const axios = axiosImport.default ?? axiosImport;
3936
3937
  class ApiClient {
3937
3938
  constructor(apiKey, tokenManager, connectionIdManager, options) {
3938
3939
  this.apiKey = apiKey;
@@ -4875,10 +4876,10 @@ const updateStateFollowDeleted = (follow, currentState, currentFeedId, connected
4875
4876
  // Update FeedResponse fields, that has the new follower/following count
4876
4877
  ...follow.target_feed
4877
4878
  };
4878
- if (source.created_by.id === connectedUserId && currentState.own_follows !== void 0) {
4879
- newState.own_follows = currentState.own_follows.filter(
4879
+ if (source.created_by.id === connectedUserId) {
4880
+ newState.own_follows = currentState.own_follows ? currentState.own_follows.filter(
4880
4881
  (followItem) => followItem.source_feed.feed !== follow.source_feed.feed
4881
- );
4882
+ ) : [];
4882
4883
  }
4883
4884
  if (currentState.followers !== void 0) {
4884
4885
  newState.followers = currentState.followers.filter(
@@ -5526,6 +5527,7 @@ function addActivitiesToState(newActivities, activities, position) {
5526
5527
  ...activities,
5527
5528
  ...position === "end" ? newActivitiesDeduplicated : []
5528
5529
  ];
5530
+ this.newActivitiesAdded(newActivitiesDeduplicated);
5529
5531
  result = { changed: true, activities: updatedActivities };
5530
5532
  }
5531
5533
  return result;
@@ -6244,6 +6246,9 @@ const deepEqual = (x, y) => {
6244
6246
  return false;
6245
6247
  }
6246
6248
  };
6249
+ function getOrCreateActiveFeed(group, id, data, watch) {
6250
+ return this.getOrCreateActiveFeed(group, id, data, watch);
6251
+ }
6247
6252
  const _Feed = class _Feed extends FeedApi {
6248
6253
  constructor(client, groupId, id, data, watch = false, addNewActivitiesTo = "start", activityAddedEventFilter) {
6249
6254
  super(client, groupId, id);
@@ -6436,7 +6441,7 @@ const _Feed = class _Feed extends FeedApi {
6436
6441
  return nextState;
6437
6442
  });
6438
6443
  }
6439
- this.client.hydratePollCache(response.activities);
6444
+ this.newActivitiesAdded(response.activities);
6440
6445
  return response;
6441
6446
  } finally {
6442
6447
  this.state.partialNext({
@@ -6837,6 +6842,18 @@ const _Feed = class _Feed extends FeedApi {
6837
6842
  }
6838
6843
  this.eventDispatcher.dispatch(event);
6839
6844
  }
6845
+ newActivitiesAdded(activities) {
6846
+ this.client.hydratePollCache(activities);
6847
+ activities.forEach((activity) => {
6848
+ if (activity.current_feed) {
6849
+ getOrCreateActiveFeed.bind(this.client)(
6850
+ activity.current_feed.group_id,
6851
+ activity.current_feed.id,
6852
+ activity.current_feed
6853
+ );
6854
+ }
6855
+ });
6856
+ }
6840
6857
  };
6841
6858
  _Feed.noop = () => {
6842
6859
  };
@@ -7381,8 +7398,7 @@ class FeedsClient extends FeedsApi {
7381
7398
  id,
7382
7399
  void 0,
7383
7400
  void 0,
7384
- options2?.addNewActivitiesTo,
7385
- options2?.activityAddedEventFilter
7401
+ options2
7386
7402
  );
7387
7403
  };
7388
7404
  this.activityWithStateUpdates = (id) => {
@@ -7400,20 +7416,30 @@ class FeedsClient extends FeedsApi {
7400
7416
  };
7401
7417
  this.eventDispatcher.dispatch(networkEvent);
7402
7418
  };
7403
- this.getOrCreateActiveFeed = (group, id, data, watch, addNewActivitiesTo, activityAddedEventFilter) => {
7419
+ this.getOrCreateActiveFeed = (group, id, data, watch, options2) => {
7404
7420
  const fid = `${group}:${id}`;
7421
+ let isCreated = false;
7405
7422
  if (!this.activeFeeds[fid]) {
7423
+ isCreated = true;
7406
7424
  this.activeFeeds[fid] = new Feed(
7407
7425
  this,
7408
7426
  group,
7409
7427
  id,
7410
7428
  data,
7411
7429
  watch,
7412
- addNewActivitiesTo,
7413
- activityAddedEventFilter
7430
+ options2?.addNewActivitiesTo,
7431
+ options2?.activityAddedEventFilter
7414
7432
  );
7415
7433
  }
7416
7434
  const feed = this.activeFeeds[fid];
7435
+ if (!isCreated && options2) {
7436
+ if (options2?.addNewActivitiesTo) {
7437
+ feed.addNewActivitiesTo = options2.addNewActivitiesTo;
7438
+ }
7439
+ if (options2?.activityAddedEventFilter) {
7440
+ feed.activityAddedEventFilter = options2.activityAddedEventFilter;
7441
+ }
7442
+ }
7417
7443
  if (!feed.currentState.watch) {
7418
7444
  if (data) handleFeedUpdated.call(feed, { feed: data });
7419
7445
  if (watch) handleWatchStarted.call(feed);
@@ -7685,6 +7711,17 @@ class FeedsClient extends FeedsApi {
7685
7711
  }
7686
7712
  return response;
7687
7713
  }
7714
+ async getFollowSuggestions(...params) {
7715
+ const response = await super.getFollowSuggestions(...params);
7716
+ response.suggestions.forEach((suggestion) => {
7717
+ this.getOrCreateActiveFeed(
7718
+ suggestion.group_id,
7719
+ suggestion.id,
7720
+ suggestion
7721
+ );
7722
+ });
7723
+ return response;
7724
+ }
7688
7725
  findAllActiveFeedsByActivityId(activityId) {
7689
7726
  return [
7690
7727
  ...Object.values(this.activeFeeds),
@@ -7764,4 +7801,4 @@ exports.replaceUniqueArrayMerge = replaceUniqueArrayMerge;
7764
7801
  exports.shouldUpdateState = shouldUpdateState;
7765
7802
  exports.uniqueArrayMerge = uniqueArrayMerge;
7766
7803
  exports.updateEntityInArray = updateEntityInArray;
7767
- //# sourceMappingURL=feeds-client-Be5gS8Xx.js.map
7804
+ //# sourceMappingURL=feeds-client-CVOa15Qx.js.map