mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-08 06:19:05 +08:00
fix(useMessageOperations): skip timestamp update for UI-only changes (#10927)
Prevent unnecessary message updates when only UI-related states change by checking the update keys and skipping timestamp updates in those cases
This commit is contained in:
parent
c32f4badbd
commit
9013fcba14
@ -20,11 +20,11 @@ import {
|
|||||||
updateMessageAndBlocksThunk,
|
updateMessageAndBlocksThunk,
|
||||||
updateTranslationBlockThunk
|
updateTranslationBlockThunk
|
||||||
} from '@renderer/store/thunk/messageThunk'
|
} from '@renderer/store/thunk/messageThunk'
|
||||||
import type { Assistant, Model, Topic, TranslateLanguageCode } from '@renderer/types'
|
import { type Assistant, type Model, objectKeys, type Topic, type TranslateLanguageCode } from '@renderer/types'
|
||||||
import type { Message, MessageBlock } from '@renderer/types/newMessage'
|
import type { Message, MessageBlock } from '@renderer/types/newMessage'
|
||||||
import { MessageBlockStatus, MessageBlockType } from '@renderer/types/newMessage'
|
import { MessageBlockStatus, MessageBlockType } from '@renderer/types/newMessage'
|
||||||
import { abortCompletion } from '@renderer/utils/abortController'
|
import { abortCompletion } from '@renderer/utils/abortController'
|
||||||
import { throttle } from 'lodash'
|
import { difference, throttle } from 'lodash'
|
||||||
import { useCallback } from 'react'
|
import { useCallback } from 'react'
|
||||||
|
|
||||||
const logger = loggerService.withContext('UseMessageOperations')
|
const logger = loggerService.withContext('UseMessageOperations')
|
||||||
@ -82,10 +82,12 @@ export function useMessageOperations(topic: Topic) {
|
|||||||
logger.error('[editMessage] Topic prop is not valid.')
|
logger.error('[editMessage] Topic prop is not valid.')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
const uiStates = ['multiModelMessageStyle', 'foldSelected'] as const satisfies (keyof Message)[]
|
||||||
|
const extraUpdate = difference(objectKeys(updates), uiStates)
|
||||||
|
const isUiUpdateOnly = extraUpdate.length === 0
|
||||||
const messageUpdates: Partial<Message> & Pick<Message, 'id'> = {
|
const messageUpdates: Partial<Message> & Pick<Message, 'id'> = {
|
||||||
id: messageId,
|
id: messageId,
|
||||||
updatedAt: new Date().toISOString(),
|
updatedAt: isUiUpdateOnly ? undefined : new Date().toISOString(),
|
||||||
...updates
|
...updates
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user