chat and message date data, begin chat sort opts.

This commit is contained in:
Webifi 2023-06-24 12:48:27 -05:00
parent 86092afcb0
commit 8835ee1d6e
5 changed files with 35 additions and 5 deletions

View File

@ -115,6 +115,10 @@
chatRequest = new ChatRequest()
chatRequest.setChat(chat)
chat.lastAccess = Date.now()
saveChatStore()
// Focus the input on mount
focusInput()

View File

@ -105,6 +105,15 @@ export const imageGenerationSizes = [
export const imageGenerationSizeTypes = ['', ...imageGenerationSizes]
export const chatSortOptions = [
{ value: 'name', text: 'Name' },
{ value: 'created', text: 'Created' },
{ value: 'updated', text: 'Last Use' },
{ value: 'lastAccess', text: 'Last View' }
]
export const chatSortOptionsKeys = chatSortOptions.map(o => o.value, [] as string[])
const profileSetting: ChatSetting & SettingSelect = {
key: 'profile',
name: 'Profile',

View File

@ -9,7 +9,7 @@
import { clickOutside } from 'svelte-use-click-outside'
import { startNewChatWithWarning } from './Util.svelte'
$: sortedChats = $chatsStorage.sort((a, b) => b.id - a.id)
$: sortedChats = $chatsStorage.sort((a, b) => ((b.created || 0) - (a.created || 0)) || (b.id - a.id))
$: activeChatId = $params && $params.chatId ? parseInt($params.chatId) : undefined
</script>

View File

@ -52,7 +52,10 @@
messages: [],
usage: {} as Record<Model, Usage>,
startSession: false,
sessionStarted: false
sessionStarted: false,
created: Date.now(),
updated: Date.now(),
lastAccess: Date.now()
})
chatsStorage.set(chats)
// Apply defaults and prepare it to start
@ -79,6 +82,7 @@
}
chat.id = chatId
chat.created = Date.now()
// Make sure images are moved to indexedDB store,
// else they would clobber local storage
@ -252,7 +256,9 @@
}, 200)
} else {
clearTimeout(setMessagesTimers[chatId])
getChat(chatId).messages = messages
const chat = getChat(chatId)
chat.updated = Date.now()
chat.messages = messages
saveChatStore()
}
}
@ -268,6 +274,7 @@
export const addMessage = (chatId: number, message: Message) => {
const messages = getMessages(chatId)
if (!message.uuid) message.uuid = uuidv4()
if (!message.created) message.created = Date.now()
if (messages.indexOf(message) < 0) {
// Don't have message, add it
messages[messages.length] = message
@ -286,7 +293,10 @@
console.error("Couldn't insert after message:", insertAfter)
return
}
newMessages.forEach(m => { m.uuid = m.uuid || uuidv4() })
newMessages.forEach(m => {
m.uuid = m.uuid || uuidv4()
m.created = m.created || Date.now()
})
messages.splice(index + 1, 0, ...newMessages)
setMessages(chatId, messages.filter(m => true))
}

View File

@ -1,11 +1,13 @@
<script context="module" lang="ts">
import { supportedModelKeys } from './Models.svelte'
import { imageGenerationSizeTypes } from './Settings.svelte'
import { chatSortOptionsKeys, imageGenerationSizeTypes } from './Settings.svelte'
export type Model = typeof supportedModelKeys[number];
export type ImageGenerationSizes = typeof imageGenerationSizeTypes[number];
export type ChatSortTypes = typeof chatSortOptionsKeys[number];
export type ModelDetail = {
prompt: number;
completion: number;
@ -37,6 +39,7 @@
finish_reason?: string;
streaming?: boolean;
image?: ChatImage;
created?: number;
};
export type ResponseAlteration = {
@ -109,6 +112,9 @@
settings: ChatSettings;
startSession: boolean;
sessionStarted: boolean;
created: number;
updated: number;
lastAccess: number;
};
type ResponseOK = {
@ -159,6 +165,7 @@
lastProfile?: string;
defaultProfile?: string;
hideSummarized?: boolean;
chatSort: keyof ChatSortTypes;
};
type SettingNumber = {