@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.
- package/CHANGELOG.md +15 -0
- package/dist/cjs/index.js +3 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/react-bindings.js +39 -33
- package/dist/cjs/react-bindings.js.map +1 -1
- package/dist/es/index.mjs +4 -3
- package/dist/es/index.mjs.map +1 -1
- package/dist/es/react-bindings.mjs +39 -33
- package/dist/es/react-bindings.mjs.map +1 -1
- package/dist/{feeds-client-DYnxEI2D.mjs → feeds-client-C-6NrDBy.mjs} +196 -182
- package/dist/feeds-client-C-6NrDBy.mjs.map +1 -0
- package/dist/{feeds-client-BUsd5D-y.js → feeds-client-CyaHg6lu.js} +196 -182
- package/dist/feeds-client-CyaHg6lu.js.map +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/types/activity-with-state-updates/activity-with-state-updates.d.ts +1 -1
- package/dist/types/activity-with-state-updates/activity-with-state-updates.d.ts.map +1 -1
- package/dist/types/bindings/react/hooks/feed-state-hooks/index.d.ts +1 -0
- package/dist/types/bindings/react/hooks/feed-state-hooks/index.d.ts.map +1 -1
- package/dist/types/bindings/react/hooks/feed-state-hooks/useOwnCapabilities.d.ts.map +1 -1
- package/dist/types/bindings/react/hooks/feed-state-hooks/useOwnFollowings.d.ts +8 -0
- package/dist/types/bindings/react/hooks/feed-state-hooks/useOwnFollowings.d.ts.map +1 -0
- package/dist/types/common/types.d.ts +1 -1
- package/dist/types/common/types.d.ts.map +1 -1
- package/dist/types/feed/event-handlers/activity/handle-activity-added.d.ts.map +1 -1
- package/dist/types/feed/event-handlers/activity/handle-activity-updated.d.ts.map +1 -1
- package/dist/types/feed/feed.d.ts +2 -1
- package/dist/types/feed/feed.d.ts.map +1 -1
- package/dist/types/feeds-client/feeds-client.d.ts +7 -9
- package/dist/types/feeds-client/feeds-client.d.ts.map +1 -1
- package/dist/types/gen/models/index.d.ts +4 -0
- package/dist/types/gen/models/index.d.ts.map +1 -1
- package/dist/types/utils/check-own-fields-equality.d.ts +2 -0
- package/dist/types/utils/check-own-fields-equality.d.ts.map +1 -1
- package/dist/types/utils/throttling/index.d.ts +1 -1
- package/dist/types/utils/throttling/index.d.ts.map +1 -1
- package/dist/types/utils/throttling/throttled-get-batched-own-fields.d.ts +14 -0
- package/dist/types/utils/throttling/throttled-get-batched-own-fields.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/activity-with-state-updates/activity-with-state-updates.ts +7 -2
- package/src/bindings/react/hooks/feed-state-hooks/index.ts +1 -0
- package/src/bindings/react/hooks/feed-state-hooks/useOwnCapabilities.ts +14 -23
- package/src/bindings/react/hooks/feed-state-hooks/useOwnFollowings.ts +18 -0
- package/src/common/types.ts +1 -1
- package/src/feed/event-handlers/activity/handle-activity-added.ts +0 -6
- package/src/feed/event-handlers/activity/handle-activity-updated.ts +0 -4
- package/src/feed/feed.ts +51 -39
- package/src/feeds-client/feeds-client.ts +88 -91
- package/src/gen/models/index.ts +8 -0
- package/src/utils/check-own-fields-equality.ts +37 -10
- package/src/utils/throttling/index.ts +1 -1
- package/src/utils/throttling/{throttled-get-batched-own-capabilities.ts → throttled-get-batched-own-fields.ts} +10 -10
- package/dist/feeds-client-BUsd5D-y.js.map +0 -1
- package/dist/feeds-client-DYnxEI2D.mjs.map +0 -1
- package/dist/types/utils/throttling/throttled-get-batched-own-capabilities.d.ts +0 -14
- package/dist/types/utils/throttling/throttled-get-batched-own-capabilities.d.ts.map +0 -1
|
@@ -3923,7 +3923,7 @@ const getRateLimitFromResponseHeader = (response_headers) => {
|
|
|
3923
3923
|
};
|
|
3924
3924
|
return result;
|
|
3925
3925
|
};
|
|
3926
|
-
const version = "0.3.
|
|
3926
|
+
const version = "0.3.33";
|
|
3927
3927
|
const axios = axiosImport.default ?? axiosImport;
|
|
3928
3928
|
class ApiClient {
|
|
3929
3929
|
constructor(apiKey, tokenManager, connectionIdManager, options) {
|
|
@@ -4785,7 +4785,6 @@ function updateEntityInArray({
|
|
|
4785
4785
|
updatedEntities[index] = newEntity;
|
|
4786
4786
|
return { changed: true, entities: updatedEntities };
|
|
4787
4787
|
}
|
|
4788
|
-
const ownFeedFields = ["own_capabilities", "own_follows", "own_membership"];
|
|
4789
4788
|
const updateStateFollowCreated = (follow, currentState, currentFeedId, connectedUserId) => {
|
|
4790
4789
|
if (follow.status !== "accepted") {
|
|
4791
4790
|
return { changed: false, data: currentState };
|
|
@@ -5536,10 +5535,6 @@ function handleActivityAdded(event) {
|
|
|
5536
5535
|
if (result.changed) {
|
|
5537
5536
|
const activity = event.activity;
|
|
5538
5537
|
this.client.hydratePollCache([activity]);
|
|
5539
|
-
const currentFeed = activity.current_feed;
|
|
5540
|
-
if (currentFeed) {
|
|
5541
|
-
this.client.hydrateCapabilitiesCache([currentFeed]);
|
|
5542
|
-
}
|
|
5543
5538
|
this.state.partialNext({ activities: result.activities });
|
|
5544
5539
|
}
|
|
5545
5540
|
}
|
|
@@ -5651,9 +5646,6 @@ function handleActivityUpdated(payload, fromWs) {
|
|
|
5651
5646
|
];
|
|
5652
5647
|
if (result1?.changed || result2.changed) {
|
|
5653
5648
|
this.client.hydratePollCache([payload.activity]);
|
|
5654
|
-
if (payload.activity.current_feed) {
|
|
5655
|
-
this.client.hydrateCapabilitiesCache([payload.activity.current_feed]);
|
|
5656
|
-
}
|
|
5657
5649
|
this.state.partialNext({
|
|
5658
5650
|
activities: result1?.changed ? result1.entities : currentActivities,
|
|
5659
5651
|
pinned_activities: result2.entities
|
|
@@ -6238,6 +6230,91 @@ const deepEqual = (x, y) => {
|
|
|
6238
6230
|
function getOrCreateActiveFeed(...args) {
|
|
6239
6231
|
return this.getOrCreateActiveFeed(...args);
|
|
6240
6232
|
}
|
|
6233
|
+
const throttle = (fn, timeout = 200, {
|
|
6234
|
+
leading = true,
|
|
6235
|
+
trailing = false
|
|
6236
|
+
} = {}) => {
|
|
6237
|
+
let timer = null;
|
|
6238
|
+
let storedArgs = null;
|
|
6239
|
+
let storedThis = null;
|
|
6240
|
+
let lastInvokeTime;
|
|
6241
|
+
const invoke = (args, thisArg) => {
|
|
6242
|
+
lastInvokeTime = Date.now();
|
|
6243
|
+
fn.apply(thisArg, args);
|
|
6244
|
+
};
|
|
6245
|
+
const scheduleTrailing = (delay) => {
|
|
6246
|
+
if (timer) return;
|
|
6247
|
+
timer = setTimeout(() => {
|
|
6248
|
+
timer = null;
|
|
6249
|
+
if (trailing && storedArgs) {
|
|
6250
|
+
invoke(storedArgs, storedThis);
|
|
6251
|
+
storedArgs = null;
|
|
6252
|
+
storedThis = null;
|
|
6253
|
+
}
|
|
6254
|
+
}, delay);
|
|
6255
|
+
};
|
|
6256
|
+
return {
|
|
6257
|
+
throttledFn: function(...args) {
|
|
6258
|
+
const now = Date.now();
|
|
6259
|
+
const hasBeenInvoked = lastInvokeTime != null;
|
|
6260
|
+
if (!hasBeenInvoked && !leading) lastInvokeTime = now;
|
|
6261
|
+
const timeSinceLast = hasBeenInvoked ? now - lastInvokeTime : timeout;
|
|
6262
|
+
const remaining = timeout - timeSinceLast;
|
|
6263
|
+
if (trailing) {
|
|
6264
|
+
storedArgs = args;
|
|
6265
|
+
storedThis = this;
|
|
6266
|
+
}
|
|
6267
|
+
if (remaining <= 0) {
|
|
6268
|
+
if (timer) {
|
|
6269
|
+
clearTimeout(timer);
|
|
6270
|
+
timer = null;
|
|
6271
|
+
}
|
|
6272
|
+
if (leading) {
|
|
6273
|
+
if (trailing) {
|
|
6274
|
+
if (storedArgs === args) {
|
|
6275
|
+
storedArgs = null;
|
|
6276
|
+
storedThis = null;
|
|
6277
|
+
}
|
|
6278
|
+
}
|
|
6279
|
+
invoke(args, this);
|
|
6280
|
+
} else {
|
|
6281
|
+
if (trailing) scheduleTrailing(timeout);
|
|
6282
|
+
}
|
|
6283
|
+
return;
|
|
6284
|
+
}
|
|
6285
|
+
if (trailing && !timer) {
|
|
6286
|
+
scheduleTrailing(remaining);
|
|
6287
|
+
}
|
|
6288
|
+
},
|
|
6289
|
+
cancelTimer: () => {
|
|
6290
|
+
if (timer) {
|
|
6291
|
+
clearTimeout(timer);
|
|
6292
|
+
timer = null;
|
|
6293
|
+
}
|
|
6294
|
+
}
|
|
6295
|
+
};
|
|
6296
|
+
};
|
|
6297
|
+
const BATCH_OWN_FIELDS_API_LIMIT = 100;
|
|
6298
|
+
const DEFAULT_BATCH_OWN_FIELDS_THROTTLING_INTERVAL = 2e3;
|
|
6299
|
+
const queuedFeeds = /* @__PURE__ */ new Set();
|
|
6300
|
+
function queueBatchedOwnFields({ feeds }) {
|
|
6301
|
+
for (const feed of feeds) {
|
|
6302
|
+
queuedFeeds.add(feed);
|
|
6303
|
+
}
|
|
6304
|
+
if (queuedFeeds.size > 0) {
|
|
6305
|
+
this.throttledGetBatchOwnFields(
|
|
6306
|
+
[...queuedFeeds].slice(0, BATCH_OWN_FIELDS_API_LIMIT),
|
|
6307
|
+
(feedsToClear) => {
|
|
6308
|
+
for (const feed of feedsToClear) {
|
|
6309
|
+
queuedFeeds.delete(feed);
|
|
6310
|
+
}
|
|
6311
|
+
}
|
|
6312
|
+
);
|
|
6313
|
+
}
|
|
6314
|
+
}
|
|
6315
|
+
function clearQueuedFeeds() {
|
|
6316
|
+
queuedFeeds.clear();
|
|
6317
|
+
}
|
|
6241
6318
|
const _Feed = class _Feed extends FeedApi {
|
|
6242
6319
|
constructor(client, groupId, id, data, watch = false, addNewActivitiesTo = "start", activityAddedEventFilter) {
|
|
6243
6320
|
super(client, groupId, id);
|
|
@@ -6372,10 +6449,6 @@ const _Feed = class _Feed extends FeedApi {
|
|
|
6372
6449
|
currentActivityFeeds.push(activity.current_feed);
|
|
6373
6450
|
}
|
|
6374
6451
|
}
|
|
6375
|
-
this.client.hydrateCapabilitiesCache([
|
|
6376
|
-
response.feed,
|
|
6377
|
-
...currentActivityFeeds
|
|
6378
|
-
]);
|
|
6379
6452
|
if (request?.next) {
|
|
6380
6453
|
const { activities: currentActivities = [] } = this.currentState;
|
|
6381
6454
|
const result = addActivitiesToState.bind(this)(
|
|
@@ -6802,29 +6875,18 @@ const _Feed = class _Feed extends FeedApi {
|
|
|
6802
6875
|
...request,
|
|
6803
6876
|
feeds: [this.feed]
|
|
6804
6877
|
});
|
|
6805
|
-
const currentFeed = response.activity.current_feed;
|
|
6806
|
-
if (currentFeed) {
|
|
6807
|
-
this.client.hydrateCapabilitiesCache([currentFeed]);
|
|
6808
|
-
}
|
|
6809
6878
|
return response;
|
|
6810
6879
|
}
|
|
6811
6880
|
handleWSEvent(event) {
|
|
6812
6881
|
const eventHandler = this.eventHandlers[event.type];
|
|
6813
6882
|
if (eventHandler !== _Feed.noop) {
|
|
6814
|
-
if ("activity" in event && this.hasActivity(event.activity.id)) {
|
|
6883
|
+
if ("activity" in event && event.activity.feeds.length > 1 && this.hasActivity(event.activity.id)) {
|
|
6815
6884
|
const currentActivity = this.currentState.activities?.find(
|
|
6816
6885
|
(a) => a.id === event.activity.id
|
|
6817
6886
|
);
|
|
6818
|
-
if (
|
|
6887
|
+
if (!event.activity.current_feed && currentActivity?.current_feed) {
|
|
6819
6888
|
event.activity.current_feed = currentActivity.current_feed;
|
|
6820
6889
|
}
|
|
6821
|
-
if (event.activity.feeds.length === 1 && event.activity.current_feed && currentActivity?.current_feed) {
|
|
6822
|
-
ownFeedFields.forEach((field) => {
|
|
6823
|
-
if (field in currentActivity.current_feed) {
|
|
6824
|
-
event.activity.current_feed[field] = currentActivity.current_feed[field];
|
|
6825
|
-
}
|
|
6826
|
-
});
|
|
6827
|
-
}
|
|
6828
6890
|
}
|
|
6829
6891
|
eventHandler?.(event);
|
|
6830
6892
|
}
|
|
@@ -6839,7 +6901,7 @@ const _Feed = class _Feed extends FeedApi {
|
|
|
6839
6901
|
}
|
|
6840
6902
|
getOrCreateFeeds(activities, options) {
|
|
6841
6903
|
const enrichmentOptions = this.currentState.last_get_or_create_request_config?.enrichment_options;
|
|
6842
|
-
if (
|
|
6904
|
+
if (this.shouldAddToActiveFeeds(enrichmentOptions)) {
|
|
6843
6905
|
const feedsToGetOrCreate = /* @__PURE__ */ new Map();
|
|
6844
6906
|
activities.forEach((activity) => {
|
|
6845
6907
|
if (activity.current_feed && !feedsToGetOrCreate.has(activity.current_feed.feed)) {
|
|
@@ -6849,15 +6911,44 @@ const _Feed = class _Feed extends FeedApi {
|
|
|
6849
6911
|
);
|
|
6850
6912
|
}
|
|
6851
6913
|
});
|
|
6852
|
-
Array.from(feedsToGetOrCreate.values())
|
|
6914
|
+
const newFeeds = Array.from(feedsToGetOrCreate.values());
|
|
6915
|
+
const fieldsToUpdate = [];
|
|
6916
|
+
if (!options.fromWebSocket) {
|
|
6917
|
+
fieldsToUpdate.push(
|
|
6918
|
+
"own_capabilities",
|
|
6919
|
+
"own_follows",
|
|
6920
|
+
"own_membership"
|
|
6921
|
+
);
|
|
6922
|
+
if (enrichmentOptions?.enrich_own_followings) {
|
|
6923
|
+
fieldsToUpdate.push("own_followings");
|
|
6924
|
+
}
|
|
6925
|
+
}
|
|
6926
|
+
newFeeds.forEach((feed) => {
|
|
6853
6927
|
getOrCreateActiveFeed.bind(this.client)({
|
|
6854
6928
|
group: feed.group_id,
|
|
6855
6929
|
id: feed.id,
|
|
6856
6930
|
data: feed,
|
|
6857
|
-
|
|
6931
|
+
fieldsToUpdate
|
|
6858
6932
|
});
|
|
6859
6933
|
});
|
|
6934
|
+
if (options.fromWebSocket) {
|
|
6935
|
+
const uninitializedFeeds = newFeeds.filter((feedResponse) => {
|
|
6936
|
+
const feed = this.client.feed(feedResponse.group_id, feedResponse.id);
|
|
6937
|
+
return feed.currentState.own_capabilities === void 0;
|
|
6938
|
+
});
|
|
6939
|
+
if (uninitializedFeeds.length > 0) {
|
|
6940
|
+
queueBatchedOwnFields.bind(this.client)({
|
|
6941
|
+
feeds: uninitializedFeeds.map((feed) => feed.feed)
|
|
6942
|
+
});
|
|
6943
|
+
}
|
|
6944
|
+
}
|
|
6945
|
+
}
|
|
6946
|
+
}
|
|
6947
|
+
shouldAddToActiveFeeds(enrichmentOptions) {
|
|
6948
|
+
if (!enrichmentOptions) {
|
|
6949
|
+
return true;
|
|
6860
6950
|
}
|
|
6951
|
+
return !enrichmentOptions?.skip_activity && !enrichmentOptions?.skip_activity_current_feed && !enrichmentOptions?.skip_all;
|
|
6861
6952
|
}
|
|
6862
6953
|
};
|
|
6863
6954
|
_Feed.noop = () => {
|
|
@@ -6912,91 +7003,6 @@ function updateCommentCount({
|
|
|
6912
7003
|
}, false);
|
|
6913
7004
|
}
|
|
6914
7005
|
}
|
|
6915
|
-
const throttle = (fn, timeout = 200, {
|
|
6916
|
-
leading = true,
|
|
6917
|
-
trailing = false
|
|
6918
|
-
} = {}) => {
|
|
6919
|
-
let timer = null;
|
|
6920
|
-
let storedArgs = null;
|
|
6921
|
-
let storedThis = null;
|
|
6922
|
-
let lastInvokeTime;
|
|
6923
|
-
const invoke = (args, thisArg) => {
|
|
6924
|
-
lastInvokeTime = Date.now();
|
|
6925
|
-
fn.apply(thisArg, args);
|
|
6926
|
-
};
|
|
6927
|
-
const scheduleTrailing = (delay) => {
|
|
6928
|
-
if (timer) return;
|
|
6929
|
-
timer = setTimeout(() => {
|
|
6930
|
-
timer = null;
|
|
6931
|
-
if (trailing && storedArgs) {
|
|
6932
|
-
invoke(storedArgs, storedThis);
|
|
6933
|
-
storedArgs = null;
|
|
6934
|
-
storedThis = null;
|
|
6935
|
-
}
|
|
6936
|
-
}, delay);
|
|
6937
|
-
};
|
|
6938
|
-
return {
|
|
6939
|
-
throttledFn: function(...args) {
|
|
6940
|
-
const now = Date.now();
|
|
6941
|
-
const hasBeenInvoked = lastInvokeTime != null;
|
|
6942
|
-
if (!hasBeenInvoked && !leading) lastInvokeTime = now;
|
|
6943
|
-
const timeSinceLast = hasBeenInvoked ? now - lastInvokeTime : timeout;
|
|
6944
|
-
const remaining = timeout - timeSinceLast;
|
|
6945
|
-
if (trailing) {
|
|
6946
|
-
storedArgs = args;
|
|
6947
|
-
storedThis = this;
|
|
6948
|
-
}
|
|
6949
|
-
if (remaining <= 0) {
|
|
6950
|
-
if (timer) {
|
|
6951
|
-
clearTimeout(timer);
|
|
6952
|
-
timer = null;
|
|
6953
|
-
}
|
|
6954
|
-
if (leading) {
|
|
6955
|
-
if (trailing) {
|
|
6956
|
-
if (storedArgs === args) {
|
|
6957
|
-
storedArgs = null;
|
|
6958
|
-
storedThis = null;
|
|
6959
|
-
}
|
|
6960
|
-
}
|
|
6961
|
-
invoke(args, this);
|
|
6962
|
-
} else {
|
|
6963
|
-
if (trailing) scheduleTrailing(timeout);
|
|
6964
|
-
}
|
|
6965
|
-
return;
|
|
6966
|
-
}
|
|
6967
|
-
if (trailing && !timer) {
|
|
6968
|
-
scheduleTrailing(remaining);
|
|
6969
|
-
}
|
|
6970
|
-
},
|
|
6971
|
-
cancelTimer: () => {
|
|
6972
|
-
if (timer) {
|
|
6973
|
-
clearTimeout(timer);
|
|
6974
|
-
timer = null;
|
|
6975
|
-
}
|
|
6976
|
-
}
|
|
6977
|
-
};
|
|
6978
|
-
};
|
|
6979
|
-
const BATCH_OWN_CAPABILITIES_API_LIMIT = 100;
|
|
6980
|
-
const DEFAULT_BATCH_OWN_CAPABILITIES_THROTTLING_INTERVAL = 2e3;
|
|
6981
|
-
const queuedFeeds = /* @__PURE__ */ new Set();
|
|
6982
|
-
function queueBatchedOwnCapabilities({ feeds }) {
|
|
6983
|
-
for (const feed of feeds) {
|
|
6984
|
-
queuedFeeds.add(feed);
|
|
6985
|
-
}
|
|
6986
|
-
if (queuedFeeds.size > 0) {
|
|
6987
|
-
this.throttledGetBatchOwnCapabilities(
|
|
6988
|
-
[...queuedFeeds].slice(0, BATCH_OWN_CAPABILITIES_API_LIMIT),
|
|
6989
|
-
(feedsToClear) => {
|
|
6990
|
-
for (const feed of feedsToClear) {
|
|
6991
|
-
queuedFeeds.delete(feed);
|
|
6992
|
-
}
|
|
6993
|
-
}
|
|
6994
|
-
);
|
|
6995
|
-
}
|
|
6996
|
-
}
|
|
6997
|
-
function clearQueuedFeeds() {
|
|
6998
|
-
queuedFeeds.clear();
|
|
6999
|
-
}
|
|
7000
7006
|
function connectActivityToFeed({
|
|
7001
7007
|
fid
|
|
7002
7008
|
}) {
|
|
@@ -7121,8 +7127,13 @@ class ActivityWithStateUpdates {
|
|
|
7121
7127
|
initialState
|
|
7122
7128
|
}) {
|
|
7123
7129
|
this.feed = connectActivityToFeed.call(this.feedsClient, { fid });
|
|
7130
|
+
const { activities } = addActivitiesToState.bind(this.feed)(
|
|
7131
|
+
[initialState],
|
|
7132
|
+
[],
|
|
7133
|
+
"start"
|
|
7134
|
+
);
|
|
7124
7135
|
this.feed?.state.partialNext({
|
|
7125
|
-
activities
|
|
7136
|
+
activities
|
|
7126
7137
|
});
|
|
7127
7138
|
}
|
|
7128
7139
|
subscribeToFeedState() {
|
|
@@ -7147,20 +7158,20 @@ class ActivityWithStateUpdates {
|
|
|
7147
7158
|
function getFeed() {
|
|
7148
7159
|
return this.feed;
|
|
7149
7160
|
}
|
|
7150
|
-
const
|
|
7161
|
+
const areFollowArraysEqual = (currentFollows, newFollows) => {
|
|
7151
7162
|
const existingFollows = new Set(
|
|
7152
|
-
|
|
7163
|
+
currentFollows?.map(
|
|
7153
7164
|
(f) => `${f.source_feed.feed}:${f.target_feed.feed}:${f.updated_at.getTime()}`
|
|
7154
7165
|
)
|
|
7155
7166
|
);
|
|
7156
|
-
const
|
|
7157
|
-
|
|
7167
|
+
const newFollowsSet = new Set(
|
|
7168
|
+
newFollows?.map(
|
|
7158
7169
|
(f) => `${f.source_feed.feed}:${f.target_feed.feed}:${f.updated_at.getTime()}`
|
|
7159
7170
|
)
|
|
7160
7171
|
);
|
|
7161
|
-
if (existingFollows.size ===
|
|
7172
|
+
if (existingFollows.size === newFollowsSet.size) {
|
|
7162
7173
|
const areEqual = Array.from(existingFollows).every(
|
|
7163
|
-
(f) =>
|
|
7174
|
+
(f) => newFollowsSet.has(f)
|
|
7164
7175
|
);
|
|
7165
7176
|
if (areEqual) {
|
|
7166
7177
|
return true;
|
|
@@ -7168,9 +7179,21 @@ const isOwnFollowsEqual = (currentState, newState) => {
|
|
|
7168
7179
|
}
|
|
7169
7180
|
return false;
|
|
7170
7181
|
};
|
|
7182
|
+
const isOwnFollowsEqual = (currentState, newState) => {
|
|
7183
|
+
return areFollowArraysEqual(currentState.own_follows, newState.own_follows);
|
|
7184
|
+
};
|
|
7171
7185
|
const isOwnMembershipEqual = (currentState, newState) => {
|
|
7172
7186
|
return (currentState.own_membership?.updated_at.getTime() ?? 0) === (newState.own_membership?.updated_at.getTime() ?? 0);
|
|
7173
7187
|
};
|
|
7188
|
+
const isOwnCapabilitiesEqual = (currentState, newState) => {
|
|
7189
|
+
return [...currentState.own_capabilities ?? []].sort().join(",") === [...newState.own_capabilities ?? []].sort().join(",");
|
|
7190
|
+
};
|
|
7191
|
+
const isOwnFollowingsEqual = (currentState, newState) => {
|
|
7192
|
+
return areFollowArraysEqual(
|
|
7193
|
+
currentState.own_followings,
|
|
7194
|
+
newState.own_followings
|
|
7195
|
+
);
|
|
7196
|
+
};
|
|
7174
7197
|
class FeedsClient extends FeedsApi {
|
|
7175
7198
|
constructor(apiKey, options) {
|
|
7176
7199
|
const tokenManager = new TokenManager();
|
|
@@ -7186,11 +7209,8 @@ class FeedsClient extends FeedsApi {
|
|
|
7186
7209
|
this.activeActivities = {};
|
|
7187
7210
|
this.activeFeeds = {};
|
|
7188
7211
|
this.healthyConnectionChangedEventCount = 0;
|
|
7189
|
-
this.
|
|
7190
|
-
const {
|
|
7191
|
-
throttledFn: throttledGetBatchOwnCapabilities,
|
|
7192
|
-
cancelTimer: cancel
|
|
7193
|
-
} = throttle(
|
|
7212
|
+
this.setGetBatchOwnFieldsThrottlingInterval = (throttlingMs) => {
|
|
7213
|
+
const { throttledFn: throttledGetBatchOwnFields, cancelTimer: cancel } = throttle(
|
|
7194
7214
|
(feeds, callback) => {
|
|
7195
7215
|
this.ownBatch({
|
|
7196
7216
|
feeds
|
|
@@ -7206,8 +7226,8 @@ class FeedsClient extends FeedsApi {
|
|
|
7206
7226
|
throttlingMs,
|
|
7207
7227
|
{ trailing: true }
|
|
7208
7228
|
);
|
|
7209
|
-
this.
|
|
7210
|
-
this.
|
|
7229
|
+
this.throttledGetBatchOwnFields = throttledGetBatchOwnFields;
|
|
7230
|
+
this.cancelGetBatchOwnFieldsTimer = cancel;
|
|
7211
7231
|
};
|
|
7212
7232
|
this.recoverOnReconnect = async () => {
|
|
7213
7233
|
this.healthyConnectionChangedEventCount++;
|
|
@@ -7239,8 +7259,8 @@ class FeedsClient extends FeedsApi {
|
|
|
7239
7259
|
throw new Error(`Can't connect a new user, call "disconnectUser" first`);
|
|
7240
7260
|
}
|
|
7241
7261
|
this.tokenManager.setTokenOrProvider(tokenProvider);
|
|
7242
|
-
this.
|
|
7243
|
-
this.
|
|
7262
|
+
this.setGetBatchOwnFieldsThrottlingInterval(
|
|
7263
|
+
this.query_batch_own_fields_throttling_interval
|
|
7244
7264
|
);
|
|
7245
7265
|
try {
|
|
7246
7266
|
addConnectionEventListeners(this.updateNetworkConnectionStatus);
|
|
@@ -7412,10 +7432,9 @@ class FeedsClient extends FeedsApi {
|
|
|
7412
7432
|
this.activeFeeds = {};
|
|
7413
7433
|
this.state.partialNext({
|
|
7414
7434
|
connected_user: void 0,
|
|
7415
|
-
is_ws_connection_healthy: false
|
|
7416
|
-
own_capabilities_by_fid: {}
|
|
7435
|
+
is_ws_connection_healthy: false
|
|
7417
7436
|
});
|
|
7418
|
-
this.
|
|
7437
|
+
this.cancelGetBatchOwnFieldsTimer();
|
|
7419
7438
|
clearQueuedFeeds();
|
|
7420
7439
|
};
|
|
7421
7440
|
this.on = this.eventDispatcher.on;
|
|
@@ -7424,7 +7443,8 @@ class FeedsClient extends FeedsApi {
|
|
|
7424
7443
|
return this.getOrCreateActiveFeed({
|
|
7425
7444
|
group: groupId,
|
|
7426
7445
|
id,
|
|
7427
|
-
options: options2
|
|
7446
|
+
options: options2,
|
|
7447
|
+
fieldsToUpdate: []
|
|
7428
7448
|
});
|
|
7429
7449
|
};
|
|
7430
7450
|
this.activityWithStateUpdates = (id) => {
|
|
@@ -7448,7 +7468,7 @@ class FeedsClient extends FeedsApi {
|
|
|
7448
7468
|
data,
|
|
7449
7469
|
watch,
|
|
7450
7470
|
options: options2,
|
|
7451
|
-
|
|
7471
|
+
fieldsToUpdate
|
|
7452
7472
|
}) => {
|
|
7453
7473
|
const fid = `${group}:${id}`;
|
|
7454
7474
|
let isCreated = false;
|
|
@@ -7477,23 +7497,28 @@ class FeedsClient extends FeedsApi {
|
|
|
7477
7497
|
if (!isCreated && data) {
|
|
7478
7498
|
if ((feed.currentState.updated_at?.getTime() ?? 0) < data.updated_at.getTime()) {
|
|
7479
7499
|
handleFeedUpdated.call(feed, { feed: data });
|
|
7480
|
-
} else if ((feed.currentState.updated_at?.getTime() ?? 0) === data.updated_at.getTime()
|
|
7481
|
-
const
|
|
7482
|
-
|
|
7483
|
-
|
|
7484
|
-
|
|
7485
|
-
|
|
7486
|
-
|
|
7487
|
-
|
|
7488
|
-
|
|
7489
|
-
|
|
7500
|
+
} else if ((feed.currentState.updated_at?.getTime() ?? 0) === data.updated_at.getTime()) {
|
|
7501
|
+
const fieldsToUpdateData = [];
|
|
7502
|
+
const fieldChecks = [
|
|
7503
|
+
["own_capabilities", isOwnCapabilitiesEqual],
|
|
7504
|
+
["own_follows", isOwnFollowsEqual],
|
|
7505
|
+
["own_membership", isOwnMembershipEqual],
|
|
7506
|
+
["own_followings", isOwnFollowingsEqual]
|
|
7507
|
+
];
|
|
7508
|
+
fieldChecks.forEach(([field, isEqual]) => {
|
|
7509
|
+
if (fieldsToUpdate.includes(field) && !isEqual(feed.currentState, data)) {
|
|
7510
|
+
fieldsToUpdateData.push(field);
|
|
7511
|
+
}
|
|
7512
|
+
});
|
|
7513
|
+
if (fieldsToUpdateData.length > 0) {
|
|
7514
|
+
const fieldsToUpdatePayload = fieldsToUpdateData.reduce(
|
|
7490
7515
|
(acc, field) => {
|
|
7491
7516
|
acc[field] = data[field];
|
|
7492
7517
|
return acc;
|
|
7493
7518
|
},
|
|
7494
7519
|
{}
|
|
7495
7520
|
);
|
|
7496
|
-
feed.state.partialNext(
|
|
7521
|
+
feed.state.partialNext(fieldsToUpdatePayload);
|
|
7497
7522
|
}
|
|
7498
7523
|
}
|
|
7499
7524
|
}
|
|
@@ -7503,14 +7528,13 @@ class FeedsClient extends FeedsApi {
|
|
|
7503
7528
|
};
|
|
7504
7529
|
this.state = new StateStore({
|
|
7505
7530
|
connected_user: void 0,
|
|
7506
|
-
is_ws_connection_healthy: false
|
|
7507
|
-
own_capabilities_by_fid: {}
|
|
7531
|
+
is_ws_connection_healthy: false
|
|
7508
7532
|
});
|
|
7509
7533
|
this.moderation = new ModerationClient(apiClient);
|
|
7510
7534
|
this.tokenManager = tokenManager;
|
|
7511
7535
|
this.connectionIdManager = connectionIdManager;
|
|
7512
7536
|
this.polls_by_id = /* @__PURE__ */ new Map();
|
|
7513
|
-
this.
|
|
7537
|
+
this.query_batch_own_fields_throttling_interval = options?.query_batch_own_fields_throttling_interval ?? DEFAULT_BATCH_OWN_FIELDS_THROTTLING_INTERVAL;
|
|
7514
7538
|
feedsLoggerSystem.configureLoggers(options?.configure_loggers_options);
|
|
7515
7539
|
this.on("all", (event) => {
|
|
7516
7540
|
const fid = event.fid;
|
|
@@ -7533,7 +7557,8 @@ class FeedsClient extends FeedsApi {
|
|
|
7533
7557
|
this.getOrCreateActiveFeed({
|
|
7534
7558
|
group: event.feed.group_id,
|
|
7535
7559
|
id: event.feed.id,
|
|
7536
|
-
data: event.feed
|
|
7560
|
+
data: event.feed,
|
|
7561
|
+
fieldsToUpdate: []
|
|
7537
7562
|
});
|
|
7538
7563
|
break;
|
|
7539
7564
|
}
|
|
@@ -7651,25 +7676,6 @@ class FeedsClient extends FeedsApi {
|
|
|
7651
7676
|
}
|
|
7652
7677
|
}
|
|
7653
7678
|
}
|
|
7654
|
-
hydrateCapabilitiesCache(feedResponses) {
|
|
7655
|
-
let ownCapabilitiesCache = this.state.getLatestValue().own_capabilities_by_fid;
|
|
7656
|
-
const capabilitiesToFetchQueue = [];
|
|
7657
|
-
for (const feedResponse of feedResponses) {
|
|
7658
|
-
const { feed, own_capabilities } = feedResponse;
|
|
7659
|
-
if (!Object.prototype.hasOwnProperty.call(ownCapabilitiesCache, feed)) {
|
|
7660
|
-
if (own_capabilities) {
|
|
7661
|
-
ownCapabilitiesCache = {
|
|
7662
|
-
...ownCapabilitiesCache,
|
|
7663
|
-
[feed]: own_capabilities
|
|
7664
|
-
};
|
|
7665
|
-
} else {
|
|
7666
|
-
capabilitiesToFetchQueue.push(feed);
|
|
7667
|
-
}
|
|
7668
|
-
}
|
|
7669
|
-
}
|
|
7670
|
-
queueBatchedOwnCapabilities.bind(this)({ feeds: capabilitiesToFetchQueue });
|
|
7671
|
-
this.state.partialNext({ own_capabilities_by_fid: ownCapabilitiesCache });
|
|
7672
|
-
}
|
|
7673
7679
|
async queryFeeds(request) {
|
|
7674
7680
|
const response = await this._queryFeeds(request);
|
|
7675
7681
|
const feedResponses = response.feeds;
|
|
@@ -7678,10 +7684,15 @@ class FeedsClient extends FeedsApi {
|
|
|
7678
7684
|
group: feedResponse.group_id,
|
|
7679
7685
|
id: feedResponse.id,
|
|
7680
7686
|
data: feedResponse,
|
|
7681
|
-
watch: request?.watch
|
|
7687
|
+
watch: request?.watch,
|
|
7688
|
+
fieldsToUpdate: [
|
|
7689
|
+
"own_capabilities",
|
|
7690
|
+
"own_follows",
|
|
7691
|
+
"own_membership",
|
|
7692
|
+
"own_followings"
|
|
7693
|
+
]
|
|
7682
7694
|
})
|
|
7683
7695
|
);
|
|
7684
|
-
this.hydrateCapabilitiesCache(feedResponses);
|
|
7685
7696
|
return {
|
|
7686
7697
|
feeds,
|
|
7687
7698
|
next: response.next,
|
|
@@ -7692,13 +7703,12 @@ class FeedsClient extends FeedsApi {
|
|
|
7692
7703
|
}
|
|
7693
7704
|
async ownBatch(request) {
|
|
7694
7705
|
const response = await super.ownBatch(request);
|
|
7695
|
-
|
|
7696
|
-
|
|
7697
|
-
|
|
7698
|
-
|
|
7699
|
-
}
|
|
7700
|
-
);
|
|
7701
|
-
this.hydrateCapabilitiesCache(feedResponses);
|
|
7706
|
+
Object.entries(response.data).forEach(([fid, ownFields]) => {
|
|
7707
|
+
const feed = this.activeFeeds[fid];
|
|
7708
|
+
if (feed) {
|
|
7709
|
+
feed.state.partialNext(ownFields);
|
|
7710
|
+
}
|
|
7711
|
+
});
|
|
7702
7712
|
return response;
|
|
7703
7713
|
}
|
|
7704
7714
|
async updateFollow(request) {
|
|
@@ -7757,7 +7767,6 @@ class FeedsClient extends FeedsApi {
|
|
|
7757
7767
|
}
|
|
7758
7768
|
async getOrCreateFeed(request) {
|
|
7759
7769
|
const response = await super.getOrCreateFeed(request);
|
|
7760
|
-
this.hydrateCapabilitiesCache([response.feed]);
|
|
7761
7770
|
if (request.watch) {
|
|
7762
7771
|
const feeds = this.findAllActiveFeedsByFid(
|
|
7763
7772
|
`${request.feed_group_id}:${request.feed_id}`
|
|
@@ -7772,7 +7781,13 @@ class FeedsClient extends FeedsApi {
|
|
|
7772
7781
|
this.getOrCreateActiveFeed({
|
|
7773
7782
|
group: suggestion.group_id,
|
|
7774
7783
|
id: suggestion.id,
|
|
7775
|
-
data: suggestion
|
|
7784
|
+
data: suggestion,
|
|
7785
|
+
fieldsToUpdate: [
|
|
7786
|
+
"own_capabilities",
|
|
7787
|
+
"own_follows",
|
|
7788
|
+
"own_membership",
|
|
7789
|
+
"own_followings"
|
|
7790
|
+
]
|
|
7776
7791
|
});
|
|
7777
7792
|
});
|
|
7778
7793
|
return response;
|
|
@@ -7854,9 +7869,8 @@ export {
|
|
|
7854
7869
|
updateEntityInArray as l,
|
|
7855
7870
|
feedsLoggerSystem as m,
|
|
7856
7871
|
ensureExhausted as n,
|
|
7857
|
-
ownFeedFields as o,
|
|
7858
7872
|
replaceUniqueArrayMerge as r,
|
|
7859
7873
|
shouldUpdateState as s,
|
|
7860
7874
|
uniqueArrayMerge as u
|
|
7861
7875
|
};
|
|
7862
|
-
//# sourceMappingURL=feeds-client-
|
|
7876
|
+
//# sourceMappingURL=feeds-client-C-6NrDBy.mjs.map
|