@@ -623,7 +623,11 @@ export function renderChatMobileToggle(state: AppViewState) {
|
623 | 623 | `; |
624 | 624 | } |
625 | 625 | |
626 | | -export function switchChatSession(state: AppViewState, nextSessionKey: string) { |
| 626 | +function switchChatSessionInternal( |
| 627 | +state: AppViewState, |
| 628 | +nextSessionKey: string, |
| 629 | +opts?: { awaitInitialLoad?: boolean }, |
| 630 | +): Promise<void> | undefined { |
627 | 631 | const previousSessionKey = state.sessionKey; |
628 | 632 | const nextSessionRow = |
629 | 633 | state.sessionsResult?.sessions.find((row) => row.key === nextSessionKey) ?? |
@@ -644,11 +648,33 @@ export function switchChatSession(state: AppViewState, nextSessionKey: string) {
|
644 | 648 | nextSessionKey, |
645 | 649 | true, |
646 | 650 | ); |
647 | | -void syncSelectedSessionMessageSubscription( |
| 651 | +const subscriptionSync = syncSelectedSessionMessageSubscription( |
648 | 652 | state as unknown as AppViewState & { chatSessionMessageSubscriptionKey?: string | null }, |
649 | 653 | ); |
650 | | -void loadChatHistory(state as unknown as ChatState); |
651 | | -void refreshSessionOptions(state); |
| 654 | +const historyLoad = loadChatHistory(state as unknown as ChatState); |
| 655 | +const sessionsRefresh = refreshSessionOptions(state); |
| 656 | +if (opts?.awaitInitialLoad) { |
| 657 | +void sessionsRefresh; |
| 658 | +return Promise.allSettled([subscriptionSync, historyLoad]).then(() => undefined); |
| 659 | +} |
| 660 | +void subscriptionSync; |
| 661 | +void historyLoad; |
| 662 | +void sessionsRefresh; |
| 663 | +return undefined; |
| 664 | +} |
| 665 | + |
| 666 | +export function switchChatSession(state: AppViewState, nextSessionKey: string): void { |
| 667 | +void switchChatSessionInternal(state, nextSessionKey); |
| 668 | +} |
| 669 | + |
| 670 | +export function switchChatSessionAndWait( |
| 671 | +state: AppViewState, |
| 672 | +nextSessionKey: string, |
| 673 | +): Promise<void> { |
| 674 | +return ( |
| 675 | +switchChatSessionInternal(state, nextSessionKey, { awaitInitialLoad: true }) ?? |
| 676 | +Promise.resolve() |
| 677 | +); |
652 | 678 | } |
653 | 679 | |
654 | 680 | export function dismissChatError(state: AppViewState) { |
|