@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.
@@ -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.47";
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,9 +4578,12 @@ 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
4589
  let ownVotesByOptionId = currentState.own_votes_by_option_id;
@@ -4570,7 +4599,10 @@ class StreamPoll {
4570
4599
  }
4571
4600
  }
4572
4601
  if (isVoteAnswer(event.poll_vote)) {
4573
- latestAnswers = [event.poll_vote, ...latestAnswers];
4602
+ latestAnswers = [
4603
+ event.poll_vote,
4604
+ ...latestAnswers.filter((a) => a.id !== event.poll_vote.id)
4605
+ ];
4574
4606
  } else {
4575
4607
  maxVotedOptionIds = getMaxVotedOptionIds(
4576
4608
  event.poll.vote_counts_by_option
@@ -4596,9 +4628,12 @@ class StreamPoll {
4596
4628
  };
4597
4629
  this.handleVoteChanged = (event) => {
4598
4630
  if (event.poll?.id && event.poll.id !== this.id) return;
4599
- if (!isPollVoteChangedEvent(event)) return;
4600
4631
  const currentState = this.data;
4601
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
+ }
4602
4637
  let latestAnswers = [...currentState.latest_answers];
4603
4638
  let ownAnswer = currentState.own_answer;
4604
4639
  let ownVotesByOptionId = currentState.own_votes_by_option_id;
@@ -4657,9 +4692,12 @@ class StreamPoll {
4657
4692
  };
4658
4693
  this.handleVoteRemoved = (event) => {
4659
4694
  if (event.poll?.id && event.poll.id !== this.id) return;
4660
- if (!isPollVoteRemovedEvent(event)) return;
4661
4695
  const currentState = this.data;
4662
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
+ }
4663
4701
  let latestAnswers = [...currentState.latest_answers];
4664
4702
  let ownAnswer = currentState.own_answer;
4665
4703
  const ownVotesByOptionId = { ...currentState.own_votes_by_option_id };
@@ -4803,6 +4841,13 @@ class FeedApi {
4803
4841
  ...request
4804
4842
  });
4805
4843
  }
4844
+ queryPinnedActivities(request) {
4845
+ return this.feedsApi.queryPinnedActivities({
4846
+ feed_id: this.id,
4847
+ feed_group_id: this.group,
4848
+ ...request
4849
+ });
4850
+ }
4806
4851
  stopWatching(request) {
4807
4852
  return this.feedsApi.stopWatchingFeed({
4808
4853
  feed_id: this.id,
@@ -7536,6 +7581,34 @@ class FeedsClient extends FeedsApi {
7536
7581
  }
7537
7582
  });
7538
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
+ };
7539
7612
  this.uploadFile = (request) => {
7540
7613
  return super.uploadFile({
7541
7614
  file: request?.file
@@ -8113,4 +8186,4 @@ exports.replaceUniqueArrayMerge = replaceUniqueArrayMerge;
8113
8186
  exports.shouldUpdateState = shouldUpdateState;
8114
8187
  exports.uniqueArrayMerge = uniqueArrayMerge;
8115
8188
  exports.updateEntityInArray = updateEntityInArray;
8116
- //# sourceMappingURL=feeds-client-CxjZlEtX.js.map
8189
+ //# sourceMappingURL=feeds-client-DuJuJuEJ.js.map