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

@@ -51,6 +51,11 @@ class MessageModel : public QAbstractListModel
*/
Q_PROPERTY(NeoChatRoom *room READ room WRITE setRoom NOTIFY roomChanged)
/**
* @brief The model index of the read marker.
*/
Q_PROPERTY(QPersistentModelIndex readMarkerIndex READ readMarkerIndex NOTIFY readMarkerIndexChanged)
public:
/**
* @brief Defines the model roles.
@@ -94,6 +99,8 @@ public:
[[nodiscard]] NeoChatRoom *room() const;
void setRoom(NeoChatRoom *room);
QPersistentModelIndex readMarkerIndex() const;
/**
* @brief Get the given role value at the given index.
*
@@ -109,9 +116,9 @@ public:
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
/**
* @brief Get the row number of the given event ID in the model.
* @brief Get the QModelIndex of the given event ID in the model.
*/
Q_INVOKABLE [[nodiscard]] int eventIdToRow(const QString &eventID) const;
Q_INVOKABLE QModelIndex indexforEventId(const QString &eventId) const;
static void setHiddenFilter(std::function<bool(const Quotient::RoomEvent *)> hiddenFilter);
@@ -123,6 +130,26 @@ Q_SIGNALS:
*/
void roomChanged();
/**
* @brief Emitted when the reader marker is added.
*/
void readMarkerAdded();
/**
* @brief Emitted when the reader marker index is changed.
*/
void readMarkerIndexChanged();
/**
* @brief Emitted when the model is about to reset.
*/
void modelAboutToBeReset();
/**
* @brief Emitted when the model has been reset.
*/
void modelResetComplete();
/**
* @brief A signal to tell the MessageModel that a new event has been added.
*
@@ -131,6 +158,11 @@ Q_SIGNALS:
*/
void newEventAdded(const Quotient::RoomEvent *event);
/**
* @brief A signal that should be emitted when the local user posts a new event in the room.
*/
void newLocalUserEventAdded();
void threadsEnabledChanged();
protected:
@@ -145,6 +177,8 @@ protected:
void refreshEventRoles(int row, const QList<int> &roles = {});
void refreshLastUserEvents(int baseTimelineRow);
void moveReadMarker(const QString &toEventId);
void clearModel();
void clearEventObjects();