stream-chat 9.14.0 → 9.15.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.
@@ -42,6 +42,7 @@ export declare class MiddlewareExecutor<TValue, THandlers extends string> {
42
42
  unique?: boolean;
43
43
  }): this;
44
44
  setOrder(order: string[]): void;
45
+ remove(middlewareIds: string | string[]): void;
45
46
  protected executeMiddlewareChain({ eventName, initialValue, mode, }: ExecuteParams<TValue>): Promise<MiddlewareExecutionResult<TValue>>;
46
47
  execute({ eventName, initialValue: initialState, mode, }: ExecuteParams<TValue>): Promise<MiddlewareExecutionResult<TValue>>;
47
48
  }
@@ -47,7 +47,7 @@ export declare class Poll {
47
47
  createOption: (option: PollOptionData) => Promise<import("./types").APIResponse & import("./types").CreatePollOptionAPIResponse>;
48
48
  updateOption: (option: PollOptionData) => Promise<import("./types").APIResponse & import("./types").CreatePollOptionAPIResponse>;
49
49
  deleteOption: (optionId: string) => Promise<import("./types").APIResponse>;
50
- castVote: (optionId: string, messageId: string) => Promise<import("./types").APIResponse & import("./types").CastVoteAPIResponse>;
50
+ castVote: (optionId: string, messageId: string) => Promise<(import("./types").APIResponse & import("./types").CastVoteAPIResponse) | undefined>;
51
51
  removeVote: (voteId: string, messageId: string) => Promise<import("./types").APIResponse & {
52
52
  vote: PollVote;
53
53
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stream-chat",
3
- "version": "9.14.0",
3
+ "version": "9.15.0",
4
4
  "description": "JS SDK for the Stream Chat API",
5
5
  "homepage": "https://getstream.io/chat/",
6
6
  "author": {
package/src/middleware.ts CHANGED
@@ -110,6 +110,15 @@ export class MiddlewareExecutor<TValue, THandlers extends string> {
110
110
  .filter(Boolean) as Middleware<TValue, THandlers>[];
111
111
  }
112
112
 
113
+ remove(middlewareIds: string | string[]) {
114
+ if (!middlewareIds && !middlewareIds.length) return;
115
+ this.middleware = this.middleware.filter((md) =>
116
+ typeof middlewareIds === 'string'
117
+ ? middlewareIds !== md.id
118
+ : !middlewareIds.includes(md.id),
119
+ );
120
+ }
121
+
113
122
  protected async executeMiddlewareChain({
114
123
  eventName,
115
124
  initialValue,
package/src/poll.ts CHANGED
@@ -324,20 +324,17 @@ export class Poll {
324
324
  max_votes_allowed && max_votes_allowed === Object.keys(ownVotesByOptionId).length;
325
325
 
326
326
  if (reachedVoteLimit) {
327
- let oldestVote = Object.values(ownVotesByOptionId)[0];
328
- Object.values(ownVotesByOptionId)
329
- .slice(1)
330
- .forEach((vote) => {
331
- if (
332
- !oldestVote?.created_at ||
333
- new Date(vote.created_at) < new Date(oldestVote.created_at)
334
- ) {
335
- oldestVote = vote;
336
- }
337
- });
338
- if (oldestVote?.id) {
339
- await this.removeVote(oldestVote.id, messageId);
340
- }
327
+ this.client.notifications.addInfo({
328
+ message: 'Reached the vote limit. Remove an existing vote first.',
329
+ origin: {
330
+ emitter: 'Poll',
331
+ context: { messageId, optionId },
332
+ },
333
+ options: {
334
+ type: 'validation:poll:castVote:limit',
335
+ },
336
+ });
337
+ return;
341
338
  }
342
339
  return await this.client.castPollVote(messageId, this.id as string, {
343
340
  option_id: optionId,