fix: setReactions updates blocks in-place with dataChanged signal
This commit is contained in:
parent
d5f0770b0a
commit
1cce42f2d6
|
|
@ -113,25 +113,31 @@ QHash<int, QByteArray> ChatBlockModel::roleNames() const
|
|||
|
||||
void ChatBlockModel::setReactions(const QVariantMap &reactions)
|
||||
{
|
||||
// Build a lookup: response ID -> emoji
|
||||
QHash<QString, QString> reactionMap;
|
||||
for (auto it = reactions.constBegin(); it != reactions.constEnd(); ++it)
|
||||
reactionMap[it.key()] = it.value().toString();
|
||||
|
||||
// Update all assistant blocks
|
||||
bool changed = false;
|
||||
// Update m_allBlocks for future scroll/loadEarlier
|
||||
for (int i = 0; i < m_allBlocks.size(); ++i) {
|
||||
if (m_allBlocks[i].type == ChatBlock::Assistant && m_allBlocks[i].responseId != "") {
|
||||
QString emoji = reactionMap.value(m_allBlocks[i].responseId);
|
||||
if (m_allBlocks[i].reaction != emoji) {
|
||||
m_allBlocks[i].reaction = emoji;
|
||||
changed = true;
|
||||
if (m_allBlocks[i].type == ChatBlock::Assistant && !m_allBlocks[i].responseId.isEmpty())
|
||||
m_allBlocks[i].reaction = reactionMap.value(m_allBlocks[i].responseId);
|
||||
}
|
||||
|
||||
// Update visible m_blocks with dataChanged signal
|
||||
for (int i = 0; i < m_blocks.size(); ++i) {
|
||||
if (m_blocks[i].type == ChatBlock::Assistant && !m_blocks[i].responseId.isEmpty()) {
|
||||
QString emoji = reactionMap.value(m_blocks[i].responseId);
|
||||
if (m_blocks[i].reaction != emoji) {
|
||||
m_blocks[i].reaction = emoji;
|
||||
emit dataChanged(index(i), index(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
// Rebuild visible blocks
|
||||
reparse();
|
||||
|
||||
// Update filtered blocks too
|
||||
for (int i = 0; i < m_filteredBlocks.size(); ++i) {
|
||||
if (m_filteredBlocks[i].type == ChatBlock::Assistant && !m_filteredBlocks[i].responseId.isEmpty())
|
||||
m_filteredBlocks[i].reaction = reactionMap.value(m_filteredBlocks[i].responseId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in New Issue