@stream-io/feeds-client 0.3.7 → 0.3.8

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cjs/index.js +2 -1
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/react-bindings.js +76 -14
  5. package/dist/cjs/react-bindings.js.map +1 -1
  6. package/dist/es/index.mjs +3 -2
  7. package/dist/es/react-bindings.mjs +76 -14
  8. package/dist/es/react-bindings.mjs.map +1 -1
  9. package/dist/{feeds-client-DLiLkrA0.js → feeds-client-CwioZBvA.js} +274 -52
  10. package/dist/feeds-client-CwioZBvA.js.map +1 -0
  11. package/dist/{feeds-client-3aXF89xy.mjs → feeds-client-DVbsjKUf.mjs} +274 -52
  12. package/dist/feeds-client-DVbsjKUf.mjs.map +1 -0
  13. package/dist/types/activity-with-state-updates/activity-with-state-updates.d.ts +49 -0
  14. package/dist/types/activity-with-state-updates/activity-with-state-updates.d.ts.map +1 -0
  15. package/dist/types/activity-with-state-updates/get-feed.d.ts +3 -0
  16. package/dist/types/activity-with-state-updates/get-feed.d.ts.map +1 -0
  17. package/dist/types/bindings/react/hooks/feed-state-hooks/index.d.ts +1 -0
  18. package/dist/types/bindings/react/hooks/feed-state-hooks/index.d.ts.map +1 -1
  19. package/dist/types/bindings/react/hooks/feed-state-hooks/useActivityComments.d.ts +32 -0
  20. package/dist/types/bindings/react/hooks/feed-state-hooks/useActivityComments.d.ts.map +1 -0
  21. package/dist/types/bindings/react/hooks/feed-state-hooks/useComments.d.ts +4 -0
  22. package/dist/types/bindings/react/hooks/feed-state-hooks/useComments.d.ts.map +1 -1
  23. package/dist/types/bindings/react/hooks/feed-state-hooks/useOwnCapabilities.d.ts.map +1 -1
  24. package/dist/types/bindings/react/hooks/useCreateFeedsClient.d.ts.map +1 -1
  25. package/dist/types/common/real-time/event-models.d.ts +1 -0
  26. package/dist/types/common/real-time/event-models.d.ts.map +1 -1
  27. package/dist/types/feed/feed.d.ts +1 -1
  28. package/dist/types/feed/feed.d.ts.map +1 -1
  29. package/dist/types/feeds-client/active-activity.d.ts +8 -0
  30. package/dist/types/feeds-client/active-activity.d.ts.map +1 -0
  31. package/dist/types/feeds-client/feeds-client.d.ts +36 -3
  32. package/dist/types/feeds-client/feeds-client.d.ts.map +1 -1
  33. package/dist/types/index.d.ts +1 -0
  34. package/dist/types/index.d.ts.map +1 -1
  35. package/dist/types/types.d.ts.map +1 -1
  36. package/package.json +1 -1
  37. package/src/activity-with-state-updates/activity-with-state-updates.ts +190 -0
  38. package/src/activity-with-state-updates/get-feed.ts +5 -0
  39. package/src/bindings/react/hooks/feed-state-hooks/index.ts +1 -0
  40. package/src/bindings/react/hooks/feed-state-hooks/useActivityComments.ts +113 -0
  41. package/src/bindings/react/hooks/feed-state-hooks/useComments.ts +4 -0
  42. package/src/bindings/react/hooks/feed-state-hooks/useOwnCapabilities.ts +12 -9
  43. package/src/bindings/react/hooks/useCreateFeedsClient.ts +0 -6
  44. package/src/common/real-time/event-models.ts +5 -1
  45. package/src/feed/feed.ts +16 -6
  46. package/src/feeds-client/active-activity.ts +42 -0
  47. package/src/feeds-client/feeds-client.ts +162 -53
  48. package/src/index.ts +1 -0
  49. package/src/test-utils/response-generators.ts +1 -0
  50. package/src/types.ts +8 -10
  51. package/dist/feeds-client-3aXF89xy.mjs.map +0 -1
  52. package/dist/feeds-client-DLiLkrA0.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import require$$0, { useCallback, useMemo, useState, useEffect, createContext, useContext, useRef } from "react";
2
2
  import "@stream-io/state-store";
3
- import { F as FeedsClient, g as isCommentResponse, c as checkHasAnotherPage } from "../feeds-client-3aXF89xy.mjs";
3
+ import { F as FeedsClient, g as isCommentResponse, c as checkHasAnotherPage } from "../feeds-client-DVbsjKUf.mjs";
4
4
  import "axios";
5
5
  var shim = { exports: {} };
6
6
  var useSyncExternalStoreShim_production = {};
@@ -401,7 +401,6 @@ const useCreateFeedsClient = ({
401
401
  const _client = new FeedsClient(apiKey, cachedOptions);
402
402
  const connectionPromise = _client.connectUser(cachedUserData, tokenOrProvider).then(() => {
403
403
  setError(null);
404
- console.log("Successfully connected user: ", cachedUserData.id);
405
404
  }).catch((err) => {
406
405
  setError(err);
407
406
  });
@@ -413,10 +412,6 @@ const useCreateFeedsClient = ({
413
412
  return _client.disconnectUser();
414
413
  }).catch((err) => {
415
414
  setError(err);
416
- }).then(() => {
417
- console.log(
418
- `Connection for user "${cachedUserData.id}" has been closed`
419
- );
420
415
  });
421
416
  };
422
417
  }, [apiKey, cachedUserData, cachedOptions, tokenOrProvider]);
@@ -519,14 +514,17 @@ const useOwnCapabilities = (feedFromProps) => {
519
514
  const feedFromContext = useFeedContext();
520
515
  const feed = feedFromProps ?? feedFromContext;
521
516
  const fid = feed?.feed;
522
- const selector2 = useCallback((currentState) => {
523
- if (!fid) {
524
- return { feedOwnCapabilities: stableEmptyArray };
525
- }
526
- return {
527
- feedOwnCapabilities: currentState.own_capabilities_by_fid[fid] ?? stableEmptyArray
528
- };
529
- }, [fid]);
517
+ const selector2 = useCallback(
518
+ (currentState) => {
519
+ if (!fid) {
520
+ return { feedOwnCapabilities: stableEmptyArray };
521
+ }
522
+ return {
523
+ feedOwnCapabilities: currentState.own_capabilities_by_fid[fid] ?? stableEmptyArray
524
+ };
525
+ },
526
+ [fid]
527
+ );
530
528
  const { feedOwnCapabilities = stableEmptyArray } = useStateStore(client?.state, selector2) ?? {};
531
529
  return feedOwnCapabilities;
532
530
  };
@@ -683,6 +681,69 @@ const useIsAggregatedActivitySeen = ({
683
681
  [lastSeenAt, aggregatedActivity.updated_at, seenActivities, group]
684
682
  );
685
683
  };
684
+ const canLoadComments = (feedOrActivity) => {
685
+ return "loadNextPageCommentReplies" in feedOrActivity && "loadNextPageActivityComments" in feedOrActivity;
686
+ };
687
+ function useActivityComments({
688
+ feed: feedFromProps,
689
+ parentComment,
690
+ activity
691
+ }) {
692
+ const feedFromContext = useFeedContext();
693
+ const feed = feedFromProps ?? feedFromContext;
694
+ const feedOrActivity = feed ?? activity;
695
+ if (!feedOrActivity) {
696
+ throw new Error("Feed or activity is required");
697
+ }
698
+ if (!canLoadComments(feedOrActivity)) {
699
+ throw new Error("Feed or activity does not support loading comments");
700
+ }
701
+ if (!(activity || parentComment)) {
702
+ throw new Error("Activity or parent comment is required");
703
+ }
704
+ const entityId = parentComment?.id ?? activity?.id ?? "";
705
+ const selector2 = useCallback(
706
+ (state) => ({
707
+ comments: state.comments_by_entity_id?.[entityId]?.comments,
708
+ comments_pagination: state.comments_by_entity_id?.[entityId]?.pagination
709
+ }),
710
+ [entityId]
711
+ );
712
+ const data = useStateStore(
713
+ feedOrActivity.state,
714
+ selector2
715
+ );
716
+ const loadNextPage = useCallback(
717
+ (request) => {
718
+ if (parentComment) {
719
+ return feedOrActivity.loadNextPageCommentReplies(
720
+ parentComment,
721
+ request
722
+ );
723
+ } else {
724
+ if (activity && canLoadComments(activity)) {
725
+ return activity.loadNextPageActivityComments(request);
726
+ } else if (feed) {
727
+ return feed.loadNextPageActivityComments(activity?.id ?? "", request);
728
+ } else {
729
+ throw new Error("Activity or feed is required");
730
+ }
731
+ }
732
+ },
733
+ [feedOrActivity, feed, parentComment, activity]
734
+ );
735
+ return useMemo(() => {
736
+ return {
737
+ ...data,
738
+ has_next_page: checkHasAnotherPage(
739
+ data.comments,
740
+ data.comments_pagination?.next
741
+ ),
742
+ is_loading_next_page: data?.comments_pagination?.loading_next_page ?? false,
743
+ loadNextPage
744
+ };
745
+ }, [data, loadNextPage]);
746
+ }
686
747
  const StreamSearchResultsContext = createContext(void 0);
687
748
  const useSearchResultsContext = () => {
688
749
  return useContext(StreamSearchResultsContext);
@@ -1266,6 +1327,7 @@ export {
1266
1327
  StreamSearchContext,
1267
1328
  StreamSearchResults,
1268
1329
  StreamSearchResultsContext,
1330
+ useActivityComments,
1269
1331
  useAggregatedActivities,
1270
1332
  useClientConnectedUser,
1271
1333
  useComments,