Refactor TimelineView

Refactor TimelineView to make it more reliable and prepare for read marker choice. This is done by creating signalling from the mode when reset which can be used to move the scrollbar to the newest meassage.

Some of the spaghetti is also removed so there is no need for ChatBar and TimelineView to talk directly.

The code to mark messages as read if they are all visible after 10s has been removed infour of just marking as read on entry if all are visible. This is temporary until a follow up providing user options is finished (although it will be one of the options)
This commit is contained in:
James Graham
2025-06-14 12:16:39 +01:00
parent 235143528c
commit 6a5a2e6144
17 changed files with 368 additions and 318 deletions

View File

@@ -60,6 +60,7 @@ void TimelineMessageModel::connectNewRoom()
connect(m_room, &Room::pendingEventAdded, this, [this](const Quotient::RoomEvent *event) {
m_initialized = true;
Q_EMIT newEventAdded(event);
Q_EMIT newLocalUserEventAdded();
beginInsertRows({}, 0, 0);
endInsertRows();
});
@@ -143,44 +144,6 @@ int TimelineMessageModel::timelineServerIndex() const
return m_room ? int(m_room->pendingEvents().size()) : 0;
}
void TimelineMessageModel::moveReadMarker(const QString &toEventId)
{
const auto timelineIt = m_room->findInTimeline(toEventId);
if (timelineIt == m_room->historyEdge()) {
return;
}
int newRow = int(timelineIt - m_room->messageEvents().rbegin()) + timelineServerIndex();
if (!m_lastReadEventIndex.isValid()) {
// Not valid index means we don't display any marker yet, in this case
// we create the new index and insert the row in case the read marker
// need to be displayed.
if (newRow > timelineServerIndex()) {
// The user didn't read all the messages yet.
m_initialized = true;
beginInsertRows({}, newRow, newRow);
m_lastReadEventIndex = QPersistentModelIndex(index(newRow, 0));
endInsertRows();
return;
}
// The user read all the messages and we didn't display any read marker yet
// => do nothing
return;
}
if (newRow <= timelineServerIndex()) {
// The user read all the messages => remove read marker
beginRemoveRows({}, m_lastReadEventIndex.row(), m_lastReadEventIndex.row());
m_lastReadEventIndex = QModelIndex();
endRemoveRows();
return;
}
// The user didn't read all the messages yet but moved the reader marker.
beginMoveRows({}, m_lastReadEventIndex.row(), m_lastReadEventIndex.row(), {}, newRow);
m_lastReadEventIndex = QPersistentModelIndex(index(newRow, 0));
endMoveRows();
}
std::optional<std::reference_wrapper<const RoomEvent>> TimelineMessageModel::getEventForIndex(QModelIndex index) const
{
const auto row = index.row();