@stream-io/feeds-client 0.3.2 → 0.3.4

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.
@@ -3782,7 +3782,7 @@ const getRateLimitFromResponseHeader = (response_headers) => {
3782
3782
  };
3783
3783
  return result;
3784
3784
  };
3785
- const version = "0.3.2";
3785
+ const version = "0.3.4";
3786
3786
  class ApiClient {
3787
3787
  constructor(apiKey, tokenManager, connectionIdManager, options) {
3788
3788
  this.apiKey = apiKey;
@@ -5379,6 +5379,11 @@ function addActivitiesToState(newActivities, activities, position) {
5379
5379
  return result;
5380
5380
  }
5381
5381
  function handleActivityAdded(event) {
5382
+ if (this.activityAddedEventFilter) {
5383
+ if (!this.activityAddedEventFilter(event)) {
5384
+ return;
5385
+ }
5386
+ }
5382
5387
  const currentActivities = this.currentState.activities;
5383
5388
  const result = addActivitiesToState.bind(this)(
5384
5389
  [event.activity],
@@ -6073,8 +6078,9 @@ function handleActivityFeedback(event) {
6073
6078
  }
6074
6079
  }
6075
6080
  const _Feed = class _Feed extends FeedApi {
6076
- constructor(client, groupId, id, data, watch = false, addNewActivitiesTo = "start") {
6081
+ constructor(client, groupId, id, data, watch = false, addNewActivitiesTo = "start", activityAddedEventFilter) {
6077
6082
  super(client, groupId, id);
6083
+ this.activityAddedEventFilter = activityAddedEventFilter;
6078
6084
  this.indexedActivityIds = /* @__PURE__ */ new Set();
6079
6085
  this.stateUpdateQueue = /* @__PURE__ */ new Set();
6080
6086
  this.eventHandlers = {
@@ -6170,6 +6176,11 @@ const _Feed = class _Feed extends FeedApi {
6170
6176
  hasActivity(activityId) {
6171
6177
  return this.indexedActivityIds.has(activityId);
6172
6178
  }
6179
+ hasPinnedActivity(activityId) {
6180
+ return this.currentState.pinned_activities?.some(
6181
+ (pinnedActivity) => pinnedActivity.activity.id === activityId
6182
+ );
6183
+ }
6173
6184
  async synchronize() {
6174
6185
  const { last_get_or_create_request_config } = this.state.getLatestValue();
6175
6186
  if (last_get_or_create_request_config?.watch) {
@@ -6589,9 +6600,17 @@ const _Feed = class _Feed extends FeedApi {
6589
6600
  });
6590
6601
  return response;
6591
6602
  }
6603
+ /**
6604
+ * Fetches the next page of activities for the feed.
6605
+ * @returns The response from the API or `undefined` if there is no next page.
6606
+ */
6592
6607
  async getNextPage() {
6593
6608
  const currentState = this.currentState;
6609
+ if (!currentState.next) {
6610
+ return;
6611
+ }
6594
6612
  return await this.getOrCreate({
6613
+ ...currentState.last_get_or_create_request_config,
6595
6614
  member_pagination: {
6596
6615
  limit: 0
6597
6616
  },
@@ -6601,8 +6620,8 @@ const _Feed = class _Feed extends FeedApi {
6601
6620
  following_pagination: {
6602
6621
  limit: 0
6603
6622
  },
6604
- next: currentState.next,
6605
- limit: currentState.last_get_or_create_request_config?.limit ?? 20
6623
+ watch: void 0,
6624
+ next: currentState.next
6606
6625
  });
6607
6626
  }
6608
6627
  async addActivity(request) {
@@ -7010,7 +7029,8 @@ class FeedsClient extends FeedsApi {
7010
7029
  id,
7011
7030
  void 0,
7012
7031
  void 0,
7013
- options2?.addNewActivitiesTo
7032
+ options2?.addNewActivitiesTo,
7033
+ options2?.activityAddedEventFilter
7014
7034
  );
7015
7035
  };
7016
7036
  this.updateNetworkConnectionStatus = (event) => {
@@ -7020,7 +7040,7 @@ class FeedsClient extends FeedsApi {
7020
7040
  };
7021
7041
  this.eventDispatcher.dispatch(networkEvent);
7022
7042
  };
7023
- this.getOrCreateActiveFeed = (group, id, data, watch, addNewActivitiesTo) => {
7043
+ this.getOrCreateActiveFeed = (group, id, data, watch, addNewActivitiesTo, activityAddedEventFilter) => {
7024
7044
  const fid = `${group}:${id}`;
7025
7045
  if (!this.activeFeeds[fid]) {
7026
7046
  this.activeFeeds[fid] = new Feed(
@@ -7029,7 +7049,8 @@ class FeedsClient extends FeedsApi {
7029
7049
  id,
7030
7050
  data,
7031
7051
  watch,
7032
- addNewActivitiesTo
7052
+ addNewActivitiesTo,
7053
+ activityAddedEventFilter
7033
7054
  );
7034
7055
  }
7035
7056
  const feed = this.activeFeeds[fid];
@@ -7139,13 +7160,13 @@ class FeedsClient extends FeedsApi {
7139
7160
  case "feeds.bookmark.deleted":
7140
7161
  case "feeds.bookmark.updated": {
7141
7162
  const activityId = event.bookmark.activity.id;
7142
- const feeds = this.findActiveFeedByActivityId(activityId);
7163
+ const feeds = this.findActiveFeedsByActivityId(activityId);
7143
7164
  feeds.forEach((f) => f.handleWSEvent(event));
7144
7165
  break;
7145
7166
  }
7146
7167
  case "feeds.activity.feedback": {
7147
7168
  const activityId = event.activity_feedback.activity_id;
7148
- const feeds = this.findActiveFeedByActivityId(activityId);
7169
+ const feeds = this.findActiveFeedsByActivityId(activityId);
7149
7170
  feeds.forEach((f) => f.handleWSEvent(event));
7150
7171
  break;
7151
7172
  }
@@ -7283,11 +7304,9 @@ class FeedsClient extends FeedsApi {
7283
7304
  }
7284
7305
  return response;
7285
7306
  }
7286
- findActiveFeedByActivityId(activityId) {
7307
+ findActiveFeedsByActivityId(activityId) {
7287
7308
  return Object.values(this.activeFeeds).filter(
7288
- (feed) => feed.currentState.activities?.some(
7289
- (activity) => activity.id === activityId
7290
- )
7309
+ (feed) => feed.hasActivity(activityId) || feed.hasPinnedActivity(activityId)
7291
7310
  );
7292
7311
  }
7293
7312
  }
@@ -7312,4 +7331,4 @@ exports.replaceUniqueArrayMerge = replaceUniqueArrayMerge;
7312
7331
  exports.shouldUpdateState = shouldUpdateState;
7313
7332
  exports.uniqueArrayMerge = uniqueArrayMerge;
7314
7333
  exports.updateEntityInArray = updateEntityInArray;
7315
- //# sourceMappingURL=feeds-client-jZwPzici.js.map
7334
+ //# sourceMappingURL=feeds-client-HvoTzr-z.js.map