aboutsummaryrefslogtreecommitdiff
path: root/room.h
diff options
context:
space:
mode:
Diffstat (limited to 'room.h')
-rw-r--r--room.h56
1 files changed, 47 insertions, 9 deletions
diff --git a/room.h b/room.h
index ff76b25a..582b89c4 100644
--- a/room.h
+++ b/room.h
@@ -18,6 +18,9 @@
#pragma once
+#include <memory>
+#include <deque>
+
#include <QtCore/QList>
#include <QtCore/QStringList>
#include <QtCore/QObject>
@@ -26,8 +29,6 @@
#include "jobs/syncjob.h"
#include "joinstate.h"
-#include <deque>
-
namespace QMatrixClient
{
class Event;
@@ -35,18 +36,42 @@ namespace QMatrixClient
class User;
class MemberSorter;
+ class TimelineItem
+ {
+ public:
+ // For compatibility with Qt containers, even though we use
+ // a std:: container now
+ using index_t = int;
+
+ TimelineItem(Event* e, index_t number) : evt(e), idx(number) { }
+
+ Event* event() const { return evt.get(); }
+ Event* operator->() const { return event(); } //< Synonym for event()
+ index_t index() const { return idx; }
+
+ private:
+ std::unique_ptr<Event> evt;
+ index_t idx;
+ };
+ inline QDebug& operator<<(QDebug& d, const TimelineItem& ti)
+ {
+ QDebugStateSaver dss(d);
+ d.nospace() << "(" << ti.index() << "|" << ti->id() << ")";
+ return d;
+ }
+
class Room: public QObject
{
Q_OBJECT
- Q_PROPERTY(QString readMarkerEventId READ readMarkerEventId WRITE markMessagesAsRead NOTIFY readMarkerPromoted)
+ Q_PROPERTY(QString readMarkerEventId READ readMarkerEventId WRITE markMessagesAsRead NOTIFY readMarkerMoved)
public:
- using Timeline = Owning< std::deque<Event*> >;
+ using Timeline = std::deque<TimelineItem>;
+ using rev_iter_t = Timeline::const_reverse_iterator;
Room(Connection* connection, QString id);
virtual ~Room();
Q_INVOKABLE QString id() const;
- Q_INVOKABLE const Timeline& messageEvents() const;
Q_INVOKABLE QString name() const;
Q_INVOKABLE QStringList aliases() const;
Q_INVOKABLE QString canonicalAlias() const;
@@ -72,6 +97,21 @@ namespace QMatrixClient
Q_INVOKABLE void updateData(SyncRoomData& data );
Q_INVOKABLE void setJoinState( JoinState state );
+ const Timeline& messageEvents() const;
+ /**
+ * A convenience method returning the read marker to the before-oldest
+ * message
+ */
+ rev_iter_t timelineEdge() const;
+ Q_INVOKABLE TimelineItem::index_t minTimelineIndex() const;
+ Q_INVOKABLE TimelineItem::index_t maxTimelineIndex() const;
+ Q_INVOKABLE bool isValidIndex(TimelineItem::index_t timelineIndex) const;
+
+ rev_iter_t findInTimeline(TimelineItem::index_t index) const;
+ rev_iter_t findInTimeline(QString evtId) const;
+
+ rev_iter_t readMarker(const User* user) const;
+ rev_iter_t readMarker() const;
QString readMarkerEventId() const;
/**
* @brief Mark the event with uptoEventId as read
@@ -81,7 +121,7 @@ namespace QMatrixClient
* for this message or, if it's from the local user, for
* the nearest non-local message before. uptoEventId must be non-empty.
*/
- Q_INVOKABLE void markMessagesAsRead(QString uptoEventId);
+ void markMessagesAsRead(QString uptoEventId);
Q_INVOKABLE bool hasUnreadMessages();
@@ -119,7 +159,7 @@ namespace QMatrixClient
void highlightCountChanged(Room* room);
void notificationCountChanged(Room* room);
void lastReadEventChanged(User* user);
- void readMarkerPromoted();
+ void readMarkerMoved();
void unreadMessagesChanged(Room* room);
protected:
@@ -135,8 +175,6 @@ namespace QMatrixClient
void addNewMessageEvents(Events events);
void addHistoricalMessageEvents(Events events);
-
- void setLastReadEvent(User* user, Event* event);
};
class MemberSorter