@stream-io/feeds-client 0.3.46 → 0.3.48

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 (42) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/cjs/index.js +1 -1
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/react-bindings.js +56 -23
  5. package/dist/cjs/react-bindings.js.map +1 -1
  6. package/dist/es/index.mjs +2 -2
  7. package/dist/es/index.mjs.map +1 -1
  8. package/dist/es/react-bindings.mjs +56 -23
  9. package/dist/es/react-bindings.mjs.map +1 -1
  10. package/dist/{feeds-client-CSg4hlZ4.mjs → feeds-client-D-EFo20w.mjs} +100 -23
  11. package/dist/feeds-client-D-EFo20w.mjs.map +1 -0
  12. package/dist/{feeds-client-CF1yEox0.js → feeds-client-DuJuJuEJ.js} +100 -23
  13. package/dist/feeds-client-DuJuJuEJ.js.map +1 -0
  14. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  15. package/dist/types/bindings/react/hooks/feed-state-hooks/index.d.ts +1 -0
  16. package/dist/types/bindings/react/hooks/feed-state-hooks/index.d.ts.map +1 -1
  17. package/dist/types/bindings/react/hooks/feed-state-hooks/useMembers.d.ts +17 -0
  18. package/dist/types/bindings/react/hooks/feed-state-hooks/useMembers.d.ts.map +1 -0
  19. package/dist/types/common/Poll.d.ts +9 -4
  20. package/dist/types/common/Poll.d.ts.map +1 -1
  21. package/dist/types/feed/event-handlers/activity-updater.d.ts +2 -2
  22. package/dist/types/feed/event-handlers/activity-updater.d.ts.map +1 -1
  23. package/dist/types/feeds-client/feeds-client.d.ts +11 -1
  24. package/dist/types/feeds-client/feeds-client.d.ts.map +1 -1
  25. package/dist/types/gen/feeds/FeedApi.d.ts +2 -1
  26. package/dist/types/gen/feeds/FeedApi.d.ts.map +1 -1
  27. package/dist/types/gen/feeds/FeedsApi.d.ts +5 -1
  28. package/dist/types/gen/feeds/FeedsApi.d.ts.map +1 -1
  29. package/dist/types/gen/models/index.d.ts +13 -0
  30. package/dist/types/gen/models/index.d.ts.map +1 -1
  31. package/package.json +1 -1
  32. package/src/bindings/react/hooks/feed-state-hooks/index.ts +1 -0
  33. package/src/bindings/react/hooks/feed-state-hooks/useMembers.ts +55 -0
  34. package/src/common/Poll.ts +47 -26
  35. package/src/feed/event-handlers/activity-updater.ts +2 -0
  36. package/src/feeds-client/feeds-client.ts +52 -11
  37. package/src/gen/feeds/FeedApi.ts +12 -0
  38. package/src/gen/feeds/FeedsApi.ts +36 -0
  39. package/src/gen/model-decoders/decoders.ts +7 -0
  40. package/src/gen/models/index.ts +22 -0
  41. package/dist/feeds-client-CF1yEox0.js.map +0 -1
  42. package/dist/feeds-client-CSg4hlZ4.mjs.map +0 -1
@@ -1242,6 +1242,12 @@ decoders.QueryModerationConfigsResponse = (input) => {
1242
1242
  };
1243
1243
  return decode(typeMappings, input);
1244
1244
  };
1245
+ decoders.QueryPinnedActivitiesResponse = (input) => {
1246
+ const typeMappings = {
1247
+ pinned_activities: { type: "ActivityPinResponse", isSingle: false }
1248
+ };
1249
+ return decode(typeMappings, input);
1250
+ };
1245
1251
  decoders.QueryPollsResponse = (input) => {
1246
1252
  const typeMappings = {
1247
1253
  polls: { type: "PollResponseData", isSingle: false }
@@ -2589,6 +2595,29 @@ class FeedsApi {
2589
2595
  decoders.RejectFeedMemberInviteResponse?.(response.body);
2590
2596
  return { ...response.body, metadata: response.metadata };
2591
2597
  }
2598
+ async queryPinnedActivities(request) {
2599
+ const pathParams = {
2600
+ feed_group_id: request?.feed_group_id,
2601
+ feed_id: request?.feed_id
2602
+ };
2603
+ const body = {
2604
+ limit: request?.limit,
2605
+ next: request?.next,
2606
+ prev: request?.prev,
2607
+ sort: request?.sort,
2608
+ filter: request?.filter
2609
+ };
2610
+ const response = await this.apiClient.sendRequest(
2611
+ "POST",
2612
+ "/api/v2/feeds/feed_groups/{feed_group_id}/feeds/{feed_id}/pinned_activities/query",
2613
+ pathParams,
2614
+ void 0,
2615
+ body,
2616
+ "application/json"
2617
+ );
2618
+ decoders.QueryPinnedActivitiesResponse?.(response.body);
2619
+ return { ...response.body, metadata: response.metadata };
2620
+ }
2592
2621
  async stopWatchingFeed(request) {
2593
2622
  const queryParams = {
2594
2623
  connection_id: request?.connection_id
@@ -4028,7 +4057,7 @@ const getRateLimitFromResponseHeader = (response_headers) => {
4028
4057
  };
4029
4058
  return result;
4030
4059
  };
4031
- const version = "0.3.46";
4060
+ const version = "0.3.48";
4032
4061
  const axios = axiosImport.default ?? axiosImport;
4033
4062
  class ApiClient {
4034
4063
  constructor(apiKey, tokenManager, connectionIdManager, options) {
@@ -4501,9 +4530,6 @@ class ModerationClient extends ModerationApi {
4501
4530
  }
4502
4531
  const isPollUpdatedEvent = (e) => e.type === "feeds.poll.updated";
4503
4532
  const isPollClosedEventEvent = (e) => e.type === "feeds.poll.closed";
4504
- const isPollVoteCastedEvent = (e) => e.type === "feeds.poll.vote_casted";
4505
- const isPollVoteChangedEvent = (e) => e.type === "feeds.poll.vote_changed";
4506
- const isPollVoteRemovedEvent = (e) => e.type === "feeds.poll.vote_removed";
4507
4533
  const isVoteAnswer = (vote) => !!vote?.answer_text;
4508
4534
  class StreamPoll {
4509
4535
  constructor({ client, poll }) {
@@ -4552,22 +4578,31 @@ class StreamPoll {
4552
4578
  };
4553
4579
  this.handleVoteCasted = (event) => {
4554
4580
  if (event.poll?.id && event.poll.id !== this.id) return;
4555
- if (!isPollVoteCastedEvent(event)) return;
4556
4581
  const currentState = this.data;
4557
4582
  const isOwnVote = event.poll_vote.user_id === this.client.state.getLatestValue().connected_user?.id;
4583
+ if (isOwnVote) {
4584
+ const alreadyApplied = isVoteAnswer(event.poll_vote) ? currentState.own_answer?.id === event.poll_vote.id : !!event.poll_vote.option_id && currentState.own_votes_by_option_id[event.poll_vote.option_id]?.id === event.poll_vote.id;
4585
+ if (alreadyApplied) return;
4586
+ }
4558
4587
  let latestAnswers = [...currentState.latest_answers];
4559
4588
  let ownAnswer = currentState.own_answer;
4560
- const ownVotesByOptionId = currentState.own_votes_by_option_id;
4589
+ let ownVotesByOptionId = currentState.own_votes_by_option_id;
4561
4590
  let maxVotedOptionIds = currentState.max_voted_option_ids;
4562
4591
  if (isOwnVote) {
4563
4592
  if (isVoteAnswer(event.poll_vote)) {
4564
4593
  ownAnswer = event.poll_vote;
4565
4594
  } else if (event.poll_vote.option_id) {
4566
- ownVotesByOptionId[event.poll_vote.option_id] = event.poll_vote;
4595
+ ownVotesByOptionId = {
4596
+ ...ownVotesByOptionId,
4597
+ [event.poll_vote.option_id]: event.poll_vote
4598
+ };
4567
4599
  }
4568
4600
  }
4569
4601
  if (isVoteAnswer(event.poll_vote)) {
4570
- latestAnswers = [event.poll_vote, ...latestAnswers];
4602
+ latestAnswers = [
4603
+ event.poll_vote,
4604
+ ...latestAnswers.filter((a) => a.id !== event.poll_vote.id)
4605
+ ];
4571
4606
  } else {
4572
4607
  maxVotedOptionIds = getMaxVotedOptionIds(
4573
4608
  event.poll.vote_counts_by_option
@@ -4593,9 +4628,12 @@ class StreamPoll {
4593
4628
  };
4594
4629
  this.handleVoteChanged = (event) => {
4595
4630
  if (event.poll?.id && event.poll.id !== this.id) return;
4596
- if (!isPollVoteChangedEvent(event)) return;
4597
4631
  const currentState = this.data;
4598
4632
  const isOwnVote = event.poll_vote.user_id === this.client.state.getLatestValue().connected_user?.id;
4633
+ if (isOwnVote) {
4634
+ const alreadyApplied = isVoteAnswer(event.poll_vote) ? currentState.own_answer?.id === event.poll_vote.id : !!event.poll_vote.option_id && currentState.own_votes_by_option_id[event.poll_vote.option_id]?.id === event.poll_vote.id;
4635
+ if (alreadyApplied) return;
4636
+ }
4599
4637
  let latestAnswers = [...currentState.latest_answers];
4600
4638
  let ownAnswer = currentState.own_answer;
4601
4639
  let ownVotesByOptionId = currentState.own_votes_by_option_id;
@@ -4654,9 +4692,12 @@ class StreamPoll {
4654
4692
  };
4655
4693
  this.handleVoteRemoved = (event) => {
4656
4694
  if (event.poll?.id && event.poll.id !== this.id) return;
4657
- if (!isPollVoteRemovedEvent(event)) return;
4658
4695
  const currentState = this.data;
4659
4696
  const isOwnVote = event.poll_vote.user_id === this.client.state.getLatestValue().connected_user?.id;
4697
+ if (isOwnVote) {
4698
+ const alreadyApplied = isVoteAnswer(event.poll_vote) ? !currentState.own_answer : !!event.poll_vote.option_id && !(event.poll_vote.option_id in currentState.own_votes_by_option_id);
4699
+ if (alreadyApplied) return;
4700
+ }
4660
4701
  let latestAnswers = [...currentState.latest_answers];
4661
4702
  let ownAnswer = currentState.own_answer;
4662
4703
  const ownVotesByOptionId = { ...currentState.own_votes_by_option_id };
@@ -4800,6 +4841,13 @@ class FeedApi {
4800
4841
  ...request
4801
4842
  });
4802
4843
  }
4844
+ queryPinnedActivities(request) {
4845
+ return this.feedsApi.queryPinnedActivities({
4846
+ feed_id: this.id,
4847
+ feed_group_id: this.group,
4848
+ ...request
4849
+ });
4850
+ }
4803
4851
  stopWatching(request) {
4804
4852
  return this.feedsApi.stopWatchingFeed({
4805
4853
  feed_id: this.id,
@@ -5749,7 +5797,9 @@ const updateActivity = ({
5749
5797
  return {
5750
5798
  ...newActivtiy,
5751
5799
  own_reactions: currentActivity.own_reactions,
5752
- own_bookmarks: currentActivity.own_bookmarks
5800
+ own_bookmarks: currentActivity.own_bookmarks,
5801
+ friend_reactions: currentActivity.friend_reactions,
5802
+ friend_reaction_count: currentActivity.friend_reaction_count
5753
5803
  };
5754
5804
  };
5755
5805
  const sharedUpdateActivity$3 = updateActivity;
@@ -7531,6 +7581,34 @@ class FeedsClient extends FeedsApi {
7531
7581
  }
7532
7582
  });
7533
7583
  };
7584
+ this.castPollVote = async (request) => {
7585
+ const poll = this.pollFromState(request.poll_id);
7586
+ const response = await super.castPollVote(request);
7587
+ if (response.poll && response.vote && poll) {
7588
+ const payload = {
7589
+ poll: response.poll,
7590
+ poll_vote: response.vote,
7591
+ created_at: /* @__PURE__ */ new Date()
7592
+ };
7593
+ if (poll.data.enforce_unique_vote && Object.keys(poll.data.own_votes_by_option_id).length > 0) {
7594
+ poll.handleVoteChanged(payload);
7595
+ } else {
7596
+ poll.handleVoteCasted(payload);
7597
+ }
7598
+ }
7599
+ return response;
7600
+ };
7601
+ this.deletePollVote = async (request) => {
7602
+ const response = await super.deletePollVote(request);
7603
+ if (response.poll && response.vote) {
7604
+ this.pollFromState(request.poll_id)?.handleVoteRemoved({
7605
+ poll: response.poll,
7606
+ poll_vote: response.vote,
7607
+ created_at: /* @__PURE__ */ new Date()
7608
+ });
7609
+ }
7610
+ return response;
7611
+ };
7534
7612
  this.uploadFile = (request) => {
7535
7613
  return super.uploadFile({
7536
7614
  file: request?.file
@@ -7889,17 +7967,16 @@ class FeedsClient extends FeedsApi {
7889
7967
  }
7890
7968
  hydratePollCache(activities) {
7891
7969
  for (const activity of activities) {
7892
- if (!activity.poll) {
7893
- continue;
7894
- }
7895
- const pollResponse = activity.poll;
7896
- const pollFromCache = this.pollFromState(pollResponse.id);
7897
- if (!pollFromCache) {
7898
- const poll = new StreamPoll({ client: this, poll: pollResponse });
7899
- this.polls_by_id.set(poll.id, poll);
7900
- } else {
7901
- pollFromCache.reinitializeState(pollResponse);
7902
- }
7970
+ const polls = [activity.poll, activity.parent?.poll].filter((p) => !!p);
7971
+ polls.forEach((pollResponse) => {
7972
+ const pollFromCache = this.pollFromState(pollResponse.id);
7973
+ if (!pollFromCache) {
7974
+ const poll = new StreamPoll({ client: this, poll: pollResponse });
7975
+ this.polls_by_id.set(poll.id, poll);
7976
+ } else {
7977
+ pollFromCache.reinitializeState(pollResponse);
7978
+ }
7979
+ });
7903
7980
  }
7904
7981
  }
7905
7982
  async queryFeeds(request) {
@@ -8109,4 +8186,4 @@ exports.replaceUniqueArrayMerge = replaceUniqueArrayMerge;
8109
8186
  exports.shouldUpdateState = shouldUpdateState;
8110
8187
  exports.uniqueArrayMerge = uniqueArrayMerge;
8111
8188
  exports.updateEntityInArray = updateEntityInArray;
8112
- //# sourceMappingURL=feeds-client-CF1yEox0.js.map
8189
+ //# sourceMappingURL=feeds-client-DuJuJuEJ.js.map