@stream-io/feeds-client 0.3.50 → 1.0.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.
Files changed (54) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/cjs/index.js +2 -1
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/react-bindings.js +1 -1
  5. package/dist/es/index.mjs +15 -14
  6. package/dist/es/index.mjs.map +1 -1
  7. package/dist/es/react-bindings.mjs +1 -1
  8. package/dist/{feeds-client-BHpmg4_E.mjs → feeds-client-B03y08Kq.mjs} +219 -77
  9. package/dist/feeds-client-B03y08Kq.mjs.map +1 -0
  10. package/dist/{feeds-client-CKxvuiKz.js → feeds-client-tw63OGrd.js} +213 -71
  11. package/dist/feeds-client-tw63OGrd.js.map +1 -0
  12. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  13. package/dist/types/activity-with-state-updates/activity-with-state-updates.d.ts.map +1 -1
  14. package/dist/types/feed/activity-filter.d.ts +11 -0
  15. package/dist/types/feed/activity-filter.d.ts.map +1 -0
  16. package/dist/types/feed/event-handlers/activity/handle-activity-added.d.ts +3 -2
  17. package/dist/types/feed/event-handlers/activity/handle-activity-added.d.ts.map +1 -1
  18. package/dist/types/feed/event-handlers/activity/handle-activity-updated.d.ts.map +1 -1
  19. package/dist/types/feed/event-handlers/comment/handle-comment-updated.d.ts.map +1 -1
  20. package/dist/types/feed/event-handlers/follow/handle-follow-created.d.ts +2 -2
  21. package/dist/types/feed/event-handlers/follow/handle-follow-created.d.ts.map +1 -1
  22. package/dist/types/feed/feed.d.ts +20 -13
  23. package/dist/types/feed/feed.d.ts.map +1 -1
  24. package/dist/types/feeds-client/apply-new-activity-to-active-feeds.d.ts +4 -0
  25. package/dist/types/feeds-client/apply-new-activity-to-active-feeds.d.ts.map +1 -0
  26. package/dist/types/feeds-client/feeds-client.d.ts +7 -8
  27. package/dist/types/feeds-client/feeds-client.d.ts.map +1 -1
  28. package/dist/types/gen/feeds/FeedApi.d.ts +1 -0
  29. package/dist/types/gen/feeds/FeedApi.d.ts.map +1 -1
  30. package/dist/types/gen/feeds/FeedsApi.d.ts +3 -0
  31. package/dist/types/gen/feeds/FeedsApi.d.ts.map +1 -1
  32. package/dist/types/gen/models/index.d.ts +15 -0
  33. package/dist/types/gen/models/index.d.ts.map +1 -1
  34. package/dist/types/index.d.ts +1 -0
  35. package/dist/types/index.d.ts.map +1 -1
  36. package/dist/types/types.d.ts +15 -0
  37. package/dist/types/types.d.ts.map +1 -1
  38. package/package.json +2 -1
  39. package/src/activity-with-state-updates/activity-with-state-updates.ts +8 -2
  40. package/src/feed/activity-filter.ts +44 -0
  41. package/src/feed/event-handlers/activity/handle-activity-added.ts +22 -8
  42. package/src/feed/event-handlers/activity/handle-activity-updated.ts +5 -1
  43. package/src/feed/event-handlers/comment/handle-comment-updated.ts +11 -10
  44. package/src/feed/event-handlers/follow/handle-follow-created.ts +18 -1
  45. package/src/feed/feed.ts +77 -22
  46. package/src/feeds-client/apply-new-activity-to-active-feeds.ts +9 -0
  47. package/src/feeds-client/feeds-client.ts +46 -28
  48. package/src/gen/feeds/FeedApi.ts +1 -0
  49. package/src/gen/feeds/FeedsApi.ts +33 -4
  50. package/src/gen/models/index.ts +31 -1
  51. package/src/index.ts +1 -0
  52. package/src/types.ts +17 -0
  53. package/dist/feeds-client-BHpmg4_E.mjs.map +0 -1
  54. package/dist/feeds-client-CKxvuiKz.js.map +0 -1
@@ -2,6 +2,7 @@
2
2
  const stateStore = require("@stream-io/state-store");
3
3
  const loggerInternal = require("@stream-io/logger");
4
4
  const axiosImport = require("axios");
5
+ const filter = require("@stream-io/filter");
5
6
  function _interopNamespaceDefault(e) {
6
7
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
7
8
  if (e) {
@@ -1650,6 +1651,7 @@ class FeedsApi {
1650
1651
  feeds: request?.feeds,
1651
1652
  copy_custom_to_notification: request?.copy_custom_to_notification,
1652
1653
  create_notification_activity: request?.create_notification_activity,
1654
+ enrich_own_fields: request?.enrich_own_fields,
1653
1655
  expires_at: request?.expires_at,
1654
1656
  id: request?.id,
1655
1657
  parent_id: request?.parent_id,
@@ -1682,7 +1684,8 @@ class FeedsApi {
1682
1684
  }
1683
1685
  async upsertActivities(request) {
1684
1686
  const body = {
1685
- activities: request?.activities
1687
+ activities: request?.activities,
1688
+ enrich_own_fields: request?.enrich_own_fields
1686
1689
  };
1687
1690
  const response = await this.apiClient.sendRequest(
1688
1691
  "POST",
@@ -1714,6 +1717,7 @@ class FeedsApi {
1714
1717
  }
1715
1718
  async queryActivities(request) {
1716
1719
  const body = {
1720
+ enrich_own_fields: request?.enrich_own_fields,
1717
1721
  limit: request?.limit,
1718
1722
  next: request?.next,
1719
1723
  prev: request?.prev,
@@ -1933,6 +1937,7 @@ class FeedsApi {
1933
1937
  };
1934
1938
  const body = {
1935
1939
  copy_custom_to_notification: request?.copy_custom_to_notification,
1940
+ enrich_own_fields: request?.enrich_own_fields,
1936
1941
  handle_mention_notifications: request?.handle_mention_notifications,
1937
1942
  run_activity_processors: request?.run_activity_processors,
1938
1943
  unset: request?.unset,
@@ -1955,6 +1960,7 @@ class FeedsApi {
1955
1960
  };
1956
1961
  const body = {
1957
1962
  copy_custom_to_notification: request?.copy_custom_to_notification,
1963
+ enrich_own_fields: request?.enrich_own_fields,
1958
1964
  expires_at: request?.expires_at,
1959
1965
  handle_mention_notifications: request?.handle_mention_notifications,
1960
1966
  poll_id: request?.poll_id,
@@ -1986,6 +1992,9 @@ class FeedsApi {
1986
1992
  return { ...response.body, metadata: response.metadata };
1987
1993
  }
1988
1994
  async restoreActivity(request) {
1995
+ const queryParams = {
1996
+ enrich_own_fields: request?.enrich_own_fields
1997
+ };
1989
1998
  const pathParams = {
1990
1999
  id: request?.id
1991
2000
  };
@@ -1994,7 +2003,7 @@ class FeedsApi {
1994
2003
  "POST",
1995
2004
  "/api/v2/feeds/activities/{id}/restore",
1996
2005
  pathParams,
1997
- void 0,
2006
+ queryParams,
1998
2007
  body,
1999
2008
  "application/json"
2000
2009
  );
@@ -2054,6 +2063,7 @@ class FeedsApi {
2054
2063
  }
2055
2064
  async queryBookmarks(request) {
2056
2065
  const body = {
2066
+ enrich_own_fields: request?.enrich_own_fields,
2057
2067
  limit: request?.limit,
2058
2068
  next: request?.next,
2059
2069
  prev: request?.prev,
@@ -2375,6 +2385,7 @@ class FeedsApi {
2375
2385
  };
2376
2386
  const body = {
2377
2387
  description: request?.description,
2388
+ enrich_own_fields: request?.enrich_own_fields,
2378
2389
  name: request?.name,
2379
2390
  filter_tags: request?.filter_tags,
2380
2391
  custom: request?.custom
@@ -2414,6 +2425,9 @@ class FeedsApi {
2414
2425
  return { ...response.body, metadata: response.metadata };
2415
2426
  }
2416
2427
  async unpinActivity(request) {
2428
+ const queryParams = {
2429
+ enrich_own_fields: request?.enrich_own_fields
2430
+ };
2417
2431
  const pathParams = {
2418
2432
  feed_group_id: request?.feed_group_id,
2419
2433
  feed_id: request?.feed_id,
@@ -2423,7 +2437,7 @@ class FeedsApi {
2423
2437
  "DELETE",
2424
2438
  "/api/v2/feeds/feed_groups/{feed_group_id}/feeds/{feed_id}/activities/{activity_id}/pin",
2425
2439
  pathParams,
2426
- void 0
2440
+ queryParams
2427
2441
  );
2428
2442
  decoders.UnpinActivityResponse?.(response.body);
2429
2443
  return { ...response.body, metadata: response.metadata };
@@ -2434,7 +2448,9 @@ class FeedsApi {
2434
2448
  feed_id: request?.feed_id,
2435
2449
  activity_id: request?.activity_id
2436
2450
  };
2437
- const body = {};
2451
+ const body = {
2452
+ enrich_own_fields: request?.enrich_own_fields
2453
+ };
2438
2454
  const response = await this.apiClient.sendRequest(
2439
2455
  "POST",
2440
2456
  "/api/v2/feeds/feed_groups/{feed_group_id}/feeds/{feed_id}/activities/{activity_id}/pin",
@@ -2532,6 +2548,7 @@ class FeedsApi {
2532
2548
  feed_id: request?.feed_id
2533
2549
  };
2534
2550
  const body = {
2551
+ enrich_own_fields: request?.enrich_own_fields,
2535
2552
  limit: request?.limit,
2536
2553
  next: request?.next,
2537
2554
  prev: request?.prev,
@@ -2584,7 +2601,8 @@ class FeedsApi {
2584
2601
  }
2585
2602
  async createFeedsBatch(request) {
2586
2603
  const body = {
2587
- feeds: request?.feeds
2604
+ feeds: request?.feeds,
2605
+ enrich_own_fields: request?.enrich_own_fields
2588
2606
  };
2589
2607
  const response = await this.apiClient.sendRequest(
2590
2608
  "POST",
@@ -2621,6 +2639,7 @@ class FeedsApi {
2621
2639
  connection_id: request?.connection_id
2622
2640
  };
2623
2641
  const body = {
2642
+ enrich_own_fields: request?.enrich_own_fields,
2624
2643
  limit: request?.limit,
2625
2644
  next: request?.next,
2626
2645
  prev: request?.prev,
@@ -2645,6 +2664,7 @@ class FeedsApi {
2645
2664
  target: request?.target,
2646
2665
  copy_custom_to_notification: request?.copy_custom_to_notification,
2647
2666
  create_notification_activity: request?.create_notification_activity,
2667
+ enrich_own_fields: request?.enrich_own_fields,
2648
2668
  follower_role: request?.follower_role,
2649
2669
  push_preference: request?.push_preference,
2650
2670
  skip_push: request?.skip_push,
@@ -2667,6 +2687,7 @@ class FeedsApi {
2667
2687
  target: request?.target,
2668
2688
  copy_custom_to_notification: request?.copy_custom_to_notification,
2669
2689
  create_notification_activity: request?.create_notification_activity,
2690
+ enrich_own_fields: request?.enrich_own_fields,
2670
2691
  push_preference: request?.push_preference,
2671
2692
  skip_push: request?.skip_push,
2672
2693
  custom: request?.custom
@@ -2701,7 +2722,8 @@ class FeedsApi {
2701
2722
  }
2702
2723
  async followBatch(request) {
2703
2724
  const body = {
2704
- follows: request?.follows
2725
+ follows: request?.follows,
2726
+ enrich_own_fields: request?.enrich_own_fields
2705
2727
  };
2706
2728
  const response = await this.apiClient.sendRequest(
2707
2729
  "POST",
@@ -2716,7 +2738,8 @@ class FeedsApi {
2716
2738
  }
2717
2739
  async getOrCreateFollows(request) {
2718
2740
  const body = {
2719
- follows: request?.follows
2741
+ follows: request?.follows,
2742
+ enrich_own_fields: request?.enrich_own_fields
2720
2743
  };
2721
2744
  const response = await this.apiClient.sendRequest(
2722
2745
  "POST",
@@ -2766,7 +2789,8 @@ class FeedsApi {
2766
2789
  }
2767
2790
  async unfollow(request) {
2768
2791
  const queryParams = {
2769
- delete_notification_activity: request?.delete_notification_activity
2792
+ delete_notification_activity: request?.delete_notification_activity,
2793
+ enrich_own_fields: request?.enrich_own_fields
2770
2794
  };
2771
2795
  const pathParams = {
2772
2796
  source: request?.source,
@@ -2784,7 +2808,8 @@ class FeedsApi {
2784
2808
  async getOrCreateUnfollows(request) {
2785
2809
  const body = {
2786
2810
  follows: request?.follows,
2787
- delete_notification_activity: request?.delete_notification_activity
2811
+ delete_notification_activity: request?.delete_notification_activity,
2812
+ enrich_own_fields: request?.enrich_own_fields
2788
2813
  };
2789
2814
  const response = await this.apiClient.sendRequest(
2790
2815
  "POST",
@@ -4104,7 +4129,7 @@ const getRateLimitFromResponseHeader = (response_headers) => {
4104
4129
  };
4105
4130
  return result;
4106
4131
  };
4107
- const version = "0.3.50";
4132
+ const version = "1.0.0";
4108
4133
  const axios = axiosImport.default ?? axiosImport;
4109
4134
  class ApiClient {
4110
4135
  constructor(apiKey, tokenManager, connectionIdManager, options) {
@@ -5039,7 +5064,7 @@ function updateEntityInArray({
5039
5064
  updatedEntities[index] = newEntity;
5040
5065
  return { changed: true, entities: updatedEntities };
5041
5066
  }
5042
- const updateStateFollowCreated = (follow, currentState, currentFeedId, connectedUserId) => {
5067
+ const updateStateFollowCreated = (follow, currentState, currentFeedId, connectedUserId, hasOwnFields = false) => {
5043
5068
  if (follow.status !== "accepted") {
5044
5069
  return { changed: false, data: currentState };
5045
5070
  }
@@ -5048,7 +5073,12 @@ const updateStateFollowCreated = (follow, currentState, currentFeedId, connected
5048
5073
  newState = {
5049
5074
  ...newState,
5050
5075
  // Update FeedResponse fields, that has the new follower/following count
5051
- ...follow.source_feed
5076
+ ...follow.source_feed,
5077
+ ...hasOwnFields ? {
5078
+ own_capabilities: follow.source_feed.own_capabilities,
5079
+ own_follows: follow.source_feed.own_follows,
5080
+ own_followings: follow.source_feed.own_followings
5081
+ } : {}
5052
5082
  };
5053
5083
  if (currentState.following !== void 0) {
5054
5084
  newState.following = [follow, ...currentState.following];
@@ -5061,9 +5091,14 @@ const updateStateFollowCreated = (follow, currentState, currentFeedId, connected
5061
5091
  newState = {
5062
5092
  ...newState,
5063
5093
  // Update FeedResponse fields, that has the new follower/following count
5064
- ...follow.target_feed
5065
- };
5066
- if (source.created_by.id === connectedUserId) {
5094
+ ...follow.target_feed,
5095
+ ...hasOwnFields ? {
5096
+ own_capabilities: follow.target_feed.own_capabilities,
5097
+ own_follows: follow.target_feed.own_follows,
5098
+ own_followings: follow.target_feed.own_followings
5099
+ } : {}
5100
+ };
5101
+ if (source.created_by.id === connectedUserId && !hasOwnFields) {
5067
5102
  newState.own_follows = currentState.own_follows ? currentState.own_follows.concat(follow) : [follow];
5068
5103
  }
5069
5104
  if (currentState.followers !== void 0) {
@@ -5072,7 +5107,7 @@ const updateStateFollowCreated = (follow, currentState, currentFeedId, connected
5072
5107
  }
5073
5108
  return { changed: true, data: newState };
5074
5109
  };
5075
- function handleFollowCreated(eventOrResponse, fromWs) {
5110
+ function handleFollowCreated(eventOrResponse, fromWs, hasOwnFields = false) {
5076
5111
  const follow = eventOrResponse.follow;
5077
5112
  if (!shouldUpdateState({
5078
5113
  stateUpdateQueueId: getStateUpdateQueueId(follow, "follow-created"),
@@ -5088,7 +5123,8 @@ function handleFollowCreated(eventOrResponse, fromWs) {
5088
5123
  follow,
5089
5124
  this.currentState,
5090
5125
  this.feed,
5091
- connectedUser?.id
5126
+ connectedUser?.id,
5127
+ hasOwnFields
5092
5128
  );
5093
5129
  if (result.changed) {
5094
5130
  this.state.next(result.data);
@@ -5312,14 +5348,14 @@ function handleCommentUpdated(payload, fromWs) {
5312
5348
  const { comment } = payload;
5313
5349
  const entityId = comment.parent_id ?? comment.object_id;
5314
5350
  if (!shouldUpdateState({
5315
- stateUpdateQueueId: getStateUpdateQueueId(
5316
- payload,
5317
- "comment-updated"
5318
- ),
5351
+ stateUpdateQueueId: getStateUpdateQueueId(payload, "comment-updated"),
5319
5352
  stateUpdateQueue: this.stateUpdateQueue,
5320
5353
  watch: this.currentState.watch,
5321
5354
  fromWs,
5322
- isTriggeredByConnectedUser: eventTriggeredByConnectedUser.call(this, payload)
5355
+ isTriggeredByConnectedUser: eventTriggeredByConnectedUser.call(
5356
+ this,
5357
+ payload
5358
+ )
5323
5359
  })) {
5324
5360
  return;
5325
5361
  }
@@ -5329,7 +5365,10 @@ function handleCommentUpdated(payload, fromWs) {
5329
5365
  const index = this.getCommentIndex(comment, currentState);
5330
5366
  if (index === -1) return currentState;
5331
5367
  const newComments = [...entityState.comments];
5332
- newComments[index] = comment;
5368
+ newComments[index] = {
5369
+ ...comment,
5370
+ own_reactions: entityState.comments[index].own_reactions
5371
+ };
5333
5372
  return {
5334
5373
  ...currentState,
5335
5374
  comments_by_entity_id: {
@@ -5758,7 +5797,13 @@ function handleBookmarkUpdated(event) {
5758
5797
  });
5759
5798
  }
5760
5799
  }
5761
- function addActivitiesToState(newActivities, activities, position, { fromWebSocket } = { fromWebSocket: false }) {
5800
+ function addActivitiesToState(newActivities, activities, position, {
5801
+ hasOwnFields,
5802
+ backfillOwnFields
5803
+ } = {
5804
+ hasOwnFields: true,
5805
+ backfillOwnFields: true
5806
+ }) {
5762
5807
  if (activities === void 0) {
5763
5808
  return {
5764
5809
  changed: false,
@@ -5781,23 +5826,31 @@ function addActivitiesToState(newActivities, activities, position, { fromWebSock
5781
5826
  ...activities,
5782
5827
  ...position === "end" ? newActivitiesDeduplicated : []
5783
5828
  ];
5784
- this.newActivitiesAdded(newActivitiesDeduplicated, { fromWebSocket });
5829
+ this.activitiesAddedOrUpdated(newActivitiesDeduplicated, {
5830
+ hasOwnFields,
5831
+ backfillOwnFields
5832
+ });
5785
5833
  result = { changed: true, activities: updatedActivities };
5786
5834
  }
5787
5835
  return result;
5788
5836
  }
5789
5837
  function handleActivityAdded(event) {
5790
- if (this.activityAddedEventFilter) {
5791
- if (!this.activityAddedEventFilter(event)) {
5792
- return;
5793
- }
5838
+ const currentUser = this.client.state.getLatestValue().connected_user;
5839
+ const decision = this.resolveNewActivityDecision(
5840
+ event.activity,
5841
+ currentUser,
5842
+ false
5843
+ );
5844
+ if (decision === "ignore") {
5845
+ return;
5794
5846
  }
5847
+ const position = decision === "add-to-end" ? "end" : "start";
5795
5848
  const currentActivities = this.currentState.activities;
5796
5849
  const result = addActivitiesToState.bind(this)(
5797
5850
  [event.activity],
5798
5851
  currentActivities,
5799
- this.currentState.addNewActivitiesTo,
5800
- { fromWebSocket: true }
5852
+ position,
5853
+ { hasOwnFields: false, backfillOwnFields: true }
5801
5854
  );
5802
5855
  if (result.changed) {
5803
5856
  const activity = event.activity;
@@ -5914,7 +5967,10 @@ function handleActivityUpdated(payload, fromWs) {
5914
5967
  updatePinnedActivityInState(payload, currentPinnedActivities)
5915
5968
  ];
5916
5969
  if (result1?.changed || result2.changed) {
5917
- this.client.hydratePollCache([payload.activity]);
5970
+ this.activitiesAddedOrUpdated([payload.activity], {
5971
+ hasOwnFields: payload.activity.current_feed?.own_capabilities !== void 0,
5972
+ backfillOwnFields: false
5973
+ });
5918
5974
  this.state.partialNext({
5919
5975
  activities: result1?.changed ? result1.entities : currentActivities,
5920
5976
  pinned_activities: result2.entities
@@ -6426,6 +6482,30 @@ function handleWatchStarted() {
6426
6482
  function handleWatchStopped() {
6427
6483
  this.state.partialNext({ watch: false });
6428
6484
  }
6485
+ const activityResolvers = [
6486
+ {
6487
+ matchesField: (field) => field === "activity_type",
6488
+ resolve: (activity) => activity.type
6489
+ },
6490
+ {
6491
+ matchesField: (field) => field === "within_bounds",
6492
+ resolve: (activity) => activity.location
6493
+ },
6494
+ {
6495
+ matchesField: () => true,
6496
+ resolve: (item, path) => filter.resolveDotPathValue(item, path)
6497
+ }
6498
+ ];
6499
+ function activityFilter(activity, requestConfig) {
6500
+ const filter$1 = requestConfig?.filter;
6501
+ if (!filter$1 || typeof filter$1 !== "object") {
6502
+ return true;
6503
+ }
6504
+ return filter.itemMatchesFilter(activity, filter$1, {
6505
+ resolvers: [...activityResolvers],
6506
+ arrayEqMode: "contains"
6507
+ });
6508
+ }
6429
6509
  const DEFAULT_MAX_RETRIES = 3;
6430
6510
  function isRetryableError(error) {
6431
6511
  if (error instanceof StreamApiError) {
@@ -6617,9 +6697,9 @@ function clearQueuedFeeds() {
6617
6697
  queuedFeeds.clear();
6618
6698
  }
6619
6699
  const _Feed = class _Feed extends FeedApi {
6620
- constructor(client, groupId, id, data, watch = false, addNewActivitiesTo = "start", activityAddedEventFilter) {
6700
+ constructor(client, groupId, id, data, watch = false, onNewActivity) {
6621
6701
  super(client, groupId, id);
6622
- this.activityAddedEventFilter = activityAddedEventFilter;
6702
+ this.onNewActivity = onNewActivity;
6623
6703
  this.indexedActivityIds = /* @__PURE__ */ new Set();
6624
6704
  this.stateUpdateQueue = /* @__PURE__ */ new Set();
6625
6705
  this.eventHandlers = {
@@ -6689,8 +6769,7 @@ const _Feed = class _Feed extends FeedApi {
6689
6769
  is_loading: false,
6690
6770
  is_loading_activities: false,
6691
6771
  comments_by_entity_id: {},
6692
- watch,
6693
- addNewActivitiesTo
6772
+ watch
6694
6773
  });
6695
6774
  this.client = client;
6696
6775
  this.state.subscribeWithSelector(
@@ -6711,9 +6790,6 @@ const _Feed = class _Feed extends FeedApi {
6711
6790
  get currentState() {
6712
6791
  return this.state.getLatestValue();
6713
6792
  }
6714
- set addNewActivitiesTo(value) {
6715
- this.state.partialNext({ addNewActivitiesTo: value });
6716
- }
6717
6793
  hasActivity(activityId) {
6718
6794
  return this.indexedActivityIds.has(activityId);
6719
6795
  }
@@ -6722,6 +6798,24 @@ const _Feed = class _Feed extends FeedApi {
6722
6798
  (pinnedActivity) => pinnedActivity.activity.id === activityId
6723
6799
  );
6724
6800
  }
6801
+ /**
6802
+ * Resolves how to handle a new activity (WS or HTTP): ignore, add-to-start, or add-to-end.
6803
+ * Uses onNewActivity if set; else default (current user + filter match) adds to start.
6804
+ */
6805
+ resolveNewActivityDecision(activity, currentUser, _fromHttp) {
6806
+ if (this.onNewActivity) {
6807
+ return this.onNewActivity({ activity, currentUser });
6808
+ }
6809
+ if (!currentUser) return "ignore";
6810
+ if (activity.user?.id !== currentUser.id) return "ignore";
6811
+ if (!activityFilter(
6812
+ activity,
6813
+ this.currentState.last_get_or_create_request_config
6814
+ )) {
6815
+ return "ignore";
6816
+ }
6817
+ return "add-to-start";
6818
+ }
6725
6819
  async synchronize() {
6726
6820
  const { last_get_or_create_request_config } = this.state.getLatestValue();
6727
6821
  if (last_get_or_create_request_config?.watch) {
@@ -6759,7 +6853,8 @@ const _Feed = class _Feed extends FeedApi {
6759
6853
  const result = addActivitiesToState.bind(this)(
6760
6854
  response.activities,
6761
6855
  currentActivities,
6762
- "end"
6856
+ "end",
6857
+ { hasOwnFields: true, backfillOwnFields: false }
6763
6858
  );
6764
6859
  const aggregatedActivitiesResult = addAggregatedActivitiesToState(
6765
6860
  response.aggregated_activities,
@@ -6808,7 +6903,7 @@ const _Feed = class _Feed extends FeedApi {
6808
6903
  return nextState;
6809
6904
  });
6810
6905
  }
6811
- this.newActivitiesAdded(response.activities);
6906
+ this.activitiesAddedOrUpdated(response.activities);
6812
6907
  return response;
6813
6908
  } finally {
6814
6909
  this.state.partialNext({
@@ -7116,11 +7211,11 @@ const _Feed = class _Feed extends FeedApi {
7116
7211
  * _Note: Useful only for feeds with `groupId` of `user` value._
7117
7212
  */
7118
7213
  async queryFollowers(request) {
7119
- const filter = {
7214
+ const filter2 = {
7120
7215
  target_feed: this.feed
7121
7216
  };
7122
7217
  const response = await this.client.queryFollows({
7123
- filter,
7218
+ filter: filter2,
7124
7219
  ...request
7125
7220
  });
7126
7221
  return response;
@@ -7131,11 +7226,11 @@ const _Feed = class _Feed extends FeedApi {
7131
7226
  * _Note: Useful only for feeds with `groupId` of `timeline` value._
7132
7227
  */
7133
7228
  async queryFollowing(request) {
7134
- const filter = {
7229
+ const filter2 = {
7135
7230
  source_feed: this.feed
7136
7231
  };
7137
7232
  const response = await this.client.queryFollows({
7138
- filter,
7233
+ filter: filter2,
7139
7234
  ...request
7140
7235
  });
7141
7236
  return response;
@@ -7149,11 +7244,12 @@ const _Feed = class _Feed extends FeedApi {
7149
7244
  });
7150
7245
  return response;
7151
7246
  }
7152
- async unfollow(feedOrFid, options) {
7247
+ async unfollow(feedOrFid, options, enrichOwnFields) {
7153
7248
  const fid = typeof feedOrFid === "string" ? feedOrFid : feedOrFid.feed;
7154
7249
  const response = await this.client.unfollow({
7155
7250
  source: this.feed,
7156
7251
  target: fid,
7252
+ enrich_own_fields: enrichOwnFields,
7157
7253
  ...options
7158
7254
  });
7159
7255
  return response;
@@ -7182,11 +7278,41 @@ const _Feed = class _Feed extends FeedApi {
7182
7278
  next: currentState.next
7183
7279
  });
7184
7280
  }
7281
+ /**
7282
+ * Applies a new activity to this feed's state (decision + add to activities).
7283
+ * Used when the activity was added via this feed's addActivity or via client.addActivity.
7284
+ */
7285
+ addActivityFromHTTPResponse(activity) {
7286
+ const currentUser = this.client.state.getLatestValue().connected_user;
7287
+ const decision = this.resolveNewActivityDecision(
7288
+ activity,
7289
+ currentUser,
7290
+ true
7291
+ );
7292
+ if (decision !== "ignore") {
7293
+ const position = decision === "add-to-end" ? "end" : "start";
7294
+ const currentActivities = this.currentState.activities;
7295
+ const result = addActivitiesToState.bind(this)(
7296
+ [activity],
7297
+ currentActivities,
7298
+ position,
7299
+ {
7300
+ hasOwnFields: activity.current_feed?.own_capabilities !== void 0,
7301
+ backfillOwnFields: false
7302
+ }
7303
+ );
7304
+ if (result.changed) {
7305
+ this.client.hydratePollCache([activity]);
7306
+ this.state.partialNext({ activities: result.activities });
7307
+ }
7308
+ }
7309
+ }
7185
7310
  async addActivity(request) {
7186
7311
  const response = await this.client.addActivity({
7187
7312
  ...request,
7188
7313
  feeds: [this.feed]
7189
7314
  });
7315
+ this.addActivityFromHTTPResponse(response.activity);
7190
7316
  return response;
7191
7317
  }
7192
7318
  handleWSEvent(event) {
@@ -7207,7 +7333,7 @@ const _Feed = class _Feed extends FeedApi {
7207
7333
  }
7208
7334
  this.eventDispatcher.dispatch(event);
7209
7335
  }
7210
- newActivitiesAdded(activities, options = { fromWebSocket: false }) {
7336
+ activitiesAddedOrUpdated(activities, options = { hasOwnFields: true, backfillOwnFields: true }) {
7211
7337
  this.client.hydratePollCache(activities);
7212
7338
  this.getOrCreateFeeds(activities, options);
7213
7339
  }
@@ -7225,7 +7351,7 @@ const _Feed = class _Feed extends FeedApi {
7225
7351
  });
7226
7352
  const newFeeds = Array.from(feedsToGetOrCreate.values());
7227
7353
  const fieldsToUpdate = [];
7228
- if (!options.fromWebSocket) {
7354
+ if (options.hasOwnFields) {
7229
7355
  fieldsToUpdate.push("own_membership");
7230
7356
  if (!enrichmentOptions?.skip_own_capabilities) {
7231
7357
  fieldsToUpdate.push("own_capabilities");
@@ -7245,7 +7371,7 @@ const _Feed = class _Feed extends FeedApi {
7245
7371
  fieldsToUpdate
7246
7372
  });
7247
7373
  });
7248
- if (options.fromWebSocket) {
7374
+ if (!options.hasOwnFields && options.backfillOwnFields) {
7249
7375
  const uninitializedFeeds = newFeeds.filter((feedResponse) => {
7250
7376
  const feed = this.client.feed(feedResponse.group_id, feedResponse.id);
7251
7377
  return feed.currentState.own_capabilities === void 0;
@@ -7268,6 +7394,9 @@ const _Feed = class _Feed extends FeedApi {
7268
7394
  _Feed.noop = () => {
7269
7395
  };
7270
7396
  let Feed = _Feed;
7397
+ function applyNewActivityToActiveFeeds(activity) {
7398
+ return this.addActivityFromHTTPResponse(activity);
7399
+ }
7271
7400
  function handleUserUpdated(event) {
7272
7401
  this.state.next((currentState) => {
7273
7402
  let newState;
@@ -7347,7 +7476,9 @@ function disconnectActivityFromFeed(activity) {
7347
7476
  }
7348
7477
  }
7349
7478
  class ActivityWithStateUpdates {
7350
- constructor(id, feedsClient, { fromResponse } = { fromResponse: void 0 }) {
7479
+ constructor(id, feedsClient, { fromResponse } = {
7480
+ fromResponse: void 0
7481
+ }) {
7351
7482
  this.id = id;
7352
7483
  this.feedsClient = feedsClient;
7353
7484
  this.state = new stateStore.StateStore({
@@ -7398,7 +7529,7 @@ class ActivityWithStateUpdates {
7398
7529
  initialState: activityResponse
7399
7530
  });
7400
7531
  if (this.feed) {
7401
- this.feed.activityAddedEventFilter = () => false;
7532
+ this.feed.onNewActivity = () => "ignore";
7402
7533
  }
7403
7534
  if (comments) {
7404
7535
  await this.loadNextPageActivityComments(comments);
@@ -7451,7 +7582,11 @@ class ActivityWithStateUpdates {
7451
7582
  const { activities } = addActivitiesToState.bind(this.feed)(
7452
7583
  [initialState],
7453
7584
  [],
7454
- "start"
7585
+ "start",
7586
+ {
7587
+ hasOwnFields: initialState.current_feed?.own_capabilities !== void 0,
7588
+ backfillOwnFields: false
7589
+ }
7455
7590
  );
7456
7591
  this.feed?.state.partialNext({
7457
7592
  activities
@@ -7809,9 +7944,9 @@ class FeedsClient extends FeedsApi {
7809
7944
  return response;
7810
7945
  };
7811
7946
  this.queryPollAnswers = async (request) => {
7812
- const filter = request.filter ?? {};
7947
+ const filter2 = request.filter ?? {};
7813
7948
  const queryPollAnswersFilter = {
7814
- ...filter,
7949
+ ...filter2,
7815
7950
  is_answer: true
7816
7951
  };
7817
7952
  const queryPollAnswersRequest = {
@@ -7882,18 +8017,12 @@ class FeedsClient extends FeedsApi {
7882
8017
  id,
7883
8018
  data,
7884
8019
  watch,
7885
- options2?.addNewActivitiesTo,
7886
- options2?.activityAddedEventFilter
8020
+ options2?.onNewActivity
7887
8021
  );
7888
8022
  }
7889
8023
  const feed = this.activeFeeds[fid];
7890
- if (!isCreated && options2) {
7891
- if (options2?.addNewActivitiesTo) {
7892
- feed.addNewActivitiesTo = options2.addNewActivitiesTo;
7893
- }
7894
- if (options2?.activityAddedEventFilter) {
7895
- feed.activityAddedEventFilter = options2.activityAddedEventFilter;
7896
- }
8024
+ if (!isCreated && options2?.onNewActivity !== void 0) {
8025
+ feed.onNewActivity = options2.onNewActivity;
7897
8026
  }
7898
8027
  if (!feed.currentState.watch) {
7899
8028
  if (!isCreated && data) {
@@ -8073,6 +8202,16 @@ class FeedsClient extends FeedsApi {
8073
8202
  });
8074
8203
  }
8075
8204
  }
8205
+ async addActivity(request) {
8206
+ const response = await super.addActivity(request);
8207
+ request.feeds.forEach((fid) => {
8208
+ const feed = this.activeFeeds[fid];
8209
+ if (feed) {
8210
+ applyNewActivityToActiveFeeds.call(feed, response.activity);
8211
+ }
8212
+ });
8213
+ return response;
8214
+ }
8076
8215
  async queryFeeds(request) {
8077
8216
  const response = await this._queryFeeds(request);
8078
8217
  const feedResponses = response.feeds;
@@ -8082,12 +8221,12 @@ class FeedsClient extends FeedsApi {
8082
8221
  id: feedResponse.id,
8083
8222
  data: feedResponse,
8084
8223
  watch: request?.watch,
8085
- fieldsToUpdate: [
8224
+ fieldsToUpdate: request?.enrich_own_fields ? [
8086
8225
  "own_capabilities",
8087
8226
  "own_follows",
8088
8227
  "own_membership",
8089
8228
  "own_followings"
8090
- ]
8229
+ ] : []
8091
8230
  })
8092
8231
  );
8093
8232
  return {
@@ -8122,7 +8261,7 @@ class FeedsClient extends FeedsApi {
8122
8261
  // For follow API endpoints we update the state after HTTP response to allow queryFeeds with watch: false
8123
8262
  async follow(request) {
8124
8263
  const response = await super.follow(request);
8125
- this.updateStateFromFollows([response.follow]);
8264
+ this.updateStateFromFollows([response.follow], !!request.enrich_own_fields);
8126
8265
  return response;
8127
8266
  }
8128
8267
  /**
@@ -8132,12 +8271,12 @@ class FeedsClient extends FeedsApi {
8132
8271
  */
8133
8272
  async followBatch(request) {
8134
8273
  const response = await super.followBatch(request);
8135
- this.updateStateFromFollows(response.follows);
8274
+ this.updateStateFromFollows(response.follows, !!request.enrich_own_fields);
8136
8275
  return response;
8137
8276
  }
8138
8277
  async getOrCreateFollows(request) {
8139
8278
  const response = await super.getOrCreateFollows(request);
8140
- this.updateStateFromFollows(response.created);
8279
+ this.updateStateFromFollows(response.created, !!request.enrich_own_fields);
8141
8280
  return response;
8142
8281
  }
8143
8282
  async unfollow(request) {
@@ -8228,13 +8367,15 @@ class FeedsClient extends FeedsApi {
8228
8367
  }).map((a) => getFeed.call(a))
8229
8368
  ];
8230
8369
  }
8231
- updateStateFromFollows(follows) {
8370
+ updateStateFromFollows(follows, hasOwnFields) {
8232
8371
  follows.forEach((follow) => {
8233
8372
  const feeds = [
8234
8373
  ...this.findAllActiveFeedsByFid(follow.source_feed.feed),
8235
8374
  ...this.findAllActiveFeedsByFid(follow.target_feed.feed)
8236
8375
  ];
8237
- feeds.forEach((f) => handleFollowCreated.bind(f)({ follow }, false));
8376
+ feeds.forEach(
8377
+ (f) => handleFollowCreated.bind(f)({ follow }, false, hasOwnFields)
8378
+ );
8238
8379
  });
8239
8380
  }
8240
8381
  updateStateFromUnfollows(follows) {
@@ -8265,6 +8406,7 @@ exports.Feed = Feed;
8265
8406
  exports.FeedsClient = FeedsClient;
8266
8407
  exports.StreamApiError = StreamApiError;
8267
8408
  exports.StreamPoll = StreamPoll;
8409
+ exports.activityFilter = activityFilter;
8268
8410
  exports.checkHasAnotherPage = checkHasAnotherPage;
8269
8411
  exports.debounce = debounce;
8270
8412
  exports.ensureExhausted = ensureExhausted;
@@ -8280,4 +8422,4 @@ exports.replaceUniqueArrayMerge = replaceUniqueArrayMerge;
8280
8422
  exports.shouldUpdateState = shouldUpdateState;
8281
8423
  exports.uniqueArrayMerge = uniqueArrayMerge;
8282
8424
  exports.updateEntityInArray = updateEntityInArray;
8283
- //# sourceMappingURL=feeds-client-CKxvuiKz.js.map
8425
+ //# sourceMappingURL=feeds-client-tw63OGrd.js.map