fix(chat): wait for chat window before displaying welcome message

This commit is contained in:
Infuseting 2026-10-14 11:27:35 +02:00
parent ede87a3951
commit 5d9b9dd914
1 changed files with 25 additions and 1 deletions

View File

@ -6,10 +6,14 @@ import { WELCOME_CHAT, WELCOME_CHAT_MESSAGE } from "shared/welcome-chat";
@Controller() @Controller()
export class WelcomeChatController implements OnStart { export class WelcomeChatController implements OnStart {
public onStart(): void { public onStart(): void {
task.delay(WELCOME_CHAT.delaySeconds, () => this.displayWelcome()); task.spawn(() => this.displayWelcome());
} }
private displayWelcome(): void { private displayWelcome(): void {
if (!game.IsLoaded()) {
game.Loaded.Wait();
}
const deadline = os.clock() + WELCOME_CHAT.channelTimeoutSeconds; const deadline = os.clock() + WELCOME_CHAT.channelTimeoutSeconds;
const channels = TextChatService.WaitForChild( const channels = TextChatService.WaitForChild(
"TextChannels", "TextChannels",
@ -22,6 +26,26 @@ export class WelcomeChatController implements OnStart {
return; return;
} }
// Channels can exist before the chat UI subscribes to system messages.
const window = TextChatService.WaitForChild(
"ChatWindowConfiguration",
math.max(deadline - os.clock(), 0),
);
if (!window?.IsA("ChatWindowConfiguration")) {
Log.Warn("Welcome chat unavailable: the chat window configuration is missing");
return;
}
while (window.AbsoluteSize.X <= 0 || window.AbsoluteSize.Y <= 0) {
if (os.clock() >= deadline) {
Log.Warn(
"Welcome chat unavailable: the chat window did not become ready before the timeout",
);
return;
}
task.wait(0.1);
}
task.wait(WELCOME_CHAT.delaySeconds);
channel.DisplaySystemMessage(WELCOME_CHAT_MESSAGE); channel.DisplaySystemMessage(WELCOME_CHAT_MESSAGE);
} }
} }