@stream-io/feeds-client 0.1.5 → 0.1.6
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/@react-bindings/hooks/feed-state-hooks/index.ts +2 -0
- package/CHANGELOG.md +15 -0
- package/dist/@react-bindings/hooks/client-state-hooks/useWsConnectionState.d.ts +1 -1
- package/dist/@react-bindings/hooks/feed-state-hooks/index.d.ts +2 -0
- package/dist/@react-bindings/hooks/feed-state-hooks/useComments.d.ts +2 -2
- package/dist/@react-bindings/hooks/feed-state-hooks/useFeedActivities.d.ts +2 -2
- package/dist/@react-bindings/hooks/feed-state-hooks/useFeedMetadata.d.ts +12 -0
- package/dist/@react-bindings/hooks/feed-state-hooks/useFollowers.d.ts +2 -2
- package/dist/@react-bindings/hooks/feed-state-hooks/useFollowing.d.ts +2 -2
- package/dist/@react-bindings/hooks/feed-state-hooks/useOwnCapabilities.d.ts +30 -30
- package/dist/@react-bindings/hooks/feed-state-hooks/useOwnFollows.d.ts +8 -0
- package/dist/index-react-bindings.browser.cjs +128 -85
- package/dist/index-react-bindings.browser.cjs.map +1 -1
- package/dist/index-react-bindings.browser.js +127 -86
- package/dist/index-react-bindings.browser.js.map +1 -1
- package/dist/index-react-bindings.node.cjs +128 -85
- package/dist/index-react-bindings.node.cjs.map +1 -1
- package/dist/index-react-bindings.node.js +127 -86
- package/dist/index-react-bindings.node.js.map +1 -1
- package/dist/index.browser.cjs +48 -37
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +48 -37
- package/dist/index.browser.js.map +1 -1
- package/dist/index.node.cjs +48 -37
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +48 -37
- package/dist/index.node.js.map +1 -1
- package/dist/src/FeedsClient.d.ts +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -3
- package/src/Feed.ts +17 -11
- package/src/FeedsClient.ts +15 -10
- package/src/common/ActivitySearchSource.ts +5 -5
- package/src/common/ApiClient.ts +1 -1
- package/src/common/FeedSearchSource.ts +1 -1
- package/src/common/Poll.ts +35 -10
- package/src/common/TokenManager.ts +2 -3
- package/src/common/UserSearchSource.ts +1 -1
- package/src/state-updates/bookmark-utils.test.ts +134 -8
- package/src/state-updates/bookmark-utils.ts +17 -7
|
@@ -2781,7 +2781,7 @@ class TokenManager {
|
|
|
2781
2781
|
}
|
|
2782
2782
|
catch (e) {
|
|
2783
2783
|
const numberOfFailures = ++previousFailuresCount;
|
|
2784
|
-
await sleep(
|
|
2784
|
+
await sleep(1000);
|
|
2785
2785
|
if (numberOfFailures === 3) {
|
|
2786
2786
|
this.loadTokenPromise = null;
|
|
2787
2787
|
return reject(new Error(`Stream error: tried to get token ${numberOfFailures} times, but it failed with ${e}. Check your token provider`, { cause: e }));
|
|
@@ -3629,7 +3629,7 @@ class ApiClient {
|
|
|
3629
3629
|
rate_limit: getRateLimitFromResponseHeader(response_headers),
|
|
3630
3630
|
};
|
|
3631
3631
|
};
|
|
3632
|
-
this.baseUrl = options?.base_url ?? 'https://
|
|
3632
|
+
this.baseUrl = options?.base_url ?? 'https://feeds.stream-io-api.com';
|
|
3633
3633
|
this.timeout = options?.timeout ?? 3000;
|
|
3634
3634
|
this.axiosInstance = axios.create({
|
|
3635
3635
|
baseURL: this.baseUrl,
|
|
@@ -3923,6 +3923,13 @@ const removeReactionFromActivities = (event, activities, isCurrentUser) => {
|
|
|
3923
3923
|
return updateActivityInActivities$1(updatedActivity, activities);
|
|
3924
3924
|
};
|
|
3925
3925
|
|
|
3926
|
+
// Helper function to check if two bookmarks are the same
|
|
3927
|
+
// A bookmark is identified by activity_id + folder_id + user_id
|
|
3928
|
+
const isSameBookmark = (bookmark1, bookmark2) => {
|
|
3929
|
+
return (bookmark1.user.id === bookmark2.user.id &&
|
|
3930
|
+
bookmark1.activity.id === bookmark2.activity.id &&
|
|
3931
|
+
bookmark1.folder?.id === bookmark2.folder?.id);
|
|
3932
|
+
};
|
|
3926
3933
|
const updateActivityInActivities = (updatedActivity, activities) => {
|
|
3927
3934
|
const index = activities.findIndex((a) => a.id === updatedActivity.id);
|
|
3928
3935
|
if (index !== -1) {
|
|
@@ -3949,8 +3956,7 @@ const addBookmarkToActivity = (event, activity, isCurrentUser) => {
|
|
|
3949
3956
|
const removeBookmarkFromActivity = (event, activity, isCurrentUser) => {
|
|
3950
3957
|
// Update own_bookmarks if the bookmark is from the current user
|
|
3951
3958
|
const ownBookmarks = isCurrentUser
|
|
3952
|
-
? (activity.own_bookmarks || []).filter((bookmark) => bookmark
|
|
3953
|
-
bookmark.activity.id !== event.bookmark.activity.id)
|
|
3959
|
+
? (activity.own_bookmarks || []).filter((bookmark) => !isSameBookmark(bookmark, event.bookmark))
|
|
3954
3960
|
: activity.own_bookmarks;
|
|
3955
3961
|
return {
|
|
3956
3962
|
...activity,
|
|
@@ -3962,8 +3968,7 @@ const updateBookmarkInActivity = (event, activity, isCurrentUser) => {
|
|
|
3962
3968
|
// Update own_bookmarks if the bookmark is from the current user
|
|
3963
3969
|
let ownBookmarks = activity.own_bookmarks || [];
|
|
3964
3970
|
if (isCurrentUser) {
|
|
3965
|
-
const bookmarkIndex = ownBookmarks.findIndex((bookmark) => bookmark
|
|
3966
|
-
bookmark.activity.id === event.bookmark.activity.id);
|
|
3971
|
+
const bookmarkIndex = ownBookmarks.findIndex((bookmark) => isSameBookmark(bookmark, event.bookmark));
|
|
3967
3972
|
if (bookmarkIndex !== -1) {
|
|
3968
3973
|
ownBookmarks = [...ownBookmarks];
|
|
3969
3974
|
ownBookmarks[bookmarkIndex] = event.bookmark;
|
|
@@ -4045,7 +4050,7 @@ class Feed extends FeedApi {
|
|
|
4045
4050
|
},
|
|
4046
4051
|
'feeds.activity.reaction.added': (event) => {
|
|
4047
4052
|
const currentActivities = this.currentState.activities;
|
|
4048
|
-
const connectedUser = this.client.state.getLatestValue().
|
|
4053
|
+
const connectedUser = this.client.state.getLatestValue().connected_user;
|
|
4049
4054
|
const isCurrentUser = Boolean(connectedUser && event.reaction.user.id === connectedUser.id);
|
|
4050
4055
|
const result = addReactionToActivities(event, currentActivities, isCurrentUser);
|
|
4051
4056
|
if (result.changed) {
|
|
@@ -4054,7 +4059,7 @@ class Feed extends FeedApi {
|
|
|
4054
4059
|
},
|
|
4055
4060
|
'feeds.activity.reaction.deleted': (event) => {
|
|
4056
4061
|
const currentActivities = this.currentState.activities;
|
|
4057
|
-
const connectedUser = this.client.state.getLatestValue().
|
|
4062
|
+
const connectedUser = this.client.state.getLatestValue().connected_user;
|
|
4058
4063
|
const isCurrentUser = Boolean(connectedUser && event.reaction.user.id === connectedUser.id);
|
|
4059
4064
|
const result = removeReactionFromActivities(event, currentActivities, isCurrentUser);
|
|
4060
4065
|
if (result.changed) {
|
|
@@ -4193,7 +4198,7 @@ class Feed extends FeedApi {
|
|
|
4193
4198
|
// someone followed this feed
|
|
4194
4199
|
event.follow.target_feed.fid === this.fid) {
|
|
4195
4200
|
const source = event.follow.source_feed;
|
|
4196
|
-
const connectedUser = this.client.state.getLatestValue().
|
|
4201
|
+
const connectedUser = this.client.state.getLatestValue().connected_user;
|
|
4197
4202
|
this.state.next((currentState) => {
|
|
4198
4203
|
const newState = { ...currentState, ...event.follow.target_feed };
|
|
4199
4204
|
if (source.created_by.id === connectedUser?.id) {
|
|
@@ -4226,7 +4231,7 @@ class Feed extends FeedApi {
|
|
|
4226
4231
|
// someone unfollowed this feed
|
|
4227
4232
|
event.follow.target_feed.fid === this.fid) {
|
|
4228
4233
|
const source = event.follow.source_feed;
|
|
4229
|
-
const connectedUser = this.client.state.getLatestValue().
|
|
4234
|
+
const connectedUser = this.client.state.getLatestValue().connected_user;
|
|
4230
4235
|
this.state.next((currentState) => {
|
|
4231
4236
|
const newState = { ...currentState, ...event.follow.target_feed };
|
|
4232
4237
|
if (source.created_by.id === connectedUser?.id) {
|
|
@@ -4242,7 +4247,7 @@ class Feed extends FeedApi {
|
|
|
4242
4247
|
'feeds.comment.reaction.deleted': this.handleCommentReactionEvent.bind(this),
|
|
4243
4248
|
'feeds.comment.reaction.updated': Feed.noop,
|
|
4244
4249
|
'feeds.feed_member.added': (event) => {
|
|
4245
|
-
const { connectedUser } = this.client.state.getLatestValue();
|
|
4250
|
+
const { connected_user: connectedUser } = this.client.state.getLatestValue();
|
|
4246
4251
|
this.state.next((currentState) => {
|
|
4247
4252
|
let newState;
|
|
4248
4253
|
if (!checkHasAnotherPage(currentState.members, currentState.member_pagination?.next)) {
|
|
@@ -4263,7 +4268,7 @@ class Feed extends FeedApi {
|
|
|
4263
4268
|
});
|
|
4264
4269
|
},
|
|
4265
4270
|
'feeds.feed_member.removed': (event) => {
|
|
4266
|
-
const { connectedUser } = this.client.state.getLatestValue();
|
|
4271
|
+
const { connected_user: connectedUser } = this.client.state.getLatestValue();
|
|
4267
4272
|
this.state.next((currentState) => {
|
|
4268
4273
|
const newState = {
|
|
4269
4274
|
...currentState,
|
|
@@ -4276,7 +4281,7 @@ class Feed extends FeedApi {
|
|
|
4276
4281
|
});
|
|
4277
4282
|
},
|
|
4278
4283
|
'feeds.feed_member.updated': (event) => {
|
|
4279
|
-
const { connectedUser } = this.client.state.getLatestValue();
|
|
4284
|
+
const { connected_user: connectedUser } = this.client.state.getLatestValue();
|
|
4280
4285
|
this.state.next((currentState) => {
|
|
4281
4286
|
const memberIndex = currentState.members?.findIndex((member) => member.user.id === event.member.user.id) ?? -1;
|
|
4282
4287
|
let newState;
|
|
@@ -4341,7 +4346,7 @@ class Feed extends FeedApi {
|
|
|
4341
4346
|
}
|
|
4342
4347
|
handleCommentReactionEvent(event) {
|
|
4343
4348
|
const { comment, reaction } = event;
|
|
4344
|
-
const connectedUser = this.client.state.getLatestValue().
|
|
4349
|
+
const connectedUser = this.client.state.getLatestValue().connected_user;
|
|
4345
4350
|
this.state.next((currentState) => {
|
|
4346
4351
|
const forId = comment.parent_id ?? comment.object_id;
|
|
4347
4352
|
const entityState = currentState.comments_by_entity_id[forId];
|
|
@@ -4443,7 +4448,7 @@ class Feed extends FeedApi {
|
|
|
4443
4448
|
}
|
|
4444
4449
|
handleBookmarkAdded(event) {
|
|
4445
4450
|
const currentActivities = this.currentState.activities;
|
|
4446
|
-
const { connectedUser } = this.client.state.getLatestValue();
|
|
4451
|
+
const { connected_user: connectedUser } = this.client.state.getLatestValue();
|
|
4447
4452
|
const isCurrentUser = event.bookmark.user.id === connectedUser?.id;
|
|
4448
4453
|
const result = addBookmarkToActivities(event, currentActivities, isCurrentUser);
|
|
4449
4454
|
if (result.changed) {
|
|
@@ -4452,7 +4457,7 @@ class Feed extends FeedApi {
|
|
|
4452
4457
|
}
|
|
4453
4458
|
handleBookmarkDeleted(event) {
|
|
4454
4459
|
const currentActivities = this.currentState.activities;
|
|
4455
|
-
const { connectedUser } = this.client.state.getLatestValue();
|
|
4460
|
+
const { connected_user: connectedUser } = this.client.state.getLatestValue();
|
|
4456
4461
|
const isCurrentUser = event.bookmark.user.id === connectedUser?.id;
|
|
4457
4462
|
const result = removeBookmarkFromActivities(event, currentActivities, isCurrentUser);
|
|
4458
4463
|
if (result.changed) {
|
|
@@ -4461,7 +4466,7 @@ class Feed extends FeedApi {
|
|
|
4461
4466
|
}
|
|
4462
4467
|
handleBookmarkUpdated(event) {
|
|
4463
4468
|
const currentActivities = this.currentState.activities;
|
|
4464
|
-
const { connectedUser } = this.client.state.getLatestValue();
|
|
4469
|
+
const { connected_user: connectedUser } = this.client.state.getLatestValue();
|
|
4465
4470
|
const isCurrentUser = event.bookmark.user.id === connectedUser?.id;
|
|
4466
4471
|
const result = updateBookmarkInActivities(event, currentActivities, isCurrentUser);
|
|
4467
4472
|
if (result.changed) {
|
|
@@ -5016,7 +5021,8 @@ class StreamPoll {
|
|
|
5016
5021
|
if (!isPollVoteCastedEvent(event))
|
|
5017
5022
|
return;
|
|
5018
5023
|
const currentState = this.data;
|
|
5019
|
-
const isOwnVote = event.poll_vote.user_id ===
|
|
5024
|
+
const isOwnVote = event.poll_vote.user_id ===
|
|
5025
|
+
this.client.state.getLatestValue().connected_user?.id;
|
|
5020
5026
|
let latestAnswers = [...currentState.latest_answers];
|
|
5021
5027
|
let ownAnswer = currentState.own_answer;
|
|
5022
5028
|
const ownVotesByOptionId = currentState.own_votes_by_option_id;
|
|
@@ -5040,7 +5046,7 @@ class StreamPoll {
|
|
|
5040
5046
|
else {
|
|
5041
5047
|
maxVotedOptionIds = getMaxVotedOptionIds(event.poll.vote_counts_by_option);
|
|
5042
5048
|
}
|
|
5043
|
-
const { answers_count, latest_votes_by_option, vote_count, vote_counts_by_option } = event.poll;
|
|
5049
|
+
const { answers_count, latest_votes_by_option, vote_count, vote_counts_by_option, } = event.poll;
|
|
5044
5050
|
this.state.partialNext({
|
|
5045
5051
|
answers_count,
|
|
5046
5052
|
// @ts-expect-error Incompatibility between PollResponseData and Poll due to teams_role, remove when OpenAPI spec is fixed
|
|
@@ -5061,7 +5067,8 @@ class StreamPoll {
|
|
|
5061
5067
|
if (!isPollVoteChangedEvent(event))
|
|
5062
5068
|
return;
|
|
5063
5069
|
const currentState = this.data;
|
|
5064
|
-
const isOwnVote = event.poll_vote.user_id ===
|
|
5070
|
+
const isOwnVote = event.poll_vote.user_id ===
|
|
5071
|
+
this.client.state.getLatestValue().connected_user?.id;
|
|
5065
5072
|
let latestAnswers = [...currentState.latest_answers];
|
|
5066
5073
|
let ownAnswer = currentState.own_answer;
|
|
5067
5074
|
let ownVotesByOptionId = currentState.own_votes_by_option_id;
|
|
@@ -5108,7 +5115,7 @@ class StreamPoll {
|
|
|
5108
5115
|
else {
|
|
5109
5116
|
maxVotedOptionIds = getMaxVotedOptionIds(event.poll.vote_counts_by_option);
|
|
5110
5117
|
}
|
|
5111
|
-
const { answers_count, latest_votes_by_option, vote_count, vote_counts_by_option } = event.poll;
|
|
5118
|
+
const { answers_count, latest_votes_by_option, vote_count, vote_counts_by_option, } = event.poll;
|
|
5112
5119
|
this.state.partialNext({
|
|
5113
5120
|
answers_count,
|
|
5114
5121
|
// @ts-expect-error Incompatibility between PollResponseData and Poll due to teams_role, remove when OpenAPI spec is fixed
|
|
@@ -5128,7 +5135,8 @@ class StreamPoll {
|
|
|
5128
5135
|
if (!isPollVoteRemovedEvent(event))
|
|
5129
5136
|
return;
|
|
5130
5137
|
const currentState = this.data;
|
|
5131
|
-
const isOwnVote = event.poll_vote.user_id ===
|
|
5138
|
+
const isOwnVote = event.poll_vote.user_id ===
|
|
5139
|
+
this.client.state.getLatestValue().connected_user?.id;
|
|
5132
5140
|
let latestAnswers = [...currentState.latest_answers];
|
|
5133
5141
|
let ownAnswer = currentState.own_answer;
|
|
5134
5142
|
const ownVotesByOptionId = { ...currentState.own_votes_by_option_id };
|
|
@@ -5146,7 +5154,7 @@ class StreamPoll {
|
|
|
5146
5154
|
delete ownVotesByOptionId[event.poll_vote.option_id];
|
|
5147
5155
|
}
|
|
5148
5156
|
}
|
|
5149
|
-
const { answers_count, latest_votes_by_option, vote_count, vote_counts_by_option } = event.poll;
|
|
5157
|
+
const { answers_count, latest_votes_by_option, vote_count, vote_counts_by_option, } = event.poll;
|
|
5150
5158
|
this.state.partialNext({
|
|
5151
5159
|
answers_count,
|
|
5152
5160
|
// @ts-expect-error Incompatibility between PollResponseData and Poll due to teams_role, remove when OpenAPI spec is fixed
|
|
@@ -5204,7 +5212,7 @@ class FeedsClient extends FeedsApi {
|
|
|
5204
5212
|
this.healthyConnectionChangedEventCount = 0;
|
|
5205
5213
|
this.pollFromState = (id) => this.polls_by_id.get(id);
|
|
5206
5214
|
this.connectUser = async (user, tokenProvider) => {
|
|
5207
|
-
if (this.state.getLatestValue().
|
|
5215
|
+
if (this.state.getLatestValue().connected_user !== undefined ||
|
|
5208
5216
|
this.wsConnection) {
|
|
5209
5217
|
throw new Error(`Can't connect a new user, call "disconnectUser" first`);
|
|
5210
5218
|
}
|
|
@@ -5218,8 +5226,8 @@ class FeedsClient extends FeedsApi {
|
|
|
5218
5226
|
this.wsConnection.on('all', (event) => this.eventDispatcher.dispatch(event));
|
|
5219
5227
|
const connectedEvent = await this.wsConnection.connect();
|
|
5220
5228
|
this.state.partialNext({
|
|
5221
|
-
|
|
5222
|
-
|
|
5229
|
+
connected_user: connectedEvent?.me,
|
|
5230
|
+
is_ws_connection_healthy: !!this.wsConnection?.isHealthy,
|
|
5223
5231
|
});
|
|
5224
5232
|
}
|
|
5225
5233
|
catch (err) {
|
|
@@ -5278,7 +5286,10 @@ class FeedsClient extends FeedsApi {
|
|
|
5278
5286
|
removeConnectionEventListeners(this.updateNetworkConnectionStatus);
|
|
5279
5287
|
this.connectionIdManager.reset();
|
|
5280
5288
|
this.tokenManager.reset();
|
|
5281
|
-
this.state.partialNext({
|
|
5289
|
+
this.state.partialNext({
|
|
5290
|
+
connected_user: undefined,
|
|
5291
|
+
is_ws_connection_healthy: false,
|
|
5292
|
+
});
|
|
5282
5293
|
};
|
|
5283
5294
|
this.on = this.eventDispatcher.on;
|
|
5284
5295
|
this.off = this.eventDispatcher.off;
|
|
@@ -5304,8 +5315,8 @@ class FeedsClient extends FeedsApi {
|
|
|
5304
5315
|
}
|
|
5305
5316
|
};
|
|
5306
5317
|
this.state = new StateStore({
|
|
5307
|
-
|
|
5308
|
-
|
|
5318
|
+
connected_user: undefined,
|
|
5319
|
+
is_ws_connection_healthy: false,
|
|
5309
5320
|
});
|
|
5310
5321
|
this.moderation = new ModerationClient(apiClient);
|
|
5311
5322
|
this.tokenManager = tokenManager;
|
|
@@ -5317,7 +5328,7 @@ class FeedsClient extends FeedsApi {
|
|
|
5317
5328
|
switch (event.type) {
|
|
5318
5329
|
case 'connection.changed': {
|
|
5319
5330
|
const { online } = event;
|
|
5320
|
-
this.state.partialNext({
|
|
5331
|
+
this.state.partialNext({ is_ws_connection_healthy: online });
|
|
5321
5332
|
if (online) {
|
|
5322
5333
|
this.healthyConnectionChangedEventCount++;
|
|
5323
5334
|
// we skip the first event as we could potentially be querying twice
|
|
@@ -5501,11 +5512,11 @@ const useFeedsClient = () => {
|
|
|
5501
5512
|
*/
|
|
5502
5513
|
const useClientConnectedUser = () => {
|
|
5503
5514
|
const client = useFeedsClient();
|
|
5504
|
-
const { user } = useStateStore(client?.state, selector$
|
|
5515
|
+
const { user } = useStateStore(client?.state, selector$7) ?? {};
|
|
5505
5516
|
return user;
|
|
5506
5517
|
};
|
|
5507
|
-
const selector$
|
|
5508
|
-
user: nextState.
|
|
5518
|
+
const selector$7 = (nextState) => ({
|
|
5519
|
+
user: nextState.connected_user,
|
|
5509
5520
|
});
|
|
5510
5521
|
|
|
5511
5522
|
/**
|
|
@@ -5513,11 +5524,11 @@ const selector$5 = (nextState) => ({
|
|
|
5513
5524
|
*/
|
|
5514
5525
|
const useWsConnectionState = () => {
|
|
5515
5526
|
const client = useFeedsClient();
|
|
5516
|
-
const {
|
|
5517
|
-
return {
|
|
5527
|
+
const { is_healthy } = useStateStore(client?.state, selector$6) ?? {};
|
|
5528
|
+
return { is_healthy };
|
|
5518
5529
|
};
|
|
5519
|
-
const selector$
|
|
5520
|
-
|
|
5530
|
+
const selector$6 = (nextState) => ({
|
|
5531
|
+
is_healthy: nextState.is_ws_connection_healthy,
|
|
5521
5532
|
});
|
|
5522
5533
|
|
|
5523
5534
|
const StreamFeedContext = createContext(undefined);
|
|
@@ -5566,19 +5577,19 @@ const useStableCallback = (callback) => {
|
|
|
5566
5577
|
const useFeedActivities = (feedFromProps) => {
|
|
5567
5578
|
const feedFromContext = useFeedContext();
|
|
5568
5579
|
const feed = feedFromProps ?? feedFromContext;
|
|
5569
|
-
const data = useStateStore(feed?.state, selector$
|
|
5580
|
+
const data = useStateStore(feed?.state, selector$5);
|
|
5570
5581
|
const loadNextPage = useStableCallback(async () => {
|
|
5571
|
-
if (!feed || !data?.
|
|
5582
|
+
if (!feed || !data?.has_next_page || data?.is_loading) {
|
|
5572
5583
|
return;
|
|
5573
5584
|
}
|
|
5574
5585
|
await feed.getNextPage();
|
|
5575
5586
|
});
|
|
5576
5587
|
return useMemo(() => ({ ...data, loadNextPage }), [data, loadNextPage]);
|
|
5577
5588
|
};
|
|
5578
|
-
const selector$
|
|
5579
|
-
|
|
5580
|
-
|
|
5581
|
-
activities
|
|
5589
|
+
const selector$5 = ({ is_loading_activities, next, activities = [] }) => ({
|
|
5590
|
+
is_loading: is_loading_activities,
|
|
5591
|
+
has_next_page: typeof next !== 'undefined',
|
|
5592
|
+
activities,
|
|
5582
5593
|
});
|
|
5583
5594
|
|
|
5584
5595
|
function useComments({ feed: feedFromProps, parent, }) {
|
|
@@ -5607,8 +5618,8 @@ function useComments({ feed: feedFromProps, parent, }) {
|
|
|
5607
5618
|
}
|
|
5608
5619
|
return {
|
|
5609
5620
|
...data,
|
|
5610
|
-
|
|
5611
|
-
|
|
5621
|
+
has_next_page: checkHasAnotherPage(data.comments, data.comments_pagination?.next),
|
|
5622
|
+
is_loading_next_page: data?.comments_pagination?.loading_next_page ?? false,
|
|
5612
5623
|
loadNextPage,
|
|
5613
5624
|
};
|
|
5614
5625
|
}, [data, loadNextPage]);
|
|
@@ -5648,48 +5659,48 @@ const FeedOwnCapability = {
|
|
|
5648
5659
|
};
|
|
5649
5660
|
|
|
5650
5661
|
const stableEmptyArray = [];
|
|
5651
|
-
const selector$
|
|
5662
|
+
const selector$4 = (currentState) => ({
|
|
5652
5663
|
oc: currentState.own_capabilities ?? stableEmptyArray,
|
|
5653
5664
|
});
|
|
5654
5665
|
const useOwnCapabilities = (feedFromProps) => {
|
|
5655
5666
|
const feedFromContext = useFeedContext();
|
|
5656
5667
|
const feed = feedFromProps ?? feedFromContext;
|
|
5657
|
-
const { oc = stableEmptyArray } = useStateStore(feed?.state, selector$
|
|
5668
|
+
const { oc = stableEmptyArray } = useStateStore(feed?.state, selector$4) ?? {};
|
|
5658
5669
|
return useMemo(() => ({
|
|
5659
|
-
|
|
5660
|
-
|
|
5661
|
-
|
|
5662
|
-
|
|
5663
|
-
|
|
5664
|
-
|
|
5665
|
-
|
|
5666
|
-
|
|
5667
|
-
|
|
5668
|
-
|
|
5669
|
-
|
|
5670
|
-
|
|
5671
|
-
|
|
5672
|
-
|
|
5673
|
-
|
|
5674
|
-
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
|
|
5681
|
-
|
|
5682
|
-
|
|
5683
|
-
|
|
5684
|
-
|
|
5685
|
-
|
|
5686
|
-
|
|
5687
|
-
|
|
5688
|
-
|
|
5670
|
+
can_add_activity: oc.indexOf(FeedOwnCapability.ADD_ACTIVITY) > -1,
|
|
5671
|
+
can_add_activity_reaction: oc.indexOf(FeedOwnCapability.ADD_ACTIVITY_REACTION) > -1,
|
|
5672
|
+
can_add_comment: oc.indexOf(FeedOwnCapability.ADD_COMMENT) > -1,
|
|
5673
|
+
can_add_comment_reaction: oc.indexOf(FeedOwnCapability.ADD_COMMENT_REACTION) > -1,
|
|
5674
|
+
can_bookmark_activity: oc.indexOf(FeedOwnCapability.BOOKMARK_ACTIVITY) > -1,
|
|
5675
|
+
can_create_feed: oc.indexOf(FeedOwnCapability.CREATE_FEED) > -1,
|
|
5676
|
+
can_delete_bookmark: oc.indexOf(FeedOwnCapability.DELETE_BOOKMARK) > -1,
|
|
5677
|
+
can_delete_comment: oc.indexOf(FeedOwnCapability.DELETE_COMMENT) > -1,
|
|
5678
|
+
can_delete_feed: oc.indexOf(FeedOwnCapability.DELETE_FEED) > -1,
|
|
5679
|
+
can_edit_bookmark: oc.indexOf(FeedOwnCapability.EDIT_BOOKMARK) > -1,
|
|
5680
|
+
can_follow: oc.indexOf(FeedOwnCapability.FOLLOW) > -1,
|
|
5681
|
+
can_remove_activity: oc.indexOf(FeedOwnCapability.REMOVE_ACTIVITY) > -1,
|
|
5682
|
+
can_remove_activity_reaction: oc.indexOf(FeedOwnCapability.REMOVE_ACTIVITY_REACTION) > -1,
|
|
5683
|
+
can_remove_comment_reaction: oc.indexOf(FeedOwnCapability.REMOVE_COMMENT_REACTION) > -1,
|
|
5684
|
+
can_unfollow: oc.indexOf(FeedOwnCapability.UNFOLLOW) > -1,
|
|
5685
|
+
can_update_feed: oc.indexOf(FeedOwnCapability.UPDATE_FEED) > -1,
|
|
5686
|
+
can_invite_feed: oc.indexOf(FeedOwnCapability.INVITE_FEED) > -1,
|
|
5687
|
+
can_join_feed: oc.indexOf(FeedOwnCapability.JOIN_FEED) > -1,
|
|
5688
|
+
can_leave_feed: oc.indexOf(FeedOwnCapability.LEAVE_FEED) > -1,
|
|
5689
|
+
can_manage_feed_group: oc.indexOf(FeedOwnCapability.MANAGE_FEED_GROUP) > -1,
|
|
5690
|
+
can_mark_activity: oc.indexOf(FeedOwnCapability.MARK_ACTIVITY) > -1,
|
|
5691
|
+
can_pin_activity: oc.indexOf(FeedOwnCapability.PIN_ACTIVITY) > -1,
|
|
5692
|
+
can_query_feed_members: oc.indexOf(FeedOwnCapability.QUERY_FEED_MEMBERS) > -1,
|
|
5693
|
+
can_query_follows: oc.indexOf(FeedOwnCapability.QUERY_FOLLOWS) > -1,
|
|
5694
|
+
can_read_activities: oc.indexOf(FeedOwnCapability.READ_ACTIVITIES) > -1,
|
|
5695
|
+
can_read_feed: oc.indexOf(FeedOwnCapability.READ_FEED) > -1,
|
|
5696
|
+
can_update_activity: oc.indexOf(FeedOwnCapability.UPDATE_ACTIVITY) > -1,
|
|
5697
|
+
can_update_comment: oc.indexOf(FeedOwnCapability.UPDATE_COMMENT) > -1,
|
|
5698
|
+
can_update_feed_followers: oc.indexOf(FeedOwnCapability.UPDATE_FEED_FOLLOWERS) > -1,
|
|
5699
|
+
can_update_feed_members: oc.indexOf(FeedOwnCapability.UPDATE_FEED_MEMBERS) > -1,
|
|
5689
5700
|
}), [oc]);
|
|
5690
5701
|
};
|
|
5691
5702
|
|
|
5692
|
-
const selector$
|
|
5703
|
+
const selector$3 = ({ follower_count, followers, followers_pagination, }) => ({
|
|
5693
5704
|
follower_count,
|
|
5694
5705
|
followers,
|
|
5695
5706
|
followers_pagination,
|
|
@@ -5697,7 +5708,7 @@ const selector$1 = ({ follower_count, followers, followers_pagination, }) => ({
|
|
|
5697
5708
|
function useFollowers(feedFromProps) {
|
|
5698
5709
|
const feedFromContext = useFeedContext();
|
|
5699
5710
|
const feed = feedFromProps ?? feedFromContext;
|
|
5700
|
-
const data = useStateStore(feed?.state, selector$
|
|
5711
|
+
const data = useStateStore(feed?.state, selector$3);
|
|
5701
5712
|
const loadNextPage = useCallback((...options) => feed?.loadNextPageFollowers(...options), [feed]);
|
|
5702
5713
|
return useMemo(() => {
|
|
5703
5714
|
if (!data) {
|
|
@@ -5705,14 +5716,14 @@ function useFollowers(feedFromProps) {
|
|
|
5705
5716
|
}
|
|
5706
5717
|
return {
|
|
5707
5718
|
...data,
|
|
5708
|
-
|
|
5709
|
-
|
|
5719
|
+
is_loading_next_page: data.followers_pagination?.loading_next_page ?? false,
|
|
5720
|
+
has_next_page: checkHasAnotherPage(data.followers, data.followers_pagination?.next),
|
|
5710
5721
|
loadNextPage,
|
|
5711
5722
|
};
|
|
5712
5723
|
}, [data, loadNextPage]);
|
|
5713
5724
|
}
|
|
5714
5725
|
|
|
5715
|
-
const selector = ({ following_count, following, following_pagination, }) => ({
|
|
5726
|
+
const selector$2 = ({ following_count, following, following_pagination, }) => ({
|
|
5716
5727
|
following_count,
|
|
5717
5728
|
following,
|
|
5718
5729
|
following_pagination,
|
|
@@ -5720,7 +5731,7 @@ const selector = ({ following_count, following, following_pagination, }) => ({
|
|
|
5720
5731
|
function useFollowing(feedFromProps) {
|
|
5721
5732
|
const feedFromContext = useFeedContext();
|
|
5722
5733
|
const feed = feedFromProps ?? feedFromContext;
|
|
5723
|
-
const data = useStateStore(feed?.state, selector);
|
|
5734
|
+
const data = useStateStore(feed?.state, selector$2);
|
|
5724
5735
|
const loadNextPage = useCallback((...options) => feed?.loadNextPageFollowing(...options), [feed]);
|
|
5725
5736
|
return useMemo(() => {
|
|
5726
5737
|
if (!data) {
|
|
@@ -5728,13 +5739,43 @@ function useFollowing(feedFromProps) {
|
|
|
5728
5739
|
}
|
|
5729
5740
|
return {
|
|
5730
5741
|
...data,
|
|
5731
|
-
|
|
5732
|
-
|
|
5742
|
+
is_loading_next_page: data.following_pagination?.loading_next_page ?? false,
|
|
5743
|
+
has_next_page: checkHasAnotherPage(data.following, data.following_pagination?.next),
|
|
5733
5744
|
loadNextPage,
|
|
5734
5745
|
};
|
|
5735
5746
|
}, [data, loadNextPage]);
|
|
5736
5747
|
}
|
|
5737
5748
|
|
|
5749
|
+
/**
|
|
5750
|
+
* A React hook that returns a reactive object containing some often used
|
|
5751
|
+
* metadata for a feed.
|
|
5752
|
+
*/
|
|
5753
|
+
const useFeedMetadata = (feedFromProps) => {
|
|
5754
|
+
const feedFromContext = useFeedContext();
|
|
5755
|
+
const feed = feedFromProps ?? feedFromContext;
|
|
5756
|
+
return useStateStore(feed?.state, selector$1);
|
|
5757
|
+
};
|
|
5758
|
+
const selector$1 = ({ follower_count = 0, following_count = 0, created_by, created_at, updated_at, }) => ({
|
|
5759
|
+
created_by,
|
|
5760
|
+
follower_count,
|
|
5761
|
+
following_count,
|
|
5762
|
+
created_at,
|
|
5763
|
+
updated_at,
|
|
5764
|
+
});
|
|
5765
|
+
|
|
5766
|
+
/**
|
|
5767
|
+
* A React hook that returns a reactive array of feeds that the current user
|
|
5768
|
+
* owns and are following the respective feed that we are observing.
|
|
5769
|
+
*/
|
|
5770
|
+
const useOwnFollows = (feedFromProps) => {
|
|
5771
|
+
const feedFromContext = useFeedContext();
|
|
5772
|
+
const feed = feedFromProps ?? feedFromContext;
|
|
5773
|
+
return useStateStore(feed?.state, selector);
|
|
5774
|
+
};
|
|
5775
|
+
const selector = ({ own_follows }) => ({
|
|
5776
|
+
own_follows,
|
|
5777
|
+
});
|
|
5778
|
+
|
|
5738
5779
|
/**
|
|
5739
5780
|
* A utility hook that takes in an entity and a reaction type, and creates reaction actions
|
|
5740
5781
|
* that can then be used on the UI. The entity can be either an ActivityResponse or a CommentResponse
|
|
@@ -5781,5 +5822,5 @@ const StreamFeed = ({ feed, children }) => {
|
|
|
5781
5822
|
};
|
|
5782
5823
|
StreamFeed.displayName = 'StreamFeed';
|
|
5783
5824
|
|
|
5784
|
-
export { StreamFeed, StreamFeedContext, StreamFeeds, StreamFeedsContext, useClientConnectedUser, useComments, useCreateFeedsClient, useFeedActivities, useFeedContext, useFeedsClient, useFollowers, useFollowing, useOwnCapabilities, useReactionActions, useStateStore, useWsConnectionState };
|
|
5825
|
+
export { StreamFeed, StreamFeedContext, StreamFeeds, StreamFeedsContext, useClientConnectedUser, useComments, useCreateFeedsClient, useFeedActivities, useFeedContext, useFeedMetadata, useFeedsClient, useFollowers, useFollowing, useOwnCapabilities, useOwnFollows, useReactionActions, useStateStore, useWsConnectionState };
|
|
5785
5826
|
//# sourceMappingURL=index-react-bindings.node.js.map
|