@stream-io/feeds-client 0.3.17 → 0.3.19

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 (33) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +27 -0
  3. package/dist/cjs/index.js +1 -1
  4. package/dist/cjs/react-bindings.js +1 -1
  5. package/dist/es/index.mjs +2 -2
  6. package/dist/es/react-bindings.mjs +1 -1
  7. package/dist/{feeds-client-Bq_SWnZW.mjs → feeds-client-BseA5k3b.mjs} +69 -35
  8. package/dist/feeds-client-BseA5k3b.mjs.map +1 -0
  9. package/dist/{feeds-client-BGF3utPy.js → feeds-client-BwOGqhU9.js} +69 -35
  10. package/dist/feeds-client-BwOGqhU9.js.map +1 -0
  11. package/dist/types/feed/event-handlers/activity/handle-activity-updated.d.ts.map +1 -1
  12. package/dist/types/feed/event-handlers/activity-updater.d.ts.map +1 -1
  13. package/dist/types/feed/event-handlers/bookmark/handle-bookmark-added.d.ts.map +1 -1
  14. package/dist/types/feed/event-handlers/bookmark/handle-bookmark-deleted.d.ts.map +1 -1
  15. package/dist/types/feed/feed.d.ts +1 -0
  16. package/dist/types/feed/feed.d.ts.map +1 -1
  17. package/dist/types/feeds-client/feeds-client.d.ts +6 -2
  18. package/dist/types/feeds-client/feeds-client.d.ts.map +1 -1
  19. package/dist/types/feeds-client/get-or-create-active-feed.d.ts +4 -0
  20. package/dist/types/feeds-client/get-or-create-active-feed.d.ts.map +1 -0
  21. package/package.json +1 -1
  22. package/src/feed/event-handlers/activity/handle-activity-added.ts +2 -2
  23. package/src/feed/event-handlers/activity/handle-activity-updated.ts +0 -11
  24. package/src/feed/event-handlers/activity-updater.ts +0 -8
  25. package/src/feed/event-handlers/bookmark/handle-bookmark-added.ts +2 -10
  26. package/src/feed/event-handlers/bookmark/handle-bookmark-deleted.ts +2 -10
  27. package/src/feed/event-handlers/bookmark/handle-bookmark-updated.ts +2 -2
  28. package/src/feed/event-handlers/follow/handle-follow-deleted.ts +7 -7
  29. package/src/feed/feed.ts +44 -1
  30. package/src/feeds-client/feeds-client.ts +37 -7
  31. package/src/feeds-client/get-or-create-active-feed.ts +12 -0
  32. package/dist/feeds-client-BGF3utPy.js.map +0 -1
  33. package/dist/feeds-client-Bq_SWnZW.mjs.map +0 -1
@@ -3932,7 +3932,7 @@ const getRateLimitFromResponseHeader = (response_headers) => {
3932
3932
  };
3933
3933
  return result;
3934
3934
  };
3935
- const version = "0.3.17";
3935
+ const version = "0.3.19";
3936
3936
  class ApiClient {
3937
3937
  constructor(apiKey, tokenManager, connectionIdManager, options) {
3938
3938
  this.apiKey = apiKey;
@@ -4875,10 +4875,10 @@ const updateStateFollowDeleted = (follow, currentState, currentFeedId, connected
4875
4875
  // Update FeedResponse fields, that has the new follower/following count
4876
4876
  ...follow.target_feed
4877
4877
  };
4878
- if (source.created_by.id === connectedUserId && currentState.own_follows !== void 0) {
4879
- newState.own_follows = currentState.own_follows.filter(
4878
+ if (source.created_by.id === connectedUserId) {
4879
+ newState.own_follows = currentState.own_follows ? currentState.own_follows.filter(
4880
4880
  (followItem) => followItem.source_feed.feed !== follow.source_feed.feed
4881
- );
4881
+ ) : [];
4882
4882
  }
4883
4883
  if (currentState.followers !== void 0) {
4884
4884
  newState.followers = currentState.followers.filter(
@@ -5297,13 +5297,10 @@ const sharedUpdateActivity$6 = ({
5297
5297
  if (eventBelongsToCurrentUser) {
5298
5298
  newOwnBookmarks = [...newOwnBookmarks, event.bookmark];
5299
5299
  }
5300
- if (!event.bookmark.activity.current_feed && event.bookmark.activity.feeds.length === 1 && currentActivity.current_feed) {
5301
- event.bookmark.activity.current_feed = currentActivity.current_feed;
5302
- }
5303
5300
  return {
5304
- ...event.bookmark.activity,
5305
- own_bookmarks: newOwnBookmarks,
5306
- own_reactions: currentActivity.own_reactions
5301
+ ...currentActivity,
5302
+ bookmark_count: event.bookmark.activity.bookmark_count,
5303
+ own_bookmarks: newOwnBookmarks
5307
5304
  };
5308
5305
  };
5309
5306
  const addBookmarkToActivities = (event, activities, eventBelongsToCurrentUser) => updateEntityInArray({
@@ -5373,13 +5370,10 @@ const sharedUpdateActivity$5 = ({
5373
5370
  (bookmark) => !isSameBookmark(bookmark, event.bookmark)
5374
5371
  );
5375
5372
  }
5376
- if (!event.bookmark.activity.current_feed && event.bookmark.activity.feeds.length === 1 && currentActivity.current_feed) {
5377
- event.bookmark.activity.current_feed = currentActivity.current_feed;
5378
- }
5379
5373
  return {
5380
- ...event.bookmark.activity,
5381
- own_bookmarks: newOwnBookmarks,
5382
- own_reactions: currentActivity.own_reactions
5374
+ ...currentActivity,
5375
+ bookmark_count: event.bookmark.activity.bookmark_count,
5376
+ own_bookmarks: newOwnBookmarks
5383
5377
  };
5384
5378
  };
5385
5379
  const removeBookmarkFromActivities = (event, activities, eventBelongsToCurrentUser) => updateEntityInArray({
@@ -5451,9 +5445,9 @@ const sharedUpdateActivity$4 = ({
5451
5445
  }
5452
5446
  }
5453
5447
  return {
5454
- ...event.bookmark.activity,
5455
- own_bookmarks: newOwnBookmarks,
5456
- own_reactions: currentActivity.own_reactions
5448
+ ...currentActivity,
5449
+ bookmark_count: event.bookmark.activity.bookmark_count,
5450
+ own_bookmarks: newOwnBookmarks
5457
5451
  };
5458
5452
  };
5459
5453
  const updateBookmarkInActivities = (event, activities, eventBelongsToCurrentUser) => updateEntityInArray({
@@ -5532,6 +5526,7 @@ function addActivitiesToState(newActivities, activities, position) {
5532
5526
  ...activities,
5533
5527
  ...position === "end" ? newActivitiesDeduplicated : []
5534
5528
  ];
5529
+ this.newActivitiesAdded(newActivitiesDeduplicated);
5535
5530
  result = { changed: true, activities: updatedActivities };
5536
5531
  }
5537
5532
  return result;
@@ -5611,9 +5606,6 @@ const updateActivity = ({
5611
5606
  currentActivity,
5612
5607
  newActivtiy
5613
5608
  }) => {
5614
- if (!newActivtiy.current_feed && newActivtiy.feeds.length === 1 && currentActivity.current_feed) {
5615
- newActivtiy.current_feed = currentActivity.current_feed;
5616
- }
5617
5609
  return {
5618
5610
  ...newActivtiy,
5619
5611
  own_reactions: currentActivity.own_reactions,
@@ -5663,12 +5655,6 @@ function handleActivityUpdated(payload, fromWs) {
5663
5655
  activities: currentActivities,
5664
5656
  pinned_activities: currentPinnedActivities
5665
5657
  } = this.currentState;
5666
- const currentActivity = currentActivities?.find(
5667
- (a) => a.id === payload.activity.id
5668
- );
5669
- if (!payload.activity.current_feed && payload.activity.feeds.length === 1 && currentActivity?.current_feed) {
5670
- payload.activity.current_feed = currentActivity.current_feed;
5671
- }
5672
5658
  const [result1, result2] = [
5673
5659
  this.hasActivity(payload.activity.id) ? updateActivityInState(payload, currentActivities) : void 0,
5674
5660
  updatePinnedActivityInState(payload, currentPinnedActivities)
@@ -6259,6 +6245,9 @@ const deepEqual = (x, y) => {
6259
6245
  return false;
6260
6246
  }
6261
6247
  };
6248
+ function getOrCreateActiveFeed(group, id, data, watch) {
6249
+ return this.getOrCreateActiveFeed(group, id, data, watch);
6250
+ }
6262
6251
  const _Feed = class _Feed extends FeedApi {
6263
6252
  constructor(client, groupId, id, data, watch = false, addNewActivitiesTo = "start", activityAddedEventFilter) {
6264
6253
  super(client, groupId, id);
@@ -6451,7 +6440,7 @@ const _Feed = class _Feed extends FeedApi {
6451
6440
  return nextState;
6452
6441
  });
6453
6442
  }
6454
- this.client.hydratePollCache(response.activities);
6443
+ this.newActivitiesAdded(response.activities);
6455
6444
  return response;
6456
6445
  } finally {
6457
6446
  this.state.partialNext({
@@ -6832,6 +6821,19 @@ const _Feed = class _Feed extends FeedApi {
6832
6821
  handleWSEvent(event) {
6833
6822
  const eventHandler = this.eventHandlers[event.type];
6834
6823
  if (eventHandler !== _Feed.noop) {
6824
+ if ("activity" in event && this.hasActivity(event.activity.id)) {
6825
+ const currentActivity = this.currentState.activities?.find(
6826
+ (a) => a.id === event.activity.id
6827
+ );
6828
+ if (event.activity.feeds.length > 1 && !event.activity.current_feed && currentActivity?.current_feed) {
6829
+ event.activity.current_feed = currentActivity.current_feed;
6830
+ }
6831
+ if (event.activity.feeds.length === 1 && event.activity.current_feed && currentActivity?.current_feed) {
6832
+ event.activity.current_feed.own_capabilities = currentActivity.current_feed.own_capabilities;
6833
+ event.activity.current_feed.own_follows = currentActivity.current_feed.own_follows;
6834
+ event.activity.current_feed.own_membership = currentActivity.current_feed.own_membership;
6835
+ }
6836
+ }
6835
6837
  eventHandler?.(event);
6836
6838
  }
6837
6839
  if (typeof eventHandler === "undefined") {
@@ -6839,6 +6841,18 @@ const _Feed = class _Feed extends FeedApi {
6839
6841
  }
6840
6842
  this.eventDispatcher.dispatch(event);
6841
6843
  }
6844
+ newActivitiesAdded(activities) {
6845
+ this.client.hydratePollCache(activities);
6846
+ activities.forEach((activity) => {
6847
+ if (activity.current_feed) {
6848
+ getOrCreateActiveFeed.bind(this.client)(
6849
+ activity.current_feed.group_id,
6850
+ activity.current_feed.id,
6851
+ activity.current_feed
6852
+ );
6853
+ }
6854
+ });
6855
+ }
6842
6856
  };
6843
6857
  _Feed.noop = () => {
6844
6858
  };
@@ -7383,8 +7397,7 @@ class FeedsClient extends FeedsApi {
7383
7397
  id,
7384
7398
  void 0,
7385
7399
  void 0,
7386
- options2?.addNewActivitiesTo,
7387
- options2?.activityAddedEventFilter
7400
+ options2
7388
7401
  );
7389
7402
  };
7390
7403
  this.activityWithStateUpdates = (id) => {
@@ -7402,20 +7415,30 @@ class FeedsClient extends FeedsApi {
7402
7415
  };
7403
7416
  this.eventDispatcher.dispatch(networkEvent);
7404
7417
  };
7405
- this.getOrCreateActiveFeed = (group, id, data, watch, addNewActivitiesTo, activityAddedEventFilter) => {
7418
+ this.getOrCreateActiveFeed = (group, id, data, watch, options2) => {
7406
7419
  const fid = `${group}:${id}`;
7420
+ let isCreated = false;
7407
7421
  if (!this.activeFeeds[fid]) {
7422
+ isCreated = true;
7408
7423
  this.activeFeeds[fid] = new Feed(
7409
7424
  this,
7410
7425
  group,
7411
7426
  id,
7412
7427
  data,
7413
7428
  watch,
7414
- addNewActivitiesTo,
7415
- activityAddedEventFilter
7429
+ options2?.addNewActivitiesTo,
7430
+ options2?.activityAddedEventFilter
7416
7431
  );
7417
7432
  }
7418
7433
  const feed = this.activeFeeds[fid];
7434
+ if (!isCreated && options2) {
7435
+ if (options2?.addNewActivitiesTo) {
7436
+ feed.addNewActivitiesTo = options2.addNewActivitiesTo;
7437
+ }
7438
+ if (options2?.activityAddedEventFilter) {
7439
+ feed.activityAddedEventFilter = options2.activityAddedEventFilter;
7440
+ }
7441
+ }
7419
7442
  if (!feed.currentState.watch) {
7420
7443
  if (data) handleFeedUpdated.call(feed, { feed: data });
7421
7444
  if (watch) handleWatchStarted.call(feed);
@@ -7687,6 +7710,17 @@ class FeedsClient extends FeedsApi {
7687
7710
  }
7688
7711
  return response;
7689
7712
  }
7713
+ async getFollowSuggestions(...params) {
7714
+ const response = await super.getFollowSuggestions(...params);
7715
+ response.suggestions.forEach((suggestion) => {
7716
+ this.getOrCreateActiveFeed(
7717
+ suggestion.group_id,
7718
+ suggestion.id,
7719
+ suggestion
7720
+ );
7721
+ });
7722
+ return response;
7723
+ }
7690
7724
  findAllActiveFeedsByActivityId(activityId) {
7691
7725
  return [
7692
7726
  ...Object.values(this.activeFeeds),
@@ -7766,4 +7800,4 @@ exports.replaceUniqueArrayMerge = replaceUniqueArrayMerge;
7766
7800
  exports.shouldUpdateState = shouldUpdateState;
7767
7801
  exports.uniqueArrayMerge = uniqueArrayMerge;
7768
7802
  exports.updateEntityInArray = updateEntityInArray;
7769
- //# sourceMappingURL=feeds-client-BGF3utPy.js.map
7803
+ //# sourceMappingURL=feeds-client-BwOGqhU9.js.map