mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
🗨️ fix: Prevent Resetting Title to 'New Chat' on Follow-Up Message (#1870)
* fix: prevent reseting title to 'New Chat' on follow up message * chore(useSSE): remove empty line
This commit is contained in:
parent
ece5d9f588
commit
6a25dd38a4
2 changed files with 33 additions and 4 deletions
|
|
@ -24,7 +24,12 @@ import type {
|
||||||
TSubmission,
|
TSubmission,
|
||||||
ConversationData,
|
ConversationData,
|
||||||
} from 'librechat-data-provider';
|
} from 'librechat-data-provider';
|
||||||
import { addConversation, deleteConversation, updateConversation } from '~/utils';
|
import {
|
||||||
|
addConversation,
|
||||||
|
deleteConversation,
|
||||||
|
updateConversation,
|
||||||
|
getConversationById,
|
||||||
|
} from '~/utils';
|
||||||
import { useGenTitleMutation } from '~/data-provider';
|
import { useGenTitleMutation } from '~/data-provider';
|
||||||
import useContentHandler from './useContentHandler';
|
import useContentHandler from './useContentHandler';
|
||||||
import { useAuthContext } from '../AuthContext';
|
import { useAuthContext } from '../AuthContext';
|
||||||
|
|
@ -231,13 +236,21 @@ export default function useSSE(submission: TSubmission | null, index = 0) {
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { conversationId } = message;
|
const { conversationId, parentMessageId } = message;
|
||||||
|
|
||||||
let update = {} as TConversation;
|
let update = {} as TConversation;
|
||||||
setConversation((prevState) => {
|
setConversation((prevState) => {
|
||||||
|
let title = prevState?.title;
|
||||||
|
if (parentMessageId !== Constants.NO_PARENT && title?.toLowerCase()?.includes('new chat')) {
|
||||||
|
const convos = queryClient.getQueryData<ConversationData>([QueryKeys.allConversations]);
|
||||||
|
const cachedConvo = getConversationById(convos, conversationId);
|
||||||
|
title = cachedConvo?.title;
|
||||||
|
}
|
||||||
|
|
||||||
update = tConvoUpdateSchema.parse({
|
update = tConvoUpdateSchema.parse({
|
||||||
...prevState,
|
...prevState,
|
||||||
conversationId,
|
conversationId,
|
||||||
|
title,
|
||||||
}) as TConversation;
|
}) as TConversation;
|
||||||
|
|
||||||
setStorage(update);
|
setStorage(update);
|
||||||
|
|
@ -248,7 +261,7 @@ export default function useSSE(submission: TSubmission | null, index = 0) {
|
||||||
if (!convoData) {
|
if (!convoData) {
|
||||||
return convoData;
|
return convoData;
|
||||||
}
|
}
|
||||||
if (message.parentMessageId === Constants.NO_PARENT) {
|
if (parentMessageId === Constants.NO_PARENT) {
|
||||||
return addConversation(convoData, update);
|
return addConversation(convoData, update);
|
||||||
} else {
|
} else {
|
||||||
return updateConversation(convoData, update);
|
return updateConversation(convoData, update);
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ import {
|
||||||
isToday,
|
isToday,
|
||||||
isWithinInterval,
|
isWithinInterval,
|
||||||
subDays,
|
subDays,
|
||||||
getMonth,
|
|
||||||
getYear,
|
getYear,
|
||||||
startOfDay,
|
startOfDay,
|
||||||
startOfYear,
|
startOfYear,
|
||||||
|
|
@ -162,3 +161,20 @@ export const deleteConversation = (
|
||||||
|
|
||||||
return newData;
|
return newData;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getConversationById = (
|
||||||
|
data: ConversationData | undefined,
|
||||||
|
conversationId: string | null,
|
||||||
|
): TConversation | undefined => {
|
||||||
|
if (!data || !conversationId) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const page of data.pages) {
|
||||||
|
const conversation = page.conversations.find((c) => c.conversationId === conversationId);
|
||||||
|
if (conversation) {
|
||||||
|
return conversation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue