Socket
Socket
Sign inDemoInstall

stream-chat

Package Overview
Dependencies
36
Maintainers
11
Versions
283
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 8.25.1 to 8.26.0

6

dist/types/channel_state.d.ts
import { Channel } from './channel';
import { ChannelMemberResponse, ChannelMembership, FormatMessageResponse, Event, ExtendableGenerics, DefaultGenerics, MessageSetType, MessageResponse, ReactionResponse, UserResponse, PendingMessageResponse } from './types';
import { ChannelMemberResponse, ChannelMembership, FormatMessageResponse, Event, ExtendableGenerics, DefaultGenerics, MessageSetType, MessageResponse, ReactionResponse, UserResponse, PendingMessageResponse, PollVote, PollResponse } from './types';
declare type ChannelReadStatus<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = Record<string, {

@@ -169,2 +169,6 @@ last_read: Date;

};
updatePollVote: (pollVote: PollVote<StreamChatGenerics>, poll: PollResponse<StreamChatGenerics>, messageId: string) => void;
addPollVote: (pollVote: PollVote<StreamChatGenerics>, poll: PollResponse<StreamChatGenerics>, messageId: string) => void;
removePollVote: (pollVote: PollVote<StreamChatGenerics>, poll: PollResponse<StreamChatGenerics>, messageId: string) => void;
updatePoll: (poll: PollResponse<StreamChatGenerics>, messageId: string) => void;
/**

@@ -171,0 +175,0 @@ * Updates the message.user property with updated user object, for messages.

/// <reference types="node" />
import { ChannelState } from './channel_state';
import { StreamChat } from './client';
import { APIResponse, BanUserOptions, ChannelAPIResponse, ChannelData, ChannelMemberAPIResponse, ChannelQueryOptions, ChannelResponse, ChannelUpdateOptions, CreateCallOptions, CreateCallResponse, DefaultGenerics, DeleteChannelAPIResponse, Event, EventAPIResponse, EventHandler, EventTypes, ExtendableGenerics, FormatMessageResponse, GetMultipleMessagesAPIResponse, GetReactionsAPIResponse, GetRepliesAPIResponse, InviteOptions, MarkReadOptions, MarkUnreadOptions, MemberSort, Message, MessageFilters, MessagePaginationOptions, MessageResponse, MessageSetType, MuteChannelAPIResponse, PartialUpdateChannel, PartialUpdateChannelAPIResponse, PinnedMessagePaginationOptions, PinnedMessagesSort, QueryMembersOptions, Reaction, ReactionAPIResponse, SearchAPIResponse, SearchOptions, SendMessageAPIResponse, TruncateChannelAPIResponse, TruncateOptions, UpdateChannelAPIResponse, UserFilters, UserResponse, QueryChannelAPIResponse, SendMessageOptions } from './types';
import { APIResponse, BanUserOptions, ChannelAPIResponse, ChannelData, ChannelMemberAPIResponse, ChannelQueryOptions, ChannelResponse, ChannelUpdateOptions, CreateCallOptions, CreateCallResponse, DefaultGenerics, DeleteChannelAPIResponse, Event, EventAPIResponse, EventHandler, EventTypes, ExtendableGenerics, FormatMessageResponse, GetMultipleMessagesAPIResponse, GetReactionsAPIResponse, GetRepliesAPIResponse, InviteOptions, MarkReadOptions, MarkUnreadOptions, MemberSort, Message, MessageFilters, MessagePaginationOptions, MessageResponse, MessageSetType, MuteChannelAPIResponse, PartialUpdateChannel, PartialUpdateChannelAPIResponse, PinnedMessagePaginationOptions, PinnedMessagesSort, QueryMembersOptions, Reaction, ReactionAPIResponse, SearchAPIResponse, SearchOptions, SendMessageAPIResponse, TruncateChannelAPIResponse, TruncateOptions, UpdateChannelAPIResponse, UserFilters, UserResponse, QueryChannelAPIResponse, PollVoteData, SendMessageOptions } from './types';
import { Role } from './permissions';

@@ -495,2 +495,12 @@ /**

/**
* Cast or cancel one or more votes on a poll
* @param pollId string The poll id
* @param votes PollVoteData[] The votes that will be casted (or canceled in case of an empty array)
* @returns {APIResponse & PollVoteResponse} The poll votes
*/
vote(messageId: string, pollId: string, vote: PollVoteData): Promise<APIResponse & import("./types").CastVoteAPIResponse<DefaultGenerics>>;
removeVote(messageId: string, pollId: string, voteId: string): Promise<APIResponse & {
vote: import("./types").PollVote<DefaultGenerics>;
}>;
/**
* on - Listen to events on this channel.

@@ -497,0 +507,0 @@ *

@@ -33,2 +33,7 @@ export declare const EVENT_MAP: {

'notification.thread_message_new': boolean;
'poll.closed': boolean;
'poll.updated': boolean;
'poll.vote_casted': boolean;
'poll.vote_changed': boolean;
'poll.vote_removed': boolean;
'reaction.deleted': boolean;

@@ -35,0 +40,0 @@ 'reaction.new': boolean;

@@ -19,2 +19,3 @@ import { StreamChat } from './client';

read: ThreadReadStatus<StreamChatGenerics>;
data: Record<string, any>;
constructor(client: StreamChat<StreamChatGenerics>, t: ThreadResponse<StreamChatGenerics>);

@@ -21,0 +22,0 @@ getClient(): StreamChat<StreamChatGenerics>;

2

package.json
{
"name": "stream-chat",
"version": "8.25.1",
"version": "8.26.0",
"description": "JS SDK for the Stream Chat API",

@@ -5,0 +5,0 @@ "author": "GetStream",

@@ -14,2 +14,4 @@ import { Channel } from './channel';

PendingMessageResponse,
PollVote,
PollResponse,
} from './types';

@@ -490,2 +492,92 @@ import { addToMessageList } from './utils';

// this handles the case when vote on poll is changed
updatePollVote = (
pollVote: PollVote<StreamChatGenerics>,
poll: PollResponse<StreamChatGenerics>,
messageId: string,
) => {
const message = this.findMessage(messageId);
if (!message) return;
if (message.poll_id !== pollVote.poll_id) return;
const updatedPoll = { ...poll };
let ownVotes = [...(message.poll.own_votes || [])];
if (pollVote.user_id === this._channel.getClient().userID) {
if (pollVote.option_id && poll.enforce_unique_vote) {
// remove all previous votes where option_id is not empty
ownVotes = ownVotes.filter((vote) => !vote.option_id);
} else if (pollVote.answer_text) {
// remove all previous votes where option_id is empty
ownVotes = ownVotes.filter((vote) => vote.answer_text);
}
ownVotes.push(pollVote);
}
updatedPoll.own_votes = ownVotes as PollVote<StreamChatGenerics>[];
const newMessage = { ...message, poll: updatedPoll };
this.addMessageSorted((newMessage as unknown) as MessageResponse<StreamChatGenerics>, false, false);
};
addPollVote = (pollVote: PollVote<StreamChatGenerics>, poll: PollResponse<StreamChatGenerics>, messageId: string) => {
const message = this.findMessage(messageId);
if (!message) return;
if (message.poll_id !== pollVote.poll_id) return;
const updatedPoll = { ...poll };
const ownVotes = [...(message.poll.own_votes || [])];
if (pollVote.user_id === this._channel.getClient().userID) {
ownVotes.push(pollVote);
}
updatedPoll.own_votes = ownVotes as PollVote<StreamChatGenerics>[];
const newMessage = { ...message, poll: updatedPoll };
this.addMessageSorted((newMessage as unknown) as MessageResponse<StreamChatGenerics>, false, false);
};
removePollVote = (
pollVote: PollVote<StreamChatGenerics>,
poll: PollResponse<StreamChatGenerics>,
messageId: string,
) => {
const message = this.findMessage(messageId);
if (!message) return;
if (message.poll_id !== pollVote.poll_id) return;
const updatedPoll = { ...poll };
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) {
ownVotes.splice(index, 1);
}
}
updatedPoll.own_votes = ownVotes as PollVote<StreamChatGenerics>[];
const newMessage = { ...message, poll: updatedPoll };
this.addMessageSorted((newMessage as unknown) as MessageResponse<StreamChatGenerics>, false, false);
};
updatePoll = (poll: PollResponse<StreamChatGenerics>, messageId: string) => {
const message = this.findMessage(messageId);
if (!message) return;
const updatedPoll = {
...poll,
own_votes: [...(message.poll?.own_votes || [])],
};
const newMessage = { ...message, poll: updatedPoll };
this.addMessageSorted((newMessage as unknown) as MessageResponse<StreamChatGenerics>, false, false);
};
/**

@@ -492,0 +584,0 @@ * Updates the message.user property with updated user object, for messages.

@@ -56,2 +56,3 @@ import { ChannelState } from './channel_state';

QueryChannelAPIResponse,
PollVoteData,
SendMessageOptions,

@@ -1163,2 +1164,16 @@ } from './types';

/**
* Cast or cancel one or more votes on a poll
* @param pollId string The poll id
* @param votes PollVoteData[] The votes that will be casted (or canceled in case of an empty array)
* @returns {APIResponse & PollVoteResponse} The poll votes
*/
async vote(messageId: string, pollId: string, vote: PollVoteData) {
return await this.getClient().castPollVote(messageId, pollId, vote);
}
async removeVote(messageId: string, pollId: string, voteId: string) {
return await this.getClient().removePollVote(messageId, pollId, voteId);
}
/**
* on - Listen to events on this channel.

@@ -1406,2 +1421,27 @@ *

break;
case 'poll.updated':
if (event.poll) {
channelState.updatePoll(event.poll, event.message?.id || '');
}
break;
case 'poll.vote_casted':
if (event.poll_vote && event.poll) {
channelState.addPollVote(event.poll_vote, event.poll, event.message?.id || '');
}
break;
case 'poll.vote_changed':
if (event.poll_vote && event.poll) {
channelState.updatePollVote(event.poll_vote, event.poll, event.message?.id || '');
}
break;
case 'poll.vote_removed':
if (event.poll_vote && event.poll) {
channelState.removePollVote(event.poll_vote, event.poll, event.message?.id || '');
}
break;
case 'poll.closed':
if (event.message) {
channelState.addMessageSorted(event.message, false, false);
}
break;
case 'reaction.new':

@@ -1408,0 +1448,0 @@ if (event.message && event.reaction) {

@@ -33,2 +33,7 @@ export const EVENT_MAP = {

'notification.thread_message_new': true,
'poll.closed': true,
'poll.updated': true,
'poll.vote_casted': true,
'poll.vote_changed': true,
'poll.vote_removed': true,
'reaction.deleted': true,

@@ -35,0 +40,0 @@ 'reaction.new': true,

@@ -34,14 +34,27 @@ import { StreamChat } from './client';

read: ThreadReadStatus<StreamChatGenerics> = {};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
data: Record<string, any> = {};
constructor(client: StreamChat<StreamChatGenerics>, t: ThreadResponse<StreamChatGenerics>) {
this.id = t.parent_message.id;
this.message = formatMessage(t.parent_message);
this.latestReplies = t.latest_replies.map(formatMessage);
this.participants = t.thread_participants;
this.replyCount = t.reply_count;
this.channel = t.channel;
const {
parent_message_id,
parent_message,
latest_replies,
thread_participants,
reply_count,
channel,
read,
...data
} = t;
this.id = parent_message_id;
this.message = formatMessage(parent_message);
this.latestReplies = latest_replies.map(formatMessage);
this.participants = thread_participants;
this.replyCount = reply_count;
this.channel = channel;
this._channel = client.channel(t.channel.type, t.channel.id);
this._client = client;
if (t.read) {
for (const r of t.read) {
if (read) {
for (const r of read) {
this.read[r.user.id] = {

@@ -53,2 +66,3 @@ ...r,

}
this.data = data;
}

@@ -55,0 +69,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc