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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user