@stream-io/feeds-client 0.3.51 → 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.
- package/CHANGELOG.md +12 -0
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/react-bindings.js +1 -1
- package/dist/es/index.mjs +15 -14
- package/dist/es/react-bindings.mjs +1 -1
- package/dist/{feeds-client-DeAqnd1a.mjs → feeds-client-B03y08Kq.mjs} +184 -67
- package/dist/feeds-client-B03y08Kq.mjs.map +1 -0
- package/dist/{feeds-client-B4zeBggL.js → feeds-client-tw63OGrd.js} +178 -61
- package/dist/feeds-client-tw63OGrd.js.map +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/types/activity-with-state-updates/activity-with-state-updates.d.ts.map +1 -1
- package/dist/types/feed/activity-filter.d.ts +11 -0
- package/dist/types/feed/activity-filter.d.ts.map +1 -0
- package/dist/types/feed/event-handlers/activity/handle-activity-added.d.ts +3 -2
- 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/event-handlers/comment/handle-comment-updated.d.ts.map +1 -1
- package/dist/types/feed/event-handlers/follow/handle-follow-created.d.ts +2 -2
- package/dist/types/feed/event-handlers/follow/handle-follow-created.d.ts.map +1 -1
- package/dist/types/feed/feed.d.ts +17 -12
- package/dist/types/feed/feed.d.ts.map +1 -1
- package/dist/types/feeds-client/apply-new-activity-to-active-feeds.d.ts +4 -0
- package/dist/types/feeds-client/apply-new-activity-to-active-feeds.d.ts.map +1 -0
- package/dist/types/feeds-client/feeds-client.d.ts +6 -8
- package/dist/types/feeds-client/feeds-client.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +15 -0
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/activity-with-state-updates/activity-with-state-updates.ts +8 -2
- package/src/feed/activity-filter.ts +44 -0
- package/src/feed/event-handlers/activity/handle-activity-added.ts +22 -8
- package/src/feed/event-handlers/activity/handle-activity-updated.ts +5 -1
- package/src/feed/event-handlers/comment/handle-comment-updated.ts +11 -10
- package/src/feed/event-handlers/follow/handle-follow-created.ts +18 -1
- package/src/feed/feed.ts +72 -21
- package/src/feeds-client/apply-new-activity-to-active-feeds.ts +9 -0
- package/src/feeds-client/feeds-client.ts +46 -28
- package/src/index.ts +1 -0
- package/src/types.ts +17 -0
- package/dist/feeds-client-B4zeBggL.js.map +0 -1
- package/dist/feeds-client-DeAqnd1a.mjs.map +0 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const reactBindings = require("@stream-io/state-store/react-bindings");
|
|
4
4
|
const react = require("react");
|
|
5
|
-
const feedsClient = require("../feeds-client-
|
|
5
|
+
const feedsClient = require("../feeds-client-tw63OGrd.js");
|
|
6
6
|
const jsxRuntime = require("react/jsx-runtime");
|
|
7
7
|
const useCreateFeedsClient = ({
|
|
8
8
|
apiKey,
|
package/dist/es/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { StateStore } from "@stream-io/state-store";
|
|
2
2
|
export * from "@stream-io/state-store";
|
|
3
|
-
import { d as debounce } from "../feeds-client-
|
|
4
|
-
import { A, C,
|
|
3
|
+
import { d as debounce } from "../feeds-client-B03y08Kq.mjs";
|
|
4
|
+
import { A, C, b, F, S, c, a, e, o, n, l, h, f, j, g, k, i, r, s, u, m } from "../feeds-client-B03y08Kq.mjs";
|
|
5
5
|
import { LogLevelEnum } from "@stream-io/logger";
|
|
6
6
|
const ownFeedFields = ["own_capabilities", "own_follows", "own_membership"];
|
|
7
7
|
const ChannelOwnCapability = {
|
|
@@ -443,29 +443,30 @@ export {
|
|
|
443
443
|
BaseSearchSourceSync,
|
|
444
444
|
ChannelOwnCapability,
|
|
445
445
|
C as Constants,
|
|
446
|
-
|
|
446
|
+
b as Feed,
|
|
447
447
|
FeedOwnCapability,
|
|
448
448
|
FeedSearchSource,
|
|
449
449
|
F as FeedsClient,
|
|
450
450
|
LogLevelEnum,
|
|
451
451
|
SearchController,
|
|
452
452
|
S as StreamApiError,
|
|
453
|
-
|
|
453
|
+
c as StreamPoll,
|
|
454
454
|
UserSearchSource,
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
455
|
+
a as activityFilter,
|
|
456
|
+
e as checkHasAnotherPage,
|
|
457
|
+
o as ensureExhausted,
|
|
458
|
+
n as feedsLoggerSystem,
|
|
459
|
+
l as getStateUpdateQueueId,
|
|
460
|
+
h as isCommentResponse,
|
|
461
|
+
f as isFollowResponse,
|
|
462
|
+
j as isImageFile,
|
|
463
|
+
g as isReactionResponse,
|
|
464
|
+
k as isVideoFile,
|
|
464
465
|
i as isVoteAnswer,
|
|
465
466
|
ownFeedFields,
|
|
466
467
|
r as replaceUniqueArrayMerge,
|
|
467
468
|
s as shouldUpdateState,
|
|
468
469
|
u as uniqueArrayMerge,
|
|
469
|
-
|
|
470
|
+
m as updateEntityInArray
|
|
470
471
|
};
|
|
471
472
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useStateStore } from "@stream-io/state-store/react-bindings";
|
|
2
2
|
export * from "@stream-io/state-store/react-bindings";
|
|
3
3
|
import { useState, useEffect, createContext, useContext, useRef, useCallback, useMemo } from "react";
|
|
4
|
-
import { F as FeedsClient,
|
|
4
|
+
import { F as FeedsClient, h as isCommentResponse, e as checkHasAnotherPage } from "../feeds-client-B03y08Kq.mjs";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
6
|
const useCreateFeedsClient = ({
|
|
7
7
|
apiKey,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { StateStore } from "@stream-io/state-store";
|
|
2
2
|
import * as loggerInternal from "@stream-io/logger";
|
|
3
3
|
import axiosImport from "axios";
|
|
4
|
+
import { itemMatchesFilter, resolveDotPathValue } from "@stream-io/filter";
|
|
4
5
|
const decoders = {};
|
|
5
6
|
const decodeDatetimeType = (input) => typeof input === "number" ? new Date(Math.floor(input / 1e6)) : new Date(input);
|
|
6
7
|
decoders.DatetimeType = decodeDatetimeType;
|
|
@@ -4110,7 +4111,7 @@ const getRateLimitFromResponseHeader = (response_headers) => {
|
|
|
4110
4111
|
};
|
|
4111
4112
|
return result;
|
|
4112
4113
|
};
|
|
4113
|
-
const version = "0.
|
|
4114
|
+
const version = "1.0.0";
|
|
4114
4115
|
const axios = axiosImport.default ?? axiosImport;
|
|
4115
4116
|
class ApiClient {
|
|
4116
4117
|
constructor(apiKey, tokenManager, connectionIdManager, options) {
|
|
@@ -5045,7 +5046,7 @@ function updateEntityInArray({
|
|
|
5045
5046
|
updatedEntities[index] = newEntity;
|
|
5046
5047
|
return { changed: true, entities: updatedEntities };
|
|
5047
5048
|
}
|
|
5048
|
-
const updateStateFollowCreated = (follow, currentState, currentFeedId, connectedUserId) => {
|
|
5049
|
+
const updateStateFollowCreated = (follow, currentState, currentFeedId, connectedUserId, hasOwnFields = false) => {
|
|
5049
5050
|
if (follow.status !== "accepted") {
|
|
5050
5051
|
return { changed: false, data: currentState };
|
|
5051
5052
|
}
|
|
@@ -5054,7 +5055,12 @@ const updateStateFollowCreated = (follow, currentState, currentFeedId, connected
|
|
|
5054
5055
|
newState = {
|
|
5055
5056
|
...newState,
|
|
5056
5057
|
// Update FeedResponse fields, that has the new follower/following count
|
|
5057
|
-
...follow.source_feed
|
|
5058
|
+
...follow.source_feed,
|
|
5059
|
+
...hasOwnFields ? {
|
|
5060
|
+
own_capabilities: follow.source_feed.own_capabilities,
|
|
5061
|
+
own_follows: follow.source_feed.own_follows,
|
|
5062
|
+
own_followings: follow.source_feed.own_followings
|
|
5063
|
+
} : {}
|
|
5058
5064
|
};
|
|
5059
5065
|
if (currentState.following !== void 0) {
|
|
5060
5066
|
newState.following = [follow, ...currentState.following];
|
|
@@ -5067,9 +5073,14 @@ const updateStateFollowCreated = (follow, currentState, currentFeedId, connected
|
|
|
5067
5073
|
newState = {
|
|
5068
5074
|
...newState,
|
|
5069
5075
|
// Update FeedResponse fields, that has the new follower/following count
|
|
5070
|
-
...follow.target_feed
|
|
5071
|
-
|
|
5072
|
-
|
|
5076
|
+
...follow.target_feed,
|
|
5077
|
+
...hasOwnFields ? {
|
|
5078
|
+
own_capabilities: follow.target_feed.own_capabilities,
|
|
5079
|
+
own_follows: follow.target_feed.own_follows,
|
|
5080
|
+
own_followings: follow.target_feed.own_followings
|
|
5081
|
+
} : {}
|
|
5082
|
+
};
|
|
5083
|
+
if (source.created_by.id === connectedUserId && !hasOwnFields) {
|
|
5073
5084
|
newState.own_follows = currentState.own_follows ? currentState.own_follows.concat(follow) : [follow];
|
|
5074
5085
|
}
|
|
5075
5086
|
if (currentState.followers !== void 0) {
|
|
@@ -5078,7 +5089,7 @@ const updateStateFollowCreated = (follow, currentState, currentFeedId, connected
|
|
|
5078
5089
|
}
|
|
5079
5090
|
return { changed: true, data: newState };
|
|
5080
5091
|
};
|
|
5081
|
-
function handleFollowCreated(eventOrResponse, fromWs) {
|
|
5092
|
+
function handleFollowCreated(eventOrResponse, fromWs, hasOwnFields = false) {
|
|
5082
5093
|
const follow = eventOrResponse.follow;
|
|
5083
5094
|
if (!shouldUpdateState({
|
|
5084
5095
|
stateUpdateQueueId: getStateUpdateQueueId(follow, "follow-created"),
|
|
@@ -5094,7 +5105,8 @@ function handleFollowCreated(eventOrResponse, fromWs) {
|
|
|
5094
5105
|
follow,
|
|
5095
5106
|
this.currentState,
|
|
5096
5107
|
this.feed,
|
|
5097
|
-
connectedUser?.id
|
|
5108
|
+
connectedUser?.id,
|
|
5109
|
+
hasOwnFields
|
|
5098
5110
|
);
|
|
5099
5111
|
if (result.changed) {
|
|
5100
5112
|
this.state.next(result.data);
|
|
@@ -5318,14 +5330,14 @@ function handleCommentUpdated(payload, fromWs) {
|
|
|
5318
5330
|
const { comment } = payload;
|
|
5319
5331
|
const entityId = comment.parent_id ?? comment.object_id;
|
|
5320
5332
|
if (!shouldUpdateState({
|
|
5321
|
-
stateUpdateQueueId: getStateUpdateQueueId(
|
|
5322
|
-
payload,
|
|
5323
|
-
"comment-updated"
|
|
5324
|
-
),
|
|
5333
|
+
stateUpdateQueueId: getStateUpdateQueueId(payload, "comment-updated"),
|
|
5325
5334
|
stateUpdateQueue: this.stateUpdateQueue,
|
|
5326
5335
|
watch: this.currentState.watch,
|
|
5327
5336
|
fromWs,
|
|
5328
|
-
isTriggeredByConnectedUser: eventTriggeredByConnectedUser.call(
|
|
5337
|
+
isTriggeredByConnectedUser: eventTriggeredByConnectedUser.call(
|
|
5338
|
+
this,
|
|
5339
|
+
payload
|
|
5340
|
+
)
|
|
5329
5341
|
})) {
|
|
5330
5342
|
return;
|
|
5331
5343
|
}
|
|
@@ -5335,7 +5347,10 @@ function handleCommentUpdated(payload, fromWs) {
|
|
|
5335
5347
|
const index = this.getCommentIndex(comment, currentState);
|
|
5336
5348
|
if (index === -1) return currentState;
|
|
5337
5349
|
const newComments = [...entityState.comments];
|
|
5338
|
-
newComments[index] =
|
|
5350
|
+
newComments[index] = {
|
|
5351
|
+
...comment,
|
|
5352
|
+
own_reactions: entityState.comments[index].own_reactions
|
|
5353
|
+
};
|
|
5339
5354
|
return {
|
|
5340
5355
|
...currentState,
|
|
5341
5356
|
comments_by_entity_id: {
|
|
@@ -5764,7 +5779,13 @@ function handleBookmarkUpdated(event) {
|
|
|
5764
5779
|
});
|
|
5765
5780
|
}
|
|
5766
5781
|
}
|
|
5767
|
-
function addActivitiesToState(newActivities, activities, position, {
|
|
5782
|
+
function addActivitiesToState(newActivities, activities, position, {
|
|
5783
|
+
hasOwnFields,
|
|
5784
|
+
backfillOwnFields
|
|
5785
|
+
} = {
|
|
5786
|
+
hasOwnFields: true,
|
|
5787
|
+
backfillOwnFields: true
|
|
5788
|
+
}) {
|
|
5768
5789
|
if (activities === void 0) {
|
|
5769
5790
|
return {
|
|
5770
5791
|
changed: false,
|
|
@@ -5787,23 +5808,31 @@ function addActivitiesToState(newActivities, activities, position, { fromWebSock
|
|
|
5787
5808
|
...activities,
|
|
5788
5809
|
...position === "end" ? newActivitiesDeduplicated : []
|
|
5789
5810
|
];
|
|
5790
|
-
this.
|
|
5811
|
+
this.activitiesAddedOrUpdated(newActivitiesDeduplicated, {
|
|
5812
|
+
hasOwnFields,
|
|
5813
|
+
backfillOwnFields
|
|
5814
|
+
});
|
|
5791
5815
|
result = { changed: true, activities: updatedActivities };
|
|
5792
5816
|
}
|
|
5793
5817
|
return result;
|
|
5794
5818
|
}
|
|
5795
5819
|
function handleActivityAdded(event) {
|
|
5796
|
-
|
|
5797
|
-
|
|
5798
|
-
|
|
5799
|
-
|
|
5820
|
+
const currentUser = this.client.state.getLatestValue().connected_user;
|
|
5821
|
+
const decision = this.resolveNewActivityDecision(
|
|
5822
|
+
event.activity,
|
|
5823
|
+
currentUser,
|
|
5824
|
+
false
|
|
5825
|
+
);
|
|
5826
|
+
if (decision === "ignore") {
|
|
5827
|
+
return;
|
|
5800
5828
|
}
|
|
5829
|
+
const position = decision === "add-to-end" ? "end" : "start";
|
|
5801
5830
|
const currentActivities = this.currentState.activities;
|
|
5802
5831
|
const result = addActivitiesToState.bind(this)(
|
|
5803
5832
|
[event.activity],
|
|
5804
5833
|
currentActivities,
|
|
5805
|
-
|
|
5806
|
-
{
|
|
5834
|
+
position,
|
|
5835
|
+
{ hasOwnFields: false, backfillOwnFields: true }
|
|
5807
5836
|
);
|
|
5808
5837
|
if (result.changed) {
|
|
5809
5838
|
const activity = event.activity;
|
|
@@ -5920,7 +5949,10 @@ function handleActivityUpdated(payload, fromWs) {
|
|
|
5920
5949
|
updatePinnedActivityInState(payload, currentPinnedActivities)
|
|
5921
5950
|
];
|
|
5922
5951
|
if (result1?.changed || result2.changed) {
|
|
5923
|
-
this.
|
|
5952
|
+
this.activitiesAddedOrUpdated([payload.activity], {
|
|
5953
|
+
hasOwnFields: payload.activity.current_feed?.own_capabilities !== void 0,
|
|
5954
|
+
backfillOwnFields: false
|
|
5955
|
+
});
|
|
5924
5956
|
this.state.partialNext({
|
|
5925
5957
|
activities: result1?.changed ? result1.entities : currentActivities,
|
|
5926
5958
|
pinned_activities: result2.entities
|
|
@@ -6432,6 +6464,30 @@ function handleWatchStarted() {
|
|
|
6432
6464
|
function handleWatchStopped() {
|
|
6433
6465
|
this.state.partialNext({ watch: false });
|
|
6434
6466
|
}
|
|
6467
|
+
const activityResolvers = [
|
|
6468
|
+
{
|
|
6469
|
+
matchesField: (field) => field === "activity_type",
|
|
6470
|
+
resolve: (activity) => activity.type
|
|
6471
|
+
},
|
|
6472
|
+
{
|
|
6473
|
+
matchesField: (field) => field === "within_bounds",
|
|
6474
|
+
resolve: (activity) => activity.location
|
|
6475
|
+
},
|
|
6476
|
+
{
|
|
6477
|
+
matchesField: () => true,
|
|
6478
|
+
resolve: (item, path) => resolveDotPathValue(item, path)
|
|
6479
|
+
}
|
|
6480
|
+
];
|
|
6481
|
+
function activityFilter(activity, requestConfig) {
|
|
6482
|
+
const filter = requestConfig?.filter;
|
|
6483
|
+
if (!filter || typeof filter !== "object") {
|
|
6484
|
+
return true;
|
|
6485
|
+
}
|
|
6486
|
+
return itemMatchesFilter(activity, filter, {
|
|
6487
|
+
resolvers: [...activityResolvers],
|
|
6488
|
+
arrayEqMode: "contains"
|
|
6489
|
+
});
|
|
6490
|
+
}
|
|
6435
6491
|
const DEFAULT_MAX_RETRIES = 3;
|
|
6436
6492
|
function isRetryableError(error) {
|
|
6437
6493
|
if (error instanceof StreamApiError) {
|
|
@@ -6623,9 +6679,9 @@ function clearQueuedFeeds() {
|
|
|
6623
6679
|
queuedFeeds.clear();
|
|
6624
6680
|
}
|
|
6625
6681
|
const _Feed = class _Feed extends FeedApi {
|
|
6626
|
-
constructor(client, groupId, id, data, watch = false,
|
|
6682
|
+
constructor(client, groupId, id, data, watch = false, onNewActivity) {
|
|
6627
6683
|
super(client, groupId, id);
|
|
6628
|
-
this.
|
|
6684
|
+
this.onNewActivity = onNewActivity;
|
|
6629
6685
|
this.indexedActivityIds = /* @__PURE__ */ new Set();
|
|
6630
6686
|
this.stateUpdateQueue = /* @__PURE__ */ new Set();
|
|
6631
6687
|
this.eventHandlers = {
|
|
@@ -6695,8 +6751,7 @@ const _Feed = class _Feed extends FeedApi {
|
|
|
6695
6751
|
is_loading: false,
|
|
6696
6752
|
is_loading_activities: false,
|
|
6697
6753
|
comments_by_entity_id: {},
|
|
6698
|
-
watch
|
|
6699
|
-
addNewActivitiesTo
|
|
6754
|
+
watch
|
|
6700
6755
|
});
|
|
6701
6756
|
this.client = client;
|
|
6702
6757
|
this.state.subscribeWithSelector(
|
|
@@ -6717,9 +6772,6 @@ const _Feed = class _Feed extends FeedApi {
|
|
|
6717
6772
|
get currentState() {
|
|
6718
6773
|
return this.state.getLatestValue();
|
|
6719
6774
|
}
|
|
6720
|
-
set addNewActivitiesTo(value) {
|
|
6721
|
-
this.state.partialNext({ addNewActivitiesTo: value });
|
|
6722
|
-
}
|
|
6723
6775
|
hasActivity(activityId) {
|
|
6724
6776
|
return this.indexedActivityIds.has(activityId);
|
|
6725
6777
|
}
|
|
@@ -6728,6 +6780,24 @@ const _Feed = class _Feed extends FeedApi {
|
|
|
6728
6780
|
(pinnedActivity) => pinnedActivity.activity.id === activityId
|
|
6729
6781
|
);
|
|
6730
6782
|
}
|
|
6783
|
+
/**
|
|
6784
|
+
* Resolves how to handle a new activity (WS or HTTP): ignore, add-to-start, or add-to-end.
|
|
6785
|
+
* Uses onNewActivity if set; else default (current user + filter match) adds to start.
|
|
6786
|
+
*/
|
|
6787
|
+
resolveNewActivityDecision(activity, currentUser, _fromHttp) {
|
|
6788
|
+
if (this.onNewActivity) {
|
|
6789
|
+
return this.onNewActivity({ activity, currentUser });
|
|
6790
|
+
}
|
|
6791
|
+
if (!currentUser) return "ignore";
|
|
6792
|
+
if (activity.user?.id !== currentUser.id) return "ignore";
|
|
6793
|
+
if (!activityFilter(
|
|
6794
|
+
activity,
|
|
6795
|
+
this.currentState.last_get_or_create_request_config
|
|
6796
|
+
)) {
|
|
6797
|
+
return "ignore";
|
|
6798
|
+
}
|
|
6799
|
+
return "add-to-start";
|
|
6800
|
+
}
|
|
6731
6801
|
async synchronize() {
|
|
6732
6802
|
const { last_get_or_create_request_config } = this.state.getLatestValue();
|
|
6733
6803
|
if (last_get_or_create_request_config?.watch) {
|
|
@@ -6765,7 +6835,8 @@ const _Feed = class _Feed extends FeedApi {
|
|
|
6765
6835
|
const result = addActivitiesToState.bind(this)(
|
|
6766
6836
|
response.activities,
|
|
6767
6837
|
currentActivities,
|
|
6768
|
-
"end"
|
|
6838
|
+
"end",
|
|
6839
|
+
{ hasOwnFields: true, backfillOwnFields: false }
|
|
6769
6840
|
);
|
|
6770
6841
|
const aggregatedActivitiesResult = addAggregatedActivitiesToState(
|
|
6771
6842
|
response.aggregated_activities,
|
|
@@ -6814,7 +6885,7 @@ const _Feed = class _Feed extends FeedApi {
|
|
|
6814
6885
|
return nextState;
|
|
6815
6886
|
});
|
|
6816
6887
|
}
|
|
6817
|
-
this.
|
|
6888
|
+
this.activitiesAddedOrUpdated(response.activities);
|
|
6818
6889
|
return response;
|
|
6819
6890
|
} finally {
|
|
6820
6891
|
this.state.partialNext({
|
|
@@ -7189,11 +7260,41 @@ const _Feed = class _Feed extends FeedApi {
|
|
|
7189
7260
|
next: currentState.next
|
|
7190
7261
|
});
|
|
7191
7262
|
}
|
|
7263
|
+
/**
|
|
7264
|
+
* Applies a new activity to this feed's state (decision + add to activities).
|
|
7265
|
+
* Used when the activity was added via this feed's addActivity or via client.addActivity.
|
|
7266
|
+
*/
|
|
7267
|
+
addActivityFromHTTPResponse(activity) {
|
|
7268
|
+
const currentUser = this.client.state.getLatestValue().connected_user;
|
|
7269
|
+
const decision = this.resolveNewActivityDecision(
|
|
7270
|
+
activity,
|
|
7271
|
+
currentUser,
|
|
7272
|
+
true
|
|
7273
|
+
);
|
|
7274
|
+
if (decision !== "ignore") {
|
|
7275
|
+
const position = decision === "add-to-end" ? "end" : "start";
|
|
7276
|
+
const currentActivities = this.currentState.activities;
|
|
7277
|
+
const result = addActivitiesToState.bind(this)(
|
|
7278
|
+
[activity],
|
|
7279
|
+
currentActivities,
|
|
7280
|
+
position,
|
|
7281
|
+
{
|
|
7282
|
+
hasOwnFields: activity.current_feed?.own_capabilities !== void 0,
|
|
7283
|
+
backfillOwnFields: false
|
|
7284
|
+
}
|
|
7285
|
+
);
|
|
7286
|
+
if (result.changed) {
|
|
7287
|
+
this.client.hydratePollCache([activity]);
|
|
7288
|
+
this.state.partialNext({ activities: result.activities });
|
|
7289
|
+
}
|
|
7290
|
+
}
|
|
7291
|
+
}
|
|
7192
7292
|
async addActivity(request) {
|
|
7193
7293
|
const response = await this.client.addActivity({
|
|
7194
7294
|
...request,
|
|
7195
7295
|
feeds: [this.feed]
|
|
7196
7296
|
});
|
|
7297
|
+
this.addActivityFromHTTPResponse(response.activity);
|
|
7197
7298
|
return response;
|
|
7198
7299
|
}
|
|
7199
7300
|
handleWSEvent(event) {
|
|
@@ -7214,7 +7315,7 @@ const _Feed = class _Feed extends FeedApi {
|
|
|
7214
7315
|
}
|
|
7215
7316
|
this.eventDispatcher.dispatch(event);
|
|
7216
7317
|
}
|
|
7217
|
-
|
|
7318
|
+
activitiesAddedOrUpdated(activities, options = { hasOwnFields: true, backfillOwnFields: true }) {
|
|
7218
7319
|
this.client.hydratePollCache(activities);
|
|
7219
7320
|
this.getOrCreateFeeds(activities, options);
|
|
7220
7321
|
}
|
|
@@ -7232,7 +7333,7 @@ const _Feed = class _Feed extends FeedApi {
|
|
|
7232
7333
|
});
|
|
7233
7334
|
const newFeeds = Array.from(feedsToGetOrCreate.values());
|
|
7234
7335
|
const fieldsToUpdate = [];
|
|
7235
|
-
if (
|
|
7336
|
+
if (options.hasOwnFields) {
|
|
7236
7337
|
fieldsToUpdate.push("own_membership");
|
|
7237
7338
|
if (!enrichmentOptions?.skip_own_capabilities) {
|
|
7238
7339
|
fieldsToUpdate.push("own_capabilities");
|
|
@@ -7252,7 +7353,7 @@ const _Feed = class _Feed extends FeedApi {
|
|
|
7252
7353
|
fieldsToUpdate
|
|
7253
7354
|
});
|
|
7254
7355
|
});
|
|
7255
|
-
if (options.
|
|
7356
|
+
if (!options.hasOwnFields && options.backfillOwnFields) {
|
|
7256
7357
|
const uninitializedFeeds = newFeeds.filter((feedResponse) => {
|
|
7257
7358
|
const feed = this.client.feed(feedResponse.group_id, feedResponse.id);
|
|
7258
7359
|
return feed.currentState.own_capabilities === void 0;
|
|
@@ -7275,6 +7376,9 @@ const _Feed = class _Feed extends FeedApi {
|
|
|
7275
7376
|
_Feed.noop = () => {
|
|
7276
7377
|
};
|
|
7277
7378
|
let Feed = _Feed;
|
|
7379
|
+
function applyNewActivityToActiveFeeds(activity) {
|
|
7380
|
+
return this.addActivityFromHTTPResponse(activity);
|
|
7381
|
+
}
|
|
7278
7382
|
function handleUserUpdated(event) {
|
|
7279
7383
|
this.state.next((currentState) => {
|
|
7280
7384
|
let newState;
|
|
@@ -7354,7 +7458,9 @@ function disconnectActivityFromFeed(activity) {
|
|
|
7354
7458
|
}
|
|
7355
7459
|
}
|
|
7356
7460
|
class ActivityWithStateUpdates {
|
|
7357
|
-
constructor(id, feedsClient, { fromResponse } = {
|
|
7461
|
+
constructor(id, feedsClient, { fromResponse } = {
|
|
7462
|
+
fromResponse: void 0
|
|
7463
|
+
}) {
|
|
7358
7464
|
this.id = id;
|
|
7359
7465
|
this.feedsClient = feedsClient;
|
|
7360
7466
|
this.state = new StateStore({
|
|
@@ -7405,7 +7511,7 @@ class ActivityWithStateUpdates {
|
|
|
7405
7511
|
initialState: activityResponse
|
|
7406
7512
|
});
|
|
7407
7513
|
if (this.feed) {
|
|
7408
|
-
this.feed.
|
|
7514
|
+
this.feed.onNewActivity = () => "ignore";
|
|
7409
7515
|
}
|
|
7410
7516
|
if (comments) {
|
|
7411
7517
|
await this.loadNextPageActivityComments(comments);
|
|
@@ -7458,7 +7564,11 @@ class ActivityWithStateUpdates {
|
|
|
7458
7564
|
const { activities } = addActivitiesToState.bind(this.feed)(
|
|
7459
7565
|
[initialState],
|
|
7460
7566
|
[],
|
|
7461
|
-
"start"
|
|
7567
|
+
"start",
|
|
7568
|
+
{
|
|
7569
|
+
hasOwnFields: initialState.current_feed?.own_capabilities !== void 0,
|
|
7570
|
+
backfillOwnFields: false
|
|
7571
|
+
}
|
|
7462
7572
|
);
|
|
7463
7573
|
this.feed?.state.partialNext({
|
|
7464
7574
|
activities
|
|
@@ -7889,18 +7999,12 @@ class FeedsClient extends FeedsApi {
|
|
|
7889
7999
|
id,
|
|
7890
8000
|
data,
|
|
7891
8001
|
watch,
|
|
7892
|
-
options2?.
|
|
7893
|
-
options2?.activityAddedEventFilter
|
|
8002
|
+
options2?.onNewActivity
|
|
7894
8003
|
);
|
|
7895
8004
|
}
|
|
7896
8005
|
const feed = this.activeFeeds[fid];
|
|
7897
|
-
if (!isCreated && options2) {
|
|
7898
|
-
|
|
7899
|
-
feed.addNewActivitiesTo = options2.addNewActivitiesTo;
|
|
7900
|
-
}
|
|
7901
|
-
if (options2?.activityAddedEventFilter) {
|
|
7902
|
-
feed.activityAddedEventFilter = options2.activityAddedEventFilter;
|
|
7903
|
-
}
|
|
8006
|
+
if (!isCreated && options2?.onNewActivity !== void 0) {
|
|
8007
|
+
feed.onNewActivity = options2.onNewActivity;
|
|
7904
8008
|
}
|
|
7905
8009
|
if (!feed.currentState.watch) {
|
|
7906
8010
|
if (!isCreated && data) {
|
|
@@ -8080,6 +8184,16 @@ class FeedsClient extends FeedsApi {
|
|
|
8080
8184
|
});
|
|
8081
8185
|
}
|
|
8082
8186
|
}
|
|
8187
|
+
async addActivity(request) {
|
|
8188
|
+
const response = await super.addActivity(request);
|
|
8189
|
+
request.feeds.forEach((fid) => {
|
|
8190
|
+
const feed = this.activeFeeds[fid];
|
|
8191
|
+
if (feed) {
|
|
8192
|
+
applyNewActivityToActiveFeeds.call(feed, response.activity);
|
|
8193
|
+
}
|
|
8194
|
+
});
|
|
8195
|
+
return response;
|
|
8196
|
+
}
|
|
8083
8197
|
async queryFeeds(request) {
|
|
8084
8198
|
const response = await this._queryFeeds(request);
|
|
8085
8199
|
const feedResponses = response.feeds;
|
|
@@ -8089,12 +8203,12 @@ class FeedsClient extends FeedsApi {
|
|
|
8089
8203
|
id: feedResponse.id,
|
|
8090
8204
|
data: feedResponse,
|
|
8091
8205
|
watch: request?.watch,
|
|
8092
|
-
fieldsToUpdate: [
|
|
8206
|
+
fieldsToUpdate: request?.enrich_own_fields ? [
|
|
8093
8207
|
"own_capabilities",
|
|
8094
8208
|
"own_follows",
|
|
8095
8209
|
"own_membership",
|
|
8096
8210
|
"own_followings"
|
|
8097
|
-
]
|
|
8211
|
+
] : []
|
|
8098
8212
|
})
|
|
8099
8213
|
);
|
|
8100
8214
|
return {
|
|
@@ -8129,7 +8243,7 @@ class FeedsClient extends FeedsApi {
|
|
|
8129
8243
|
// For follow API endpoints we update the state after HTTP response to allow queryFeeds with watch: false
|
|
8130
8244
|
async follow(request) {
|
|
8131
8245
|
const response = await super.follow(request);
|
|
8132
|
-
this.updateStateFromFollows([response.follow]);
|
|
8246
|
+
this.updateStateFromFollows([response.follow], !!request.enrich_own_fields);
|
|
8133
8247
|
return response;
|
|
8134
8248
|
}
|
|
8135
8249
|
/**
|
|
@@ -8139,12 +8253,12 @@ class FeedsClient extends FeedsApi {
|
|
|
8139
8253
|
*/
|
|
8140
8254
|
async followBatch(request) {
|
|
8141
8255
|
const response = await super.followBatch(request);
|
|
8142
|
-
this.updateStateFromFollows(response.follows);
|
|
8256
|
+
this.updateStateFromFollows(response.follows, !!request.enrich_own_fields);
|
|
8143
8257
|
return response;
|
|
8144
8258
|
}
|
|
8145
8259
|
async getOrCreateFollows(request) {
|
|
8146
8260
|
const response = await super.getOrCreateFollows(request);
|
|
8147
|
-
this.updateStateFromFollows(response.created);
|
|
8261
|
+
this.updateStateFromFollows(response.created, !!request.enrich_own_fields);
|
|
8148
8262
|
return response;
|
|
8149
8263
|
}
|
|
8150
8264
|
async unfollow(request) {
|
|
@@ -8235,13 +8349,15 @@ class FeedsClient extends FeedsApi {
|
|
|
8235
8349
|
}).map((a) => getFeed.call(a))
|
|
8236
8350
|
];
|
|
8237
8351
|
}
|
|
8238
|
-
updateStateFromFollows(follows) {
|
|
8352
|
+
updateStateFromFollows(follows, hasOwnFields) {
|
|
8239
8353
|
follows.forEach((follow) => {
|
|
8240
8354
|
const feeds = [
|
|
8241
8355
|
...this.findAllActiveFeedsByFid(follow.source_feed.feed),
|
|
8242
8356
|
...this.findAllActiveFeedsByFid(follow.target_feed.feed)
|
|
8243
8357
|
];
|
|
8244
|
-
feeds.forEach(
|
|
8358
|
+
feeds.forEach(
|
|
8359
|
+
(f) => handleFollowCreated.bind(f)({ follow }, false, hasOwnFields)
|
|
8360
|
+
);
|
|
8245
8361
|
});
|
|
8246
8362
|
}
|
|
8247
8363
|
updateStateFromUnfollows(follows) {
|
|
@@ -8271,22 +8387,23 @@ export {
|
|
|
8271
8387
|
Constants as C,
|
|
8272
8388
|
FeedsClient as F,
|
|
8273
8389
|
StreamApiError as S,
|
|
8274
|
-
|
|
8275
|
-
|
|
8276
|
-
|
|
8390
|
+
activityFilter as a,
|
|
8391
|
+
Feed as b,
|
|
8392
|
+
StreamPoll as c,
|
|
8277
8393
|
debounce as d,
|
|
8278
|
-
|
|
8279
|
-
|
|
8280
|
-
|
|
8281
|
-
|
|
8394
|
+
checkHasAnotherPage as e,
|
|
8395
|
+
isFollowResponse as f,
|
|
8396
|
+
isReactionResponse as g,
|
|
8397
|
+
isCommentResponse as h,
|
|
8282
8398
|
isVoteAnswer as i,
|
|
8283
|
-
|
|
8284
|
-
|
|
8285
|
-
|
|
8286
|
-
|
|
8287
|
-
|
|
8399
|
+
isImageFile as j,
|
|
8400
|
+
isVideoFile as k,
|
|
8401
|
+
getStateUpdateQueueId as l,
|
|
8402
|
+
updateEntityInArray as m,
|
|
8403
|
+
feedsLoggerSystem as n,
|
|
8404
|
+
ensureExhausted as o,
|
|
8288
8405
|
replaceUniqueArrayMerge as r,
|
|
8289
8406
|
shouldUpdateState as s,
|
|
8290
8407
|
uniqueArrayMerge as u
|
|
8291
8408
|
};
|
|
8292
|
-
//# sourceMappingURL=feeds-client-
|
|
8409
|
+
//# sourceMappingURL=feeds-client-B03y08Kq.mjs.map
|