fix(chat): wait for chat window before displaying welcome message
This commit is contained in:
parent
ede87a3951
commit
5d9b9dd914
|
|
@ -6,10 +6,14 @@ import { WELCOME_CHAT, WELCOME_CHAT_MESSAGE } from "shared/welcome-chat";
|
|||
@Controller()
|
||||
export class WelcomeChatController implements OnStart {
|
||||
public onStart(): void {
|
||||
task.delay(WELCOME_CHAT.delaySeconds, () => this.displayWelcome());
|
||||
task.spawn(() => this.displayWelcome());
|
||||
}
|
||||
|
||||
private displayWelcome(): void {
|
||||
if (!game.IsLoaded()) {
|
||||
game.Loaded.Wait();
|
||||
}
|
||||
|
||||
const deadline = os.clock() + WELCOME_CHAT.channelTimeoutSeconds;
|
||||
const channels = TextChatService.WaitForChild(
|
||||
"TextChannels",
|
||||
|
|
@ -22,6 +26,26 @@ export class WelcomeChatController implements OnStart {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue