diff --git a/src/renderer/src/pages/home/Messages/Messages.tsx b/src/renderer/src/pages/home/Messages/Messages.tsx index fcda339a..1e437867 100644 --- a/src/renderer/src/pages/home/Messages/Messages.tsx +++ b/src/renderer/src/pages/home/Messages/Messages.tsx @@ -34,7 +34,7 @@ const Messages: FC = ({ assistant, topic, setActiveTopic }) => { (message: Message) => { const _messages = [...messages, message] setMessages(_messages) - localforage.setItem(`topic:${topic.id}`, { ...topic, messages: _messages }) + localforage.setItem(`topic:${topic.id}`, { id: topic.id, messages: _messages }) }, [messages, topic] ) diff --git a/src/renderer/src/store/assistants.ts b/src/renderer/src/store/assistants.ts index 229174cc..826b611f 100644 --- a/src/renderer/src/store/assistants.ts +++ b/src/renderer/src/store/assistants.ts @@ -44,11 +44,14 @@ const assistantsSlice = createSlice({ ) }, addTopic: (state, action: PayloadAction<{ assistantId: string; topic: Topic }>) => { + const topic = action.payload.topic + topic.createdAt = new Date().toISOString() + topic.updatedAt = new Date().toISOString() state.assistants = state.assistants.map((assistant) => assistant.id === action.payload.assistantId ? { ...assistant, - topics: uniqBy([action.payload.topic, ...assistant.topics], 'id') + topics: uniqBy([topic, ...assistant.topics], 'id') } : assistant ) @@ -64,13 +67,13 @@ const assistantsSlice = createSlice({ ) }, updateTopic: (state, action: PayloadAction<{ assistantId: string; topic: Topic }>) => { + const newTopic = action.payload.topic + newTopic.updatedAt = new Date().toISOString() state.assistants = state.assistants.map((assistant) => assistant.id === action.payload.assistantId ? { ...assistant, - topics: assistant.topics.map((topic) => - topic.id === action.payload.topic.id ? action.payload.topic : topic - ) + topics: assistant.topics.map((topic) => (topic.id === newTopic.id ? newTopic : topic)) } : assistant ) diff --git a/src/renderer/src/store/index.ts b/src/renderer/src/store/index.ts index db528381..08a35402 100644 --- a/src/renderer/src/store/index.ts +++ b/src/renderer/src/store/index.ts @@ -22,7 +22,7 @@ const persistedReducer = persistReducer( { key: 'cherry-studio', storage, - version: 23, + version: 24, blacklist: ['runtime'], migrate }, diff --git a/src/renderer/src/store/migrate.ts b/src/renderer/src/store/migrate.ts index 2431d243..befdc072 100644 --- a/src/renderer/src/store/migrate.ts +++ b/src/renderer/src/store/migrate.ts @@ -1,7 +1,8 @@ import { SYSTEM_MODELS } from '@renderer/config/models' import i18n from '@renderer/i18n' import { Assistant } from '@renderer/types' -import { isEmpty } from 'lodash' +import localforage from 'localforage' +import { isEmpty, pick } from 'lodash' import { createMigrate } from 'redux-persist' import { RootState } from '.' @@ -373,6 +374,27 @@ const migrateConfig = { windowStyle: 'transparent' } } + }, + '24': async (state: RootState) => { + for (const key of await localforage.keys()) { + if (key.startsWith('topic:')) { + localforage.getItem(key).then((topic) => localforage.setItem(key, pick(topic, ['id', 'messages']))) + } + } + return { + ...state, + assistants: { + ...state.assistants, + assistants: state.assistants.assistants.map((assistant) => ({ + ...assistant, + topics: assistant.topics.map((topic) => ({ + ...topic, + createdAt: new Date().toISOString(), + updatedAt: new Date().toISOString() + })) + })) + } + } } } diff --git a/src/renderer/src/types/index.ts b/src/renderer/src/types/index.ts index bf0dcd67..700afed1 100644 --- a/src/renderer/src/types/index.ts +++ b/src/renderer/src/types/index.ts @@ -36,6 +36,8 @@ export type Message = { export type Topic = { id: string name: string + createdAt: string + updatedAt: string messages: Message[] }