mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-01-16 06:32:10 +01:00
feat: Update session endTime based on the latest message timestamp during message storage
This commit is contained in:
@ -99,6 +99,23 @@ export async function storeMessagesForSession(sessionId, messages) {
|
||||
await prisma.message.createMany({
|
||||
data: messageData,
|
||||
});
|
||||
|
||||
// Extract actual end time from the latest message
|
||||
const latestMessage = messages.reduce((latest, current) => {
|
||||
return new Date(current.timestamp) > new Date(latest.timestamp) ? current : latest;
|
||||
});
|
||||
|
||||
// Update the session's endTime with the actual conversation end time
|
||||
await prisma.session.update({
|
||||
where: { id: sessionId },
|
||||
data: {
|
||||
endTime: new Date(latestMessage.timestamp),
|
||||
},
|
||||
});
|
||||
|
||||
process.stdout.write(
|
||||
`[TranscriptParser] Updated session ${sessionId} endTime to ${latestMessage.timestamp}\n`
|
||||
);
|
||||
}
|
||||
|
||||
process.stdout.write(
|
||||
|
||||
Reference in New Issue
Block a user