trim chat to last 30 blocks on initial load and session switch
This commit is contained in:
parent
2d2ba1eeaf
commit
df41aad5cb
|
|
@ -73,6 +73,17 @@ void ChatBlockModel::reset()
|
|||
emit countChanged();
|
||||
}
|
||||
|
||||
void ChatBlockModel::trimFront(int keepCount)
|
||||
{
|
||||
if (m_blocks.size() <= keepCount)
|
||||
return;
|
||||
int removeCount = m_blocks.size() - keepCount;
|
||||
beginRemoveRows(QModelIndex(), 0, removeCount - 1);
|
||||
m_blocks.remove(0, removeCount);
|
||||
endRemoveRows();
|
||||
emit countChanged();
|
||||
}
|
||||
|
||||
void ChatBlockModel::processLine(const QString &line)
|
||||
{
|
||||
QRegularExpressionMatch m = s_headerRe.match(line);
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ public:
|
|||
|
||||
Q_INVOKABLE void appendData(const QString &text);
|
||||
Q_INVOKABLE void reset();
|
||||
Q_INVOKABLE void trimFront(int keepCount);
|
||||
|
||||
signals:
|
||||
void countChanged();
|
||||
|
|
|
|||
10
gui/main.qml
10
gui/main.qml
|
|
@ -61,7 +61,10 @@ ApplicationWindow {
|
|||
|
||||
Component.onCompleted: {
|
||||
var log = ollie.readLog()
|
||||
if (log) chatModel.appendData(log)
|
||||
if (log) {
|
||||
chatModel.appendData(log)
|
||||
chatModel.trimFront(30)
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
|
|
@ -69,7 +72,10 @@ ApplicationWindow {
|
|||
function onActiveSessionIdChanged() {
|
||||
chatModel.reset()
|
||||
var log = ollie.readLog()
|
||||
if (log) chatModel.appendData(log)
|
||||
if (log) {
|
||||
chatModel.appendData(log)
|
||||
chatModel.trimFront(30)
|
||||
}
|
||||
}
|
||||
function onStreamingDone() {
|
||||
chatModel.appendData("\n[info]\nsession ended\n")
|
||||
|
|
|
|||
Reference in New Issue