@stream-io/feeds-client 1.1.0 → 1.3.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 +19 -0
- package/dist/cjs/index.js +477 -466
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/react-bindings.js +454 -449
- package/dist/cjs/react-bindings.js.map +1 -1
- package/dist/es/index.mjs +440 -466
- package/dist/es/index.mjs.map +1 -1
- package/dist/es/react-bindings.mjs +447 -479
- package/dist/es/react-bindings.mjs.map +1 -1
- package/dist/feeds-client-CqD2zQW0.mjs +8791 -0
- package/dist/feeds-client-CqD2zQW0.mjs.map +1 -0
- package/dist/feeds-client-DXci2Pbn.js +8957 -0
- package/dist/feeds-client-DXci2Pbn.js.map +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/types/common/real-time/StableWSConnection.d.ts +3 -3
- package/dist/types/common/real-time/StableWSConnection.d.ts.map +1 -1
- package/dist/types/feed/event-handlers/notification-feed/handle-notification-feed-updated.d.ts.map +1 -1
- package/dist/types/feed/feed.d.ts +2 -2
- package/dist/types/feed/feed.d.ts.map +1 -1
- package/dist/types/feeds-client/feeds-client.d.ts +3 -2
- package/dist/types/feeds-client/feeds-client.d.ts.map +1 -1
- package/dist/types/gen/feeds/FeedsApi.d.ts +4 -1
- package/dist/types/gen/feeds/FeedsApi.d.ts.map +1 -1
- package/dist/types/gen/model-decoders/event-decoder-mapping.d.ts.map +1 -1
- package/dist/types/gen/models/index.d.ts +63 -1
- package/dist/types/gen/models/index.d.ts.map +1 -1
- package/package.json +15 -15
- package/src/feed/event-handlers/notification-feed/handle-notification-feed-updated.ts +1 -5
- package/src/feed/feed.ts +1 -0
- package/src/feeds-client/feeds-client.ts +104 -45
- package/src/gen/feeds/FeedsApi.ts +26 -0
- package/src/gen/model-decoders/decoders.ts +20 -0
- package/src/gen/model-decoders/event-decoder-mapping.ts +3 -0
- package/src/gen/models/index.ts +105 -1
- package/dist/feeds-client-C1c6lcS3.js +0 -8799
- package/dist/feeds-client-C1c6lcS3.js.map +0 -1
- package/dist/feeds-client-jtUTE4AC.mjs +0 -8783
- package/dist/feeds-client-jtUTE4AC.mjs.map +0 -1
|
@@ -1,498 +1,500 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
setClient(null);
|
|
49
|
-
connectionPromise.then(() => {
|
|
50
|
-
setError(null);
|
|
51
|
-
return _client.disconnectUser();
|
|
52
|
-
}).catch((err) => {
|
|
53
|
-
setError(err);
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
}, [apiKey, cachedUserData, cachedOptions, tokenOrProvider]);
|
|
57
|
-
return client;
|
|
2
|
+
const require_feeds_client = require("../feeds-client-DXci2Pbn.js");
|
|
3
|
+
let _stream_io_state_store_react_bindings = require("@stream-io/state-store/react-bindings");
|
|
4
|
+
let react = require("react");
|
|
5
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
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] = (0, react.useState)(null);
|
|
14
|
+
const [error, setError] = (0, react.useState)(null);
|
|
15
|
+
const [cachedUserData, setCachedUserData] = (0, react.useState)(userData);
|
|
16
|
+
const [cachedOptions] = (0, react.useState)(options);
|
|
17
|
+
if (error) throw error;
|
|
18
|
+
if (userData?.id !== cachedUserData?.id) setCachedUserData(userData);
|
|
19
|
+
(0, react.useEffect)(() => {
|
|
20
|
+
const _client = new require_feeds_client.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;
|
|
58
47
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/bindings/react/contexts/StreamFeedsContext.tsx
|
|
50
|
+
var StreamFeedsContext = (0, react.createContext)(void 0);
|
|
51
|
+
/**
|
|
52
|
+
* Hook to access the nearest FeedsClient instance.
|
|
53
|
+
*/
|
|
54
|
+
var useFeedsClient = () => {
|
|
55
|
+
return (0, react.useContext)(StreamFeedsContext);
|
|
62
56
|
};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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 } = (0, _stream_io_state_store_react_bindings.useStateStore)(useFeedsClient()?.state, selector$14) ?? {};
|
|
64
|
+
return user;
|
|
67
65
|
};
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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 } = (0, _stream_io_state_store_react_bindings.useStateStore)(useFeedsClient()?.state, selector$13) ?? {};
|
|
74
|
+
return { is_healthy };
|
|
75
75
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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 = (0, react.createContext)(void 0);
|
|
80
|
+
/**
|
|
81
|
+
* Hook to access the nearest Feed instance.
|
|
82
|
+
*/
|
|
83
|
+
var useFeedContext = () => {
|
|
84
|
+
return (0, react.useContext)(StreamFeedContext);
|
|
82
85
|
};
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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 = (0, react.useRef)(callback);
|
|
113
|
+
ref.current = callback;
|
|
114
|
+
return (0, react.useCallback)((...args) => {
|
|
115
|
+
return ref.current(...args);
|
|
116
|
+
}, []);
|
|
89
117
|
};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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 = (0, _stream_io_state_store_react_bindings.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 (0, react.useMemo)(() => ({
|
|
133
|
+
...data,
|
|
134
|
+
loadNextPage
|
|
135
|
+
}), [data, loadNextPage]);
|
|
101
136
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}) => ({
|
|
107
|
-
is_loading: is_loading_activities,
|
|
108
|
-
has_next_page: typeof next !== "undefined",
|
|
109
|
-
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
|
|
110
141
|
});
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return void 0;
|
|
138
|
-
}
|
|
139
|
-
return {
|
|
140
|
-
...data,
|
|
141
|
-
has_next_page: feedsClient.checkHasAnotherPage(
|
|
142
|
-
data.comments,
|
|
143
|
-
data.comments_pagination?.next
|
|
144
|
-
),
|
|
145
|
-
is_loading_next_page: data?.comments_pagination?.loading_next_page ?? false,
|
|
146
|
-
loadNextPage
|
|
147
|
-
};
|
|
148
|
-
}, [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 = (0, react.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 = (0, _stream_io_state_store_react_bindings.useStateStore)(feed?.state, selector);
|
|
152
|
+
const loadNextPage = (0, react.useMemo)(() => {
|
|
153
|
+
if (!feed) return void 0;
|
|
154
|
+
return (request) => {
|
|
155
|
+
if (require_feeds_client.isCommentResponse(parent)) return feed.loadNextPageCommentReplies(parent, request);
|
|
156
|
+
else return feed.loadNextPageActivityComments(parent, request);
|
|
157
|
+
};
|
|
158
|
+
}, [feed, parent]);
|
|
159
|
+
return (0, react.useMemo)(() => {
|
|
160
|
+
if (!data) return;
|
|
161
|
+
return {
|
|
162
|
+
...data,
|
|
163
|
+
has_next_page: require_feeds_client.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]);
|
|
149
168
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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 };
|
|
155
174
|
};
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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 } = (0, _stream_io_state_store_react_bindings.useStateStore)(feed?.state, selector$11) ?? {};
|
|
184
|
+
return feedOwnCapabilities;
|
|
166
185
|
};
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
followers,
|
|
174
|
-
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
|
|
175
192
|
});
|
|
176
193
|
function useFollowers(feedFromProps) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
is_loading_next_page: data.followers_pagination?.loading_next_page ?? false,
|
|
191
|
-
has_next_page: feedsClient.checkHasAnotherPage(
|
|
192
|
-
data.followers,
|
|
193
|
-
data.followers_pagination?.next
|
|
194
|
-
),
|
|
195
|
-
loadNextPage
|
|
196
|
-
};
|
|
197
|
-
}, [data, loadNextPage]);
|
|
194
|
+
const feedFromContext = useFeedContext();
|
|
195
|
+
const feed = feedFromProps ?? feedFromContext;
|
|
196
|
+
const data = (0, _stream_io_state_store_react_bindings.useStateStore)(feed?.state, selector$10);
|
|
197
|
+
const loadNextPage = (0, react.useCallback)((...options) => feed?.loadNextPageFollowers(...options), [feed]);
|
|
198
|
+
return (0, react.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: require_feeds_client.checkHasAnotherPage(data.followers, data.followers_pagination?.next),
|
|
204
|
+
loadNextPage
|
|
205
|
+
};
|
|
206
|
+
}, [data, loadNextPage]);
|
|
198
207
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
following,
|
|
206
|
-
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
|
|
207
214
|
});
|
|
208
215
|
function useFollowing(feedFromProps) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
is_loading_next_page: data.following_pagination?.loading_next_page ?? false,
|
|
223
|
-
has_next_page: feedsClient.checkHasAnotherPage(
|
|
224
|
-
data.following,
|
|
225
|
-
data.following_pagination?.next
|
|
226
|
-
),
|
|
227
|
-
loadNextPage
|
|
228
|
-
};
|
|
229
|
-
}, [data, loadNextPage]);
|
|
216
|
+
const feedFromContext = useFeedContext();
|
|
217
|
+
const feed = feedFromProps ?? feedFromContext;
|
|
218
|
+
const data = (0, _stream_io_state_store_react_bindings.useStateStore)(feed?.state, selector$9);
|
|
219
|
+
const loadNextPage = (0, react.useCallback)((...options) => feed?.loadNextPageFollowing(...options), [feed]);
|
|
220
|
+
return (0, react.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: require_feeds_client.checkHasAnotherPage(data.following, data.following_pagination?.next),
|
|
226
|
+
loadNextPage
|
|
227
|
+
};
|
|
228
|
+
}, [data, loadNextPage]);
|
|
230
229
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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 (0, _stream_io_state_store_react_bindings.useStateStore)((feedFromProps ?? feedFromContext)?.state, selector$8);
|
|
235
239
|
};
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}) => ({
|
|
243
|
-
created_by,
|
|
244
|
-
follower_count,
|
|
245
|
-
following_count,
|
|
246
|
-
created_at,
|
|
247
|
-
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
|
|
248
246
|
});
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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 (0, _stream_io_state_store_react_bindings.useStateStore)((feedFromProps ?? feedFromContext)?.state, selector$7);
|
|
253
256
|
};
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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
|
|
264
267
|
});
|
|
265
268
|
function useNotificationStatus(feedFromProps) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
return reactBindings.useStateStore(feed?.state, selector$6);
|
|
269
|
+
const feedFromContext = useFeedContext();
|
|
270
|
+
return (0, _stream_io_state_store_react_bindings.useStateStore)((feedFromProps ?? feedFromContext)?.state, selector$6);
|
|
269
271
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
has_next_page: typeof next !== "undefined",
|
|
277
|
-
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
|
|
278
278
|
});
|
|
279
279
|
function useAggregatedActivities(feedFromProps) {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
[data, loadNextPage]
|
|
292
|
-
);
|
|
280
|
+
const feedFromContext = useFeedContext();
|
|
281
|
+
const feed = feedFromProps ?? feedFromContext;
|
|
282
|
+
const data = (0, _stream_io_state_store_react_bindings.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 (0, react.useMemo)(() => data ? {
|
|
288
|
+
...data,
|
|
289
|
+
loadNextPage
|
|
290
|
+
} : void 0, [data, loadNextPage]);
|
|
293
291
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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;
|
|
299
300
|
};
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
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;
|
|
305
309
|
};
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
310
|
+
//#endregion
|
|
311
|
+
//#region src/bindings/react/contexts/StreamActivityWithStateUpdatesContext.tsx
|
|
312
|
+
var StreamActivityWithStateUpdatesContext = (0, react.createContext)(void 0);
|
|
313
|
+
/**
|
|
314
|
+
* Hook to access the nearest ActivityWithStateUpdates instance.
|
|
315
|
+
*/
|
|
316
|
+
var useActivityWithStateUpdatesContext = () => {
|
|
317
|
+
return (0, react.useContext)(StreamActivityWithStateUpdatesContext);
|
|
309
318
|
};
|
|
310
|
-
|
|
311
|
-
|
|
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;
|
|
312
323
|
};
|
|
313
|
-
function useActivityComments({
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
return feedOrActivity.loadNextPageCommentReplies(
|
|
348
|
-
parentComment,
|
|
349
|
-
request
|
|
350
|
-
);
|
|
351
|
-
} else {
|
|
352
|
-
if (activity && canLoadComments(activity)) {
|
|
353
|
-
return activity.loadNextPageActivityComments(request);
|
|
354
|
-
} else if (feed) {
|
|
355
|
-
return feed.loadNextPageActivityComments(activity?.id ?? "", request);
|
|
356
|
-
} else {
|
|
357
|
-
throw new Error("Activity or feed is required");
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
},
|
|
361
|
-
[feedOrActivity, feed, parentComment, activity]
|
|
362
|
-
);
|
|
363
|
-
return react.useMemo(() => {
|
|
364
|
-
return {
|
|
365
|
-
...data,
|
|
366
|
-
has_next_page: feedsClient.checkHasAnotherPage(
|
|
367
|
-
data.comments,
|
|
368
|
-
data.comments_pagination?.next
|
|
369
|
-
),
|
|
370
|
-
is_loading_next_page: data?.comments_pagination?.loading_next_page ?? false,
|
|
371
|
-
loadNextPage
|
|
372
|
-
};
|
|
373
|
-
}, [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 = (0, react.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 = (0, _stream_io_state_store_react_bindings.useStateStore)(feedOrActivity.state, selector);
|
|
339
|
+
const loadNextPage = (0, react.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 (0, react.useMemo)(() => {
|
|
351
|
+
return {
|
|
352
|
+
...data,
|
|
353
|
+
has_next_page: require_feeds_client.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]);
|
|
374
358
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
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 (0, _stream_io_state_store_react_bindings.useStateStore)((feedFromProps ?? feedFromContext)?.state, selector$4);
|
|
379
367
|
};
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
}) => ({
|
|
388
|
-
member_count,
|
|
389
|
-
members,
|
|
390
|
-
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
|
|
391
375
|
});
|
|
392
376
|
function useMembers(feedFromProps) {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
is_loading_next_page: data.member_pagination?.loading_next_page ?? false,
|
|
407
|
-
has_next_page: feedsClient.checkHasAnotherPage(
|
|
408
|
-
data.members,
|
|
409
|
-
data.member_pagination?.next
|
|
410
|
-
),
|
|
411
|
-
loadNextPage
|
|
412
|
-
};
|
|
413
|
-
}, [data, loadNextPage]);
|
|
377
|
+
const feedFromContext = useFeedContext();
|
|
378
|
+
const feed = feedFromProps ?? feedFromContext;
|
|
379
|
+
const data = (0, _stream_io_state_store_react_bindings.useStateStore)(feed?.state, selector$3);
|
|
380
|
+
const loadNextPage = (0, react.useCallback)((...options) => feed?.loadNextPageMembers(...options), [feed]);
|
|
381
|
+
return (0, react.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: require_feeds_client.checkHasAnotherPage(data.members, data.member_pagination?.next),
|
|
387
|
+
loadNextPage
|
|
388
|
+
};
|
|
389
|
+
}, [data, loadNextPage]);
|
|
414
390
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
391
|
+
//#endregion
|
|
392
|
+
//#region src/bindings/react/contexts/StreamSearchResultsContext.tsx
|
|
393
|
+
var StreamSearchResultsContext = (0, react.createContext)(void 0);
|
|
394
|
+
/**
|
|
395
|
+
* Hook to access the nearest SearchSource instance.
|
|
396
|
+
*/
|
|
397
|
+
var useSearchResultsContext = () => {
|
|
398
|
+
return (0, react.useContext)(StreamSearchResultsContext);
|
|
418
399
|
};
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
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 } = (0, _stream_io_state_store_react_bindings.useStateStore)(source?.state, selector$2) ?? {};
|
|
406
|
+
const loadMore = useStableCallback(async () => {
|
|
407
|
+
if (hasNext) source?.search();
|
|
408
|
+
});
|
|
409
|
+
return (0, react.useMemo)(() => ({
|
|
410
|
+
items,
|
|
411
|
+
error,
|
|
412
|
+
isLoading,
|
|
413
|
+
hasNext,
|
|
414
|
+
loadMore
|
|
415
|
+
}), [
|
|
416
|
+
error,
|
|
417
|
+
hasNext,
|
|
418
|
+
isLoading,
|
|
419
|
+
items,
|
|
420
|
+
loadMore
|
|
421
|
+
]);
|
|
432
422
|
};
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
}) => ({
|
|
439
|
-
items,
|
|
440
|
-
isLoading,
|
|
441
|
-
hasNext,
|
|
442
|
-
error: lastQueryError
|
|
423
|
+
var selector$2 = ({ items, isLoading, hasNext, lastQueryError }) => ({
|
|
424
|
+
items,
|
|
425
|
+
isLoading,
|
|
426
|
+
hasNext,
|
|
427
|
+
error: lastQueryError
|
|
443
428
|
});
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
429
|
+
//#endregion
|
|
430
|
+
//#region src/bindings/react/contexts/StreamSearchContext.tsx
|
|
431
|
+
var StreamSearchContext = (0, react.createContext)(void 0);
|
|
432
|
+
/**
|
|
433
|
+
* Hook to access the nearest SearchController instance.
|
|
434
|
+
*/
|
|
435
|
+
var useSearchContext = () => {
|
|
436
|
+
return (0, react.useContext)(StreamSearchContext);
|
|
447
437
|
};
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
438
|
+
//#endregion
|
|
439
|
+
//#region src/bindings/react/hooks/search-state-hooks/useSearchQuery.ts
|
|
440
|
+
var useSearchQuery = (controllerFromProps) => {
|
|
441
|
+
const controllerFromState = useSearchContext();
|
|
442
|
+
return (0, _stream_io_state_store_react_bindings.useStateStore)((controllerFromProps ?? controllerFromState)?.state, selector$1);
|
|
452
443
|
};
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
return reactBindings.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 (0, _stream_io_state_store_react_bindings.useStateStore)((controllerFromProps ?? controllerFromState)?.state, selector);
|
|
460
450
|
};
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
451
|
+
var selector = ({ sources }) => ({ sources });
|
|
452
|
+
//#endregion
|
|
453
|
+
//#region src/bindings/react/wrappers/StreamFeeds.tsx
|
|
454
|
+
var StreamFeeds = ({ client, children }) => {
|
|
455
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StreamFeedsContext.Provider, {
|
|
456
|
+
value: client,
|
|
457
|
+
children
|
|
458
|
+
});
|
|
466
459
|
};
|
|
467
460
|
StreamFeeds.displayName = "StreamFeeds";
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
461
|
+
//#endregion
|
|
462
|
+
//#region src/bindings/react/wrappers/StreamFeed.tsx
|
|
463
|
+
var StreamFeed = ({ feed, children }) => {
|
|
464
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StreamFeedContext.Provider, {
|
|
465
|
+
value: feed,
|
|
466
|
+
children
|
|
467
|
+
});
|
|
473
468
|
};
|
|
474
469
|
StreamFeed.displayName = "StreamFeed";
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
470
|
+
//#endregion
|
|
471
|
+
//#region src/bindings/react/wrappers/StreamActivityWithStateUpdates.tsx
|
|
472
|
+
var StreamActivityWithStateUpdates = ({ activityWithStateUpdates, children }) => {
|
|
473
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StreamActivityWithStateUpdatesContext.Provider, {
|
|
474
|
+
value: activityWithStateUpdates,
|
|
475
|
+
children
|
|
476
|
+
});
|
|
480
477
|
};
|
|
481
478
|
StreamActivityWithStateUpdates.displayName = "StreamActivityWithStateUpdates";
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
479
|
+
//#endregion
|
|
480
|
+
//#region src/bindings/react/wrappers/StreamSearch.tsx
|
|
481
|
+
var StreamSearch = ({ searchController, children }) => {
|
|
482
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StreamSearchContext.Provider, {
|
|
483
|
+
value: searchController,
|
|
484
|
+
children
|
|
485
|
+
});
|
|
487
486
|
};
|
|
488
487
|
StreamSearch.displayName = "StreamSearch";
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
488
|
+
//#endregion
|
|
489
|
+
//#region src/bindings/react/wrappers/StreamSearchResults.tsx
|
|
490
|
+
var StreamSearchResults = ({ source, children }) => {
|
|
491
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StreamSearchResultsContext.Provider, {
|
|
492
|
+
value: source,
|
|
493
|
+
children
|
|
494
|
+
});
|
|
494
495
|
};
|
|
495
496
|
StreamSearchResults.displayName = "StreamSearchResults";
|
|
497
|
+
//#endregion
|
|
496
498
|
exports.StreamActivityWithStateUpdates = StreamActivityWithStateUpdates;
|
|
497
499
|
exports.StreamActivityWithStateUpdatesContext = StreamActivityWithStateUpdatesContext;
|
|
498
500
|
exports.StreamFeed = StreamFeed;
|
|
@@ -528,10 +530,13 @@ exports.useSearchResult = useSearchResult;
|
|
|
528
530
|
exports.useSearchResultsContext = useSearchResultsContext;
|
|
529
531
|
exports.useSearchSources = useSearchSources;
|
|
530
532
|
exports.useWsConnectionState = useWsConnectionState;
|
|
531
|
-
Object.keys(
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
533
|
+
Object.keys(_stream_io_state_store_react_bindings).forEach(function(k) {
|
|
534
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
535
|
+
enumerable: true,
|
|
536
|
+
get: function() {
|
|
537
|
+
return _stream_io_state_store_react_bindings[k];
|
|
538
|
+
}
|
|
539
|
+
});
|
|
536
540
|
});
|
|
537
|
-
|
|
541
|
+
|
|
542
|
+
//# sourceMappingURL=react-bindings.js.map
|