stream-chat 9.54.0 → 9.54.2
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/README.md +1 -1
- package/dist/cjs/index.browser.js +87 -19
- package/dist/cjs/index.browser.js.map +2 -2
- package/dist/cjs/index.node.js +87 -19
- package/dist/cjs/index.node.js.map +2 -2
- package/dist/esm/index.mjs +87 -19
- package/dist/esm/index.mjs.map +2 -2
- package/dist/types/channel.d.ts +1 -1
- package/dist/types/channel_state.d.ts +6 -0
- package/dist/types/client.d.ts +4 -68
- package/dist/types/connection.d.ts +12 -0
- package/dist/types/types.d.ts +26 -6
- package/dist/types/utils.d.ts +1 -0
- package/package.json +6 -1
- package/src/channel.ts +6 -0
- package/src/channel_state.ts +29 -0
- package/src/client.ts +4 -4
- package/src/connection.ts +47 -2
- package/src/messageComposer/middleware/messageComposer/attachments.ts +19 -8
- package/src/poll.ts +9 -1
- package/src/poll_optimistic_votes.ts +6 -1
- package/src/thread.ts +11 -4
- package/src/types.ts +27 -6
- package/src/utils.ts +20 -0
package/dist/types/channel.d.ts
CHANGED
|
@@ -761,7 +761,7 @@ export declare class Channel {
|
|
|
761
761
|
*/
|
|
762
762
|
_channelURL: () => string;
|
|
763
763
|
_checkInitialized(): void;
|
|
764
|
-
_initializeState(state: ChannelAPIResponse, messageSetToAddToIfDoesNotExist?: MessageSetType): {
|
|
764
|
+
_initializeState(state: ChannelAPIResponse, messageSetToAddToIfDoesNotExist?: MessageSetType, isNewestPage?: boolean): {
|
|
765
765
|
messageSet: import("./types").MessageSet;
|
|
766
766
|
filteredMessageIds: string[];
|
|
767
767
|
};
|
|
@@ -214,6 +214,12 @@ export declare class ChannelState {
|
|
|
214
214
|
findMessage(messageId: string, parentMessageId?: string): LocalMessage | undefined;
|
|
215
215
|
findMessageByTimestamp(timestampMs: number, parentMessageId?: string, exactTsMatch?: boolean): LocalMessage | null;
|
|
216
216
|
private switchToMessageSet;
|
|
217
|
+
/**
|
|
218
|
+
* Empties the latest message set if the newest page is newer than it and shares no messages
|
|
219
|
+
* with it. Merging them would hide the messages in between from pagination.
|
|
220
|
+
* Skipped while the set holds local-only messages, so they are not lost.
|
|
221
|
+
*/
|
|
222
|
+
_dropLatestMessagesDisjointFrom(newestPage: (MessageResponse | LocalMessage)[]): void;
|
|
217
223
|
private areMessageSetsOverlap;
|
|
218
224
|
private findMessageSetIndex;
|
|
219
225
|
/**
|
package/dist/types/client.d.ts
CHANGED
|
@@ -988,6 +988,7 @@ export declare class StreamChat {
|
|
|
988
988
|
* @returns {Promise<APIResponse>}
|
|
989
989
|
*/
|
|
990
990
|
flagMessage(targetMessageID: string, options?: {
|
|
991
|
+
custom?: Record<string, unknown>;
|
|
991
992
|
reason?: string;
|
|
992
993
|
user_id?: string;
|
|
993
994
|
}): Promise<FlagMessageResponse>;
|
|
@@ -1120,75 +1121,10 @@ export declare class StreamChat {
|
|
|
1120
1121
|
* @param {string} messageId
|
|
1121
1122
|
* @param {string} language
|
|
1122
1123
|
*
|
|
1123
|
-
* @return {MessageResponse} Response that includes the message
|
|
1124
|
+
* @return {APIResponse & { message: MessageResponse }} Response that includes the translated message
|
|
1124
1125
|
*/
|
|
1125
|
-
translateMessage(messageId: string, language: string): Promise<APIResponse &
|
|
1126
|
-
|
|
1127
|
-
attachments?: import("./types").Attachment[];
|
|
1128
|
-
html?: string;
|
|
1129
|
-
mml?: string;
|
|
1130
|
-
parent_id?: string;
|
|
1131
|
-
pin_expires?: string | null;
|
|
1132
|
-
pinned?: boolean;
|
|
1133
|
-
pinned_at?: string | null;
|
|
1134
|
-
poll_id?: string;
|
|
1135
|
-
quoted_message_id?: string;
|
|
1136
|
-
restricted_visibility?: string[];
|
|
1137
|
-
show_in_channel?: boolean;
|
|
1138
|
-
silent?: boolean;
|
|
1139
|
-
text?: string;
|
|
1140
|
-
type?: import("./types").MessageLabel;
|
|
1141
|
-
user?: UserResponse | null;
|
|
1142
|
-
user_id?: string;
|
|
1143
|
-
} & {
|
|
1144
|
-
type: import("./types").MessageLabel;
|
|
1145
|
-
args?: string;
|
|
1146
|
-
before_message_send_failed?: boolean;
|
|
1147
|
-
channel?: ChannelResponse;
|
|
1148
|
-
cid?: string;
|
|
1149
|
-
command?: string;
|
|
1150
|
-
command_info?: {
|
|
1151
|
-
name?: string;
|
|
1152
|
-
};
|
|
1153
|
-
created_at?: string;
|
|
1154
|
-
deleted_at?: string;
|
|
1155
|
-
deleted_reply_count?: number;
|
|
1156
|
-
i18n?: import("./types").TranslatedField;
|
|
1157
|
-
latest_reactions?: ReactionResponse[];
|
|
1158
|
-
member?: import("./types").ChannelMemberResponse;
|
|
1159
|
-
mentioned_users?: UserResponse[];
|
|
1160
|
-
mentioned_channel?: boolean;
|
|
1161
|
-
mentioned_here?: boolean;
|
|
1162
|
-
mentioned_group_ids?: string[];
|
|
1163
|
-
mentioned_groups?: import("./types").UserGroupResponse[];
|
|
1164
|
-
mentioned_roles?: string[];
|
|
1165
|
-
message_text_updated_at?: string;
|
|
1166
|
-
moderation?: import("./types").ModerationResponse;
|
|
1167
|
-
moderation_details?: import("./types").ModerationDetailsResponse;
|
|
1168
|
-
own_reactions?: ReactionResponse[] | null;
|
|
1169
|
-
pin_expires?: string | null;
|
|
1170
|
-
pinned_at?: string | null;
|
|
1171
|
-
pinned_by?: UserResponse | null;
|
|
1172
|
-
poll?: import("./types").PollResponse;
|
|
1173
|
-
reaction_counts?: {
|
|
1174
|
-
[key: string]: number;
|
|
1175
|
-
} | null;
|
|
1176
|
-
reaction_groups?: {
|
|
1177
|
-
[key: string]: import("./types").ReactionGroupResponse;
|
|
1178
|
-
} | null;
|
|
1179
|
-
reaction_scores?: {
|
|
1180
|
-
[key: string]: number;
|
|
1181
|
-
} | null;
|
|
1182
|
-
reminder?: import("./types").ReminderResponseBase;
|
|
1183
|
-
reply_count?: number;
|
|
1184
|
-
shadowed?: boolean;
|
|
1185
|
-
shared_location?: SharedLocationResponse;
|
|
1186
|
-
status?: string;
|
|
1187
|
-
thread_participants?: UserResponse[];
|
|
1188
|
-
updated_at?: string;
|
|
1189
|
-
deleted_for_me?: boolean;
|
|
1190
|
-
} & {
|
|
1191
|
-
quoted_message?: import("./types").MessageResponseBase;
|
|
1126
|
+
translateMessage(messageId: string, language: string): Promise<APIResponse & {
|
|
1127
|
+
message: MessageResponse;
|
|
1192
1128
|
}>;
|
|
1193
1129
|
/**
|
|
1194
1130
|
* translate - translates the given text to provided language
|
|
@@ -38,6 +38,12 @@ export declare class StableWSConnection {
|
|
|
38
38
|
StatusCode?: string | number;
|
|
39
39
|
}) => void;
|
|
40
40
|
requestID: string | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Set when the server sent a `connection.error` with code 40 (token expired) on an
|
|
43
|
+
* already established socket. The server closes the socket right after it, and the
|
|
44
|
+
* reconnect that follows must use a fresh token from the tokenProvider.
|
|
45
|
+
*/
|
|
46
|
+
tokenExpiredByServer: boolean;
|
|
41
47
|
resolvePromise?: (value: ConnectionOpen) => void;
|
|
42
48
|
totalFailures: number;
|
|
43
49
|
ws?: WebSocket;
|
|
@@ -99,6 +105,12 @@ export declare class StableWSConnection {
|
|
|
99
105
|
onmessage: (wsID: number, event: WebSocket.MessageEvent) => void;
|
|
100
106
|
onclose: (wsID: number, event: WebSocket.CloseEvent) => void;
|
|
101
107
|
onerror: (wsID: number, event: WebSocket.ErrorEvent) => void;
|
|
108
|
+
/**
|
|
109
|
+
* _reconnectAfterFailure - Reconnects after the socket closed or failed. If the server
|
|
110
|
+
* reported that the token expired, the token is refreshed before reconnecting.
|
|
111
|
+
* Static tokens cannot be refreshed and reconnect as before.
|
|
112
|
+
*/
|
|
113
|
+
_reconnectAfterFailure(): void;
|
|
102
114
|
/**
|
|
103
115
|
* _setHealth - Sets the connection to healthy or unhealthy.
|
|
104
116
|
* Broadcasts an event in case the connection status changed.
|
package/dist/types/types.d.ts
CHANGED
|
@@ -437,8 +437,10 @@ export type FlagMessageResponse = APIResponse & {
|
|
|
437
437
|
user: UserResponse;
|
|
438
438
|
approved_at?: string;
|
|
439
439
|
channel_cid?: string;
|
|
440
|
+
custom?: Record<string, unknown>;
|
|
440
441
|
details?: object;
|
|
441
442
|
message_user_id?: string;
|
|
443
|
+
reason?: string;
|
|
442
444
|
rejected_at?: string;
|
|
443
445
|
reviewed_at?: string;
|
|
444
446
|
reviewed_by?: string;
|
|
@@ -623,6 +625,7 @@ export type PushPreferencesResponse = {
|
|
|
623
625
|
/** Per-channel push preferences returned by the API (matches OpenAPI `ChannelPushPreferencesResponse`). */
|
|
624
626
|
export type ChannelPushPreference = {
|
|
625
627
|
chat_level?: ChatLevelPushPreference;
|
|
628
|
+
chat_preferences?: ChatPreferences;
|
|
626
629
|
disabled_until?: string;
|
|
627
630
|
};
|
|
628
631
|
export type UpsertPushPreferencesResponse = APIResponse & {
|
|
@@ -894,6 +897,7 @@ export type UserResponse = CustomUserData & {
|
|
|
894
897
|
deactivated_at?: string;
|
|
895
898
|
deleted_at?: string;
|
|
896
899
|
image?: string;
|
|
900
|
+
invisible?: boolean;
|
|
897
901
|
language?: TranslationLanguages | '';
|
|
898
902
|
last_active?: string;
|
|
899
903
|
name?: string;
|
|
@@ -1259,7 +1263,7 @@ export type UpdateChannelOptions = Partial<{
|
|
|
1259
1263
|
data: Omit<ChannelResponse, 'id' | 'cid'>;
|
|
1260
1264
|
demote_moderators: string[];
|
|
1261
1265
|
invites: string[];
|
|
1262
|
-
message:
|
|
1266
|
+
message: Message;
|
|
1263
1267
|
reject_invite: boolean;
|
|
1264
1268
|
remove_members: string[];
|
|
1265
1269
|
user: UserResponse;
|
|
@@ -1636,6 +1640,9 @@ export type ChannelFilters = QueryFilters<ContainsOperator<Omit<CustomChannelDat
|
|
|
1636
1640
|
app_banned?: 'only' | 'excluded';
|
|
1637
1641
|
has_unread?: boolean;
|
|
1638
1642
|
archived?: boolean;
|
|
1643
|
+
invite?: {
|
|
1644
|
+
$eq?: Exclude<InviteStatus, 'member'>;
|
|
1645
|
+
} | Exclude<InviteStatus, 'member'>;
|
|
1639
1646
|
'member.user.name'?: RequireOnlyOne<{
|
|
1640
1647
|
$autocomplete?: string;
|
|
1641
1648
|
$eq?: string;
|
|
@@ -1646,8 +1653,13 @@ export type ChannelFilters = QueryFilters<ContainsOperator<Omit<CustomChannelDat
|
|
|
1646
1653
|
} & QueryFilter<string>> | PrimitiveFilter<string>;
|
|
1647
1654
|
pinned?: boolean;
|
|
1648
1655
|
last_updated?: RequireOnlyOne<Pick<QueryFilter<string>, '$eq' | '$gt' | '$gte' | '$lt' | '$lte'>> | PrimitiveFilter<string>;
|
|
1656
|
+
/**
|
|
1657
|
+
* With multi-tenancy, client-side queries without a `team` filter only return channels of
|
|
1658
|
+
* the user's teams; an empty filter (`team: {}`) queries across all teams.
|
|
1659
|
+
*/
|
|
1660
|
+
team?: RequireOnlyOne<QueryFilter<ChannelResponse['team']>> | PrimitiveFilter<ChannelResponse['team']> | Record<string, never>;
|
|
1649
1661
|
} & {
|
|
1650
|
-
[Key in keyof Omit<ChannelResponse, 'name' | 'members' | keyof CustomChannelData>]: RequireOnlyOne<QueryFilter<ChannelResponse[Key]>> | PrimitiveFilter<ChannelResponse[Key]>;
|
|
1662
|
+
[Key in keyof Omit<ChannelResponse, 'name' | 'members' | 'team' | keyof CustomChannelData>]: RequireOnlyOne<QueryFilter<ChannelResponse[Key]>> | PrimitiveFilter<ChannelResponse[Key]>;
|
|
1651
1663
|
}>;
|
|
1652
1664
|
export type DraftFilters = {
|
|
1653
1665
|
channel_cid?: RequireOnlyOne<Pick<QueryFilter<DraftResponse['channel_cid']>, '$in' | '$eq'>> | PrimitiveFilter<DraftResponse['channel_cid']>;
|
|
@@ -2319,9 +2331,13 @@ export type Mute = {
|
|
|
2319
2331
|
export type PartialUpdateChannelFields = Partial<ChannelResponse> & {
|
|
2320
2332
|
config_overrides?: Partial<ChannelConfigFields>;
|
|
2321
2333
|
};
|
|
2334
|
+
/** Dot-notation path to a nested custom field, e.g. `channel_detail.topic`. */
|
|
2335
|
+
type NestedFieldPath = `${string}.${string}`;
|
|
2322
2336
|
export type PartialUpdateChannel = {
|
|
2323
|
-
set?: PartialUpdateChannelFields
|
|
2324
|
-
|
|
2337
|
+
set?: PartialUpdateChannelFields & {
|
|
2338
|
+
[path: NestedFieldPath]: unknown;
|
|
2339
|
+
};
|
|
2340
|
+
unset?: Array<keyof PartialUpdateChannelFields | NestedFieldPath>;
|
|
2325
2341
|
};
|
|
2326
2342
|
export type PartialUpdateMember = {
|
|
2327
2343
|
set?: ChannelMemberUpdates;
|
|
@@ -2334,8 +2350,10 @@ export type PartialUserUpdate = {
|
|
|
2334
2350
|
};
|
|
2335
2351
|
export type MessageUpdatableFields = Omit<MessageResponse, 'cid' | 'created_at' | 'updated_at' | 'deleted_at' | 'user' | 'user_id'>;
|
|
2336
2352
|
export type PartialMessageUpdate = {
|
|
2337
|
-
set?: Partial<MessageUpdatableFields
|
|
2338
|
-
|
|
2353
|
+
set?: Partial<MessageUpdatableFields> & {
|
|
2354
|
+
[path: NestedFieldPath]: unknown;
|
|
2355
|
+
};
|
|
2356
|
+
unset?: Array<keyof MessageUpdatableFields | NestedFieldPath>;
|
|
2339
2357
|
};
|
|
2340
2358
|
export type PendingMessageResponse = {
|
|
2341
2359
|
message: MessageResponse;
|
|
@@ -2584,6 +2602,7 @@ export type TaskStatus = {
|
|
|
2584
2602
|
};
|
|
2585
2603
|
export type TruncateOptions = {
|
|
2586
2604
|
hard_delete?: boolean;
|
|
2605
|
+
member_ids?: string[];
|
|
2587
2606
|
message?: Message;
|
|
2588
2607
|
skip_push?: boolean;
|
|
2589
2608
|
truncated_at?: Date;
|
|
@@ -2868,6 +2887,7 @@ export type ReviewQueueItem = {
|
|
|
2868
2887
|
id: string;
|
|
2869
2888
|
moderation_payload: ModerationPayload;
|
|
2870
2889
|
moderation_payload_hash: string;
|
|
2890
|
+
message?: MessageResponse;
|
|
2871
2891
|
options: any;
|
|
2872
2892
|
recommended_action: string;
|
|
2873
2893
|
results: any;
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -268,6 +268,7 @@ type MessagePaginationUpdatedParams = {
|
|
|
268
268
|
export declare function binarySearchByDateEqualOrNearestGreater(array: {
|
|
269
269
|
created_at?: string;
|
|
270
270
|
}[], targetDate: Date): number;
|
|
271
|
+
export declare const hasMessagePaginationCursor: (options?: MessagePaginationOptions) => boolean;
|
|
271
272
|
export declare const messageSetPagination: (params: MessagePaginationUpdatedParams) => {
|
|
272
273
|
hasNext: boolean;
|
|
273
274
|
hasPrev: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stream-chat",
|
|
3
|
-
"version": "9.54.
|
|
3
|
+
"version": "9.54.2",
|
|
4
4
|
"description": "JS SDK for the Stream Chat API",
|
|
5
5
|
"homepage": "https://getstream.io/chat/",
|
|
6
6
|
"author": {
|
|
@@ -66,6 +66,7 @@
|
|
|
66
66
|
"@eslint/js": "^9.39.4",
|
|
67
67
|
"@semantic-release/changelog": "^6.0.3",
|
|
68
68
|
"@semantic-release/git": "^10.0.1",
|
|
69
|
+
"@stream-io/node-sdk": "^0.8.10",
|
|
69
70
|
"@types/node": "^22.19.19",
|
|
70
71
|
"@types/sinon": "^10.0.6",
|
|
71
72
|
"@vitest/coverage-v8": "^4.1.10",
|
|
@@ -101,6 +102,10 @@
|
|
|
101
102
|
"run-types-gen": "tsc -p test/typescript/tsconfig.json",
|
|
102
103
|
"test-unit": "vitest",
|
|
103
104
|
"test-coverage": "vitest run --coverage",
|
|
105
|
+
"test-docs": "vitest run --config test/docs-snippets/vitest.config.mts",
|
|
106
|
+
"test-docs-sweep": "vitest run --config test/docs-snippets/vitest.sweep.config.mts",
|
|
107
|
+
"test-docs-sync": "vitest run --config test/docs-snippets/vitest.sync.config.mts",
|
|
108
|
+
"types-docs": "tsc -p test/docs-snippets/tsconfig.json",
|
|
104
109
|
"fix-staged": "lint-staged --config .lintstagedrc.fix.json --concurrent 1",
|
|
105
110
|
"semantic-release": "semantic-release",
|
|
106
111
|
"postinstall": "node -e \"require('fs').existsSync('scripts/install-husky.mjs') && import('./scripts/install-husky.mjs')\"",
|
package/src/channel.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { MessageReceiptsTracker } from './messageDelivery';
|
|
|
6
6
|
import {
|
|
7
7
|
channelHasReadEvents,
|
|
8
8
|
generateChannelTempCid,
|
|
9
|
+
hasMessagePaginationCursor,
|
|
9
10
|
invokeEventListener,
|
|
10
11
|
logChatPromiseExecution,
|
|
11
12
|
messageSetPagination,
|
|
@@ -1639,6 +1640,7 @@ export class Channel {
|
|
|
1639
1640
|
const { messageSet, filteredMessageIds } = this._initializeState(
|
|
1640
1641
|
state,
|
|
1641
1642
|
messageSetToAddToIfDoesNotExist,
|
|
1643
|
+
!hasMessagePaginationCursor(options?.messages),
|
|
1642
1644
|
);
|
|
1643
1645
|
messageSet.pagination = {
|
|
1644
1646
|
...messageSet.pagination,
|
|
@@ -2410,6 +2412,7 @@ export class Channel {
|
|
|
2410
2412
|
_initializeState(
|
|
2411
2413
|
state: ChannelAPIResponse,
|
|
2412
2414
|
messageSetToAddToIfDoesNotExist: MessageSetType = 'latest',
|
|
2415
|
+
isNewestPage = true,
|
|
2413
2416
|
) {
|
|
2414
2417
|
const { state: clientState, user, userID } = this.getClient();
|
|
2415
2418
|
|
|
@@ -2430,6 +2433,9 @@ export class Channel {
|
|
|
2430
2433
|
if (!this.state.messages) {
|
|
2431
2434
|
this.state.initMessages();
|
|
2432
2435
|
}
|
|
2436
|
+
if (messageSetToAddToIfDoesNotExist === 'latest' && isNewestPage) {
|
|
2437
|
+
this.state._dropLatestMessagesDisjointFrom(messages);
|
|
2438
|
+
}
|
|
2433
2439
|
const { messageSet, filteredMessageIds } = this.state.addMessagesSorted(
|
|
2434
2440
|
messages,
|
|
2435
2441
|
false,
|
package/src/channel_state.ts
CHANGED
|
@@ -64,6 +64,12 @@ const messageSetsOverlapByTimestamp = (a: LocalMessage[], b: LocalMessage[]) =>
|
|
|
64
64
|
aOverlapsB(a, b) ||
|
|
65
65
|
aOverlapsB(b, a);
|
|
66
66
|
|
|
67
|
+
const isLocalOnlyMessage = (message: LocalMessage) =>
|
|
68
|
+
message.status === 'sending' ||
|
|
69
|
+
message.status === 'failed' ||
|
|
70
|
+
message.type === 'error' ||
|
|
71
|
+
message.type === 'ephemeral';
|
|
72
|
+
|
|
67
73
|
/**
|
|
68
74
|
* ChannelState - A container class for the channel state.
|
|
69
75
|
*/
|
|
@@ -972,6 +978,29 @@ export class ChannelState {
|
|
|
972
978
|
this.messageSets[index].isCurrent = true;
|
|
973
979
|
}
|
|
974
980
|
|
|
981
|
+
/**
|
|
982
|
+
* Empties the latest message set if the newest page is newer than it and shares no messages
|
|
983
|
+
* with it. Merging them would hide the messages in between from pagination.
|
|
984
|
+
* Skipped while the set holds local-only messages, so they are not lost.
|
|
985
|
+
*/
|
|
986
|
+
_dropLatestMessagesDisjointFrom(newestPage: (MessageResponse | LocalMessage)[]) {
|
|
987
|
+
const latestSet = this.messageSets.find((s) => s.isLatest);
|
|
988
|
+
const newestLoaded = latestSet?.messages.slice(-1)[0];
|
|
989
|
+
const oldestReturned = newestPage.find((m) => !m.parent_id || m.show_in_channel);
|
|
990
|
+
if (!latestSet || !newestLoaded || !oldestReturned?.created_at) return;
|
|
991
|
+
if (
|
|
992
|
+
new Date(oldestReturned.created_at).getTime() <=
|
|
993
|
+
newestLoaded.created_at.getTime() ||
|
|
994
|
+
this.areMessageSetsOverlap(latestSet.messages, newestPage) ||
|
|
995
|
+
latestSet.messages.some(isLocalOnlyMessage)
|
|
996
|
+
) {
|
|
997
|
+
return;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
latestSet.messages = [];
|
|
1001
|
+
latestSet.pagination = { ...DEFAULT_MESSAGE_SET_PAGINATION };
|
|
1002
|
+
}
|
|
1003
|
+
|
|
975
1004
|
private areMessageSetsOverlap(
|
|
976
1005
|
messages1: Array<{ id: string }>,
|
|
977
1006
|
messages2: Array<{ id: string }>,
|
package/src/client.ts
CHANGED
|
@@ -2384,7 +2384,7 @@ export class StreamChat {
|
|
|
2384
2384
|
...messageSetPagination({
|
|
2385
2385
|
parentSet: updatedMessagesSet,
|
|
2386
2386
|
requestedPageSize:
|
|
2387
|
-
queryChannelsOptions?.message_limit
|
|
2387
|
+
queryChannelsOptions?.message_limit ??
|
|
2388
2388
|
DEFAULT_QUERY_CHANNELS_MESSAGE_LIST_PAGE_SIZE,
|
|
2389
2389
|
returnedPage: channelState.messages,
|
|
2390
2390
|
filteredReturnedPage: channelState.messages.filter(
|
|
@@ -3096,7 +3096,7 @@ export class StreamChat {
|
|
|
3096
3096
|
*/
|
|
3097
3097
|
async flagMessage(
|
|
3098
3098
|
targetMessageID: string,
|
|
3099
|
-
options: { reason?: string; user_id?: string } = {},
|
|
3099
|
+
options: { custom?: Record<string, unknown>; reason?: string; user_id?: string } = {},
|
|
3100
3100
|
) {
|
|
3101
3101
|
return await this.post<FlagMessageResponse>(this.baseURL + '/moderation/flag', {
|
|
3102
3102
|
target_message_id: targetMessageID,
|
|
@@ -3330,10 +3330,10 @@ export class StreamChat {
|
|
|
3330
3330
|
* @param {string} messageId
|
|
3331
3331
|
* @param {string} language
|
|
3332
3332
|
*
|
|
3333
|
-
* @return {MessageResponse} Response that includes the message
|
|
3333
|
+
* @return {APIResponse & { message: MessageResponse }} Response that includes the translated message
|
|
3334
3334
|
*/
|
|
3335
3335
|
async translateMessage(messageId: string, language: string) {
|
|
3336
|
-
return await this.post<APIResponse & MessageResponse>(
|
|
3336
|
+
return await this.post<APIResponse & { message: MessageResponse }>(
|
|
3337
3337
|
this.baseURL + `/messages/${encodeURIComponent(messageId)}/translate`,
|
|
3338
3338
|
{ language },
|
|
3339
3339
|
);
|
package/src/connection.ts
CHANGED
|
@@ -68,6 +68,12 @@ export class StableWSConnection {
|
|
|
68
68
|
},
|
|
69
69
|
) => void;
|
|
70
70
|
requestID: string | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Set when the server sent a `connection.error` with code 40 (token expired) on an
|
|
73
|
+
* already established socket. The server closes the socket right after it, and the
|
|
74
|
+
* reconnect that follows must use a fresh token from the tokenProvider.
|
|
75
|
+
*/
|
|
76
|
+
tokenExpiredByServer: boolean;
|
|
71
77
|
resolvePromise?: (value: ConnectionOpen) => void;
|
|
72
78
|
totalFailures: number;
|
|
73
79
|
ws?: WebSocket;
|
|
@@ -92,6 +98,8 @@ export class StableWSConnection {
|
|
|
92
98
|
this.wsID = 1;
|
|
93
99
|
/** Store the last event time for health checks */
|
|
94
100
|
this.lastEvent = null;
|
|
101
|
+
/** Set when the server reports that the token of the open socket expired */
|
|
102
|
+
this.tokenExpiredByServer = false;
|
|
95
103
|
/** Send a health check message every 25 seconds */
|
|
96
104
|
this.pingInterval = 25 * 1000;
|
|
97
105
|
this.connectionCheckTimeout = this.pingInterval + 10 * 1000;
|
|
@@ -229,6 +237,7 @@ export class StableWSConnection {
|
|
|
229
237
|
this.wsID += 1;
|
|
230
238
|
this.isConnecting = false;
|
|
231
239
|
this.isDisconnected = true;
|
|
240
|
+
this.tokenExpiredByServer = false;
|
|
232
241
|
|
|
233
242
|
// start by removing all the listeners
|
|
234
243
|
if (this.healthCheckTimeoutRef) {
|
|
@@ -408,6 +417,13 @@ export class StableWSConnection {
|
|
|
408
417
|
|
|
409
418
|
if (options.refreshToken) {
|
|
410
419
|
await this.client.tokenManager.loadToken();
|
|
420
|
+
|
|
421
|
+
// Another reconnect may have started while the token was loading, e.g. when
|
|
422
|
+
// the socket fires both an error and a close event.
|
|
423
|
+
if (this.isConnecting || this.isHealthy) {
|
|
424
|
+
this._log('_reconnect() - Abort (4) since already connecting or healthy');
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
411
427
|
}
|
|
412
428
|
|
|
413
429
|
try {
|
|
@@ -501,6 +517,17 @@ export class StableWSConnection {
|
|
|
501
517
|
this.scheduleNextPing();
|
|
502
518
|
}
|
|
503
519
|
|
|
520
|
+
// The server reports a token that expired after the connection was established
|
|
521
|
+
// (auto_disconnect_ws) and then closes the socket. Remember it so the reconnect
|
|
522
|
+
// refreshes the token first instead of retrying once with the expired token.
|
|
523
|
+
if (
|
|
524
|
+
data?.type === 'connection.error' &&
|
|
525
|
+
data?.error?.code === chatCodes.TOKEN_EXPIRED
|
|
526
|
+
) {
|
|
527
|
+
this._log('onmessage() - server reported that the token expired', { wsID });
|
|
528
|
+
this.tokenExpiredByServer = true;
|
|
529
|
+
}
|
|
530
|
+
|
|
504
531
|
this.client.dispatchEvent(data);
|
|
505
532
|
this.scheduleConnectionCheck();
|
|
506
533
|
};
|
|
@@ -535,7 +562,7 @@ export class StableWSConnection {
|
|
|
535
562
|
this._log(`onclose() - WS connection closed. Calling reconnect ...`, { event });
|
|
536
563
|
|
|
537
564
|
// reconnect if its an abnormal failure
|
|
538
|
-
this.
|
|
565
|
+
this._reconnectAfterFailure();
|
|
539
566
|
}
|
|
540
567
|
};
|
|
541
568
|
|
|
@@ -550,9 +577,26 @@ export class StableWSConnection {
|
|
|
550
577
|
this.rejectPromise?.(this._errorFromWSEvent(event));
|
|
551
578
|
this._log(`onerror() - WS connection resulted into error`, { event });
|
|
552
579
|
|
|
553
|
-
this.
|
|
580
|
+
this._reconnectAfterFailure();
|
|
554
581
|
};
|
|
555
582
|
|
|
583
|
+
/**
|
|
584
|
+
* _reconnectAfterFailure - Reconnects after the socket closed or failed. If the server
|
|
585
|
+
* reported that the token expired, the token is refreshed before reconnecting.
|
|
586
|
+
* Static tokens cannot be refreshed and reconnect as before.
|
|
587
|
+
*/
|
|
588
|
+
_reconnectAfterFailure() {
|
|
589
|
+
if (this.tokenExpiredByServer && !this.client.tokenManager.isStatic()) {
|
|
590
|
+
this._log(
|
|
591
|
+
'_reconnectAfterFailure() - token expired, so going to reload token and reconnect',
|
|
592
|
+
);
|
|
593
|
+
this._reconnect({ refreshToken: true });
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
this._reconnect();
|
|
598
|
+
}
|
|
599
|
+
|
|
556
600
|
/**
|
|
557
601
|
* _setHealth - Sets the connection to healthy or unhealthy.
|
|
558
602
|
* Broadcasts an event in case the connection status changed.
|
|
@@ -642,6 +686,7 @@ export class StableWSConnection {
|
|
|
642
686
|
*/
|
|
643
687
|
_setupConnectionPromise = () => {
|
|
644
688
|
this.isResolved = false;
|
|
689
|
+
this.tokenExpiredByServer = false;
|
|
645
690
|
/** a promise that is resolved once ws.open is called */
|
|
646
691
|
this.connectionOpen = new Promise<ConnectionOpen>((resolve, reject) => {
|
|
647
692
|
this.resolvePromise = resolve;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
isFinishedUpload,
|
|
3
|
+
isLocalUploadAttachment,
|
|
4
|
+
isPendingUpload,
|
|
5
|
+
} from '../../attachmentIdentity';
|
|
2
6
|
import type { MiddlewareHandlerParams } from '../../../middleware';
|
|
3
7
|
import type { Attachment } from '../../../types';
|
|
4
8
|
import type { MessageComposer } from '../../messageComposer';
|
|
@@ -16,6 +20,14 @@ const localAttachmentToAttachment = (localAttachment: LocalAttachment) => {
|
|
|
16
20
|
return attachment as Attachment;
|
|
17
21
|
};
|
|
18
22
|
|
|
23
|
+
/**
|
|
24
|
+
* An attachment that is not an upload (e.g. a custom one of an edited message or a restored
|
|
25
|
+
* draft) has no upload state and is sendable as it is. Leaving it out would drop it from the
|
|
26
|
+
* message: on an edit, the API removes every attachment missing from the payload.
|
|
27
|
+
*/
|
|
28
|
+
const isSendable = (attachment: LocalAttachment) =>
|
|
29
|
+
isFinishedUpload(attachment) || !isLocalUploadAttachment(attachment);
|
|
30
|
+
|
|
19
31
|
/**
|
|
20
32
|
* The composition step used by {@link createSendWithPendingUploadsAttachmentsMiddleware}.
|
|
21
33
|
*
|
|
@@ -46,8 +58,7 @@ const composeWithPendingUploads = ({
|
|
|
46
58
|
// settles.
|
|
47
59
|
const relevantAttachments = composer.attachmentManager.attachments.filter(
|
|
48
60
|
(attachment) =>
|
|
49
|
-
|
|
50
|
-
(!composerIsKeptAsDraft && isPendingUpload(attachment)),
|
|
61
|
+
isSendable(attachment) || (!composerIsKeptAsDraft && isPendingUpload(attachment)),
|
|
51
62
|
);
|
|
52
63
|
|
|
53
64
|
const localAttachments = (state.localMessage.attachments ?? []).concat(
|
|
@@ -56,7 +67,7 @@ const composeWithPendingUploads = ({
|
|
|
56
67
|
),
|
|
57
68
|
);
|
|
58
69
|
const messageAttachments = (state.message.attachments ?? []).concat(
|
|
59
|
-
relevantAttachments.filter(
|
|
70
|
+
relevantAttachments.filter(isSendable).map(localAttachmentToAttachment),
|
|
60
71
|
);
|
|
61
72
|
|
|
62
73
|
if (!localAttachments.length && !messageAttachments.length) return state;
|
|
@@ -153,7 +164,7 @@ export const createAttachmentsCompositionMiddleware = (
|
|
|
153
164
|
}
|
|
154
165
|
|
|
155
166
|
const attachments = (state.message.attachments ?? []).concat(
|
|
156
|
-
attachmentManager.
|
|
167
|
+
attachmentManager.attachments.filter(isSendable).map(localAttachmentToAttachment),
|
|
157
168
|
);
|
|
158
169
|
|
|
159
170
|
// prevent introducing attachments array into the payload sent to the server
|
|
@@ -187,10 +198,10 @@ export const createDraftAttachmentsCompositionMiddleware = (
|
|
|
187
198
|
const { attachmentManager } = composer;
|
|
188
199
|
if (!attachmentManager) return forward();
|
|
189
200
|
|
|
190
|
-
const
|
|
191
|
-
const attachments =
|
|
201
|
+
const sendableAttachments = attachmentManager.attachments.filter(isSendable);
|
|
202
|
+
const attachments = sendableAttachments.length
|
|
192
203
|
? (state.draft.attachments ?? []).concat(
|
|
193
|
-
|
|
204
|
+
sendableAttachments.map(localAttachmentToAttachment),
|
|
194
205
|
)
|
|
195
206
|
: undefined;
|
|
196
207
|
|
package/src/poll.ts
CHANGED
|
@@ -185,7 +185,15 @@ export class Poll {
|
|
|
185
185
|
const { id, ...pollData } = extractPollData(event.poll);
|
|
186
186
|
if (pollData.is_closed) this.closeConfirmed = true;
|
|
187
187
|
// @ts-expect-error type mismatch
|
|
188
|
-
this.state.partialNext({
|
|
188
|
+
this.state.partialNext({
|
|
189
|
+
...pollData,
|
|
190
|
+
// Server-owned translations, which `extractPollData` (an update request) leaves out. Copied
|
|
191
|
+
// even when absent: the event carries the whole poll, and a change made under channel-only
|
|
192
|
+
// translation drops the stale ones.
|
|
193
|
+
description_i18n: event.poll.description_i18n,
|
|
194
|
+
lastActivityAt: new Date(event.created_at),
|
|
195
|
+
name_i18n: event.poll.name_i18n,
|
|
196
|
+
});
|
|
189
197
|
this.upsertOfflineDb();
|
|
190
198
|
};
|
|
191
199
|
|
|
@@ -278,9 +278,14 @@ function applyOwnVoteDelta(
|
|
|
278
278
|
}
|
|
279
279
|
voteCount = Math.max(voteCount - 1, 0);
|
|
280
280
|
if (latestVotesByOption?.[optionId]) {
|
|
281
|
-
|
|
281
|
+
const latestVotes = latestVotesByOption[optionId].filter(
|
|
282
282
|
(latestVote) => latestVote.id !== vote.id,
|
|
283
283
|
);
|
|
284
|
+
if (latestVotes.length) {
|
|
285
|
+
latestVotesByOption[optionId] = latestVotes;
|
|
286
|
+
} else {
|
|
287
|
+
delete latestVotesByOption[optionId];
|
|
288
|
+
}
|
|
284
289
|
}
|
|
285
290
|
}
|
|
286
291
|
|
package/src/thread.ts
CHANGED
|
@@ -7,6 +7,8 @@ import {
|
|
|
7
7
|
} from './utils';
|
|
8
8
|
import type {
|
|
9
9
|
AscDesc,
|
|
10
|
+
ChannelData,
|
|
11
|
+
ChannelResponse,
|
|
10
12
|
EventTypes,
|
|
11
13
|
LocalMessage,
|
|
12
14
|
MessagePaginationOptions,
|
|
@@ -127,10 +129,15 @@ export class Thread extends WithSubscriptions {
|
|
|
127
129
|
}) {
|
|
128
130
|
super();
|
|
129
131
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
132
|
+
// `name` is custom channel data: widening the types compiles
|
|
133
|
+
// whether or not the app augments `CustomChannelData` with it.
|
|
134
|
+
const channelResponse: ChannelResponse & { name?: string } = threadData.channel;
|
|
135
|
+
const channelData: ChannelData & { name?: string } = { name: channelResponse.name };
|
|
136
|
+
const channel = client.channel(
|
|
137
|
+
threadData.channel.type,
|
|
138
|
+
threadData.channel.id,
|
|
139
|
+
channelData,
|
|
140
|
+
);
|
|
134
141
|
channel._hydrateMembers({
|
|
135
142
|
members: threadData.channel.members ?? [],
|
|
136
143
|
overrideCurrentState: false,
|