Skip to content

Commit 78365f3

Browse files
Migrate Vite example
1 parent e273441 commit 78365f3

10 files changed

Lines changed: 70 additions & 53 deletions

File tree

examples/vite/src/App.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ const options: ChannelOptions = {
104104
limit: 10,
105105
};
106106

107-
const sort: ChannelSort = { last_message_at: -1, updated_at: -1 };
107+
const sort: ChannelSort = [
108+
{ field: 'last_message_at', direction: -1 },
109+
{ field: 'updated_at', direction: -1 },
110+
];
108111

109112
// @ts-expect-error ai_generated isn't on LocalMessage's public type yet
110113
const isMessageAIGenerated = (message: LocalMessage) => !!message?.ai_generated;
@@ -292,7 +295,7 @@ const App = () => {
292295
$or: {
293296
enabled: true,
294297
generate: () => ({
295-
$or: [{ members: { $in: [chatClient.userID!] } }, { type: 'public' }],
298+
$or: [{ members: { $in: [chatClient.userId!] } }, { type: 'public' }],
296299
members: undefined,
297300
}),
298301
},

examples/vite/src/AppSettings/ActionsMenu/WebSocketEventPromptDialog/websocketEventAutomation.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type {
22
Channel,
33
ChannelMemberResponse,
44
Event,
5-
MessageResponseBase,
5+
MessageResponse,
66
ReactionResponse,
77
StreamChat,
88
UserResponse,
@@ -16,15 +16,13 @@ import {
1616
import type { SimulationState, SimulationUser } from './types';
1717

1818
type UnknownRecord = Record<string, unknown>;
19-
type EventPayload = Omit<
20-
Partial<Event>,
21-
'channel' | 'member' | 'message' | 'reaction' | 'user'
22-
> & {
19+
type EventPayload = {
2320
channel?: Partial<WebSocketEventTemplateContext['channel']>;
2421
member?: ChannelMemberResponse;
25-
message?: Partial<MessageResponseBase>;
22+
message?: Partial<MessageResponse>;
2623
reaction?: ReactionResponse;
2724
user?: UserResponse;
25+
[key: string]: unknown;
2826
};
2927

3028
const messageTextFragments = [
@@ -86,7 +84,7 @@ const buildReactionState = ({
8684
}: {
8785
reaction: ReactionResponse;
8886
}): Pick<
89-
MessageResponseBase,
87+
MessageResponse,
9088
'latest_reactions' | 'reaction_counts' | 'reaction_groups' | 'reaction_scores'
9189
> => {
9290
const reactionType = getId(reaction.type) ?? 'love';
@@ -113,7 +111,10 @@ const buildReactionState = ({
113111
reaction_scores: {
114112
[reactionType]: reactionScore,
115113
},
116-
};
114+
} as unknown as Pick<
115+
MessageResponse,
116+
'latest_reactions' | 'reaction_counts' | 'reaction_groups' | 'reaction_scores'
117+
>;
117118
};
118119

119120
const uniquePush = <T extends string>(items: T[], value: T) => {
@@ -390,7 +391,7 @@ export const buildFreshWebSocketEventPayload = ({
390391
text,
391392
updated_at: freshContext.createdAt,
392393
user,
393-
},
394+
} as unknown as Partial<MessageResponse>,
394395
message_id: messageId,
395396
user: eventType === 'message.new' ? user : basePayload.user,
396397
};
@@ -407,13 +408,14 @@ export const buildFreshWebSocketEventPayload = ({
407408
const reaction = {
408409
...baseReaction,
409410
created_at: freshContext.createdAt,
411+
custom: {},
410412
message_id: messageId,
411413
type: reactionType,
412414
updated_at: freshContext.createdAt,
413415
user,
414416
user_id: user.id,
415417
score: reactionScore,
416-
};
418+
} as unknown as ReactionResponse;
417419

418420
return {
419421
...basePayload,
@@ -430,7 +432,7 @@ export const buildFreshWebSocketEventPayload = ({
430432
updated_at: freshContext.createdAt,
431433
user,
432434
...buildReactionState({ reaction }),
433-
},
435+
} as unknown as Partial<MessageResponse>,
434436
message_id: messageId,
435437
reaction,
436438
user,
@@ -464,7 +466,7 @@ export const buildFreshWebSocketEventPayload = ({
464466
member,
465467
updated_at: freshContext.createdAt,
466468
user,
467-
},
469+
} as unknown as Partial<MessageResponse>,
468470
user,
469471
};
470472
}
@@ -494,7 +496,7 @@ export const trackSimulationStateFromPayload = ({
494496
simulationState,
495497
templateContext,
496498
}: {
497-
payload: Event;
499+
payload: EventPayload;
498500
simulationState: SimulationState;
499501
templateContext: WebSocketEventTemplateContext;
500502
}) => {
@@ -555,12 +557,12 @@ export const emitWebSocketEventPayload = ({
555557
simulationState: SimulationState;
556558
templateContext: WebSocketEventTemplateContext;
557559
}) => {
558-
const emittedPayload = {
560+
const emittedPayload: EventPayload = {
559561
...payload,
560562
type: eventType,
561-
} as Event;
563+
};
562564

563-
client.dispatchEvent(emittedPayload);
565+
client.dispatchEvent(emittedPayload as Event);
564566

565567
trackSimulationStateFromPayload({
566568
payload: emittedPayload,

examples/vite/src/AppSettings/ActionsMenu/WebSocketEventPromptDialog/websocketEventTemplates.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,22 @@ type BuildChannelSeedContext = Omit<WebSocketEventTemplateContext, 'channel'> &
120120
channel: Partial<DebugChannelResponse>;
121121
};
122122

123-
const createFallbackUser = (id: string, createdAt: string): DebugUserResponse => ({
124-
banned: false,
125-
blocked_user_ids: [],
126-
created_at: createdAt,
127-
id,
128-
invisible: false,
129-
language: '',
130-
last_active: createdAt,
131-
name: id,
132-
online: true,
133-
role: 'user',
134-
shadow_banned: false,
135-
teams: [],
136-
updated_at: createdAt,
137-
});
123+
const createFallbackUser = (id: string, createdAt: string): DebugUserResponse =>
124+
({
125+
banned: false,
126+
blocked_user_ids: [],
127+
created_at: createdAt,
128+
id,
129+
invisible: false,
130+
language: '',
131+
last_active: createdAt,
132+
name: id,
133+
online: true,
134+
role: 'user',
135+
shadow_banned: false,
136+
teams: [],
137+
updated_at: createdAt,
138+
}) as unknown as DebugUserResponse;
138139

139140
const getUserId = (user: DebugUserResponse) =>
140141
typeof user.id === 'string' ? user.id : 'debug-user';
@@ -154,7 +155,7 @@ const createMember = (user: DebugUserResponse): ChannelMemberResponse => {
154155
updated_at: createdAt,
155156
user,
156157
user_id: getUserId(user),
157-
};
158+
} as unknown as ChannelMemberResponse;
158159
};
159160

160161
const getMemberUserId = (member: { user?: unknown; user_id?: unknown }) => {
@@ -176,7 +177,7 @@ const buildChannel = (
176177
): DebugChannelResponse => {
177178
const createdAt = context.createdAt;
178179

179-
return {
180+
return ({
180181
cid: context.cid,
181182
config: {
182183
automod: 'disabled',
@@ -253,7 +254,7 @@ const buildChannel = (
253254
type: context.channelType,
254255
updated_at: createdAt,
255256
...overrides,
256-
};
257+
}) as unknown as DebugChannelResponse;
257258
};
258259

259260
const buildMe = (

examples/vite/src/AppSettings/tabs/Reactions/reactionsExampleData.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ const firstLikeReactionTimestamp = '2026-02-12T06:39:56.237389Z';
55
const secondLikeReactionTimestamp = '2026-02-12T06:39:52.237389Z';
66
const heartReactionTimestamp = '2026-02-12T06:35:58.021196Z';
77

8-
export const reactionsPreviewMessage: LocalMessage = {
8+
export const reactionsPreviewMessage = {
99
created_at: new Date('2026-02-12T06:34:40.000000Z'),
10-
deleted_at: null,
10+
deleted_at: undefined,
1111
id: 'settings-preview-message-id',
1212
latest_reactions: [
1313
{
1414
created_at: fireReactionTimestamp,
15+
custom: {},
1516
message_id: 'settings-preview-message-id',
1617
score: 1,
1718
type: 'fire',
@@ -26,6 +27,7 @@ export const reactionsPreviewMessage: LocalMessage = {
2627
},
2728
{
2829
created_at: firstLikeReactionTimestamp,
30+
custom: {},
2931
message_id: 'settings-preview-message-id',
3032
score: 1,
3133
type: 'like',
@@ -40,6 +42,7 @@ export const reactionsPreviewMessage: LocalMessage = {
4042
},
4143
{
4244
created_at: secondLikeReactionTimestamp,
45+
custom: {},
4346
message_id: 'settings-preview-message-id',
4447
score: 1,
4548
type: 'like',
@@ -54,17 +57,19 @@ export const reactionsPreviewMessage: LocalMessage = {
5457
},
5558
{
5659
created_at: heartReactionTimestamp,
60+
custom: {},
5761
message_id: 'settings-preview-message-id',
5862
score: 1,
5963
type: 'heart',
6064
updated_at: heartReactionTimestamp,
6165
user: { id: 'test-user-2' },
6266
user_id: 'test-user-2',
6367
},
64-
] as LocalMessage['latest_reactions'],
68+
] as unknown as LocalMessage['latest_reactions'],
6569
own_reactions: [
6670
{
6771
created_at: fireReactionTimestamp,
72+
custom: {},
6873
message_id: 'settings-preview-message-id',
6974
score: 1,
7075
type: 'fire',
@@ -74,6 +79,7 @@ export const reactionsPreviewMessage: LocalMessage = {
7479
},
7580
{
7681
created_at: firstLikeReactionTimestamp,
82+
custom: {},
7783
message_id: 'settings-preview-message-id',
7884
score: 1,
7985
type: 'like',
@@ -83,36 +89,40 @@ export const reactionsPreviewMessage: LocalMessage = {
8389
},
8490
{
8591
created_at: heartReactionTimestamp,
92+
custom: {},
8693
message_id: 'settings-preview-message-id',
8794
score: 1,
8895
type: 'heart',
8996
updated_at: heartReactionTimestamp,
9097
user: { id: 'test-user' },
9198
user_id: 'test-user',
9299
},
93-
] as LocalMessage['own_reactions'],
94-
pinned_at: null,
100+
] as unknown as LocalMessage['own_reactions'],
101+
pinned_at: undefined,
95102
reaction_counts: { fire: 1, heart: 1, like: 2 },
96103
reaction_groups: {
97104
fire: {
98105
count: 1,
99106
first_reaction_at: fireReactionTimestamp,
100107
last_reaction_at: fireReactionTimestamp,
108+
latest_reactions_by: [],
101109
sum_scores: 1,
102110
},
103111
heart: {
104112
count: 1,
105113
first_reaction_at: heartReactionTimestamp,
106114
last_reaction_at: heartReactionTimestamp,
115+
latest_reactions_by: [],
107116
sum_scores: 1,
108117
},
109118
like: {
110119
count: 2,
111120
first_reaction_at: secondLikeReactionTimestamp,
112121
last_reaction_at: firstLikeReactionTimestamp,
122+
latest_reactions_by: [],
113123
sum_scores: 2,
114124
},
115-
} as LocalMessage['reaction_groups'],
125+
} as unknown as LocalMessage['reaction_groups'],
116126
reaction_scores: { fire: 1, heart: 1, like: 2 },
117127
status: 'received',
118128
text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed lectus nibh, rutrum in risus eget, dictum commodo dolor. Donec augue nisi, sollicitudin sed magna ut, tincidunt pretium lorem. ',
@@ -123,7 +133,7 @@ export const reactionsPreviewMessage: LocalMessage = {
123133
image: 'https://getstream.io/random_svg/?id=preview-user&name=Preview+User',
124134
name: 'Preview User',
125135
},
126-
};
136+
} as unknown as LocalMessage;
127137

128138
export const reactionsPreviewChannelState = {
129139
channel: {

examples/vite/src/ChannelPreviewOverlay/ChannelPreviewOverlay.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const useChannelMembershipState = () => {
1616
const { client } = useChatContext();
1717
const { channel } = useChannelStateContext();
1818
const members = useChannelMembersState(channel);
19-
const membership = members[client.userID!] as ChannelMemberResponse | undefined;
19+
const membership = members[client.userId!] as ChannelMemberResponse | undefined;
2020

2121
const isMember = typeof membership?.channel_role === 'string';
2222
const canJoin = channel.data?.own_capabilities?.includes('join-channel');
@@ -32,7 +32,7 @@ export const ChannelPreviewOverlay = () => {
3232
const handleJoin = useCallback(async () => {
3333
setJoining(true);
3434
try {
35-
await channel.addMembers([client.userID!]);
35+
await channel.addMembers([client.userId!]);
3636
} catch (error) {
3737
addNotification({
3838
emitter: 'ChannelPreviewOverlay',
@@ -48,7 +48,7 @@ export const ChannelPreviewOverlay = () => {
4848
} finally {
4949
setJoining(false);
5050
}
51-
}, [addNotification, channel, client.userID]);
51+
}, [addNotification, channel, client.userId]);
5252

5353
if (isMember) return null;
5454

examples/vite/src/ChatLayout/ChannelMembersRemoveView.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const toError = (error: unknown) =>
2626
error instanceof Error ? error : new Error('An unknown error occurred');
2727

2828
const getUserDisplayName = (user?: UserResponse) =>
29-
user?.name || user?.username || user?.id || '';
29+
// @ts-expect-error username is not typed
30+
user?.name || user?.custom.username || user?.id || '';
3031

3132
const getMemberDisplayName = (member: ChannelMemberResponse) =>
3233
getUserDisplayName(member.user) || member.user_id || '';

examples/vite/src/ChatLayout/Sync.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export const ThreadStateSync = () => {
198198
isRestoringThread.current = true;
199199

200200
client
201-
.getThread(threadIdToRestore)
201+
.getThreadAndHydrate(threadIdToRestore)
202202
.then((thread) => {
203203
if (!thread || cancelled) return;
204204

examples/vite/src/CustomMessageActions/ConfigurableMessageActions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ const CustomDeleteMessageAlert = ({
116116
appearance='outline'
117117
className='str-chat__delete-message-alert__delete-button'
118118
data-testid='delete-message-alert-delete-button'
119-
onClick={() => onDelete({ deleteForMe, hardDelete })}
119+
onClick={() => onDelete({ delete_for_me: deleteForMe, hard: hardDelete })}
120120
size='md'
121121
variant='danger'
122122
>

examples/vite/src/CustomMessageUi/variants.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ const CustomMessageUiMetadata = ({
183183
{messageTextUpdatedAt && (
184184
<div
185185
className='custom-message-ui__metadata-edited-status'
186-
title={messageTextUpdatedAt}
186+
title={messageTextUpdatedAt.toISOString()}
187187
>
188188
Edited
189189
</div>

0 commit comments

Comments
 (0)