@stream-io/feeds-client 1.1.0 → 1.2.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.
@@ -1,532 +1,500 @@
1
+ import { t as FeedsClient, u as isCommentResponse, v as checkHasAnotherPage } from "../feeds-client-ACVPbpUP.mjs";
1
2
  import { useStateStore } from "@stream-io/state-store/react-bindings";
2
- export * from "@stream-io/state-store/react-bindings";
3
- import { useState, useEffect, createContext, useContext, useRef, useCallback, useMemo } from "react";
4
- import { F as FeedsClient, h as isCommentResponse, e as checkHasAnotherPage } from "../feeds-client-jtUTE4AC.mjs";
3
+ import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
5
4
  import { jsx } from "react/jsx-runtime";
6
- const useCreateFeedsClient = ({
7
- apiKey,
8
- tokenOrProvider,
9
- userData: userDataOrAnonymous,
10
- options
11
- }) => {
12
- const userData = userDataOrAnonymous === "anonymous" ? void 0 : userDataOrAnonymous;
13
- if (userDataOrAnonymous !== "anonymous" && !tokenOrProvider) {
14
- throw new Error(
15
- 'Token provider can only be omitted when connecting anonymous user. If you want to connect as a guest, provide "guest" instead of a token provider.'
16
- );
17
- }
18
- const [client, setClient] = useState(null);
19
- const [error, setError] = useState(null);
20
- const [cachedUserData, setCachedUserData] = useState(userData);
21
- const [cachedOptions] = useState(options);
22
- if (error) {
23
- throw error;
24
- }
25
- if (userData?.id !== cachedUserData?.id) {
26
- setCachedUserData(userData);
27
- }
28
- useEffect(() => {
29
- const _client = new FeedsClient(apiKey, cachedOptions);
30
- let connectionPromise;
31
- if (!cachedUserData) {
32
- connectionPromise = _client.connectAnonymous();
33
- } else if (tokenOrProvider === "guest") {
34
- connectionPromise = _client.connectGuest({
35
- user: cachedUserData
36
- });
37
- } else {
38
- connectionPromise = _client.connectUser(cachedUserData, tokenOrProvider);
39
- }
40
- connectionPromise = connectionPromise.then(() => {
41
- setError(null);
42
- }).catch((err) => {
43
- setError(err);
44
- });
45
- setClient(_client);
46
- return () => {
47
- setClient(null);
48
- connectionPromise.then(() => {
49
- setError(null);
50
- return _client.disconnectUser();
51
- }).catch((err) => {
52
- setError(err);
53
- });
54
- };
55
- }, [apiKey, cachedUserData, cachedOptions, tokenOrProvider]);
56
- return client;
5
+ export * from "@stream-io/state-store/react-bindings";
6
+ //#region src/bindings/react/hooks/useCreateFeedsClient.ts
7
+ /**
8
+ * A React hook to create, connect and return an instance of `FeedsClient`.
9
+ */
10
+ var useCreateFeedsClient = ({ apiKey, tokenOrProvider, userData: userDataOrAnonymous, options }) => {
11
+ const userData = userDataOrAnonymous === "anonymous" ? void 0 : userDataOrAnonymous;
12
+ if (userDataOrAnonymous !== "anonymous" && !tokenOrProvider) throw new Error("Token provider can only be omitted when connecting anonymous user. If you want to connect as a guest, provide \"guest\" instead of a token provider.");
13
+ const [client, setClient] = useState(null);
14
+ const [error, setError] = useState(null);
15
+ const [cachedUserData, setCachedUserData] = useState(userData);
16
+ const [cachedOptions] = useState(options);
17
+ if (error) throw error;
18
+ if (userData?.id !== cachedUserData?.id) setCachedUserData(userData);
19
+ useEffect(() => {
20
+ const _client = new FeedsClient(apiKey, cachedOptions);
21
+ let connectionPromise;
22
+ if (!cachedUserData) connectionPromise = _client.connectAnonymous();
23
+ else if (tokenOrProvider === "guest") connectionPromise = _client.connectGuest({ user: cachedUserData });
24
+ else connectionPromise = _client.connectUser(cachedUserData, tokenOrProvider);
25
+ connectionPromise = connectionPromise.then(() => {
26
+ setError(null);
27
+ }).catch((err) => {
28
+ setError(err);
29
+ });
30
+ setClient(_client);
31
+ return () => {
32
+ setClient(null);
33
+ connectionPromise.then(() => {
34
+ setError(null);
35
+ return _client.disconnectUser();
36
+ }).catch((err) => {
37
+ setError(err);
38
+ });
39
+ };
40
+ }, [
41
+ apiKey,
42
+ cachedUserData,
43
+ cachedOptions,
44
+ tokenOrProvider
45
+ ]);
46
+ return client;
57
47
  };
58
- const StreamFeedsContext = createContext(void 0);
59
- const useFeedsClient = () => {
60
- return useContext(StreamFeedsContext);
48
+ //#endregion
49
+ //#region src/bindings/react/contexts/StreamFeedsContext.tsx
50
+ var StreamFeedsContext = createContext(void 0);
51
+ /**
52
+ * Hook to access the nearest FeedsClient instance.
53
+ */
54
+ var useFeedsClient = () => {
55
+ return useContext(StreamFeedsContext);
61
56
  };
62
- const useClientConnectedUser = () => {
63
- const client = useFeedsClient();
64
- const { user } = useStateStore(client?.state, selector$e) ?? {};
65
- return user;
57
+ //#endregion
58
+ //#region src/bindings/react/hooks/client-state-hooks/useClientConnectedUser.ts
59
+ /**
60
+ * A React hook that returns the currently connected user on a `FeedsClient` instance and null otherwise.
61
+ */
62
+ var useClientConnectedUser = () => {
63
+ const { user } = useStateStore(useFeedsClient()?.state, selector$14) ?? {};
64
+ return user;
66
65
  };
67
- const selector$e = (nextState) => ({
68
- user: nextState.connected_user
69
- });
70
- const useWsConnectionState = () => {
71
- const client = useFeedsClient();
72
- const { is_healthy } = useStateStore(client?.state, selector$d) ?? {};
73
- return { is_healthy };
66
+ var selector$14 = (nextState) => ({ user: nextState.connected_user });
67
+ //#endregion
68
+ //#region src/bindings/react/hooks/client-state-hooks/useWsConnectionState.ts
69
+ /**
70
+ * A React hook that returns the websocket connection state of `FeedsClient`.
71
+ */
72
+ var useWsConnectionState = () => {
73
+ const { is_healthy } = useStateStore(useFeedsClient()?.state, selector$13) ?? {};
74
+ return { is_healthy };
74
75
  };
75
- const selector$d = (nextState) => ({
76
- is_healthy: nextState.is_ws_connection_healthy
77
- });
78
- const StreamFeedContext = createContext(void 0);
79
- const useFeedContext = () => {
80
- return useContext(StreamFeedContext);
76
+ var selector$13 = (nextState) => ({ is_healthy: nextState.is_ws_connection_healthy });
77
+ //#endregion
78
+ //#region src/bindings/react/contexts/StreamFeedContext.tsx
79
+ var StreamFeedContext = createContext(void 0);
80
+ /**
81
+ * Hook to access the nearest Feed instance.
82
+ */
83
+ var useFeedContext = () => {
84
+ return useContext(StreamFeedContext);
81
85
  };
82
- const useStableCallback = (callback) => {
83
- const ref = useRef(callback);
84
- ref.current = callback;
85
- return useCallback((...args) => {
86
- return ref.current(...args);
87
- }, []);
86
+ //#endregion
87
+ //#region src/bindings/react/hooks/internal/useStableCallback.ts
88
+ /**
89
+ * A utility hook implementing a stable callback. It takes in an unstable method that
90
+ * is supposed to be invoked somewhere deeper in the DOM tree without making it
91
+ * change its reference every time the parent component rerenders. It will also return
92
+ * the value of the callback if it does return one.
93
+ * A common use-case would be having a function whose invocation depends on state
94
+ * somewhere high up in the DOM tree and wanting to use the same function deeper
95
+ * down, for example in a leaf node and simply using useCallback results in
96
+ * cascading dependency hell. If we wrap it in useStableCallback, we would be able
97
+ * to:
98
+ * - Use the same function as a dependency of another hook (since it is stable)
99
+ * - Still invoke it and get the latest state
100
+ *
101
+ * **Caveats:**
102
+ * - Never wrap a function that is supposed to return a React.ReactElement in
103
+ * useStableCallback, since React will not know that the DOM needs to be updated
104
+ * whenever the callback value changes (for example, renderItem from FlatList must
105
+ * never be wrapped in this hook)
106
+ * - Always prefer using a standard useCallback/stable function wherever possible
107
+ * (the purpose of useStableCallback is to bridge the gap between top level contexts
108
+ * and cascading rereders in downstream components - **not** as an escape hatch)
109
+ * @param callback - the callback we want to stabilize
110
+ */
111
+ var useStableCallback = (callback) => {
112
+ const ref = useRef(callback);
113
+ ref.current = callback;
114
+ return useCallback((...args) => {
115
+ return ref.current(...args);
116
+ }, []);
88
117
  };
89
- const useFeedActivities = (feedFromProps) => {
90
- const feedFromContext = useFeedContext();
91
- const feed = feedFromProps ?? feedFromContext;
92
- const data = useStateStore(feed?.state, selector$c);
93
- const loadNextPage = useStableCallback(async () => {
94
- if (!feed || !data?.has_next_page || data?.is_loading) {
95
- return;
96
- }
97
- await feed.getNextPage();
98
- });
99
- return useMemo(() => ({ ...data, loadNextPage }), [data, loadNextPage]);
118
+ //#endregion
119
+ //#region src/bindings/react/hooks/feed-state-hooks/useFeedActivities.ts
120
+ /**
121
+ * A React hook that returns a reactive object containing the current activities,
122
+ * loading state and whether there is a next page to paginate to or not.
123
+ */
124
+ var useFeedActivities = (feedFromProps) => {
125
+ const feedFromContext = useFeedContext();
126
+ const feed = feedFromProps ?? feedFromContext;
127
+ const data = useStateStore(feed?.state, selector$12);
128
+ const loadNextPage = useStableCallback(async () => {
129
+ if (!feed || !data?.has_next_page || data?.is_loading) return;
130
+ await feed.getNextPage();
131
+ });
132
+ return useMemo(() => ({
133
+ ...data,
134
+ loadNextPage
135
+ }), [data, loadNextPage]);
100
136
  };
101
- const selector$c = ({
102
- is_loading_activities,
103
- next,
104
- activities = []
105
- }) => ({
106
- is_loading: is_loading_activities,
107
- has_next_page: typeof next !== "undefined",
108
- activities
137
+ var selector$12 = ({ is_loading_activities, next, activities = [] }) => ({
138
+ is_loading: is_loading_activities,
139
+ has_next_page: typeof next !== "undefined",
140
+ activities
109
141
  });
110
- function useComments({
111
- feed: feedFromProps,
112
- parent
113
- }) {
114
- const feedFromContext = useFeedContext();
115
- const feed = feedFromProps ?? feedFromContext;
116
- const selector2 = useCallback(
117
- (state) => ({
118
- comments: state.comments_by_entity_id?.[parent.id]?.comments,
119
- comments_pagination: state.comments_by_entity_id?.[parent.id]?.pagination
120
- }),
121
- [parent.id]
122
- );
123
- const data = useStateStore(feed?.state, selector2);
124
- const loadNextPage = useMemo(() => {
125
- if (!feed) return void 0;
126
- return (request) => {
127
- if (isCommentResponse(parent)) {
128
- return feed.loadNextPageCommentReplies(parent, request);
129
- } else {
130
- return feed.loadNextPageActivityComments(parent, request);
131
- }
132
- };
133
- }, [feed, parent]);
134
- return useMemo(() => {
135
- if (!data) {
136
- return void 0;
137
- }
138
- return {
139
- ...data,
140
- has_next_page: checkHasAnotherPage(
141
- data.comments,
142
- data.comments_pagination?.next
143
- ),
144
- is_loading_next_page: data?.comments_pagination?.loading_next_page ?? false,
145
- loadNextPage
146
- };
147
- }, [data, loadNextPage]);
142
+ //#endregion
143
+ //#region src/bindings/react/hooks/feed-state-hooks/useComments.ts
144
+ function useComments({ feed: feedFromProps, parent }) {
145
+ const feedFromContext = useFeedContext();
146
+ const feed = feedFromProps ?? feedFromContext;
147
+ const selector = useCallback((state) => ({
148
+ comments: state.comments_by_entity_id?.[parent.id]?.comments,
149
+ comments_pagination: state.comments_by_entity_id?.[parent.id]?.pagination
150
+ }), [parent.id]);
151
+ const data = useStateStore(feed?.state, selector);
152
+ const loadNextPage = useMemo(() => {
153
+ if (!feed) return void 0;
154
+ return (request) => {
155
+ if (isCommentResponse(parent)) return feed.loadNextPageCommentReplies(parent, request);
156
+ else return feed.loadNextPageActivityComments(parent, request);
157
+ };
158
+ }, [feed, parent]);
159
+ return useMemo(() => {
160
+ if (!data) return;
161
+ return {
162
+ ...data,
163
+ has_next_page: checkHasAnotherPage(data.comments, data.comments_pagination?.next),
164
+ is_loading_next_page: data?.comments_pagination?.loading_next_page ?? false,
165
+ loadNextPage
166
+ };
167
+ }, [data, loadNextPage]);
148
168
  }
149
- const stableEmptyArray = [];
150
- const selector$b = (currentState) => {
151
- return {
152
- feedOwnCapabilities: currentState.own_capabilities ?? stableEmptyArray
153
- };
169
+ //#endregion
170
+ //#region src/bindings/react/hooks/feed-state-hooks/useOwnCapabilities.ts
171
+ var stableEmptyArray = [];
172
+ var selector$11 = (currentState) => {
173
+ return { feedOwnCapabilities: currentState.own_capabilities ?? stableEmptyArray };
154
174
  };
155
- const useOwnCapabilities = (feedFromProps) => {
156
- const client = useFeedsClient();
157
- const feedFromContext = useFeedContext();
158
- let feed = feedFromProps ?? feedFromContext;
159
- if (typeof feed === "string") {
160
- const [groupId, id] = feed.split(":");
161
- feed = groupId && id ? client?.feed(groupId, id) : void 0;
162
- }
163
- const { feedOwnCapabilities = stableEmptyArray } = useStateStore(feed?.state, selector$b) ?? {};
164
- return feedOwnCapabilities;
175
+ var useOwnCapabilities = (feedFromProps) => {
176
+ const client = useFeedsClient();
177
+ const feedFromContext = useFeedContext();
178
+ let feed = feedFromProps ?? feedFromContext;
179
+ if (typeof feed === "string") {
180
+ const [groupId, id] = feed.split(":");
181
+ feed = groupId && id ? client?.feed(groupId, id) : void 0;
182
+ }
183
+ const { feedOwnCapabilities = stableEmptyArray } = useStateStore(feed?.state, selector$11) ?? {};
184
+ return feedOwnCapabilities;
165
185
  };
166
- const selector$a = ({
167
- follower_count,
168
- followers,
169
- followers_pagination
170
- }) => ({
171
- follower_count,
172
- followers,
173
- followers_pagination
186
+ //#endregion
187
+ //#region src/bindings/react/hooks/feed-state-hooks/useFollowers.ts
188
+ var selector$10 = ({ follower_count, followers, followers_pagination }) => ({
189
+ follower_count,
190
+ followers,
191
+ followers_pagination
174
192
  });
175
193
  function useFollowers(feedFromProps) {
176
- const feedFromContext = useFeedContext();
177
- const feed = feedFromProps ?? feedFromContext;
178
- const data = useStateStore(feed?.state, selector$a);
179
- const loadNextPage = useCallback(
180
- (...options) => feed?.loadNextPageFollowers(...options),
181
- [feed]
182
- );
183
- return useMemo(() => {
184
- if (!data) {
185
- return void 0;
186
- }
187
- return {
188
- ...data,
189
- is_loading_next_page: data.followers_pagination?.loading_next_page ?? false,
190
- has_next_page: checkHasAnotherPage(
191
- data.followers,
192
- data.followers_pagination?.next
193
- ),
194
- loadNextPage
195
- };
196
- }, [data, loadNextPage]);
194
+ const feedFromContext = useFeedContext();
195
+ const feed = feedFromProps ?? feedFromContext;
196
+ const data = useStateStore(feed?.state, selector$10);
197
+ const loadNextPage = useCallback((...options) => feed?.loadNextPageFollowers(...options), [feed]);
198
+ return useMemo(() => {
199
+ if (!data) return;
200
+ return {
201
+ ...data,
202
+ is_loading_next_page: data.followers_pagination?.loading_next_page ?? false,
203
+ has_next_page: checkHasAnotherPage(data.followers, data.followers_pagination?.next),
204
+ loadNextPage
205
+ };
206
+ }, [data, loadNextPage]);
197
207
  }
198
- const selector$9 = ({
199
- following_count,
200
- following,
201
- following_pagination
202
- }) => ({
203
- following_count,
204
- following,
205
- following_pagination
208
+ //#endregion
209
+ //#region src/bindings/react/hooks/feed-state-hooks/useFollowing.ts
210
+ var selector$9 = ({ following_count, following, following_pagination }) => ({
211
+ following_count,
212
+ following,
213
+ following_pagination
206
214
  });
207
215
  function useFollowing(feedFromProps) {
208
- const feedFromContext = useFeedContext();
209
- const feed = feedFromProps ?? feedFromContext;
210
- const data = useStateStore(feed?.state, selector$9);
211
- const loadNextPage = useCallback(
212
- (...options) => feed?.loadNextPageFollowing(...options),
213
- [feed]
214
- );
215
- return useMemo(() => {
216
- if (!data) {
217
- return void 0;
218
- }
219
- return {
220
- ...data,
221
- is_loading_next_page: data.following_pagination?.loading_next_page ?? false,
222
- has_next_page: checkHasAnotherPage(
223
- data.following,
224
- data.following_pagination?.next
225
- ),
226
- loadNextPage
227
- };
228
- }, [data, loadNextPage]);
216
+ const feedFromContext = useFeedContext();
217
+ const feed = feedFromProps ?? feedFromContext;
218
+ const data = useStateStore(feed?.state, selector$9);
219
+ const loadNextPage = useCallback((...options) => feed?.loadNextPageFollowing(...options), [feed]);
220
+ return useMemo(() => {
221
+ if (!data) return;
222
+ return {
223
+ ...data,
224
+ is_loading_next_page: data.following_pagination?.loading_next_page ?? false,
225
+ has_next_page: checkHasAnotherPage(data.following, data.following_pagination?.next),
226
+ loadNextPage
227
+ };
228
+ }, [data, loadNextPage]);
229
229
  }
230
- const useFeedMetadata = (feedFromProps) => {
231
- const feedFromContext = useFeedContext();
232
- const feed = feedFromProps ?? feedFromContext;
233
- return useStateStore(feed?.state, selector$8);
230
+ //#endregion
231
+ //#region src/bindings/react/hooks/feed-state-hooks/useFeedMetadata.ts
232
+ /**
233
+ * A React hook that returns a reactive object containing some often used
234
+ * metadata for a feed.
235
+ */
236
+ var useFeedMetadata = (feedFromProps) => {
237
+ const feedFromContext = useFeedContext();
238
+ return useStateStore((feedFromProps ?? feedFromContext)?.state, selector$8);
234
239
  };
235
- const selector$8 = ({
236
- follower_count = 0,
237
- following_count = 0,
238
- created_by,
239
- created_at,
240
- updated_at
241
- }) => ({
242
- created_by,
243
- follower_count,
244
- following_count,
245
- created_at,
246
- updated_at
240
+ var selector$8 = ({ follower_count = 0, following_count = 0, created_by, created_at, updated_at }) => ({
241
+ created_by,
242
+ follower_count,
243
+ following_count,
244
+ created_at,
245
+ updated_at
247
246
  });
248
- const useOwnFollows = (feedFromProps) => {
249
- const feedFromContext = useFeedContext();
250
- const feed = feedFromProps ?? feedFromContext;
251
- return useStateStore(feed?.state, selector$7);
247
+ //#endregion
248
+ //#region src/bindings/react/hooks/feed-state-hooks/useOwnFollows.ts
249
+ /**
250
+ * A React hook that returns a reactive array of feeds that the current user
251
+ * owns and are following the respective feed that we are observing.
252
+ */
253
+ var useOwnFollows = (feedFromProps) => {
254
+ const feedFromContext = useFeedContext();
255
+ return useStateStore((feedFromProps ?? feedFromContext)?.state, selector$7);
252
256
  };
253
- const selector$7 = ({ own_follows }) => ({
254
- own_follows
255
- });
256
- const selector$6 = ({ notification_status }) => ({
257
- unread: notification_status?.unread ?? 0,
258
- unseen: notification_status?.unseen ?? 0,
259
- last_read_at: notification_status?.last_read_at,
260
- last_seen_at: notification_status?.last_seen_at,
261
- read_activities: notification_status?.read_activities,
262
- seen_activities: notification_status?.seen_activities
257
+ var selector$7 = ({ own_follows }) => ({ own_follows });
258
+ //#endregion
259
+ //#region src/bindings/react/hooks/feed-state-hooks/useNotificationStatus.ts
260
+ var selector$6 = ({ notification_status }) => ({
261
+ unread: notification_status?.unread ?? 0,
262
+ unseen: notification_status?.unseen ?? 0,
263
+ last_read_at: notification_status?.last_read_at,
264
+ last_seen_at: notification_status?.last_seen_at,
265
+ read_activities: notification_status?.read_activities,
266
+ seen_activities: notification_status?.seen_activities
263
267
  });
264
268
  function useNotificationStatus(feedFromProps) {
265
- const feedFromContext = useFeedContext();
266
- const feed = feedFromProps ?? feedFromContext;
267
- return useStateStore(feed?.state, selector$6);
269
+ const feedFromContext = useFeedContext();
270
+ return useStateStore((feedFromProps ?? feedFromContext)?.state, selector$6);
268
271
  }
269
- const selector$5 = ({
270
- is_loading_activities,
271
- next,
272
- aggregated_activities = []
273
- }) => ({
274
- is_loading: is_loading_activities,
275
- has_next_page: typeof next !== "undefined",
276
- aggregated_activities
272
+ //#endregion
273
+ //#region src/bindings/react/hooks/feed-state-hooks/useAggregatedActivities.ts
274
+ var selector$5 = ({ is_loading_activities, next, aggregated_activities = [] }) => ({
275
+ is_loading: is_loading_activities,
276
+ has_next_page: typeof next !== "undefined",
277
+ aggregated_activities
277
278
  });
278
279
  function useAggregatedActivities(feedFromProps) {
279
- const feedFromContext = useFeedContext();
280
- const feed = feedFromProps ?? feedFromContext;
281
- const data = useStateStore(feed?.state, selector$5);
282
- const loadNextPage = useStableCallback(async () => {
283
- if (!feed || !data?.has_next_page || data?.is_loading) {
284
- return;
285
- }
286
- await feed.getNextPage();
287
- });
288
- return useMemo(
289
- () => data ? { ...data, loadNextPage } : void 0,
290
- [data, loadNextPage]
291
- );
280
+ const feedFromContext = useFeedContext();
281
+ const feed = feedFromProps ?? feedFromContext;
282
+ const data = useStateStore(feed?.state, selector$5);
283
+ const loadNextPage = useStableCallback(async () => {
284
+ if (!feed || !data?.has_next_page || data?.is_loading) return;
285
+ await feed.getNextPage();
286
+ });
287
+ return useMemo(() => data ? {
288
+ ...data,
289
+ loadNextPage
290
+ } : void 0, [data, loadNextPage]);
292
291
  }
293
- const useIsAggregatedActivityRead = ({
294
- feed: _,
295
- aggregatedActivity
296
- }) => {
297
- return aggregatedActivity.is_read;
292
+ //#endregion
293
+ //#region src/bindings/react/hooks/feed-state-hooks/useIsAggregatedActivityRead.ts
294
+ /**
295
+ * @deprecated use aggregatedActivity.is_read instead
296
+ * @returns
297
+ */
298
+ var useIsAggregatedActivityRead = ({ feed: _, aggregatedActivity }) => {
299
+ return aggregatedActivity.is_read;
298
300
  };
299
- const useIsAggregatedActivitySeen = ({
300
- feed: _,
301
- aggregatedActivity
302
- }) => {
303
- return aggregatedActivity.is_seen;
301
+ //#endregion
302
+ //#region src/bindings/react/hooks/feed-state-hooks/useIsAggregatedActivitySeen.ts
303
+ /**
304
+ * @deprecated use aggregatedActivity.is_seen instead
305
+ * @returns
306
+ */
307
+ var useIsAggregatedActivitySeen = ({ feed: _, aggregatedActivity }) => {
308
+ return aggregatedActivity.is_seen;
304
309
  };
305
- const StreamActivityWithStateUpdatesContext = createContext(void 0);
306
- const useActivityWithStateUpdatesContext = () => {
307
- return useContext(StreamActivityWithStateUpdatesContext);
310
+ //#endregion
311
+ //#region src/bindings/react/contexts/StreamActivityWithStateUpdatesContext.tsx
312
+ var StreamActivityWithStateUpdatesContext = createContext(void 0);
313
+ /**
314
+ * Hook to access the nearest ActivityWithStateUpdates instance.
315
+ */
316
+ var useActivityWithStateUpdatesContext = () => {
317
+ return useContext(StreamActivityWithStateUpdatesContext);
308
318
  };
309
- const canLoadComments = (feedOrActivity) => {
310
- return "loadNextPageCommentReplies" in feedOrActivity && "loadNextPageActivityComments" in feedOrActivity;
319
+ //#endregion
320
+ //#region src/bindings/react/hooks/feed-state-hooks/useActivityComments.ts
321
+ var canLoadComments = (feedOrActivity) => {
322
+ return "loadNextPageCommentReplies" in feedOrActivity && "loadNextPageActivityComments" in feedOrActivity;
311
323
  };
312
- function useActivityComments({
313
- feed: feedFromProps,
314
- parentComment,
315
- activity: activityFromProps
316
- } = {}) {
317
- const feedFromContext = useFeedContext();
318
- const feed = feedFromProps ?? feedFromContext;
319
- const activityFromContext = useActivityWithStateUpdatesContext();
320
- const activity = activityFromProps ?? activityFromContext;
321
- const feedOrActivity = activity && canLoadComments(activity) ? activity : feed;
322
- if (!feedOrActivity) {
323
- throw new Error("Feed or activity is required");
324
- }
325
- if (!canLoadComments(feedOrActivity)) {
326
- throw new Error("Feed or activity does not support loading comments");
327
- }
328
- if (!(activity || parentComment)) {
329
- throw new Error("Activity or parent comment is required");
330
- }
331
- const entityId = parentComment?.id ?? activity?.id ?? "";
332
- const selector2 = useCallback(
333
- (state) => ({
334
- comments: state.comments_by_entity_id?.[entityId]?.comments,
335
- comments_pagination: state.comments_by_entity_id?.[entityId]?.pagination
336
- }),
337
- [entityId]
338
- );
339
- const data = useStateStore(
340
- feedOrActivity.state,
341
- selector2
342
- );
343
- const loadNextPage = useCallback(
344
- (request) => {
345
- if (parentComment) {
346
- return feedOrActivity.loadNextPageCommentReplies(
347
- parentComment,
348
- request
349
- );
350
- } else {
351
- if (activity && canLoadComments(activity)) {
352
- return activity.loadNextPageActivityComments(request);
353
- } else if (feed) {
354
- return feed.loadNextPageActivityComments(activity?.id ?? "", request);
355
- } else {
356
- throw new Error("Activity or feed is required");
357
- }
358
- }
359
- },
360
- [feedOrActivity, feed, parentComment, activity]
361
- );
362
- return useMemo(() => {
363
- return {
364
- ...data,
365
- has_next_page: checkHasAnotherPage(
366
- data.comments,
367
- data.comments_pagination?.next
368
- ),
369
- is_loading_next_page: data?.comments_pagination?.loading_next_page ?? false,
370
- loadNextPage
371
- };
372
- }, [data, loadNextPage]);
324
+ function useActivityComments({ feed: feedFromProps, parentComment, activity: activityFromProps } = {}) {
325
+ const feedFromContext = useFeedContext();
326
+ const feed = feedFromProps ?? feedFromContext;
327
+ const activityFromContext = useActivityWithStateUpdatesContext();
328
+ const activity = activityFromProps ?? activityFromContext;
329
+ const feedOrActivity = activity && canLoadComments(activity) ? activity : feed;
330
+ if (!feedOrActivity) throw new Error("Feed or activity is required");
331
+ if (!canLoadComments(feedOrActivity)) throw new Error("Feed or activity does not support loading comments");
332
+ if (!(activity || parentComment)) throw new Error("Activity or parent comment is required");
333
+ const entityId = parentComment?.id ?? activity?.id ?? "";
334
+ const selector = useCallback((state) => ({
335
+ comments: state.comments_by_entity_id?.[entityId]?.comments,
336
+ comments_pagination: state.comments_by_entity_id?.[entityId]?.pagination
337
+ }), [entityId]);
338
+ const data = useStateStore(feedOrActivity.state, selector);
339
+ const loadNextPage = useCallback((request) => {
340
+ if (parentComment) return feedOrActivity.loadNextPageCommentReplies(parentComment, request);
341
+ else if (activity && canLoadComments(activity)) return activity.loadNextPageActivityComments(request);
342
+ else if (feed) return feed.loadNextPageActivityComments(activity?.id ?? "", request);
343
+ else throw new Error("Activity or feed is required");
344
+ }, [
345
+ feedOrActivity,
346
+ feed,
347
+ parentComment,
348
+ activity
349
+ ]);
350
+ return useMemo(() => {
351
+ return {
352
+ ...data,
353
+ has_next_page: checkHasAnotherPage(data.comments, data.comments_pagination?.next),
354
+ is_loading_next_page: data?.comments_pagination?.loading_next_page ?? false,
355
+ loadNextPage
356
+ };
357
+ }, [data, loadNextPage]);
373
358
  }
374
- const useOwnFollowings = (feedFromProps) => {
375
- const feedFromContext = useFeedContext();
376
- const feed = feedFromProps ?? feedFromContext;
377
- return useStateStore(feed?.state, selector$4);
359
+ //#endregion
360
+ //#region src/bindings/react/hooks/feed-state-hooks/useOwnFollowings.ts
361
+ /**
362
+ * A React hook that returns a reactive array of feeds that the feeds's owner is following and is owned by the current user.
363
+ */
364
+ var useOwnFollowings = (feedFromProps) => {
365
+ const feedFromContext = useFeedContext();
366
+ return useStateStore((feedFromProps ?? feedFromContext)?.state, selector$4);
378
367
  };
379
- const selector$4 = ({ own_followings }) => ({
380
- own_followings
381
- });
382
- const selector$3 = ({
383
- member_count,
384
- members,
385
- member_pagination
386
- }) => ({
387
- member_count,
388
- members,
389
- member_pagination
368
+ var selector$4 = ({ own_followings }) => ({ own_followings });
369
+ //#endregion
370
+ //#region src/bindings/react/hooks/feed-state-hooks/useMembers.ts
371
+ var selector$3 = ({ member_count, members, member_pagination }) => ({
372
+ member_count,
373
+ members,
374
+ member_pagination
390
375
  });
391
376
  function useMembers(feedFromProps) {
392
- const feedFromContext = useFeedContext();
393
- const feed = feedFromProps ?? feedFromContext;
394
- const data = useStateStore(feed?.state, selector$3);
395
- const loadNextPage = useCallback(
396
- (...options) => feed?.loadNextPageMembers(...options),
397
- [feed]
398
- );
399
- return useMemo(() => {
400
- if (!data) {
401
- return void 0;
402
- }
403
- return {
404
- ...data,
405
- is_loading_next_page: data.member_pagination?.loading_next_page ?? false,
406
- has_next_page: checkHasAnotherPage(
407
- data.members,
408
- data.member_pagination?.next
409
- ),
410
- loadNextPage
411
- };
412
- }, [data, loadNextPage]);
377
+ const feedFromContext = useFeedContext();
378
+ const feed = feedFromProps ?? feedFromContext;
379
+ const data = useStateStore(feed?.state, selector$3);
380
+ const loadNextPage = useCallback((...options) => feed?.loadNextPageMembers(...options), [feed]);
381
+ return useMemo(() => {
382
+ if (!data) return;
383
+ return {
384
+ ...data,
385
+ is_loading_next_page: data.member_pagination?.loading_next_page ?? false,
386
+ has_next_page: checkHasAnotherPage(data.members, data.member_pagination?.next),
387
+ loadNextPage
388
+ };
389
+ }, [data, loadNextPage]);
413
390
  }
414
- const StreamSearchResultsContext = createContext(void 0);
415
- const useSearchResultsContext = () => {
416
- return useContext(StreamSearchResultsContext);
391
+ //#endregion
392
+ //#region src/bindings/react/contexts/StreamSearchResultsContext.tsx
393
+ var StreamSearchResultsContext = createContext(void 0);
394
+ /**
395
+ * Hook to access the nearest SearchSource instance.
396
+ */
397
+ var useSearchResultsContext = () => {
398
+ return useContext(StreamSearchResultsContext);
417
399
  };
418
- const useSearchResult = (sourceFromProps) => {
419
- const sourceFromContext = useSearchResultsContext();
420
- const source = sourceFromProps ?? sourceFromContext;
421
- const { items, error, isLoading, hasNext } = useStateStore(source?.state, selector$2) ?? {};
422
- const loadMore = useStableCallback(async () => {
423
- if (hasNext) {
424
- source?.search();
425
- }
426
- });
427
- return useMemo(
428
- () => ({ items, error, isLoading, hasNext, loadMore }),
429
- [error, hasNext, isLoading, items, loadMore]
430
- );
400
+ //#endregion
401
+ //#region src/bindings/react/hooks/search-state-hooks/useSearchResult.ts
402
+ var useSearchResult = (sourceFromProps) => {
403
+ const sourceFromContext = useSearchResultsContext();
404
+ const source = sourceFromProps ?? sourceFromContext;
405
+ const { items, error, isLoading, hasNext } = useStateStore(source?.state, selector$2) ?? {};
406
+ const loadMore = useStableCallback(async () => {
407
+ if (hasNext) source?.search();
408
+ });
409
+ return useMemo(() => ({
410
+ items,
411
+ error,
412
+ isLoading,
413
+ hasNext,
414
+ loadMore
415
+ }), [
416
+ error,
417
+ hasNext,
418
+ isLoading,
419
+ items,
420
+ loadMore
421
+ ]);
431
422
  };
432
- const selector$2 = ({
433
- items,
434
- isLoading,
435
- hasNext,
436
- lastQueryError
437
- }) => ({
438
- items,
439
- isLoading,
440
- hasNext,
441
- error: lastQueryError
423
+ var selector$2 = ({ items, isLoading, hasNext, lastQueryError }) => ({
424
+ items,
425
+ isLoading,
426
+ hasNext,
427
+ error: lastQueryError
442
428
  });
443
- const StreamSearchContext = createContext(void 0);
444
- const useSearchContext = () => {
445
- return useContext(StreamSearchContext);
429
+ //#endregion
430
+ //#region src/bindings/react/contexts/StreamSearchContext.tsx
431
+ var StreamSearchContext = createContext(void 0);
432
+ /**
433
+ * Hook to access the nearest SearchController instance.
434
+ */
435
+ var useSearchContext = () => {
436
+ return useContext(StreamSearchContext);
446
437
  };
447
- const useSearchQuery = (controllerFromProps) => {
448
- const controllerFromState = useSearchContext();
449
- const controller = controllerFromProps ?? controllerFromState;
450
- return useStateStore(controller?.state, selector$1);
438
+ //#endregion
439
+ //#region src/bindings/react/hooks/search-state-hooks/useSearchQuery.ts
440
+ var useSearchQuery = (controllerFromProps) => {
441
+ const controllerFromState = useSearchContext();
442
+ return useStateStore((controllerFromProps ?? controllerFromState)?.state, selector$1);
451
443
  };
452
- const selector$1 = ({ searchQuery }) => ({
453
- searchQuery
454
- });
455
- const useSearchSources = (controllerFromProps) => {
456
- const controllerFromState = useSearchContext();
457
- const controller = controllerFromProps ?? controllerFromState;
458
- return useStateStore(controller?.state, selector);
444
+ var selector$1 = ({ searchQuery }) => ({ searchQuery });
445
+ //#endregion
446
+ //#region src/bindings/react/hooks/search-state-hooks/useSearchSources.ts
447
+ var useSearchSources = (controllerFromProps) => {
448
+ const controllerFromState = useSearchContext();
449
+ return useStateStore((controllerFromProps ?? controllerFromState)?.state, selector);
459
450
  };
460
- const selector = ({ sources }) => ({
461
- sources
462
- });
463
- const StreamFeeds = ({ client, children }) => {
464
- return /* @__PURE__ */ jsx(StreamFeedsContext.Provider, { value: client, children });
451
+ var selector = ({ sources }) => ({ sources });
452
+ //#endregion
453
+ //#region src/bindings/react/wrappers/StreamFeeds.tsx
454
+ var StreamFeeds = ({ client, children }) => {
455
+ return /* @__PURE__ */ jsx(StreamFeedsContext.Provider, {
456
+ value: client,
457
+ children
458
+ });
465
459
  };
466
460
  StreamFeeds.displayName = "StreamFeeds";
467
- const StreamFeed = ({
468
- feed,
469
- children
470
- }) => {
471
- return /* @__PURE__ */ jsx(StreamFeedContext.Provider, { value: feed, children });
461
+ //#endregion
462
+ //#region src/bindings/react/wrappers/StreamFeed.tsx
463
+ var StreamFeed = ({ feed, children }) => {
464
+ return /* @__PURE__ */ jsx(StreamFeedContext.Provider, {
465
+ value: feed,
466
+ children
467
+ });
472
468
  };
473
469
  StreamFeed.displayName = "StreamFeed";
474
- const StreamActivityWithStateUpdates = ({
475
- activityWithStateUpdates,
476
- children
477
- }) => {
478
- return /* @__PURE__ */ jsx(StreamActivityWithStateUpdatesContext.Provider, { value: activityWithStateUpdates, children });
470
+ //#endregion
471
+ //#region src/bindings/react/wrappers/StreamActivityWithStateUpdates.tsx
472
+ var StreamActivityWithStateUpdates = ({ activityWithStateUpdates, children }) => {
473
+ return /* @__PURE__ */ jsx(StreamActivityWithStateUpdatesContext.Provider, {
474
+ value: activityWithStateUpdates,
475
+ children
476
+ });
479
477
  };
480
478
  StreamActivityWithStateUpdates.displayName = "StreamActivityWithStateUpdates";
481
- const StreamSearch = ({
482
- searchController,
483
- children
484
- }) => {
485
- return /* @__PURE__ */ jsx(StreamSearchContext.Provider, { value: searchController, children });
479
+ //#endregion
480
+ //#region src/bindings/react/wrappers/StreamSearch.tsx
481
+ var StreamSearch = ({ searchController, children }) => {
482
+ return /* @__PURE__ */ jsx(StreamSearchContext.Provider, {
483
+ value: searchController,
484
+ children
485
+ });
486
486
  };
487
487
  StreamSearch.displayName = "StreamSearch";
488
- const StreamSearchResults = ({
489
- source,
490
- children
491
- }) => {
492
- return /* @__PURE__ */ jsx(StreamSearchResultsContext.Provider, { value: source, children });
488
+ //#endregion
489
+ //#region src/bindings/react/wrappers/StreamSearchResults.tsx
490
+ var StreamSearchResults = ({ source, children }) => {
491
+ return /* @__PURE__ */ jsx(StreamSearchResultsContext.Provider, {
492
+ value: source,
493
+ children
494
+ });
493
495
  };
494
496
  StreamSearchResults.displayName = "StreamSearchResults";
495
- export {
496
- StreamActivityWithStateUpdates,
497
- StreamActivityWithStateUpdatesContext,
498
- StreamFeed,
499
- StreamFeedContext,
500
- StreamFeeds,
501
- StreamFeedsContext,
502
- StreamSearch,
503
- StreamSearchContext,
504
- StreamSearchResults,
505
- StreamSearchResultsContext,
506
- useActivityComments,
507
- useActivityWithStateUpdatesContext,
508
- useAggregatedActivities,
509
- useClientConnectedUser,
510
- useComments,
511
- useCreateFeedsClient,
512
- useFeedActivities,
513
- useFeedContext,
514
- useFeedMetadata,
515
- useFeedsClient,
516
- useFollowers,
517
- useFollowing,
518
- useIsAggregatedActivityRead,
519
- useIsAggregatedActivitySeen,
520
- useMembers,
521
- useNotificationStatus,
522
- useOwnCapabilities,
523
- useOwnFollowings,
524
- useOwnFollows,
525
- useSearchContext,
526
- useSearchQuery,
527
- useSearchResult,
528
- useSearchResultsContext,
529
- useSearchSources,
530
- useWsConnectionState
531
- };
532
- //# sourceMappingURL=react-bindings.mjs.map
497
+ //#endregion
498
+ export { StreamActivityWithStateUpdates, StreamActivityWithStateUpdatesContext, StreamFeed, StreamFeedContext, StreamFeeds, StreamFeedsContext, StreamSearch, StreamSearchContext, StreamSearchResults, StreamSearchResultsContext, useActivityComments, useActivityWithStateUpdatesContext, useAggregatedActivities, useClientConnectedUser, useComments, useCreateFeedsClient, useFeedActivities, useFeedContext, useFeedMetadata, useFeedsClient, useFollowers, useFollowing, useIsAggregatedActivityRead, useIsAggregatedActivitySeen, useMembers, useNotificationStatus, useOwnCapabilities, useOwnFollowings, useOwnFollows, useSearchContext, useSearchQuery, useSearchResult, useSearchResultsContext, useSearchSources, useWsConnectionState };
499
+
500
+ //# sourceMappingURL=react-bindings.mjs.map