@stream-io/feeds-client 0.3.32 → 0.3.34
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 +18 -0
- package/README.md +3 -2
- package/dist/cjs/index.js +3 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/react-bindings.js +40 -36
- 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 +40 -36
- package/dist/es/react-bindings.mjs.map +1 -1
- package/dist/{feeds-client-BNhvggk2.mjs → feeds-client-C-2_fdH1.mjs} +229 -209
- package/dist/feeds-client-C-2_fdH1.mjs.map +1 -0
- package/dist/{feeds-client-B9rwEWH3.js → feeds-client-Xj6kDjVH.js} +229 -209
- package/dist/feeds-client-Xj6kDjVH.js.map +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/types/activity-with-state-updates/activity-with-state-updates.d.ts +4 -2
- 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/bindings/react/hooks/useCreateFeedsClient.d.ts.map +1 -1
- 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/active-activity.d.ts +2 -1
- package/dist/types/feeds-client/active-activity.d.ts.map +1 -1
- package/dist/types/feeds-client/feeds-client.d.ts +14 -12
- package/dist/types/feeds-client/feeds-client.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 +17 -3
- 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/bindings/react/hooks/useCreateFeedsClient.ts +1 -3
- 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 +53 -39
- package/src/feeds-client/active-activity.ts +8 -4
- package/src/feeds-client/feeds-client.ts +110 -114
- 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-B9rwEWH3.js.map +0 -1
- package/dist/feeds-client-BNhvggk2.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
|
@@ -3941,7 +3941,7 @@ const getRateLimitFromResponseHeader = (response_headers) => {
|
|
|
3941
3941
|
};
|
|
3942
3942
|
return result;
|
|
3943
3943
|
};
|
|
3944
|
-
const version = "0.3.
|
|
3944
|
+
const version = "0.3.34";
|
|
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 (
|
|
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 (
|
|
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,16 +6929,47 @@ const _Feed = class _Feed extends FeedApi {
|
|
|
6867
6929
|
);
|
|
6868
6930
|
}
|
|
6869
6931
|
});
|
|
6870
|
-
Array.from(feedsToGetOrCreate.values())
|
|
6932
|
+
const newFeeds = Array.from(feedsToGetOrCreate.values());
|
|
6933
|
+
const fieldsToUpdate = [];
|
|
6934
|
+
if (!options.fromWebSocket) {
|
|
6935
|
+
fieldsToUpdate.push("own_membership");
|
|
6936
|
+
if (!enrichmentOptions?.skip_own_capabilities) {
|
|
6937
|
+
fieldsToUpdate.push("own_capabilities");
|
|
6938
|
+
}
|
|
6939
|
+
if (!enrichmentOptions?.skip_own_follows) {
|
|
6940
|
+
fieldsToUpdate.push("own_follows");
|
|
6941
|
+
}
|
|
6942
|
+
if (enrichmentOptions?.enrich_own_followings) {
|
|
6943
|
+
fieldsToUpdate.push("own_followings");
|
|
6944
|
+
}
|
|
6945
|
+
}
|
|
6946
|
+
newFeeds.forEach((feed) => {
|
|
6871
6947
|
getOrCreateActiveFeed.bind(this.client)({
|
|
6872
6948
|
group: feed.group_id,
|
|
6873
6949
|
id: feed.id,
|
|
6874
6950
|
data: feed,
|
|
6875
|
-
|
|
6951
|
+
fieldsToUpdate
|
|
6876
6952
|
});
|
|
6877
6953
|
});
|
|
6954
|
+
if (options.fromWebSocket) {
|
|
6955
|
+
const uninitializedFeeds = newFeeds.filter((feedResponse) => {
|
|
6956
|
+
const feed = this.client.feed(feedResponse.group_id, feedResponse.id);
|
|
6957
|
+
return feed.currentState.own_capabilities === void 0;
|
|
6958
|
+
});
|
|
6959
|
+
if (uninitializedFeeds.length > 0) {
|
|
6960
|
+
queueBatchedOwnFields.bind(this.client)({
|
|
6961
|
+
feeds: uninitializedFeeds.map((feed) => feed.feed)
|
|
6962
|
+
});
|
|
6963
|
+
}
|
|
6964
|
+
}
|
|
6878
6965
|
}
|
|
6879
6966
|
}
|
|
6967
|
+
shouldAddToActiveFeeds(enrichmentOptions) {
|
|
6968
|
+
if (!enrichmentOptions) {
|
|
6969
|
+
return true;
|
|
6970
|
+
}
|
|
6971
|
+
return !enrichmentOptions?.skip_activity && !enrichmentOptions?.skip_activity_current_feed && !enrichmentOptions?.skip_all;
|
|
6972
|
+
}
|
|
6880
6973
|
};
|
|
6881
6974
|
_Feed.noop = () => {
|
|
6882
6975
|
};
|
|
@@ -6930,91 +7023,6 @@ function updateCommentCount({
|
|
|
6930
7023
|
}, false);
|
|
6931
7024
|
}
|
|
6932
7025
|
}
|
|
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
7026
|
function connectActivityToFeed({
|
|
7019
7027
|
fid
|
|
7020
7028
|
}) {
|
|
@@ -7038,14 +7046,14 @@ function isAnyFeedWatched(fids) {
|
|
|
7038
7046
|
}
|
|
7039
7047
|
return false;
|
|
7040
7048
|
}
|
|
7041
|
-
function disconnectActivityFromFeed(
|
|
7042
|
-
const
|
|
7043
|
-
if (
|
|
7044
|
-
|
|
7049
|
+
function disconnectActivityFromFeed(activity) {
|
|
7050
|
+
const index = this.activeActivities.indexOf(activity);
|
|
7051
|
+
if (index !== -1) {
|
|
7052
|
+
this.activeActivities.splice(index, 1);
|
|
7045
7053
|
}
|
|
7046
7054
|
}
|
|
7047
7055
|
class ActivityWithStateUpdates {
|
|
7048
|
-
constructor(id, feedsClient) {
|
|
7056
|
+
constructor(id, feedsClient, { fromResponse } = { fromResponse: void 0 }) {
|
|
7049
7057
|
this.id = id;
|
|
7050
7058
|
this.feedsClient = feedsClient;
|
|
7051
7059
|
this.state = new stateStore.StateStore({
|
|
@@ -7053,6 +7061,13 @@ class ActivityWithStateUpdates {
|
|
|
7053
7061
|
comments_by_entity_id: {},
|
|
7054
7062
|
is_loading: false
|
|
7055
7063
|
});
|
|
7064
|
+
if (fromResponse) {
|
|
7065
|
+
this.setFeed({
|
|
7066
|
+
fid: fromResponse.feeds[0],
|
|
7067
|
+
initialState: fromResponse
|
|
7068
|
+
});
|
|
7069
|
+
this.subscribeToFeedState();
|
|
7070
|
+
}
|
|
7056
7071
|
}
|
|
7057
7072
|
get currentState() {
|
|
7058
7073
|
return this.state.getLatestValue();
|
|
@@ -7121,7 +7136,7 @@ class ActivityWithStateUpdates {
|
|
|
7121
7136
|
}
|
|
7122
7137
|
dispose() {
|
|
7123
7138
|
this.unsubscribeFromFeedState?.();
|
|
7124
|
-
disconnectActivityFromFeed.call(this.feedsClient, this
|
|
7139
|
+
disconnectActivityFromFeed.call(this.feedsClient, this);
|
|
7125
7140
|
}
|
|
7126
7141
|
/**
|
|
7127
7142
|
* @internal
|
|
@@ -7139,8 +7154,13 @@ class ActivityWithStateUpdates {
|
|
|
7139
7154
|
initialState
|
|
7140
7155
|
}) {
|
|
7141
7156
|
this.feed = connectActivityToFeed.call(this.feedsClient, { fid });
|
|
7157
|
+
const { activities } = addActivitiesToState.bind(this.feed)(
|
|
7158
|
+
[initialState],
|
|
7159
|
+
[],
|
|
7160
|
+
"start"
|
|
7161
|
+
);
|
|
7142
7162
|
this.feed?.state.partialNext({
|
|
7143
|
-
activities
|
|
7163
|
+
activities
|
|
7144
7164
|
});
|
|
7145
7165
|
}
|
|
7146
7166
|
subscribeToFeedState() {
|
|
@@ -7165,20 +7185,20 @@ class ActivityWithStateUpdates {
|
|
|
7165
7185
|
function getFeed() {
|
|
7166
7186
|
return this.feed;
|
|
7167
7187
|
}
|
|
7168
|
-
const
|
|
7188
|
+
const areFollowArraysEqual = (currentFollows, newFollows) => {
|
|
7169
7189
|
const existingFollows = new Set(
|
|
7170
|
-
|
|
7190
|
+
currentFollows?.map(
|
|
7171
7191
|
(f) => `${f.source_feed.feed}:${f.target_feed.feed}:${f.updated_at.getTime()}`
|
|
7172
7192
|
)
|
|
7173
7193
|
);
|
|
7174
|
-
const
|
|
7175
|
-
|
|
7194
|
+
const newFollowsSet = new Set(
|
|
7195
|
+
newFollows?.map(
|
|
7176
7196
|
(f) => `${f.source_feed.feed}:${f.target_feed.feed}:${f.updated_at.getTime()}`
|
|
7177
7197
|
)
|
|
7178
7198
|
);
|
|
7179
|
-
if (existingFollows.size ===
|
|
7199
|
+
if (existingFollows.size === newFollowsSet.size) {
|
|
7180
7200
|
const areEqual = Array.from(existingFollows).every(
|
|
7181
|
-
(f) =>
|
|
7201
|
+
(f) => newFollowsSet.has(f)
|
|
7182
7202
|
);
|
|
7183
7203
|
if (areEqual) {
|
|
7184
7204
|
return true;
|
|
@@ -7186,9 +7206,21 @@ const isOwnFollowsEqual = (currentState, newState) => {
|
|
|
7186
7206
|
}
|
|
7187
7207
|
return false;
|
|
7188
7208
|
};
|
|
7209
|
+
const isOwnFollowsEqual = (currentState, newState) => {
|
|
7210
|
+
return areFollowArraysEqual(currentState.own_follows, newState.own_follows);
|
|
7211
|
+
};
|
|
7189
7212
|
const isOwnMembershipEqual = (currentState, newState) => {
|
|
7190
7213
|
return (currentState.own_membership?.updated_at.getTime() ?? 0) === (newState.own_membership?.updated_at.getTime() ?? 0);
|
|
7191
7214
|
};
|
|
7215
|
+
const isOwnCapabilitiesEqual = (currentState, newState) => {
|
|
7216
|
+
return [...currentState.own_capabilities ?? []].sort().join(",") === [...newState.own_capabilities ?? []].sort().join(",");
|
|
7217
|
+
};
|
|
7218
|
+
const isOwnFollowingsEqual = (currentState, newState) => {
|
|
7219
|
+
return areFollowArraysEqual(
|
|
7220
|
+
currentState.own_followings,
|
|
7221
|
+
newState.own_followings
|
|
7222
|
+
);
|
|
7223
|
+
};
|
|
7192
7224
|
class FeedsClient extends FeedsApi {
|
|
7193
7225
|
constructor(apiKey, options) {
|
|
7194
7226
|
const tokenManager = new TokenManager();
|
|
@@ -7201,14 +7233,11 @@ class FeedsClient extends FeedsApi {
|
|
|
7201
7233
|
);
|
|
7202
7234
|
super(apiClient);
|
|
7203
7235
|
this.eventDispatcher = new EventDispatcher();
|
|
7204
|
-
this.activeActivities =
|
|
7236
|
+
this.activeActivities = [];
|
|
7205
7237
|
this.activeFeeds = {};
|
|
7206
7238
|
this.healthyConnectionChangedEventCount = 0;
|
|
7207
|
-
this.
|
|
7208
|
-
const {
|
|
7209
|
-
throttledFn: throttledGetBatchOwnCapabilities,
|
|
7210
|
-
cancelTimer: cancel
|
|
7211
|
-
} = throttle(
|
|
7239
|
+
this.setGetBatchOwnFieldsThrottlingInterval = (throttlingMs) => {
|
|
7240
|
+
const { throttledFn: throttledGetBatchOwnFields, cancelTimer: cancel } = throttle(
|
|
7212
7241
|
(feeds, callback) => {
|
|
7213
7242
|
this.ownBatch({
|
|
7214
7243
|
feeds
|
|
@@ -7224,23 +7253,22 @@ class FeedsClient extends FeedsApi {
|
|
|
7224
7253
|
throttlingMs,
|
|
7225
7254
|
{ trailing: true }
|
|
7226
7255
|
);
|
|
7227
|
-
this.
|
|
7228
|
-
this.
|
|
7256
|
+
this.throttledGetBatchOwnFields = throttledGetBatchOwnFields;
|
|
7257
|
+
this.cancelGetBatchOwnFieldsTimer = cancel;
|
|
7229
7258
|
};
|
|
7230
7259
|
this.recoverOnReconnect = async () => {
|
|
7231
7260
|
this.healthyConnectionChangedEventCount++;
|
|
7232
7261
|
if (this.healthyConnectionChangedEventCount > 1) {
|
|
7233
7262
|
const feedEntries = Object.entries(this.activeFeeds);
|
|
7234
|
-
const activityEntries = Object.entries(this.activeActivities);
|
|
7235
7263
|
const results = await Promise.allSettled([
|
|
7236
7264
|
...feedEntries.map(([, feed]) => feed.synchronize()),
|
|
7237
|
-
...
|
|
7265
|
+
...this.activeActivities.map((activity) => activity.synchronize())
|
|
7238
7266
|
]);
|
|
7239
7267
|
const failures = results.flatMap((result, index) => {
|
|
7240
7268
|
if (result.status === "fulfilled") {
|
|
7241
7269
|
return [];
|
|
7242
7270
|
}
|
|
7243
|
-
const activity =
|
|
7271
|
+
const activity = this.activeActivities[index - feedEntries.length];
|
|
7244
7272
|
const feed = feedEntries[index]?.[0] ?? (activity && getFeed.call(activity)?.feed);
|
|
7245
7273
|
return [{ feed, reason: result.reason, activity_id: activity?.id }];
|
|
7246
7274
|
});
|
|
@@ -7257,8 +7285,8 @@ class FeedsClient extends FeedsApi {
|
|
|
7257
7285
|
throw new Error(`Can't connect a new user, call "disconnectUser" first`);
|
|
7258
7286
|
}
|
|
7259
7287
|
this.tokenManager.setTokenOrProvider(tokenProvider);
|
|
7260
|
-
this.
|
|
7261
|
-
this.
|
|
7288
|
+
this.setGetBatchOwnFieldsThrottlingInterval(
|
|
7289
|
+
this.query_batch_own_fields_throttling_interval
|
|
7262
7290
|
);
|
|
7263
7291
|
try {
|
|
7264
7292
|
addConnectionEventListeners(this.updateNetworkConnectionStatus);
|
|
@@ -7426,14 +7454,13 @@ class FeedsClient extends FeedsApi {
|
|
|
7426
7454
|
this.connectionIdManager.reset();
|
|
7427
7455
|
this.tokenManager.reset();
|
|
7428
7456
|
this.polls_by_id.clear();
|
|
7429
|
-
this.activeActivities =
|
|
7457
|
+
this.activeActivities = [];
|
|
7430
7458
|
this.activeFeeds = {};
|
|
7431
7459
|
this.state.partialNext({
|
|
7432
7460
|
connected_user: void 0,
|
|
7433
|
-
is_ws_connection_healthy: false
|
|
7434
|
-
own_capabilities_by_fid: {}
|
|
7461
|
+
is_ws_connection_healthy: false
|
|
7435
7462
|
});
|
|
7436
|
-
this.
|
|
7463
|
+
this.cancelGetBatchOwnFieldsTimer();
|
|
7437
7464
|
clearQueuedFeeds();
|
|
7438
7465
|
};
|
|
7439
7466
|
this.on = this.eventDispatcher.on;
|
|
@@ -7442,15 +7469,15 @@ class FeedsClient extends FeedsApi {
|
|
|
7442
7469
|
return this.getOrCreateActiveFeed({
|
|
7443
7470
|
group: groupId,
|
|
7444
7471
|
id,
|
|
7445
|
-
options: options2
|
|
7472
|
+
options: options2,
|
|
7473
|
+
fieldsToUpdate: []
|
|
7446
7474
|
});
|
|
7447
7475
|
};
|
|
7448
|
-
this.activityWithStateUpdates = (id
|
|
7449
|
-
|
|
7450
|
-
|
|
7451
|
-
|
|
7452
|
-
|
|
7453
|
-
}
|
|
7476
|
+
this.activityWithStateUpdates = (id, { fromResponse } = {
|
|
7477
|
+
fromResponse: void 0
|
|
7478
|
+
}) => {
|
|
7479
|
+
const activity = new ActivityWithStateUpdates(id, this, { fromResponse });
|
|
7480
|
+
this.activeActivities.push(activity);
|
|
7454
7481
|
return activity;
|
|
7455
7482
|
};
|
|
7456
7483
|
this.updateNetworkConnectionStatus = (event) => {
|
|
@@ -7466,7 +7493,7 @@ class FeedsClient extends FeedsApi {
|
|
|
7466
7493
|
data,
|
|
7467
7494
|
watch,
|
|
7468
7495
|
options: options2,
|
|
7469
|
-
|
|
7496
|
+
fieldsToUpdate
|
|
7470
7497
|
}) => {
|
|
7471
7498
|
const fid = `${group}:${id}`;
|
|
7472
7499
|
let isCreated = false;
|
|
@@ -7495,23 +7522,28 @@ class FeedsClient extends FeedsApi {
|
|
|
7495
7522
|
if (!isCreated && data) {
|
|
7496
7523
|
if ((feed.currentState.updated_at?.getTime() ?? 0) < data.updated_at.getTime()) {
|
|
7497
7524
|
handleFeedUpdated.call(feed, { feed: data });
|
|
7498
|
-
} else if ((feed.currentState.updated_at?.getTime() ?? 0) === data.updated_at.getTime()
|
|
7499
|
-
const
|
|
7500
|
-
|
|
7501
|
-
|
|
7502
|
-
|
|
7503
|
-
|
|
7504
|
-
|
|
7505
|
-
|
|
7506
|
-
|
|
7507
|
-
|
|
7525
|
+
} else if ((feed.currentState.updated_at?.getTime() ?? 0) === data.updated_at.getTime()) {
|
|
7526
|
+
const fieldsToUpdateData = [];
|
|
7527
|
+
const fieldChecks = [
|
|
7528
|
+
["own_capabilities", isOwnCapabilitiesEqual],
|
|
7529
|
+
["own_follows", isOwnFollowsEqual],
|
|
7530
|
+
["own_membership", isOwnMembershipEqual],
|
|
7531
|
+
["own_followings", isOwnFollowingsEqual]
|
|
7532
|
+
];
|
|
7533
|
+
fieldChecks.forEach(([field, isEqual]) => {
|
|
7534
|
+
if (fieldsToUpdate.includes(field) && !isEqual(feed.currentState, data)) {
|
|
7535
|
+
fieldsToUpdateData.push(field);
|
|
7536
|
+
}
|
|
7537
|
+
});
|
|
7538
|
+
if (fieldsToUpdateData.length > 0) {
|
|
7539
|
+
const fieldsToUpdatePayload = fieldsToUpdateData.reduce(
|
|
7508
7540
|
(acc, field) => {
|
|
7509
7541
|
acc[field] = data[field];
|
|
7510
7542
|
return acc;
|
|
7511
7543
|
},
|
|
7512
7544
|
{}
|
|
7513
7545
|
);
|
|
7514
|
-
feed.state.partialNext(
|
|
7546
|
+
feed.state.partialNext(fieldsToUpdatePayload);
|
|
7515
7547
|
}
|
|
7516
7548
|
}
|
|
7517
7549
|
}
|
|
@@ -7521,14 +7553,13 @@ class FeedsClient extends FeedsApi {
|
|
|
7521
7553
|
};
|
|
7522
7554
|
this.state = new stateStore.StateStore({
|
|
7523
7555
|
connected_user: void 0,
|
|
7524
|
-
is_ws_connection_healthy: false
|
|
7525
|
-
own_capabilities_by_fid: {}
|
|
7556
|
+
is_ws_connection_healthy: false
|
|
7526
7557
|
});
|
|
7527
7558
|
this.moderation = new ModerationClient(apiClient);
|
|
7528
7559
|
this.tokenManager = tokenManager;
|
|
7529
7560
|
this.connectionIdManager = connectionIdManager;
|
|
7530
7561
|
this.polls_by_id = /* @__PURE__ */ new Map();
|
|
7531
|
-
this.
|
|
7562
|
+
this.query_batch_own_fields_throttling_interval = options?.query_batch_own_fields_throttling_interval ?? DEFAULT_BATCH_OWN_FIELDS_THROTTLING_INTERVAL;
|
|
7532
7563
|
feedsLoggerSystem.configureLoggers(options?.configure_loggers_options);
|
|
7533
7564
|
this.on("all", (event) => {
|
|
7534
7565
|
const fid = event.fid;
|
|
@@ -7551,7 +7582,8 @@ class FeedsClient extends FeedsApi {
|
|
|
7551
7582
|
this.getOrCreateActiveFeed({
|
|
7552
7583
|
group: event.feed.group_id,
|
|
7553
7584
|
id: event.feed.id,
|
|
7554
|
-
data: event.feed
|
|
7585
|
+
data: event.feed,
|
|
7586
|
+
fieldsToUpdate: []
|
|
7555
7587
|
});
|
|
7556
7588
|
break;
|
|
7557
7589
|
}
|
|
@@ -7559,12 +7591,9 @@ class FeedsClient extends FeedsApi {
|
|
|
7559
7591
|
feeds.forEach((f) => f.handleWSEvent(event));
|
|
7560
7592
|
if (typeof fid === "string") {
|
|
7561
7593
|
delete this.activeFeeds[fid];
|
|
7562
|
-
|
|
7563
|
-
|
|
7564
|
-
|
|
7565
|
-
delete this.activeActivities[activityId];
|
|
7566
|
-
}
|
|
7567
|
-
});
|
|
7594
|
+
this.activeActivities = this.activeActivities.filter(
|
|
7595
|
+
(activity) => getFeed.call(activity)?.feed !== fid
|
|
7596
|
+
);
|
|
7568
7597
|
}
|
|
7569
7598
|
break;
|
|
7570
7599
|
}
|
|
@@ -7642,7 +7671,9 @@ class FeedsClient extends FeedsApi {
|
|
|
7642
7671
|
default: {
|
|
7643
7672
|
feeds.forEach((f) => f.handleWSEvent(event));
|
|
7644
7673
|
if (event.type === "feeds.activity.deleted") {
|
|
7645
|
-
|
|
7674
|
+
this.activeActivities = this.activeActivities.filter(
|
|
7675
|
+
(activity) => activity.id !== event.activity.id
|
|
7676
|
+
);
|
|
7646
7677
|
}
|
|
7647
7678
|
}
|
|
7648
7679
|
}
|
|
@@ -7669,25 +7700,6 @@ class FeedsClient extends FeedsApi {
|
|
|
7669
7700
|
}
|
|
7670
7701
|
}
|
|
7671
7702
|
}
|
|
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
7703
|
async queryFeeds(request) {
|
|
7692
7704
|
const response = await this._queryFeeds(request);
|
|
7693
7705
|
const feedResponses = response.feeds;
|
|
@@ -7696,10 +7708,15 @@ class FeedsClient extends FeedsApi {
|
|
|
7696
7708
|
group: feedResponse.group_id,
|
|
7697
7709
|
id: feedResponse.id,
|
|
7698
7710
|
data: feedResponse,
|
|
7699
|
-
watch: request?.watch
|
|
7711
|
+
watch: request?.watch,
|
|
7712
|
+
fieldsToUpdate: [
|
|
7713
|
+
"own_capabilities",
|
|
7714
|
+
"own_follows",
|
|
7715
|
+
"own_membership",
|
|
7716
|
+
"own_followings"
|
|
7717
|
+
]
|
|
7700
7718
|
})
|
|
7701
7719
|
);
|
|
7702
|
-
this.hydrateCapabilitiesCache(feedResponses);
|
|
7703
7720
|
return {
|
|
7704
7721
|
feeds,
|
|
7705
7722
|
next: response.next,
|
|
@@ -7710,13 +7727,12 @@ class FeedsClient extends FeedsApi {
|
|
|
7710
7727
|
}
|
|
7711
7728
|
async ownBatch(request) {
|
|
7712
7729
|
const response = await super.ownBatch(request);
|
|
7713
|
-
|
|
7714
|
-
|
|
7715
|
-
|
|
7716
|
-
|
|
7717
|
-
}
|
|
7718
|
-
);
|
|
7719
|
-
this.hydrateCapabilitiesCache(feedResponses);
|
|
7730
|
+
Object.entries(response.data).forEach(([fid, ownFields]) => {
|
|
7731
|
+
const feed = this.activeFeeds[fid];
|
|
7732
|
+
if (feed) {
|
|
7733
|
+
feed.state.partialNext(ownFields);
|
|
7734
|
+
}
|
|
7735
|
+
});
|
|
7720
7736
|
return response;
|
|
7721
7737
|
}
|
|
7722
7738
|
async updateFollow(request) {
|
|
@@ -7775,7 +7791,6 @@ class FeedsClient extends FeedsApi {
|
|
|
7775
7791
|
}
|
|
7776
7792
|
async getOrCreateFeed(request) {
|
|
7777
7793
|
const response = await super.getOrCreateFeed(request);
|
|
7778
|
-
this.hydrateCapabilitiesCache([response.feed]);
|
|
7779
7794
|
if (request.watch) {
|
|
7780
7795
|
const feeds = this.findAllActiveFeedsByFid(
|
|
7781
7796
|
`${request.feed_group_id}:${request.feed_id}`
|
|
@@ -7786,14 +7801,20 @@ class FeedsClient extends FeedsApi {
|
|
|
7786
7801
|
}
|
|
7787
7802
|
async getFollowSuggestions(...params) {
|
|
7788
7803
|
const response = await super.getFollowSuggestions(...params);
|
|
7789
|
-
response.suggestions.
|
|
7790
|
-
this.getOrCreateActiveFeed({
|
|
7804
|
+
const feeds = response.suggestions.map((suggestion) => {
|
|
7805
|
+
return this.getOrCreateActiveFeed({
|
|
7791
7806
|
group: suggestion.group_id,
|
|
7792
7807
|
id: suggestion.id,
|
|
7793
|
-
data: suggestion
|
|
7808
|
+
data: suggestion,
|
|
7809
|
+
fieldsToUpdate: [
|
|
7810
|
+
"own_capabilities",
|
|
7811
|
+
"own_follows",
|
|
7812
|
+
"own_membership",
|
|
7813
|
+
"own_followings"
|
|
7814
|
+
]
|
|
7794
7815
|
});
|
|
7795
7816
|
});
|
|
7796
|
-
return response;
|
|
7817
|
+
return { ...response, feeds };
|
|
7797
7818
|
}
|
|
7798
7819
|
findAllActiveFeedsByActivityId(activityId) {
|
|
7799
7820
|
return [
|
|
@@ -7870,9 +7891,8 @@ exports.isImageFile = isImageFile;
|
|
|
7870
7891
|
exports.isReactionResponse = isReactionResponse;
|
|
7871
7892
|
exports.isVideoFile = isVideoFile;
|
|
7872
7893
|
exports.isVoteAnswer = isVoteAnswer;
|
|
7873
|
-
exports.ownFeedFields = ownFeedFields;
|
|
7874
7894
|
exports.replaceUniqueArrayMerge = replaceUniqueArrayMerge;
|
|
7875
7895
|
exports.shouldUpdateState = shouldUpdateState;
|
|
7876
7896
|
exports.uniqueArrayMerge = uniqueArrayMerge;
|
|
7877
7897
|
exports.updateEntityInArray = updateEntityInArray;
|
|
7878
|
-
//# sourceMappingURL=feeds-client-
|
|
7898
|
+
//# sourceMappingURL=feeds-client-Xj6kDjVH.js.map
|