@stream-io/feeds-client 0.3.31 → 0.3.33

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 (55) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cjs/index.js +3 -2
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/react-bindings.js +39 -33
  5. package/dist/cjs/react-bindings.js.map +1 -1
  6. package/dist/es/index.mjs +4 -3
  7. package/dist/es/index.mjs.map +1 -1
  8. package/dist/es/react-bindings.mjs +39 -33
  9. package/dist/es/react-bindings.mjs.map +1 -1
  10. package/dist/{feeds-client-DYnxEI2D.mjs → feeds-client-C-6NrDBy.mjs} +196 -182
  11. package/dist/feeds-client-C-6NrDBy.mjs.map +1 -0
  12. package/dist/{feeds-client-BUsd5D-y.js → feeds-client-CyaHg6lu.js} +196 -182
  13. package/dist/feeds-client-CyaHg6lu.js.map +1 -0
  14. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  15. package/dist/types/activity-with-state-updates/activity-with-state-updates.d.ts +1 -1
  16. package/dist/types/activity-with-state-updates/activity-with-state-updates.d.ts.map +1 -1
  17. package/dist/types/bindings/react/hooks/feed-state-hooks/index.d.ts +1 -0
  18. package/dist/types/bindings/react/hooks/feed-state-hooks/index.d.ts.map +1 -1
  19. package/dist/types/bindings/react/hooks/feed-state-hooks/useOwnCapabilities.d.ts.map +1 -1
  20. package/dist/types/bindings/react/hooks/feed-state-hooks/useOwnFollowings.d.ts +8 -0
  21. package/dist/types/bindings/react/hooks/feed-state-hooks/useOwnFollowings.d.ts.map +1 -0
  22. package/dist/types/common/types.d.ts +1 -1
  23. package/dist/types/common/types.d.ts.map +1 -1
  24. package/dist/types/feed/event-handlers/activity/handle-activity-added.d.ts.map +1 -1
  25. package/dist/types/feed/event-handlers/activity/handle-activity-updated.d.ts.map +1 -1
  26. package/dist/types/feed/feed.d.ts +2 -1
  27. package/dist/types/feed/feed.d.ts.map +1 -1
  28. package/dist/types/feeds-client/feeds-client.d.ts +7 -9
  29. package/dist/types/feeds-client/feeds-client.d.ts.map +1 -1
  30. package/dist/types/gen/models/index.d.ts +4 -0
  31. package/dist/types/gen/models/index.d.ts.map +1 -1
  32. package/dist/types/utils/check-own-fields-equality.d.ts +2 -0
  33. package/dist/types/utils/check-own-fields-equality.d.ts.map +1 -1
  34. package/dist/types/utils/throttling/index.d.ts +1 -1
  35. package/dist/types/utils/throttling/index.d.ts.map +1 -1
  36. package/dist/types/utils/throttling/throttled-get-batched-own-fields.d.ts +14 -0
  37. package/dist/types/utils/throttling/throttled-get-batched-own-fields.d.ts.map +1 -0
  38. package/package.json +1 -1
  39. package/src/activity-with-state-updates/activity-with-state-updates.ts +7 -2
  40. package/src/bindings/react/hooks/feed-state-hooks/index.ts +1 -0
  41. package/src/bindings/react/hooks/feed-state-hooks/useOwnCapabilities.ts +14 -23
  42. package/src/bindings/react/hooks/feed-state-hooks/useOwnFollowings.ts +18 -0
  43. package/src/common/types.ts +1 -1
  44. package/src/feed/event-handlers/activity/handle-activity-added.ts +0 -6
  45. package/src/feed/event-handlers/activity/handle-activity-updated.ts +0 -4
  46. package/src/feed/feed.ts +51 -39
  47. package/src/feeds-client/feeds-client.ts +88 -91
  48. package/src/gen/models/index.ts +8 -0
  49. package/src/utils/check-own-fields-equality.ts +37 -10
  50. package/src/utils/throttling/index.ts +1 -1
  51. package/src/utils/throttling/{throttled-get-batched-own-capabilities.ts → throttled-get-batched-own-fields.ts} +10 -10
  52. package/dist/feeds-client-BUsd5D-y.js.map +0 -1
  53. package/dist/feeds-client-DYnxEI2D.mjs.map +0 -1
  54. package/dist/types/utils/throttling/throttled-get-batched-own-capabilities.d.ts +0 -14
  55. package/dist/types/utils/throttling/throttled-get-batched-own-capabilities.d.ts.map +0 -1
@@ -3941,7 +3941,7 @@ const getRateLimitFromResponseHeader = (response_headers) => {
3941
3941
  };
3942
3942
  return result;
3943
3943
  };
3944
- const version = "0.3.31";
3944
+ const version = "0.3.33";
3945
3945
  const axios = axiosImport.default ?? axiosImport;
3946
3946
  class ApiClient {
3947
3947
  constructor(apiKey, tokenManager, connectionIdManager, options) {
@@ -4803,7 +4803,6 @@ function updateEntityInArray({
4803
4803
  updatedEntities[index] = newEntity;
4804
4804
  return { changed: true, entities: updatedEntities };
4805
4805
  }
4806
- const ownFeedFields = ["own_capabilities", "own_follows", "own_membership"];
4807
4806
  const updateStateFollowCreated = (follow, currentState, currentFeedId, connectedUserId) => {
4808
4807
  if (follow.status !== "accepted") {
4809
4808
  return { changed: false, data: currentState };
@@ -5554,10 +5553,6 @@ function handleActivityAdded(event) {
5554
5553
  if (result.changed) {
5555
5554
  const activity = event.activity;
5556
5555
  this.client.hydratePollCache([activity]);
5557
- const currentFeed = activity.current_feed;
5558
- if (currentFeed) {
5559
- this.client.hydrateCapabilitiesCache([currentFeed]);
5560
- }
5561
5556
  this.state.partialNext({ activities: result.activities });
5562
5557
  }
5563
5558
  }
@@ -5669,9 +5664,6 @@ function handleActivityUpdated(payload, fromWs) {
5669
5664
  ];
5670
5665
  if (result1?.changed || result2.changed) {
5671
5666
  this.client.hydratePollCache([payload.activity]);
5672
- if (payload.activity.current_feed) {
5673
- this.client.hydrateCapabilitiesCache([payload.activity.current_feed]);
5674
- }
5675
5667
  this.state.partialNext({
5676
5668
  activities: result1?.changed ? result1.entities : currentActivities,
5677
5669
  pinned_activities: result2.entities
@@ -6256,6 +6248,91 @@ const deepEqual = (x, y) => {
6256
6248
  function getOrCreateActiveFeed(...args) {
6257
6249
  return this.getOrCreateActiveFeed(...args);
6258
6250
  }
6251
+ const throttle = (fn, timeout = 200, {
6252
+ leading = true,
6253
+ trailing = false
6254
+ } = {}) => {
6255
+ let timer = null;
6256
+ let storedArgs = null;
6257
+ let storedThis = null;
6258
+ let lastInvokeTime;
6259
+ const invoke = (args, thisArg) => {
6260
+ lastInvokeTime = Date.now();
6261
+ fn.apply(thisArg, args);
6262
+ };
6263
+ const scheduleTrailing = (delay) => {
6264
+ if (timer) return;
6265
+ timer = setTimeout(() => {
6266
+ timer = null;
6267
+ if (trailing && storedArgs) {
6268
+ invoke(storedArgs, storedThis);
6269
+ storedArgs = null;
6270
+ storedThis = null;
6271
+ }
6272
+ }, delay);
6273
+ };
6274
+ return {
6275
+ throttledFn: function(...args) {
6276
+ const now = Date.now();
6277
+ const hasBeenInvoked = lastInvokeTime != null;
6278
+ if (!hasBeenInvoked && !leading) lastInvokeTime = now;
6279
+ const timeSinceLast = hasBeenInvoked ? now - lastInvokeTime : timeout;
6280
+ const remaining = timeout - timeSinceLast;
6281
+ if (trailing) {
6282
+ storedArgs = args;
6283
+ storedThis = this;
6284
+ }
6285
+ if (remaining <= 0) {
6286
+ if (timer) {
6287
+ clearTimeout(timer);
6288
+ timer = null;
6289
+ }
6290
+ if (leading) {
6291
+ if (trailing) {
6292
+ if (storedArgs === args) {
6293
+ storedArgs = null;
6294
+ storedThis = null;
6295
+ }
6296
+ }
6297
+ invoke(args, this);
6298
+ } else {
6299
+ if (trailing) scheduleTrailing(timeout);
6300
+ }
6301
+ return;
6302
+ }
6303
+ if (trailing && !timer) {
6304
+ scheduleTrailing(remaining);
6305
+ }
6306
+ },
6307
+ cancelTimer: () => {
6308
+ if (timer) {
6309
+ clearTimeout(timer);
6310
+ timer = null;
6311
+ }
6312
+ }
6313
+ };
6314
+ };
6315
+ const BATCH_OWN_FIELDS_API_LIMIT = 100;
6316
+ const DEFAULT_BATCH_OWN_FIELDS_THROTTLING_INTERVAL = 2e3;
6317
+ const queuedFeeds = /* @__PURE__ */ new Set();
6318
+ function queueBatchedOwnFields({ feeds }) {
6319
+ for (const feed of feeds) {
6320
+ queuedFeeds.add(feed);
6321
+ }
6322
+ if (queuedFeeds.size > 0) {
6323
+ this.throttledGetBatchOwnFields(
6324
+ [...queuedFeeds].slice(0, BATCH_OWN_FIELDS_API_LIMIT),
6325
+ (feedsToClear) => {
6326
+ for (const feed of feedsToClear) {
6327
+ queuedFeeds.delete(feed);
6328
+ }
6329
+ }
6330
+ );
6331
+ }
6332
+ }
6333
+ function clearQueuedFeeds() {
6334
+ queuedFeeds.clear();
6335
+ }
6259
6336
  const _Feed = class _Feed extends FeedApi {
6260
6337
  constructor(client, groupId, id, data, watch = false, addNewActivitiesTo = "start", activityAddedEventFilter) {
6261
6338
  super(client, groupId, id);
@@ -6390,10 +6467,6 @@ const _Feed = class _Feed extends FeedApi {
6390
6467
  currentActivityFeeds.push(activity.current_feed);
6391
6468
  }
6392
6469
  }
6393
- this.client.hydrateCapabilitiesCache([
6394
- response.feed,
6395
- ...currentActivityFeeds
6396
- ]);
6397
6470
  if (request?.next) {
6398
6471
  const { activities: currentActivities = [] } = this.currentState;
6399
6472
  const result = addActivitiesToState.bind(this)(
@@ -6820,29 +6893,18 @@ const _Feed = class _Feed extends FeedApi {
6820
6893
  ...request,
6821
6894
  feeds: [this.feed]
6822
6895
  });
6823
- const currentFeed = response.activity.current_feed;
6824
- if (currentFeed) {
6825
- this.client.hydrateCapabilitiesCache([currentFeed]);
6826
- }
6827
6896
  return response;
6828
6897
  }
6829
6898
  handleWSEvent(event) {
6830
6899
  const eventHandler = this.eventHandlers[event.type];
6831
6900
  if (eventHandler !== _Feed.noop) {
6832
- if ("activity" in event && this.hasActivity(event.activity.id)) {
6901
+ if ("activity" in event && event.activity.feeds.length > 1 && this.hasActivity(event.activity.id)) {
6833
6902
  const currentActivity = this.currentState.activities?.find(
6834
6903
  (a) => a.id === event.activity.id
6835
6904
  );
6836
- if (event.activity.feeds.length > 1 && !event.activity.current_feed && currentActivity?.current_feed) {
6905
+ if (!event.activity.current_feed && currentActivity?.current_feed) {
6837
6906
  event.activity.current_feed = currentActivity.current_feed;
6838
6907
  }
6839
- if (event.activity.feeds.length === 1 && event.activity.current_feed && currentActivity?.current_feed) {
6840
- ownFeedFields.forEach((field) => {
6841
- if (field in currentActivity.current_feed) {
6842
- event.activity.current_feed[field] = currentActivity.current_feed[field];
6843
- }
6844
- });
6845
- }
6846
6908
  }
6847
6909
  eventHandler?.(event);
6848
6910
  }
@@ -6857,7 +6919,7 @@ const _Feed = class _Feed extends FeedApi {
6857
6919
  }
6858
6920
  getOrCreateFeeds(activities, options) {
6859
6921
  const enrichmentOptions = this.currentState.last_get_or_create_request_config?.enrichment_options;
6860
- if (!enrichmentOptions?.skip_activity_current_feed && !enrichmentOptions?.skip_all) {
6922
+ if (this.shouldAddToActiveFeeds(enrichmentOptions)) {
6861
6923
  const feedsToGetOrCreate = /* @__PURE__ */ new Map();
6862
6924
  activities.forEach((activity) => {
6863
6925
  if (activity.current_feed && !feedsToGetOrCreate.has(activity.current_feed.feed)) {
@@ -6867,15 +6929,44 @@ const _Feed = class _Feed extends FeedApi {
6867
6929
  );
6868
6930
  }
6869
6931
  });
6870
- Array.from(feedsToGetOrCreate.values()).forEach((feed) => {
6932
+ const newFeeds = Array.from(feedsToGetOrCreate.values());
6933
+ const fieldsToUpdate = [];
6934
+ if (!options.fromWebSocket) {
6935
+ fieldsToUpdate.push(
6936
+ "own_capabilities",
6937
+ "own_follows",
6938
+ "own_membership"
6939
+ );
6940
+ if (enrichmentOptions?.enrich_own_followings) {
6941
+ fieldsToUpdate.push("own_followings");
6942
+ }
6943
+ }
6944
+ newFeeds.forEach((feed) => {
6871
6945
  getOrCreateActiveFeed.bind(this.client)({
6872
6946
  group: feed.group_id,
6873
6947
  id: feed.id,
6874
6948
  data: feed,
6875
- fromWebSocket: options.fromWebSocket
6949
+ fieldsToUpdate
6876
6950
  });
6877
6951
  });
6952
+ if (options.fromWebSocket) {
6953
+ const uninitializedFeeds = newFeeds.filter((feedResponse) => {
6954
+ const feed = this.client.feed(feedResponse.group_id, feedResponse.id);
6955
+ return feed.currentState.own_capabilities === void 0;
6956
+ });
6957
+ if (uninitializedFeeds.length > 0) {
6958
+ queueBatchedOwnFields.bind(this.client)({
6959
+ feeds: uninitializedFeeds.map((feed) => feed.feed)
6960
+ });
6961
+ }
6962
+ }
6963
+ }
6964
+ }
6965
+ shouldAddToActiveFeeds(enrichmentOptions) {
6966
+ if (!enrichmentOptions) {
6967
+ return true;
6878
6968
  }
6969
+ return !enrichmentOptions?.skip_activity && !enrichmentOptions?.skip_activity_current_feed && !enrichmentOptions?.skip_all;
6879
6970
  }
6880
6971
  };
6881
6972
  _Feed.noop = () => {
@@ -6930,91 +7021,6 @@ function updateCommentCount({
6930
7021
  }, false);
6931
7022
  }
6932
7023
  }
6933
- const throttle = (fn, timeout = 200, {
6934
- leading = true,
6935
- trailing = false
6936
- } = {}) => {
6937
- let timer = null;
6938
- let storedArgs = null;
6939
- let storedThis = null;
6940
- let lastInvokeTime;
6941
- const invoke = (args, thisArg) => {
6942
- lastInvokeTime = Date.now();
6943
- fn.apply(thisArg, args);
6944
- };
6945
- const scheduleTrailing = (delay) => {
6946
- if (timer) return;
6947
- timer = setTimeout(() => {
6948
- timer = null;
6949
- if (trailing && storedArgs) {
6950
- invoke(storedArgs, storedThis);
6951
- storedArgs = null;
6952
- storedThis = null;
6953
- }
6954
- }, delay);
6955
- };
6956
- return {
6957
- throttledFn: function(...args) {
6958
- const now = Date.now();
6959
- const hasBeenInvoked = lastInvokeTime != null;
6960
- if (!hasBeenInvoked && !leading) lastInvokeTime = now;
6961
- const timeSinceLast = hasBeenInvoked ? now - lastInvokeTime : timeout;
6962
- const remaining = timeout - timeSinceLast;
6963
- if (trailing) {
6964
- storedArgs = args;
6965
- storedThis = this;
6966
- }
6967
- if (remaining <= 0) {
6968
- if (timer) {
6969
- clearTimeout(timer);
6970
- timer = null;
6971
- }
6972
- if (leading) {
6973
- if (trailing) {
6974
- if (storedArgs === args) {
6975
- storedArgs = null;
6976
- storedThis = null;
6977
- }
6978
- }
6979
- invoke(args, this);
6980
- } else {
6981
- if (trailing) scheduleTrailing(timeout);
6982
- }
6983
- return;
6984
- }
6985
- if (trailing && !timer) {
6986
- scheduleTrailing(remaining);
6987
- }
6988
- },
6989
- cancelTimer: () => {
6990
- if (timer) {
6991
- clearTimeout(timer);
6992
- timer = null;
6993
- }
6994
- }
6995
- };
6996
- };
6997
- const BATCH_OWN_CAPABILITIES_API_LIMIT = 100;
6998
- const DEFAULT_BATCH_OWN_CAPABILITIES_THROTTLING_INTERVAL = 2e3;
6999
- const queuedFeeds = /* @__PURE__ */ new Set();
7000
- function queueBatchedOwnCapabilities({ feeds }) {
7001
- for (const feed of feeds) {
7002
- queuedFeeds.add(feed);
7003
- }
7004
- if (queuedFeeds.size > 0) {
7005
- this.throttledGetBatchOwnCapabilities(
7006
- [...queuedFeeds].slice(0, BATCH_OWN_CAPABILITIES_API_LIMIT),
7007
- (feedsToClear) => {
7008
- for (const feed of feedsToClear) {
7009
- queuedFeeds.delete(feed);
7010
- }
7011
- }
7012
- );
7013
- }
7014
- }
7015
- function clearQueuedFeeds() {
7016
- queuedFeeds.clear();
7017
- }
7018
7024
  function connectActivityToFeed({
7019
7025
  fid
7020
7026
  }) {
@@ -7139,8 +7145,13 @@ class ActivityWithStateUpdates {
7139
7145
  initialState
7140
7146
  }) {
7141
7147
  this.feed = connectActivityToFeed.call(this.feedsClient, { fid });
7148
+ const { activities } = addActivitiesToState.bind(this.feed)(
7149
+ [initialState],
7150
+ [],
7151
+ "start"
7152
+ );
7142
7153
  this.feed?.state.partialNext({
7143
- activities: [initialState]
7154
+ activities
7144
7155
  });
7145
7156
  }
7146
7157
  subscribeToFeedState() {
@@ -7165,20 +7176,20 @@ class ActivityWithStateUpdates {
7165
7176
  function getFeed() {
7166
7177
  return this.feed;
7167
7178
  }
7168
- const isOwnFollowsEqual = (currentState, newState) => {
7179
+ const areFollowArraysEqual = (currentFollows, newFollows) => {
7169
7180
  const existingFollows = new Set(
7170
- currentState.own_follows?.map(
7181
+ currentFollows?.map(
7171
7182
  (f) => `${f.source_feed.feed}:${f.target_feed.feed}:${f.updated_at.getTime()}`
7172
7183
  )
7173
7184
  );
7174
- const newFollows = new Set(
7175
- newState.own_follows?.map(
7185
+ const newFollowsSet = new Set(
7186
+ newFollows?.map(
7176
7187
  (f) => `${f.source_feed.feed}:${f.target_feed.feed}:${f.updated_at.getTime()}`
7177
7188
  )
7178
7189
  );
7179
- if (existingFollows.size === newFollows.size) {
7190
+ if (existingFollows.size === newFollowsSet.size) {
7180
7191
  const areEqual = Array.from(existingFollows).every(
7181
- (f) => newFollows.has(f)
7192
+ (f) => newFollowsSet.has(f)
7182
7193
  );
7183
7194
  if (areEqual) {
7184
7195
  return true;
@@ -7186,9 +7197,21 @@ const isOwnFollowsEqual = (currentState, newState) => {
7186
7197
  }
7187
7198
  return false;
7188
7199
  };
7200
+ const isOwnFollowsEqual = (currentState, newState) => {
7201
+ return areFollowArraysEqual(currentState.own_follows, newState.own_follows);
7202
+ };
7189
7203
  const isOwnMembershipEqual = (currentState, newState) => {
7190
7204
  return (currentState.own_membership?.updated_at.getTime() ?? 0) === (newState.own_membership?.updated_at.getTime() ?? 0);
7191
7205
  };
7206
+ const isOwnCapabilitiesEqual = (currentState, newState) => {
7207
+ return [...currentState.own_capabilities ?? []].sort().join(",") === [...newState.own_capabilities ?? []].sort().join(",");
7208
+ };
7209
+ const isOwnFollowingsEqual = (currentState, newState) => {
7210
+ return areFollowArraysEqual(
7211
+ currentState.own_followings,
7212
+ newState.own_followings
7213
+ );
7214
+ };
7192
7215
  class FeedsClient extends FeedsApi {
7193
7216
  constructor(apiKey, options) {
7194
7217
  const tokenManager = new TokenManager();
@@ -7204,11 +7227,8 @@ class FeedsClient extends FeedsApi {
7204
7227
  this.activeActivities = {};
7205
7228
  this.activeFeeds = {};
7206
7229
  this.healthyConnectionChangedEventCount = 0;
7207
- this.setGetBatchOwnCapabilitiesThrottlingInterval = (throttlingMs) => {
7208
- const {
7209
- throttledFn: throttledGetBatchOwnCapabilities,
7210
- cancelTimer: cancel
7211
- } = throttle(
7230
+ this.setGetBatchOwnFieldsThrottlingInterval = (throttlingMs) => {
7231
+ const { throttledFn: throttledGetBatchOwnFields, cancelTimer: cancel } = throttle(
7212
7232
  (feeds, callback) => {
7213
7233
  this.ownBatch({
7214
7234
  feeds
@@ -7224,8 +7244,8 @@ class FeedsClient extends FeedsApi {
7224
7244
  throttlingMs,
7225
7245
  { trailing: true }
7226
7246
  );
7227
- this.throttledGetBatchOwnCapabilities = throttledGetBatchOwnCapabilities;
7228
- this.cancelGetBatchOwnCapabilitiesTimer = cancel;
7247
+ this.throttledGetBatchOwnFields = throttledGetBatchOwnFields;
7248
+ this.cancelGetBatchOwnFieldsTimer = cancel;
7229
7249
  };
7230
7250
  this.recoverOnReconnect = async () => {
7231
7251
  this.healthyConnectionChangedEventCount++;
@@ -7257,8 +7277,8 @@ class FeedsClient extends FeedsApi {
7257
7277
  throw new Error(`Can't connect a new user, call "disconnectUser" first`);
7258
7278
  }
7259
7279
  this.tokenManager.setTokenOrProvider(tokenProvider);
7260
- this.setGetBatchOwnCapabilitiesThrottlingInterval(
7261
- this.query_batch_own_capabilties_throttling_interval
7280
+ this.setGetBatchOwnFieldsThrottlingInterval(
7281
+ this.query_batch_own_fields_throttling_interval
7262
7282
  );
7263
7283
  try {
7264
7284
  addConnectionEventListeners(this.updateNetworkConnectionStatus);
@@ -7430,10 +7450,9 @@ class FeedsClient extends FeedsApi {
7430
7450
  this.activeFeeds = {};
7431
7451
  this.state.partialNext({
7432
7452
  connected_user: void 0,
7433
- is_ws_connection_healthy: false,
7434
- own_capabilities_by_fid: {}
7453
+ is_ws_connection_healthy: false
7435
7454
  });
7436
- this.cancelGetBatchOwnCapabilitiesTimer();
7455
+ this.cancelGetBatchOwnFieldsTimer();
7437
7456
  clearQueuedFeeds();
7438
7457
  };
7439
7458
  this.on = this.eventDispatcher.on;
@@ -7442,7 +7461,8 @@ class FeedsClient extends FeedsApi {
7442
7461
  return this.getOrCreateActiveFeed({
7443
7462
  group: groupId,
7444
7463
  id,
7445
- options: options2
7464
+ options: options2,
7465
+ fieldsToUpdate: []
7446
7466
  });
7447
7467
  };
7448
7468
  this.activityWithStateUpdates = (id) => {
@@ -7466,7 +7486,7 @@ class FeedsClient extends FeedsApi {
7466
7486
  data,
7467
7487
  watch,
7468
7488
  options: options2,
7469
- fromWebSocket = false
7489
+ fieldsToUpdate
7470
7490
  }) => {
7471
7491
  const fid = `${group}:${id}`;
7472
7492
  let isCreated = false;
@@ -7495,23 +7515,28 @@ class FeedsClient extends FeedsApi {
7495
7515
  if (!isCreated && data) {
7496
7516
  if ((feed.currentState.updated_at?.getTime() ?? 0) < data.updated_at.getTime()) {
7497
7517
  handleFeedUpdated.call(feed, { feed: data });
7498
- } else if ((feed.currentState.updated_at?.getTime() ?? 0) === data.updated_at.getTime() && !fromWebSocket) {
7499
- const fieldsToUpdate = [];
7500
- if (!isOwnFollowsEqual(feed.currentState, data)) {
7501
- fieldsToUpdate.push("own_follows");
7502
- }
7503
- if (!isOwnMembershipEqual(feed.currentState, data)) {
7504
- fieldsToUpdate.push("own_membership");
7505
- }
7506
- if (fieldsToUpdate.length > 0) {
7507
- const fieldsToUpdateData = fieldsToUpdate.reduce(
7518
+ } else if ((feed.currentState.updated_at?.getTime() ?? 0) === data.updated_at.getTime()) {
7519
+ const fieldsToUpdateData = [];
7520
+ const fieldChecks = [
7521
+ ["own_capabilities", isOwnCapabilitiesEqual],
7522
+ ["own_follows", isOwnFollowsEqual],
7523
+ ["own_membership", isOwnMembershipEqual],
7524
+ ["own_followings", isOwnFollowingsEqual]
7525
+ ];
7526
+ fieldChecks.forEach(([field, isEqual]) => {
7527
+ if (fieldsToUpdate.includes(field) && !isEqual(feed.currentState, data)) {
7528
+ fieldsToUpdateData.push(field);
7529
+ }
7530
+ });
7531
+ if (fieldsToUpdateData.length > 0) {
7532
+ const fieldsToUpdatePayload = fieldsToUpdateData.reduce(
7508
7533
  (acc, field) => {
7509
7534
  acc[field] = data[field];
7510
7535
  return acc;
7511
7536
  },
7512
7537
  {}
7513
7538
  );
7514
- feed.state.partialNext(fieldsToUpdateData);
7539
+ feed.state.partialNext(fieldsToUpdatePayload);
7515
7540
  }
7516
7541
  }
7517
7542
  }
@@ -7521,14 +7546,13 @@ class FeedsClient extends FeedsApi {
7521
7546
  };
7522
7547
  this.state = new stateStore.StateStore({
7523
7548
  connected_user: void 0,
7524
- is_ws_connection_healthy: false,
7525
- own_capabilities_by_fid: {}
7549
+ is_ws_connection_healthy: false
7526
7550
  });
7527
7551
  this.moderation = new ModerationClient(apiClient);
7528
7552
  this.tokenManager = tokenManager;
7529
7553
  this.connectionIdManager = connectionIdManager;
7530
7554
  this.polls_by_id = /* @__PURE__ */ new Map();
7531
- this.query_batch_own_capabilties_throttling_interval = options?.query_batch_own_capabilties_throttling_interval ?? DEFAULT_BATCH_OWN_CAPABILITIES_THROTTLING_INTERVAL;
7555
+ this.query_batch_own_fields_throttling_interval = options?.query_batch_own_fields_throttling_interval ?? DEFAULT_BATCH_OWN_FIELDS_THROTTLING_INTERVAL;
7532
7556
  feedsLoggerSystem.configureLoggers(options?.configure_loggers_options);
7533
7557
  this.on("all", (event) => {
7534
7558
  const fid = event.fid;
@@ -7551,7 +7575,8 @@ class FeedsClient extends FeedsApi {
7551
7575
  this.getOrCreateActiveFeed({
7552
7576
  group: event.feed.group_id,
7553
7577
  id: event.feed.id,
7554
- data: event.feed
7578
+ data: event.feed,
7579
+ fieldsToUpdate: []
7555
7580
  });
7556
7581
  break;
7557
7582
  }
@@ -7669,25 +7694,6 @@ class FeedsClient extends FeedsApi {
7669
7694
  }
7670
7695
  }
7671
7696
  }
7672
- hydrateCapabilitiesCache(feedResponses) {
7673
- let ownCapabilitiesCache = this.state.getLatestValue().own_capabilities_by_fid;
7674
- const capabilitiesToFetchQueue = [];
7675
- for (const feedResponse of feedResponses) {
7676
- const { feed, own_capabilities } = feedResponse;
7677
- if (!Object.prototype.hasOwnProperty.call(ownCapabilitiesCache, feed)) {
7678
- if (own_capabilities) {
7679
- ownCapabilitiesCache = {
7680
- ...ownCapabilitiesCache,
7681
- [feed]: own_capabilities
7682
- };
7683
- } else {
7684
- capabilitiesToFetchQueue.push(feed);
7685
- }
7686
- }
7687
- }
7688
- queueBatchedOwnCapabilities.bind(this)({ feeds: capabilitiesToFetchQueue });
7689
- this.state.partialNext({ own_capabilities_by_fid: ownCapabilitiesCache });
7690
- }
7691
7697
  async queryFeeds(request) {
7692
7698
  const response = await this._queryFeeds(request);
7693
7699
  const feedResponses = response.feeds;
@@ -7696,10 +7702,15 @@ class FeedsClient extends FeedsApi {
7696
7702
  group: feedResponse.group_id,
7697
7703
  id: feedResponse.id,
7698
7704
  data: feedResponse,
7699
- watch: request?.watch
7705
+ watch: request?.watch,
7706
+ fieldsToUpdate: [
7707
+ "own_capabilities",
7708
+ "own_follows",
7709
+ "own_membership",
7710
+ "own_followings"
7711
+ ]
7700
7712
  })
7701
7713
  );
7702
- this.hydrateCapabilitiesCache(feedResponses);
7703
7714
  return {
7704
7715
  feeds,
7705
7716
  next: response.next,
@@ -7710,13 +7721,12 @@ class FeedsClient extends FeedsApi {
7710
7721
  }
7711
7722
  async ownBatch(request) {
7712
7723
  const response = await super.ownBatch(request);
7713
- const feedResponses = Object.entries(response.data).map(
7714
- ([feed, ownFields]) => ({
7715
- feed,
7716
- own_capabilities: ownFields.own_capabilities
7717
- })
7718
- );
7719
- this.hydrateCapabilitiesCache(feedResponses);
7724
+ Object.entries(response.data).forEach(([fid, ownFields]) => {
7725
+ const feed = this.activeFeeds[fid];
7726
+ if (feed) {
7727
+ feed.state.partialNext(ownFields);
7728
+ }
7729
+ });
7720
7730
  return response;
7721
7731
  }
7722
7732
  async updateFollow(request) {
@@ -7775,7 +7785,6 @@ class FeedsClient extends FeedsApi {
7775
7785
  }
7776
7786
  async getOrCreateFeed(request) {
7777
7787
  const response = await super.getOrCreateFeed(request);
7778
- this.hydrateCapabilitiesCache([response.feed]);
7779
7788
  if (request.watch) {
7780
7789
  const feeds = this.findAllActiveFeedsByFid(
7781
7790
  `${request.feed_group_id}:${request.feed_id}`
@@ -7790,7 +7799,13 @@ class FeedsClient extends FeedsApi {
7790
7799
  this.getOrCreateActiveFeed({
7791
7800
  group: suggestion.group_id,
7792
7801
  id: suggestion.id,
7793
- data: suggestion
7802
+ data: suggestion,
7803
+ fieldsToUpdate: [
7804
+ "own_capabilities",
7805
+ "own_follows",
7806
+ "own_membership",
7807
+ "own_followings"
7808
+ ]
7794
7809
  });
7795
7810
  });
7796
7811
  return response;
@@ -7870,9 +7885,8 @@ exports.isImageFile = isImageFile;
7870
7885
  exports.isReactionResponse = isReactionResponse;
7871
7886
  exports.isVideoFile = isVideoFile;
7872
7887
  exports.isVoteAnswer = isVoteAnswer;
7873
- exports.ownFeedFields = ownFeedFields;
7874
7888
  exports.replaceUniqueArrayMerge = replaceUniqueArrayMerge;
7875
7889
  exports.shouldUpdateState = shouldUpdateState;
7876
7890
  exports.uniqueArrayMerge = uniqueArrayMerge;
7877
7891
  exports.updateEntityInArray = updateEntityInArray;
7878
- //# sourceMappingURL=feeds-client-BUsd5D-y.js.map
7892
+ //# sourceMappingURL=feeds-client-CyaHg6lu.js.map