@stream-io/feeds-client 0.3.47 → 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.
@@ -1,7 +1,7 @@
1
1
  import { useStateStore } from "@stream-io/state-store/react-bindings";
2
2
  export * from "@stream-io/state-store/react-bindings";
3
3
  import { useState, useEffect, createContext, useContext, useRef, useCallback, useMemo } from "react";
4
- import { F as FeedsClient, g as isCommentResponse, c as checkHasAnotherPage } from "../feeds-client-ykIZW9Hi.mjs";
4
+ import { F as FeedsClient, g as isCommentResponse, c as checkHasAnotherPage } from "../feeds-client-D-EFo20w.mjs";
5
5
  import { jsx } from "react/jsx-runtime";
6
6
  const useCreateFeedsClient = ({
7
7
  apiKey,
@@ -1224,6 +1224,12 @@ decoders.QueryModerationConfigsResponse = (input) => {
1224
1224
  };
1225
1225
  return decode(typeMappings, input);
1226
1226
  };
1227
+ decoders.QueryPinnedActivitiesResponse = (input) => {
1228
+ const typeMappings = {
1229
+ pinned_activities: { type: "ActivityPinResponse", isSingle: false }
1230
+ };
1231
+ return decode(typeMappings, input);
1232
+ };
1227
1233
  decoders.QueryPollsResponse = (input) => {
1228
1234
  const typeMappings = {
1229
1235
  polls: { type: "PollResponseData", isSingle: false }
@@ -2571,6 +2577,29 @@ class FeedsApi {
2571
2577
  decoders.RejectFeedMemberInviteResponse?.(response.body);
2572
2578
  return { ...response.body, metadata: response.metadata };
2573
2579
  }
2580
+ async queryPinnedActivities(request) {
2581
+ const pathParams = {
2582
+ feed_group_id: request?.feed_group_id,
2583
+ feed_id: request?.feed_id
2584
+ };
2585
+ const body = {
2586
+ limit: request?.limit,
2587
+ next: request?.next,
2588
+ prev: request?.prev,
2589
+ sort: request?.sort,
2590
+ filter: request?.filter
2591
+ };
2592
+ const response = await this.apiClient.sendRequest(
2593
+ "POST",
2594
+ "/api/v2/feeds/feed_groups/{feed_group_id}/feeds/{feed_id}/pinned_activities/query",
2595
+ pathParams,
2596
+ void 0,
2597
+ body,
2598
+ "application/json"
2599
+ );
2600
+ decoders.QueryPinnedActivitiesResponse?.(response.body);
2601
+ return { ...response.body, metadata: response.metadata };
2602
+ }
2574
2603
  async stopWatchingFeed(request) {
2575
2604
  const queryParams = {
2576
2605
  connection_id: request?.connection_id
@@ -4010,7 +4039,7 @@ const getRateLimitFromResponseHeader = (response_headers) => {
4010
4039
  };
4011
4040
  return result;
4012
4041
  };
4013
- const version = "0.3.47";
4042
+ const version = "0.3.48";
4014
4043
  const axios = axiosImport.default ?? axiosImport;
4015
4044
  class ApiClient {
4016
4045
  constructor(apiKey, tokenManager, connectionIdManager, options) {
@@ -4483,9 +4512,6 @@ class ModerationClient extends ModerationApi {
4483
4512
  }
4484
4513
  const isPollUpdatedEvent = (e) => e.type === "feeds.poll.updated";
4485
4514
  const isPollClosedEventEvent = (e) => e.type === "feeds.poll.closed";
4486
- const isPollVoteCastedEvent = (e) => e.type === "feeds.poll.vote_casted";
4487
- const isPollVoteChangedEvent = (e) => e.type === "feeds.poll.vote_changed";
4488
- const isPollVoteRemovedEvent = (e) => e.type === "feeds.poll.vote_removed";
4489
4515
  const isVoteAnswer = (vote) => !!vote?.answer_text;
4490
4516
  class StreamPoll {
4491
4517
  constructor({ client, poll }) {
@@ -4534,9 +4560,12 @@ class StreamPoll {
4534
4560
  };
4535
4561
  this.handleVoteCasted = (event) => {
4536
4562
  if (event.poll?.id && event.poll.id !== this.id) return;
4537
- if (!isPollVoteCastedEvent(event)) return;
4538
4563
  const currentState = this.data;
4539
4564
  const isOwnVote = event.poll_vote.user_id === this.client.state.getLatestValue().connected_user?.id;
4565
+ if (isOwnVote) {
4566
+ 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;
4567
+ if (alreadyApplied) return;
4568
+ }
4540
4569
  let latestAnswers = [...currentState.latest_answers];
4541
4570
  let ownAnswer = currentState.own_answer;
4542
4571
  let ownVotesByOptionId = currentState.own_votes_by_option_id;
@@ -4552,7 +4581,10 @@ class StreamPoll {
4552
4581
  }
4553
4582
  }
4554
4583
  if (isVoteAnswer(event.poll_vote)) {
4555
- latestAnswers = [event.poll_vote, ...latestAnswers];
4584
+ latestAnswers = [
4585
+ event.poll_vote,
4586
+ ...latestAnswers.filter((a) => a.id !== event.poll_vote.id)
4587
+ ];
4556
4588
  } else {
4557
4589
  maxVotedOptionIds = getMaxVotedOptionIds(
4558
4590
  event.poll.vote_counts_by_option
@@ -4578,9 +4610,12 @@ class StreamPoll {
4578
4610
  };
4579
4611
  this.handleVoteChanged = (event) => {
4580
4612
  if (event.poll?.id && event.poll.id !== this.id) return;
4581
- if (!isPollVoteChangedEvent(event)) return;
4582
4613
  const currentState = this.data;
4583
4614
  const isOwnVote = event.poll_vote.user_id === this.client.state.getLatestValue().connected_user?.id;
4615
+ if (isOwnVote) {
4616
+ 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;
4617
+ if (alreadyApplied) return;
4618
+ }
4584
4619
  let latestAnswers = [...currentState.latest_answers];
4585
4620
  let ownAnswer = currentState.own_answer;
4586
4621
  let ownVotesByOptionId = currentState.own_votes_by_option_id;
@@ -4639,9 +4674,12 @@ class StreamPoll {
4639
4674
  };
4640
4675
  this.handleVoteRemoved = (event) => {
4641
4676
  if (event.poll?.id && event.poll.id !== this.id) return;
4642
- if (!isPollVoteRemovedEvent(event)) return;
4643
4677
  const currentState = this.data;
4644
4678
  const isOwnVote = event.poll_vote.user_id === this.client.state.getLatestValue().connected_user?.id;
4679
+ if (isOwnVote) {
4680
+ 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);
4681
+ if (alreadyApplied) return;
4682
+ }
4645
4683
  let latestAnswers = [...currentState.latest_answers];
4646
4684
  let ownAnswer = currentState.own_answer;
4647
4685
  const ownVotesByOptionId = { ...currentState.own_votes_by_option_id };
@@ -4785,6 +4823,13 @@ class FeedApi {
4785
4823
  ...request
4786
4824
  });
4787
4825
  }
4826
+ queryPinnedActivities(request) {
4827
+ return this.feedsApi.queryPinnedActivities({
4828
+ feed_id: this.id,
4829
+ feed_group_id: this.group,
4830
+ ...request
4831
+ });
4832
+ }
4788
4833
  stopWatching(request) {
4789
4834
  return this.feedsApi.stopWatchingFeed({
4790
4835
  feed_id: this.id,
@@ -7518,6 +7563,34 @@ class FeedsClient extends FeedsApi {
7518
7563
  }
7519
7564
  });
7520
7565
  };
7566
+ this.castPollVote = async (request) => {
7567
+ const poll = this.pollFromState(request.poll_id);
7568
+ const response = await super.castPollVote(request);
7569
+ if (response.poll && response.vote && poll) {
7570
+ const payload = {
7571
+ poll: response.poll,
7572
+ poll_vote: response.vote,
7573
+ created_at: /* @__PURE__ */ new Date()
7574
+ };
7575
+ if (poll.data.enforce_unique_vote && Object.keys(poll.data.own_votes_by_option_id).length > 0) {
7576
+ poll.handleVoteChanged(payload);
7577
+ } else {
7578
+ poll.handleVoteCasted(payload);
7579
+ }
7580
+ }
7581
+ return response;
7582
+ };
7583
+ this.deletePollVote = async (request) => {
7584
+ const response = await super.deletePollVote(request);
7585
+ if (response.poll && response.vote) {
7586
+ this.pollFromState(request.poll_id)?.handleVoteRemoved({
7587
+ poll: response.poll,
7588
+ poll_vote: response.vote,
7589
+ created_at: /* @__PURE__ */ new Date()
7590
+ });
7591
+ }
7592
+ return response;
7593
+ };
7521
7594
  this.uploadFile = (request) => {
7522
7595
  return super.uploadFile({
7523
7596
  file: request?.file
@@ -8097,4 +8170,4 @@ export {
8097
8170
  shouldUpdateState as s,
8098
8171
  uniqueArrayMerge as u
8099
8172
  };
8100
- //# sourceMappingURL=feeds-client-ykIZW9Hi.mjs.map
8173
+ //# sourceMappingURL=feeds-client-D-EFo20w.mjs.map