stream-chat 8.26.0 → 8.27.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stream-chat",
3
- "version": "8.26.0",
3
+ "version": "8.27.0",
4
4
  "description": "JS SDK for the Stream Chat API",
5
5
  "author": "GetStream",
6
6
  "homepage": "https://getstream.io/chat/",
@@ -500,7 +500,7 @@ export class ChannelState<StreamChatGenerics extends ExtendableGenerics = Defaul
500
500
  if (message.poll_id !== pollVote.poll_id) return;
501
501
 
502
502
  const updatedPoll = { ...poll };
503
- let ownVotes = [...(message.poll.own_votes || [])];
503
+ let ownVotes = [...(message.poll?.own_votes || [])];
504
504
 
505
505
  if (pollVote.user_id === this._channel.getClient().userID) {
506
506
  if (pollVote.option_id && poll.enforce_unique_vote) {
@@ -527,7 +527,7 @@ export class ChannelState<StreamChatGenerics extends ExtendableGenerics = Defaul
527
527
  if (message.poll_id !== pollVote.poll_id) return;
528
528
 
529
529
  const updatedPoll = { ...poll };
530
- const ownVotes = [...(message.poll.own_votes || [])];
530
+ const ownVotes = [...(message.poll?.own_votes || [])];
531
531
 
532
532
  if (pollVote.user_id === this._channel.getClient().userID) {
533
533
  ownVotes.push(pollVote);
@@ -550,7 +550,7 @@ export class ChannelState<StreamChatGenerics extends ExtendableGenerics = Defaul
550
550
  if (message.poll_id !== pollVote.poll_id) return;
551
551
 
552
552
  const updatedPoll = { ...poll };
553
- const ownVotes = [...(message.poll.own_votes || [])];
553
+ const ownVotes = [...(message.poll?.own_votes || [])];
554
554
  if (pollVote.user_id === this._channel.getClient().userID) {
555
555
  const index = ownVotes.findIndex((vote) => vote.option_id === pollVote.option_id);
556
556
  if (index > -1) {
package/src/client.ts CHANGED
@@ -193,6 +193,10 @@ import {
193
193
  PollSort,
194
194
  QueryPollsOptions,
195
195
  QueryVotesOptions,
196
+ ReactionFilters,
197
+ ReactionSort,
198
+ QueryReactionsAPIResponse,
199
+ QueryReactionsOptions,
196
200
  } from './types';
197
201
  import { InsightMetrics, postInsights } from './insights';
198
202
  import { Thread } from './thread';
@@ -1590,6 +1594,37 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
1590
1594
  return this.hydrateActiveChannels(data.channels, stateOptions);
1591
1595
  }
1592
1596
 
1597
+ /**
1598
+ * queryReactions - Query reactions
1599
+ *
1600
+ * @param {ReactionFilters<StreamChatGenerics>} filter object MongoDB style filters
1601
+ * @param {ReactionSort<StreamChatGenerics>} [sort] Sort options, for instance {created_at: -1}.
1602
+ * @param {QueryReactionsOptions} [options] Pagination object
1603
+ *
1604
+ * @return {Promise<{ QueryReactionsAPIResponse } search channels response
1605
+ */
1606
+ async queryReactions(
1607
+ messageID: string,
1608
+ filter: ReactionFilters<StreamChatGenerics>,
1609
+ sort: ReactionSort<StreamChatGenerics> = [],
1610
+ options: QueryReactionsOptions = {},
1611
+ ) {
1612
+ // Make sure we wait for the connect promise if there is a pending one
1613
+ await this.wsPromise;
1614
+
1615
+ // Return a list of channels
1616
+ const payload = {
1617
+ filter,
1618
+ sort: normalizeQuerySort(sort),
1619
+ ...options,
1620
+ };
1621
+
1622
+ return await this.post<QueryReactionsAPIResponse<StreamChatGenerics>>(
1623
+ this.baseURL + '/messages/' + messageID + '/reactions',
1624
+ payload,
1625
+ );
1626
+ }
1627
+
1593
1628
  hydrateActiveChannels(
1594
1629
  channelsFromApi: ChannelAPIResponse<StreamChatGenerics>[] = [],
1595
1630
  stateOptions: ChannelStateOptions = {},
package/src/types.ts CHANGED
@@ -293,6 +293,12 @@ export type ChannelResponse<
293
293
  updated_at?: string;
294
294
  };
295
295
 
296
+ export type QueryReactionsOptions = Pager;
297
+
298
+ export type QueryReactionsAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & {
299
+ reactions: ReactionResponse<StreamChatGenerics>[];
300
+ };
301
+
296
302
  export type QueryChannelsAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & {
297
303
  channels: Omit<ChannelAPIResponse<StreamChatGenerics>, keyof APIResponse>[];
298
304
  };
@@ -621,7 +627,6 @@ export type MessageResponse<
621
627
  export type MessageResponseBase<
622
628
  StreamChatGenerics extends ExtendableGenerics = DefaultGenerics
623
629
  > = MessageBase<StreamChatGenerics> & {
624
- poll: PollResponse<StreamChatGenerics>;
625
630
  type: MessageLabel;
626
631
  args?: string;
627
632
  before_message_send_failed?: boolean;
@@ -643,6 +648,7 @@ export type MessageResponseBase<
643
648
  pin_expires?: string | null;
644
649
  pinned_at?: string | null;
645
650
  pinned_by?: UserResponse<StreamChatGenerics> | null;
651
+ poll?: PollResponse<StreamChatGenerics>;
646
652
  reaction_counts?: { [key: string]: number } | null;
647
653
  reaction_scores?: { [key: string]: number } | null;
648
654
  reply_count?: number;
@@ -1354,6 +1360,26 @@ export type BannedUsersFilters = QueryFilters<
1354
1360
  }
1355
1361
  >;
1356
1362
 
1363
+ export type ReactionFilters<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = QueryFilters<
1364
+ {
1365
+ user_id?:
1366
+ | RequireOnlyOne<Pick<QueryFilter<ReactionResponse<StreamChatGenerics>['user_id']>, '$eq' | '$in'>>
1367
+ | PrimitiveFilter<ReactionResponse<StreamChatGenerics>['user_id']>;
1368
+ } & {
1369
+ type?:
1370
+ | RequireOnlyOne<Pick<QueryFilter<ReactionResponse<StreamChatGenerics>['type']>, '$eq'>>
1371
+ | PrimitiveFilter<ReactionResponse<StreamChatGenerics>['type']>;
1372
+ } & {
1373
+ created_at?:
1374
+ | RequireOnlyOne<Pick<QueryFilter<PollResponse['created_at']>, '$eq' | '$gt' | '$lt' | '$gte' | '$lte'>>
1375
+ | PrimitiveFilter<PollResponse['created_at']>;
1376
+ } & {
1377
+ [Key in keyof Omit<ReactionResponse<StreamChatGenerics>, 'user_id' | 'type' | 'created_at'>]: RequireOnlyOne<
1378
+ QueryFilter<ReactionResponse<StreamChatGenerics>[Key]>
1379
+ >;
1380
+ }
1381
+ >;
1382
+
1357
1383
  export type ChannelFilters<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = QueryFilters<
1358
1384
  ContainsOperator<StreamChatGenerics['channelType']> & {
1359
1385
  members?:
@@ -1689,6 +1715,16 @@ export type BannedUsersSort = BannedUsersSortBase | Array<BannedUsersSortBase>;
1689
1715
 
1690
1716
  export type BannedUsersSortBase = { created_at?: AscDesc };
1691
1717
 
1718
+ export type ReactionSort<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> =
1719
+ | ReactionSortBase<StreamChatGenerics>
1720
+ | Array<ReactionSortBase<StreamChatGenerics>>;
1721
+
1722
+ export type ReactionSortBase<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = Sort<
1723
+ StreamChatGenerics['reactionType']
1724
+ > & {
1725
+ created_at?: AscDesc;
1726
+ };
1727
+
1692
1728
  export type ChannelSort<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> =
1693
1729
  | ChannelSortBase<StreamChatGenerics>
1694
1730
  | Array<ChannelSortBase<StreamChatGenerics>>;