Skip to content

Commit

Permalink
MessageEventModel: refresh the event adjacent to just added
Browse files Browse the repository at this point in the history
Closes #312.
  • Loading branch information
KitsuneRal committed May 24, 2018
1 parent 61ae274 commit fdc66bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
18 changes: 14 additions & 4 deletions client/models/messageeventmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,21 @@ void MessageEventModel::changeRoom(QuaternionRoom* room)
connect(m_currentRoom, &Room::aboutToAddHistoricalMessages, this,
[=](RoomEventsRange events)
{
if (rowCount() > 0)
nextNewerRow = rowCount() - 1;
beginInsertRows(QModelIndex(), rowCount(),
rowCount() + int(events.size()) - 1);
});
connect(m_currentRoom, &Room::addedMessages,
this, &MessageEventModel::endInsertRows);
connect(m_currentRoom, &Room::addedMessages, this,
[=] {
if (nextNewerRow > -1)
{
const auto idx = index(nextNewerRow);
emit dataChanged(idx, idx);
nextNewerRow = -1;
}
endInsertRows();
});
connect(m_currentRoom, &Room::readMarkerMoved, this, [this] {
refreshEventRoles(
std::exchange(lastReadEventId,
Expand Down Expand Up @@ -139,8 +149,8 @@ void MessageEventModel::refreshEventRoles(const QString& eventId,
const auto it = m_currentRoom->findInTimeline(eventId);
if (it != m_currentRoom->timelineEdge())
{
const auto row = it - m_currentRoom->messageEvents().rbegin();
emit dataChanged(index(row), index(row), roles);
const auto idx = index(it - m_currentRoom->messageEvents().rbegin());
emit dataChanged(idx, idx, roles);
}
}

Expand Down
1 change: 1 addition & 0 deletions client/models/messageeventmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class MessageEventModel: public QAbstractListModel
private:
QuaternionRoom* m_currentRoom;
QString lastReadEventId;
int nextNewerRow = -1;

QDateTime makeMessageTimestamp(QuaternionRoom::rev_iter_t baseIt) const;
QString makeDateString(QuaternionRoom::rev_iter_t baseIt) const;
Expand Down

0 comments on commit fdc66bd

Please sign in to comment.