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/dist/browser.es.js +1659 -748
- package/dist/browser.es.js.map +1 -1
- package/dist/browser.full-bundle.min.js +1 -1
- package/dist/browser.full-bundle.min.js.map +1 -1
- package/dist/browser.js +1660 -744
- package/dist/browser.js.map +1 -1
- package/dist/index.es.js +1659 -748
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +1660 -744
- package/dist/index.js.map +1 -1
- package/dist/types/channel.d.ts +1 -1
- package/dist/types/channel.d.ts.map +1 -1
- package/dist/types/channel_state.d.ts +1 -5
- package/dist/types/channel_state.d.ts.map +1 -1
- package/dist/types/client.d.ts +27 -15
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/index.d.ts +8 -6
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/poll.d.ts +64 -0
- package/dist/types/poll.d.ts.map +1 -0
- package/dist/types/poll_manager.d.ts +31 -0
- package/dist/types/poll_manager.d.ts.map +1 -0
- package/dist/types/types.d.ts +32 -19
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/channel.ts +2 -25
- package/src/channel_state.ts +0 -92
- package/src/client.ts +112 -70
- package/src/index.ts +8 -6
- package/src/poll.ts +414 -0
- package/src/poll_manager.ts +162 -0
- package/src/types.ts +59 -35
package/src/channel_state.ts
CHANGED
|
@@ -9,8 +9,6 @@ import {
|
|
|
9
9
|
MessageSet,
|
|
10
10
|
MessageSetType,
|
|
11
11
|
PendingMessageResponse,
|
|
12
|
-
PollResponse,
|
|
13
|
-
PollVote,
|
|
14
12
|
ReactionResponse,
|
|
15
13
|
UserResponse,
|
|
16
14
|
} from './types';
|
|
@@ -493,96 +491,6 @@ export class ChannelState<StreamChatGenerics extends ExtendableGenerics = Defaul
|
|
|
493
491
|
return { removed: result.length < msgArray.length, result };
|
|
494
492
|
};
|
|
495
493
|
|
|
496
|
-
// this handles the case when vote on poll is changed
|
|
497
|
-
updatePollVote = (
|
|
498
|
-
pollVote: PollVote<StreamChatGenerics>,
|
|
499
|
-
poll: PollResponse<StreamChatGenerics>,
|
|
500
|
-
messageId: string,
|
|
501
|
-
) => {
|
|
502
|
-
const message = this.findMessage(messageId);
|
|
503
|
-
if (!message) return;
|
|
504
|
-
|
|
505
|
-
if (message.poll_id !== pollVote.poll_id) return;
|
|
506
|
-
|
|
507
|
-
const updatedPoll = { ...poll };
|
|
508
|
-
let ownVotes = [...(message.poll?.own_votes || [])];
|
|
509
|
-
|
|
510
|
-
if (pollVote.user_id === this._channel.getClient().userID) {
|
|
511
|
-
if (pollVote.option_id && poll.enforce_unique_vote) {
|
|
512
|
-
// remove all previous votes where option_id is not empty
|
|
513
|
-
ownVotes = ownVotes.filter((vote) => !vote.option_id);
|
|
514
|
-
} else if (pollVote.answer_text) {
|
|
515
|
-
// remove all previous votes where option_id is empty
|
|
516
|
-
ownVotes = ownVotes.filter((vote) => vote.answer_text);
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
ownVotes.push(pollVote);
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
updatedPoll.own_votes = ownVotes as PollVote<StreamChatGenerics>[];
|
|
523
|
-
const newMessage = { ...message, poll: updatedPoll };
|
|
524
|
-
|
|
525
|
-
this.addMessageSorted((newMessage as unknown) as MessageResponse<StreamChatGenerics>, false, false);
|
|
526
|
-
};
|
|
527
|
-
|
|
528
|
-
addPollVote = (pollVote: PollVote<StreamChatGenerics>, poll: PollResponse<StreamChatGenerics>, messageId: string) => {
|
|
529
|
-
const message = this.findMessage(messageId);
|
|
530
|
-
if (!message) return;
|
|
531
|
-
|
|
532
|
-
if (message.poll_id !== pollVote.poll_id) return;
|
|
533
|
-
|
|
534
|
-
const updatedPoll = { ...poll };
|
|
535
|
-
const ownVotes = [...(message.poll?.own_votes || [])];
|
|
536
|
-
|
|
537
|
-
if (pollVote.user_id === this._channel.getClient().userID) {
|
|
538
|
-
ownVotes.push(pollVote);
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
updatedPoll.own_votes = ownVotes as PollVote<StreamChatGenerics>[];
|
|
542
|
-
const newMessage = { ...message, poll: updatedPoll };
|
|
543
|
-
|
|
544
|
-
this.addMessageSorted((newMessage as unknown) as MessageResponse<StreamChatGenerics>, false, false);
|
|
545
|
-
};
|
|
546
|
-
|
|
547
|
-
removePollVote = (
|
|
548
|
-
pollVote: PollVote<StreamChatGenerics>,
|
|
549
|
-
poll: PollResponse<StreamChatGenerics>,
|
|
550
|
-
messageId: string,
|
|
551
|
-
) => {
|
|
552
|
-
const message = this.findMessage(messageId);
|
|
553
|
-
if (!message) return;
|
|
554
|
-
|
|
555
|
-
if (message.poll_id !== pollVote.poll_id) return;
|
|
556
|
-
|
|
557
|
-
const updatedPoll = { ...poll };
|
|
558
|
-
const ownVotes = [...(message.poll?.own_votes || [])];
|
|
559
|
-
if (pollVote.user_id === this._channel.getClient().userID) {
|
|
560
|
-
const index = ownVotes.findIndex((vote) => vote.option_id === pollVote.option_id);
|
|
561
|
-
if (index > -1) {
|
|
562
|
-
ownVotes.splice(index, 1);
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
updatedPoll.own_votes = ownVotes as PollVote<StreamChatGenerics>[];
|
|
567
|
-
|
|
568
|
-
const newMessage = { ...message, poll: updatedPoll };
|
|
569
|
-
this.addMessageSorted((newMessage as unknown) as MessageResponse<StreamChatGenerics>, false, false);
|
|
570
|
-
};
|
|
571
|
-
|
|
572
|
-
updatePoll = (poll: PollResponse<StreamChatGenerics>, messageId: string) => {
|
|
573
|
-
const message = this.findMessage(messageId);
|
|
574
|
-
if (!message) return;
|
|
575
|
-
|
|
576
|
-
const updatedPoll = {
|
|
577
|
-
...poll,
|
|
578
|
-
own_votes: [...(message.poll?.own_votes || [])],
|
|
579
|
-
};
|
|
580
|
-
|
|
581
|
-
const newMessage = { ...message, poll: updatedPoll };
|
|
582
|
-
|
|
583
|
-
this.addMessageSorted((newMessage as unknown) as MessageResponse<StreamChatGenerics>, false, false);
|
|
584
|
-
};
|
|
585
|
-
|
|
586
494
|
/**
|
|
587
495
|
* Updates the message.user property with updated user object, for messages.
|
|
588
496
|
*
|
package/src/client.ts
CHANGED
|
@@ -42,10 +42,12 @@ import {
|
|
|
42
42
|
BlockList,
|
|
43
43
|
BlockListResponse,
|
|
44
44
|
BlockUserAPIResponse,
|
|
45
|
-
CampaignResponse,
|
|
46
45
|
CampaignData,
|
|
47
46
|
CampaignFilters,
|
|
48
47
|
CampaignQueryOptions,
|
|
48
|
+
CampaignResponse,
|
|
49
|
+
CampaignSort,
|
|
50
|
+
CastVoteAPIResponse,
|
|
49
51
|
ChannelAPIResponse,
|
|
50
52
|
ChannelData,
|
|
51
53
|
ChannelFilters,
|
|
@@ -66,6 +68,9 @@ import {
|
|
|
66
68
|
CreateImportOptions,
|
|
67
69
|
CreateImportResponse,
|
|
68
70
|
CreateImportURLResponse,
|
|
71
|
+
CreatePollAPIResponse,
|
|
72
|
+
CreatePollData,
|
|
73
|
+
CreatePollOptionAPIResponse,
|
|
69
74
|
CustomPermissionOptions,
|
|
70
75
|
DeactivateUsersOptions,
|
|
71
76
|
DefaultGenerics,
|
|
@@ -92,13 +97,18 @@ import {
|
|
|
92
97
|
FlagsPaginationOptions,
|
|
93
98
|
FlagsResponse,
|
|
94
99
|
FlagUserResponse,
|
|
100
|
+
GetBlockedUsersAPIResponse,
|
|
95
101
|
GetCallTokenResponse,
|
|
96
102
|
GetChannelTypeResponse,
|
|
97
103
|
GetCommandResponse,
|
|
98
104
|
GetImportResponse,
|
|
99
105
|
GetMessageAPIResponse,
|
|
106
|
+
GetMessageOptions,
|
|
107
|
+
GetPollAPIResponse,
|
|
108
|
+
GetPollOptionAPIResponse,
|
|
100
109
|
GetRateLimitsResponse,
|
|
101
|
-
|
|
110
|
+
GetThreadAPIResponse,
|
|
111
|
+
GetThreadOptions,
|
|
102
112
|
GetUnreadCountAPIResponse,
|
|
103
113
|
GetUnreadCountBatchAPIResponse,
|
|
104
114
|
ListChannelResponse,
|
|
@@ -120,11 +130,15 @@ import {
|
|
|
120
130
|
OwnUserResponse,
|
|
121
131
|
PartialMessageUpdate,
|
|
122
132
|
PartialPollUpdate,
|
|
133
|
+
PartialThreadUpdate,
|
|
123
134
|
PartialUserUpdate,
|
|
124
135
|
PermissionAPIResponse,
|
|
125
136
|
PermissionsAPIResponse,
|
|
137
|
+
PollAnswersAPIResponse,
|
|
126
138
|
PollData,
|
|
127
139
|
PollOptionData,
|
|
140
|
+
PollSort,
|
|
141
|
+
PollVote,
|
|
128
142
|
PollVoteData,
|
|
129
143
|
PollVotesAPIResponse,
|
|
130
144
|
PushProvider,
|
|
@@ -133,9 +147,24 @@ import {
|
|
|
133
147
|
PushProviderListResponse,
|
|
134
148
|
PushProviderUpsertResponse,
|
|
135
149
|
QueryChannelsAPIResponse,
|
|
136
|
-
|
|
150
|
+
QueryMessageHistoryFilters,
|
|
151
|
+
QueryMessageHistoryOptions,
|
|
152
|
+
QueryMessageHistoryResponse,
|
|
153
|
+
QueryMessageHistorySort,
|
|
154
|
+
QueryPollsFilters,
|
|
155
|
+
QueryPollsOptions,
|
|
137
156
|
QueryPollsResponse,
|
|
157
|
+
QueryReactionsAPIResponse,
|
|
158
|
+
QueryReactionsOptions,
|
|
159
|
+
QuerySegmentsOptions,
|
|
160
|
+
QuerySegmentTargetsFilter,
|
|
161
|
+
QueryThreadsAPIResponse,
|
|
162
|
+
QueryThreadsOptions,
|
|
163
|
+
QueryVotesFilters,
|
|
164
|
+
QueryVotesOptions,
|
|
165
|
+
ReactionFilters,
|
|
138
166
|
ReactionResponse,
|
|
167
|
+
ReactionSort,
|
|
139
168
|
ReactivateUserOptions,
|
|
140
169
|
ReactivateUsersOptions,
|
|
141
170
|
ReservedMessageFields,
|
|
@@ -145,10 +174,12 @@ import {
|
|
|
145
174
|
SearchMessageSortBase,
|
|
146
175
|
SearchOptions,
|
|
147
176
|
SearchPayload,
|
|
148
|
-
SegmentResponse,
|
|
149
177
|
SegmentData,
|
|
178
|
+
SegmentResponse,
|
|
179
|
+
SegmentTargetsResponse,
|
|
150
180
|
SegmentType,
|
|
151
181
|
SendFileAPIResponse,
|
|
182
|
+
SortParam,
|
|
152
183
|
StreamChatOptions,
|
|
153
184
|
SyncOptions,
|
|
154
185
|
SyncResponse,
|
|
@@ -166,50 +197,22 @@ import {
|
|
|
166
197
|
UpdatedMessage,
|
|
167
198
|
UpdateMessageAPIResponse,
|
|
168
199
|
UpdateMessageOptions,
|
|
200
|
+
UpdatePollAPIResponse,
|
|
201
|
+
UpdatePollOptionAPIResponse,
|
|
169
202
|
UpdateSegmentData,
|
|
170
203
|
UserCustomEvent,
|
|
171
204
|
UserFilters,
|
|
172
205
|
UserOptions,
|
|
173
206
|
UserResponse,
|
|
174
207
|
UserSort,
|
|
175
|
-
GetThreadAPIResponse,
|
|
176
|
-
PartialThreadUpdate,
|
|
177
|
-
QueryThreadsOptions,
|
|
178
|
-
GetThreadOptions,
|
|
179
|
-
CampaignSort,
|
|
180
|
-
SegmentTargetsResponse,
|
|
181
|
-
QuerySegmentTargetsFilter,
|
|
182
|
-
SortParam,
|
|
183
|
-
GetMessageOptions,
|
|
184
|
-
GetBlockedUsersAPIResponse,
|
|
185
|
-
QueryVotesFilters,
|
|
186
208
|
VoteSort,
|
|
187
|
-
CreatePollAPIResponse,
|
|
188
|
-
GetPollAPIResponse,
|
|
189
|
-
UpdatePollAPIResponse,
|
|
190
|
-
CreatePollOptionAPIResponse,
|
|
191
|
-
GetPollOptionAPIResponse,
|
|
192
|
-
UpdatePollOptionAPIResponse,
|
|
193
|
-
PollVote,
|
|
194
|
-
CastVoteAPIResponse,
|
|
195
|
-
QueryPollsFilters,
|
|
196
|
-
PollSort,
|
|
197
|
-
QueryPollsOptions,
|
|
198
|
-
QueryVotesOptions,
|
|
199
|
-
ReactionFilters,
|
|
200
|
-
ReactionSort,
|
|
201
|
-
QueryReactionsAPIResponse,
|
|
202
|
-
QueryReactionsOptions,
|
|
203
|
-
QueryMessageHistoryFilters,
|
|
204
|
-
QueryMessageHistorySort,
|
|
205
|
-
QueryMessageHistoryOptions,
|
|
206
|
-
QueryMessageHistoryResponse,
|
|
207
209
|
} from './types';
|
|
208
210
|
import { InsightMetrics, postInsights } from './insights';
|
|
209
211
|
import { Thread } from './thread';
|
|
210
212
|
import { Moderation } from './moderation';
|
|
211
213
|
import { ThreadManager } from './thread_manager';
|
|
212
214
|
import { DEFAULT_QUERY_CHANNELS_MESSAGE_LIST_PAGE_SIZE } from './constants';
|
|
215
|
+
import { PollManager } from './poll_manager';
|
|
213
216
|
|
|
214
217
|
function isString(x: unknown): x is string {
|
|
215
218
|
return typeof x === 'string' || x instanceof String;
|
|
@@ -223,6 +226,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
223
226
|
[key: string]: Channel<StreamChatGenerics>;
|
|
224
227
|
};
|
|
225
228
|
threads: ThreadManager<StreamChatGenerics>;
|
|
229
|
+
polls: PollManager<StreamChatGenerics>;
|
|
226
230
|
anonymous: boolean;
|
|
227
231
|
persistUserOnConnectionFailure?: boolean;
|
|
228
232
|
axiosInstance: AxiosInstance;
|
|
@@ -410,6 +414,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
410
414
|
this.logger = isFunction(inputOptions.logger) ? inputOptions.logger : () => null;
|
|
411
415
|
this.recoverStateOnReconnect = this.options.recoverStateOnReconnect;
|
|
412
416
|
this.threads = new ThreadManager({ client: this });
|
|
417
|
+
this.polls = new PollManager({ client: this });
|
|
413
418
|
}
|
|
414
419
|
|
|
415
420
|
/**
|
|
@@ -1676,6 +1681,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
1676
1681
|
logger: this.logger,
|
|
1677
1682
|
}),
|
|
1678
1683
|
};
|
|
1684
|
+
this.polls.hydratePollCache(updatedMessagesSet.messages, true);
|
|
1679
1685
|
}
|
|
1680
1686
|
|
|
1681
1687
|
channels.push(c);
|
|
@@ -3544,12 +3550,12 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
3544
3550
|
|
|
3545
3551
|
/**
|
|
3546
3552
|
* Creates a poll
|
|
3547
|
-
* @param
|
|
3553
|
+
* @param poll PollData The poll that will be created
|
|
3548
3554
|
* @param userId string The user id (only serverside)
|
|
3549
3555
|
* @returns {APIResponse & CreatePollAPIResponse} The poll
|
|
3550
3556
|
*/
|
|
3551
|
-
async createPoll(poll:
|
|
3552
|
-
return await this.post<APIResponse & CreatePollAPIResponse
|
|
3557
|
+
async createPoll(poll: CreatePollData<StreamChatGenerics>, userId?: string) {
|
|
3558
|
+
return await this.post<APIResponse & CreatePollAPIResponse<StreamChatGenerics>>(this.baseURL + `/polls`, {
|
|
3553
3559
|
...poll,
|
|
3554
3560
|
...(userId ? { user_id: userId } : {}),
|
|
3555
3561
|
});
|
|
@@ -3561,8 +3567,8 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
3561
3567
|
* @param userId string The user id (only serverside)
|
|
3562
3568
|
* @returns {APIResponse & GetPollAPIResponse} The poll
|
|
3563
3569
|
*/
|
|
3564
|
-
async getPoll(id: string, userId?: string): Promise<APIResponse & GetPollAPIResponse
|
|
3565
|
-
return await this.get<APIResponse & GetPollAPIResponse
|
|
3570
|
+
async getPoll(id: string, userId?: string): Promise<APIResponse & GetPollAPIResponse<StreamChatGenerics>> {
|
|
3571
|
+
return await this.get<APIResponse & GetPollAPIResponse<StreamChatGenerics>>(
|
|
3566
3572
|
this.baseURL + `/polls/${encodeURIComponent(id)}`,
|
|
3567
3573
|
userId ? { user_id: userId } : {},
|
|
3568
3574
|
);
|
|
@@ -3574,8 +3580,8 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
3574
3580
|
* @param userId string The user id (only serverside)
|
|
3575
3581
|
* @returns {APIResponse & PollResponse} The poll
|
|
3576
3582
|
*/
|
|
3577
|
-
async updatePoll(poll: PollData
|
|
3578
|
-
return await this.put<APIResponse & UpdatePollAPIResponse
|
|
3583
|
+
async updatePoll(poll: PollData<StreamChatGenerics>, userId?: string) {
|
|
3584
|
+
return await this.put<APIResponse & UpdatePollAPIResponse<StreamChatGenerics>>(this.baseURL + `/polls`, {
|
|
3579
3585
|
...poll,
|
|
3580
3586
|
...(userId ? { user_id: userId } : {}),
|
|
3581
3587
|
});
|
|
@@ -3591,13 +3597,16 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
3591
3597
|
*/
|
|
3592
3598
|
async partialUpdatePoll(
|
|
3593
3599
|
id: string,
|
|
3594
|
-
partialPollObject: PartialPollUpdate
|
|
3600
|
+
partialPollObject: PartialPollUpdate<StreamChatGenerics>,
|
|
3595
3601
|
userId?: string,
|
|
3596
|
-
): Promise<APIResponse & UpdatePollAPIResponse
|
|
3597
|
-
return await this.patch<APIResponse & UpdatePollAPIResponse
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3602
|
+
): Promise<APIResponse & UpdatePollAPIResponse<StreamChatGenerics>> {
|
|
3603
|
+
return await this.patch<APIResponse & UpdatePollAPIResponse<StreamChatGenerics>>(
|
|
3604
|
+
this.baseURL + `/polls/${encodeURIComponent(id)}`,
|
|
3605
|
+
{
|
|
3606
|
+
...partialPollObject,
|
|
3607
|
+
...(userId ? { user_id: userId } : {}),
|
|
3608
|
+
},
|
|
3609
|
+
);
|
|
3601
3610
|
}
|
|
3602
3611
|
|
|
3603
3612
|
/**
|
|
@@ -3618,13 +3627,16 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
3618
3627
|
* @param userId string The user id (only serverside)
|
|
3619
3628
|
* @returns {APIResponse & UpdatePollAPIResponse} The poll
|
|
3620
3629
|
*/
|
|
3621
|
-
async closePoll(id: string, userId?: string): Promise<APIResponse & UpdatePollAPIResponse
|
|
3622
|
-
return this.partialUpdatePoll(
|
|
3623
|
-
|
|
3624
|
-
|
|
3630
|
+
async closePoll(id: string, userId?: string): Promise<APIResponse & UpdatePollAPIResponse<StreamChatGenerics>> {
|
|
3631
|
+
return this.partialUpdatePoll(
|
|
3632
|
+
id,
|
|
3633
|
+
{
|
|
3634
|
+
set: {
|
|
3635
|
+
is_closed: true,
|
|
3636
|
+
} as PartialPollUpdate<StreamChatGenerics>['set'],
|
|
3625
3637
|
},
|
|
3626
|
-
|
|
3627
|
-
|
|
3638
|
+
userId,
|
|
3639
|
+
);
|
|
3628
3640
|
}
|
|
3629
3641
|
|
|
3630
3642
|
/**
|
|
@@ -3634,8 +3646,8 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
3634
3646
|
* @param userId string The user id (only serverside)
|
|
3635
3647
|
* @returns {APIResponse & PollOptionResponse} The poll option
|
|
3636
3648
|
*/
|
|
3637
|
-
async createPollOption(pollId: string, option: PollOptionData
|
|
3638
|
-
return await this.post<APIResponse & CreatePollOptionAPIResponse
|
|
3649
|
+
async createPollOption(pollId: string, option: PollOptionData<StreamChatGenerics>, userId?: string) {
|
|
3650
|
+
return await this.post<APIResponse & CreatePollOptionAPIResponse<StreamChatGenerics>>(
|
|
3639
3651
|
this.baseURL + `/polls/${encodeURIComponent(pollId)}/options`,
|
|
3640
3652
|
{
|
|
3641
3653
|
...option,
|
|
@@ -3652,7 +3664,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
3652
3664
|
* @returns {APIResponse & PollOptionResponse} The poll option
|
|
3653
3665
|
*/
|
|
3654
3666
|
async getPollOption(pollId: string, optionId: string, userId?: string) {
|
|
3655
|
-
return await this.get<APIResponse & GetPollOptionAPIResponse
|
|
3667
|
+
return await this.get<APIResponse & GetPollOptionAPIResponse<StreamChatGenerics>>(
|
|
3656
3668
|
this.baseURL + `/polls/${encodeURIComponent(pollId)}/options/${encodeURIComponent(optionId)}`,
|
|
3657
3669
|
userId ? { user_id: userId } : {},
|
|
3658
3670
|
);
|
|
@@ -3665,8 +3677,8 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
3665
3677
|
* @param userId string The user id (only serverside)
|
|
3666
3678
|
* @returns
|
|
3667
3679
|
*/
|
|
3668
|
-
async updatePollOption(pollId: string, option: PollOptionData
|
|
3669
|
-
return await this.put<APIResponse & UpdatePollOptionAPIResponse
|
|
3680
|
+
async updatePollOption(pollId: string, option: PollOptionData<StreamChatGenerics>, userId?: string) {
|
|
3681
|
+
return await this.put<APIResponse & UpdatePollOptionAPIResponse<StreamChatGenerics>>(
|
|
3670
3682
|
this.baseURL + `/polls/${encodeURIComponent(pollId)}/options`,
|
|
3671
3683
|
{
|
|
3672
3684
|
...option,
|
|
@@ -3698,7 +3710,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
3698
3710
|
* @returns {APIResponse & CastVoteAPIResponse} The poll vote
|
|
3699
3711
|
*/
|
|
3700
3712
|
async castPollVote(messageId: string, pollId: string, vote: PollVoteData, userId?: string) {
|
|
3701
|
-
return await this.post<APIResponse & CastVoteAPIResponse
|
|
3713
|
+
return await this.post<APIResponse & CastVoteAPIResponse<StreamChatGenerics>>(
|
|
3702
3714
|
this.baseURL + `/messages/${encodeURIComponent(messageId)}/polls/${encodeURIComponent(pollId)}/vote`,
|
|
3703
3715
|
{
|
|
3704
3716
|
vote,
|
|
@@ -3750,9 +3762,9 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
3750
3762
|
sort: PollSort = [],
|
|
3751
3763
|
options: QueryPollsOptions = {},
|
|
3752
3764
|
userId?: string,
|
|
3753
|
-
): Promise<APIResponse & QueryPollsResponse
|
|
3765
|
+
): Promise<APIResponse & QueryPollsResponse<StreamChatGenerics>> {
|
|
3754
3766
|
const q = userId ? `?user_id=${userId}` : '';
|
|
3755
|
-
return await this.post<APIResponse & QueryPollsResponse
|
|
3767
|
+
return await this.post<APIResponse & QueryPollsResponse<StreamChatGenerics>>(this.baseURL + `/polls/query${q}`, {
|
|
3756
3768
|
filter,
|
|
3757
3769
|
sort: normalizeQuerySort(sort),
|
|
3758
3770
|
...options,
|
|
@@ -3774,9 +3786,9 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
3774
3786
|
sort: VoteSort = [],
|
|
3775
3787
|
options: QueryVotesOptions = {},
|
|
3776
3788
|
userId?: string,
|
|
3777
|
-
): Promise<APIResponse & PollVotesAPIResponse
|
|
3789
|
+
): Promise<APIResponse & PollVotesAPIResponse<StreamChatGenerics>> {
|
|
3778
3790
|
const q = userId ? `?user_id=${userId}` : '';
|
|
3779
|
-
return await this.post<APIResponse & PollVotesAPIResponse
|
|
3791
|
+
return await this.post<APIResponse & PollVotesAPIResponse<StreamChatGenerics>>(
|
|
3780
3792
|
this.baseURL + `/polls/${encodeURIComponent(pollId)}/votes${q}`,
|
|
3781
3793
|
{
|
|
3782
3794
|
filter,
|
|
@@ -3786,6 +3798,33 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
3786
3798
|
);
|
|
3787
3799
|
}
|
|
3788
3800
|
|
|
3801
|
+
/**
|
|
3802
|
+
* Queries poll answers
|
|
3803
|
+
* @param pollId
|
|
3804
|
+
* @param filter
|
|
3805
|
+
* @param sort
|
|
3806
|
+
* @param options Option object, {limit: 10, offset:0}
|
|
3807
|
+
* @param userId string The user id (only serverside)
|
|
3808
|
+
* @returns {APIResponse & PollAnswersAPIResponse} The poll votes
|
|
3809
|
+
*/
|
|
3810
|
+
async queryPollAnswers(
|
|
3811
|
+
pollId: string,
|
|
3812
|
+
filter: QueryVotesFilters = {},
|
|
3813
|
+
sort: VoteSort = [],
|
|
3814
|
+
options: QueryVotesOptions = {},
|
|
3815
|
+
userId?: string,
|
|
3816
|
+
): Promise<APIResponse & PollAnswersAPIResponse<StreamChatGenerics>> {
|
|
3817
|
+
const q = userId ? `?user_id=${userId}` : '';
|
|
3818
|
+
return await this.post<APIResponse & PollAnswersAPIResponse<StreamChatGenerics>>(
|
|
3819
|
+
this.baseURL + `/polls/${encodeURIComponent(pollId)}/votes${q}`,
|
|
3820
|
+
{
|
|
3821
|
+
filter: { ...filter, is_answer: true },
|
|
3822
|
+
sort: normalizeQuerySort(sort),
|
|
3823
|
+
...options,
|
|
3824
|
+
},
|
|
3825
|
+
);
|
|
3826
|
+
}
|
|
3827
|
+
|
|
3789
3828
|
/**
|
|
3790
3829
|
* Query message history
|
|
3791
3830
|
* @param filter
|
|
@@ -3797,12 +3836,15 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
|
|
|
3797
3836
|
filter: QueryMessageHistoryFilters = {},
|
|
3798
3837
|
sort: QueryMessageHistorySort = [],
|
|
3799
3838
|
options: QueryMessageHistoryOptions = {},
|
|
3800
|
-
): Promise<APIResponse & QueryMessageHistoryResponse
|
|
3801
|
-
return await this.post<APIResponse & QueryMessageHistoryResponse
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3839
|
+
): Promise<APIResponse & QueryMessageHistoryResponse<StreamChatGenerics>> {
|
|
3840
|
+
return await this.post<APIResponse & QueryMessageHistoryResponse<StreamChatGenerics>>(
|
|
3841
|
+
this.baseURL + '/messages/history',
|
|
3842
|
+
{
|
|
3843
|
+
filter,
|
|
3844
|
+
sort: normalizeQuerySort(sort),
|
|
3845
|
+
...options,
|
|
3846
|
+
},
|
|
3847
|
+
);
|
|
3806
3848
|
}
|
|
3807
3849
|
|
|
3808
3850
|
/**
|
package/src/index.ts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
export * from './base64';
|
|
2
|
+
export * from './campaign';
|
|
2
3
|
export * from './client';
|
|
3
4
|
export * from './client_state';
|
|
4
5
|
export * from './channel';
|
|
5
6
|
export * from './channel_state';
|
|
6
|
-
export * from './thread';
|
|
7
|
-
export * from './thread_manager';
|
|
8
7
|
export * from './connection';
|
|
9
8
|
export * from './events';
|
|
9
|
+
export * from './insights';
|
|
10
10
|
export * from './moderation';
|
|
11
11
|
export * from './permissions';
|
|
12
|
+
export * from './poll';
|
|
13
|
+
export * from './poll_manager';
|
|
14
|
+
export * from './segment';
|
|
12
15
|
export * from './signing';
|
|
16
|
+
export * from './store';
|
|
17
|
+
export * from './thread';
|
|
18
|
+
export * from './thread_manager';
|
|
13
19
|
export * from './token_manager';
|
|
14
|
-
export * from './insights';
|
|
15
20
|
export * from './types';
|
|
16
|
-
export * from './segment';
|
|
17
|
-
export * from './campaign';
|
|
18
21
|
export { isOwnUser, chatCodes, logChatPromiseExecution, formatMessage } from './utils';
|
|
19
|
-
export * from './store';
|