stream-chat 8.41.1 → 8.42.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/src/types.ts CHANGED
@@ -1227,7 +1227,7 @@ export type Event<StreamChatGenerics extends ExtendableGenerics = DefaultGeneric
1227
1227
  online?: boolean;
1228
1228
  parent_id?: string;
1229
1229
  poll?: PollResponse<StreamChatGenerics>;
1230
- poll_vote?: PollVote<StreamChatGenerics>;
1230
+ poll_vote?: PollVote<StreamChatGenerics> | PollAnswer<StreamChatGenerics>;
1231
1231
  queriedChannels?: {
1232
1232
  channels: ChannelAPIResponse<StreamChatGenerics>[];
1233
1233
  isLatestMessageSet?: boolean;
@@ -1490,6 +1490,12 @@ export type ChannelFilters<StreamChatGenerics extends ExtendableGenerics = Defau
1490
1490
  }
1491
1491
  >;
1492
1492
 
1493
+ export type QueryPollsParams = {
1494
+ filter?: QueryPollsFilters;
1495
+ options?: QueryPollsOptions;
1496
+ sort?: PollSort;
1497
+ };
1498
+
1493
1499
  export type QueryPollsOptions = Pager;
1494
1500
 
1495
1501
  export type VotesFiltersOptions = {
@@ -3017,30 +3023,23 @@ export type UpdatePollAPIResponse<StreamChatGenerics extends ExtendableGenerics
3017
3023
 
3018
3024
  export type PollResponse<
3019
3025
  StreamChatGenerics extends ExtendableGenerics = DefaultGenerics
3020
- > = StreamChatGenerics['pollType'] & {
3021
- answers_count: number;
3022
- created_at: string;
3023
- created_by: UserResponse<StreamChatGenerics> | null;
3024
- created_by_id: string;
3025
- enforce_unique_vote: boolean;
3026
- id: string;
3027
- latest_answers: PollVote<StreamChatGenerics>[];
3028
- latest_votes_by_option: Record<string, PollVote<StreamChatGenerics>[]>;
3029
- max_votes_allowed: number;
3030
- name: string;
3031
- options: PollOption<StreamChatGenerics>[];
3032
- updated_at: string;
3033
- vote_count: number;
3034
- vote_counts_by_option: Record<string, number>;
3035
- allow_answers?: boolean;
3036
- allow_user_suggested_options?: boolean;
3037
- channel?: ChannelAPIResponse<StreamChatGenerics> | null;
3038
- cid?: string;
3039
- description?: string;
3040
- is_closed?: boolean;
3041
- own_votes?: PollVote<StreamChatGenerics>[];
3042
- voting_visibility?: VotingVisibility;
3043
- };
3026
+ > = StreamChatGenerics['pollType'] &
3027
+ PollEnrichData<StreamChatGenerics> & {
3028
+ created_at: string;
3029
+ created_by: UserResponse<StreamChatGenerics> | null;
3030
+ created_by_id: string;
3031
+ enforce_unique_vote: boolean;
3032
+ id: string;
3033
+ max_votes_allowed: number;
3034
+ name: string;
3035
+ options: PollOption<StreamChatGenerics>[];
3036
+ updated_at: string;
3037
+ allow_answers?: boolean;
3038
+ allow_user_suggested_options?: boolean;
3039
+ description?: string;
3040
+ is_closed?: boolean;
3041
+ voting_visibility?: VotingVisibility;
3042
+ };
3044
3043
 
3045
3044
  export type PollOption<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = {
3046
3045
  created_at: string;
@@ -3057,15 +3056,24 @@ export enum VotingVisibility {
3057
3056
  public = 'public',
3058
3057
  }
3059
3058
 
3059
+ export type PollEnrichData<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = {
3060
+ answers_count: number;
3061
+ latest_answers: PollAnswer<StreamChatGenerics>[]; // not updated with WS events, ordered DESC by created_at, seems like updated_at cannot be different from created_at
3062
+ latest_votes_by_option: Record<string, PollVote<StreamChatGenerics>[]>; // not updated with WS events; always null in anonymous polls
3063
+ vote_count: number;
3064
+ vote_counts_by_option: Record<string, number>;
3065
+ own_votes?: (PollVote<StreamChatGenerics> | PollAnswer<StreamChatGenerics>)[]; // not updated with WS events
3066
+ };
3067
+
3060
3068
  export type PollData<
3061
3069
  StreamChatGenerics extends ExtendableGenerics = DefaultGenerics
3062
3070
  > = StreamChatGenerics['pollType'] & {
3071
+ id: string;
3063
3072
  name: string;
3064
3073
  allow_answers?: boolean;
3065
3074
  allow_user_suggested_options?: boolean;
3066
3075
  description?: string;
3067
3076
  enforce_unique_vote?: boolean;
3068
- id?: string;
3069
3077
  is_closed?: boolean;
3070
3078
  max_votes_allowed?: number;
3071
3079
  options?: PollOptionData<StreamChatGenerics>[];
@@ -3073,15 +3081,19 @@ export type PollData<
3073
3081
  voting_visibility?: VotingVisibility;
3074
3082
  };
3075
3083
 
3084
+ export type CreatePollData<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = Partial<
3085
+ PollData<StreamChatGenerics>
3086
+ > &
3087
+ Pick<PollData<StreamChatGenerics>, 'name'>;
3088
+
3076
3089
  export type PartialPollUpdate<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = {
3077
- // id: string;
3078
- set?: Partial<PollResponse<StreamChatGenerics>>;
3079
- unset?: Array<keyof PollResponse<StreamChatGenerics>>;
3090
+ set?: Partial<PollData<StreamChatGenerics>>;
3091
+ unset?: Array<keyof PollData<StreamChatGenerics>>;
3080
3092
  };
3081
3093
 
3082
3094
  export type PollOptionData<
3083
3095
  StreamChatGenerics extends ExtendableGenerics = DefaultGenerics
3084
- > = StreamChatGenerics['pollType'] & {
3096
+ > = StreamChatGenerics['pollOptionType'] & {
3085
3097
  text: string;
3086
3098
  id?: string;
3087
3099
  position?: number;
@@ -3130,21 +3142,33 @@ export type PollOptionResponse<
3130
3142
  export type PollVote<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = {
3131
3143
  created_at: string;
3132
3144
  id: string;
3133
- is_answer: boolean;
3134
3145
  poll_id: string;
3135
- user_id: string;
3136
- answer_text?: string;
3146
+ updated_at: string;
3137
3147
  option_id?: string;
3138
3148
  user?: UserResponse<StreamChatGenerics>;
3149
+ user_id?: string;
3150
+ };
3151
+
3152
+ export type PollAnswer<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = Exclude<
3153
+ PollVote<StreamChatGenerics>,
3154
+ 'option_id'
3155
+ > & {
3156
+ answer_text: string;
3157
+ is_answer: boolean; // this is absolutely redundant prop as answer_text indicates that a vote is an answer
3139
3158
  };
3140
3159
 
3141
3160
  export type PollVotesAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = {
3142
- votes: PollVote<StreamChatGenerics>[];
3161
+ votes: (PollVote<StreamChatGenerics> | PollAnswer<StreamChatGenerics>)[];
3162
+ next?: string;
3163
+ };
3164
+
3165
+ export type PollAnswersAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = {
3166
+ votes: PollAnswer<StreamChatGenerics>[]; // todo: should be changes to answers?
3143
3167
  next?: string;
3144
3168
  };
3145
3169
 
3146
3170
  export type CastVoteAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = {
3147
- vote: PollVote<StreamChatGenerics>;
3171
+ vote: PollVote<StreamChatGenerics> | PollAnswer<StreamChatGenerics>;
3148
3172
  };
3149
3173
 
3150
3174
  export type QueryMessageHistoryFilters = QueryFilters<