fix: align OverlayViewModel message dedup with ChatViewModel
Removed the legacy isDup check (role+content+msgType) that could suppress multi_message items already seen as review items. Now deduplicates by message ID only and inserts at correct timestamp position, matching the fixed ChatViewModel behavior. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -80,20 +80,17 @@ class OverlayViewModel(
|
||||
chatRepository.observeMessages().collect { message ->
|
||||
_messages.update { list ->
|
||||
val updated = list.toMutableList()
|
||||
val idx = updated.indexOfLast { it.id == message.id }
|
||||
if (idx >= 0) {
|
||||
updated[idx] = message
|
||||
val existingIdx = updated.indexOfLast { it.id == message.id }
|
||||
if (existingIdx >= 0) {
|
||||
updated[existingIdx] = message
|
||||
} else {
|
||||
val isDup = updated.any {
|
||||
it.role == message.role && it.content == message.content && it.msgType == message.msgType
|
||||
}
|
||||
if (!isDup) {
|
||||
updated.add(message)
|
||||
// Insert at correct position for ascending timestamp (oldest first for top-down layout)
|
||||
val insertAt = updated.indexOfFirst { it.timestamp >= message.timestamp }
|
||||
if (insertAt >= 0) updated.add(insertAt, message) else updated.add(message)
|
||||
val animIdx = _messageAnimIndex.value.toMutableMap()
|
||||
animIdx[message.id] = animCounter++
|
||||
_messageAnimIndex.value = animIdx
|
||||
}
|
||||
}
|
||||
updated.deduplicate()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user