Skip to content

Commit

Permalink
fix: make poll type optional on message response (#1281)
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalnarkhede authored Apr 24, 2024
1 parent ef21c10 commit cf311e0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/channel_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ export class ChannelState<StreamChatGenerics extends ExtendableGenerics = Defaul
if (message.poll_id !== pollVote.poll_id) return;

const updatedPoll = { ...poll };
let ownVotes = [...(message.poll.own_votes || [])];
let ownVotes = [...(message.poll?.own_votes || [])];

if (pollVote.user_id === this._channel.getClient().userID) {
if (pollVote.option_id && poll.enforce_unique_vote) {
Expand All @@ -527,7 +527,7 @@ export class ChannelState<StreamChatGenerics extends ExtendableGenerics = Defaul
if (message.poll_id !== pollVote.poll_id) return;

const updatedPoll = { ...poll };
const ownVotes = [...(message.poll.own_votes || [])];
const ownVotes = [...(message.poll?.own_votes || [])];

if (pollVote.user_id === this._channel.getClient().userID) {
ownVotes.push(pollVote);
Expand All @@ -550,7 +550,7 @@ export class ChannelState<StreamChatGenerics extends ExtendableGenerics = Defaul
if (message.poll_id !== pollVote.poll_id) return;

const updatedPoll = { ...poll };
const ownVotes = [...(message.poll.own_votes || [])];
const ownVotes = [...(message.poll?.own_votes || [])];
if (pollVote.user_id === this._channel.getClient().userID) {
const index = ownVotes.findIndex((vote) => vote.option_id === pollVote.option_id);
if (index > -1) {
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,6 @@ export type MessageResponse<
export type MessageResponseBase<
StreamChatGenerics extends ExtendableGenerics = DefaultGenerics
> = MessageBase<StreamChatGenerics> & {
poll: PollResponse<StreamChatGenerics>;
type: MessageLabel;
args?: string;
before_message_send_failed?: boolean;
Expand All @@ -649,6 +648,7 @@ export type MessageResponseBase<
pin_expires?: string | null;
pinned_at?: string | null;
pinned_by?: UserResponse<StreamChatGenerics> | null;
poll?: PollResponse<StreamChatGenerics>;
reaction_counts?: { [key: string]: number } | null;
reaction_scores?: { [key: string]: number } | null;
reply_count?: number;
Expand Down

0 comments on commit cf311e0

Please sign in to comment.