refac
This commit is contained in:
@@ -2413,8 +2413,11 @@
|
|||||||
taskIds = newTaskIds;
|
taskIds = newTaskIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Backend returns chat_id for new chats — set store + URL
|
// Backend returns chat_id for new chats — set store + URL.
|
||||||
if (res.chat_id && $chatId !== res.chat_id) {
|
// Only update if the user hasn't navigated to a different chat
|
||||||
|
// while the request was in flight (prevents overwriting $chatId
|
||||||
|
// and causing spurious toast notifications / state duplication).
|
||||||
|
if (res.chat_id && $chatId !== res.chat_id && $chatId === _chatId) {
|
||||||
await chatId.set(res.chat_id);
|
await chatId.set(res.chat_id);
|
||||||
if (!$temporaryChatEnabled) {
|
if (!$temporaryChatEnabled) {
|
||||||
window.history.replaceState(history.state, '', `/c/${res.chat_id}`);
|
window.history.replaceState(history.state, '', `/c/${res.chat_id}`);
|
||||||
|
|||||||
@@ -425,13 +425,13 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let isFocused = document.visibilityState !== 'visible';
|
let isInBackground = document.visibilityState !== 'visible';
|
||||||
if (window.electronAPI) {
|
if (window.electronAPI) {
|
||||||
const res = await window.electronAPI.send({
|
const res = await window.electronAPI.send({
|
||||||
type: 'window:isFocused'
|
type: 'window:isFocused'
|
||||||
});
|
});
|
||||||
if (res) {
|
if (res) {
|
||||||
isFocused = res.isFocused;
|
isInBackground = !res.isFocused;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -471,7 +471,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((event.chat_id !== $chatId && !$temporaryChatEnabled) || isFocused) {
|
if ((event.chat_id !== $chatId && !$temporaryChatEnabled) || isInBackground) {
|
||||||
if (type === 'chat:completion') {
|
if (type === 'chat:completion') {
|
||||||
const { done, content, title } = data;
|
const { done, content, title } = data;
|
||||||
const displayTitle = title || $i18n.t('New Chat');
|
const displayTitle = title || $i18n.t('New Chat');
|
||||||
@@ -639,17 +639,17 @@
|
|||||||
// check url path
|
// check url path
|
||||||
const channel = $page.url.pathname.includes(`/channels/${event.channel_id}`);
|
const channel = $page.url.pathname.includes(`/channels/${event.channel_id}`);
|
||||||
|
|
||||||
let isFocused = document.visibilityState !== 'visible';
|
let isInBackground = document.visibilityState !== 'visible';
|
||||||
if (window.electronAPI) {
|
if (window.electronAPI) {
|
||||||
const res = await window.electronAPI.send({
|
const res = await window.electronAPI.send({
|
||||||
type: 'window:isFocused'
|
type: 'window:isFocused'
|
||||||
});
|
});
|
||||||
if (res) {
|
if (res) {
|
||||||
isFocused = res.isFocused;
|
isInBackground = !res.isFocused;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!channel || isFocused) && event?.user?.id !== $user?.id) {
|
if ((!channel || isInBackground) && event?.user?.id !== $user?.id) {
|
||||||
await tick();
|
await tick();
|
||||||
const type = event?.data?.type ?? null;
|
const type = event?.data?.type ?? null;
|
||||||
const data = event?.data?.data ?? null;
|
const data = event?.data?.data ?? null;
|
||||||
|
|||||||
Reference in New Issue
Block a user