aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--room.cpp53
-rw-r--r--room.h24
2 files changed, 69 insertions, 8 deletions
diff --git a/room.cpp b/room.cpp
index f8640573..65761856 100644
--- a/room.cpp
+++ b/room.cpp
@@ -63,8 +63,7 @@ class Room::Private
Private(Connection* c, QString id_, JoinState initialJoinState)
: q(nullptr), connection(c), id(std::move(id_))
- , avatar(c), joinState(initialJoinState), unreadMessages(false)
- , highlightCount(0), notificationCount(0)
+ , avatar(c), joinState(initialJoinState)
{ }
Room* q;
@@ -85,12 +84,14 @@ class Room::Private
QString topic;
Avatar avatar;
JoinState joinState;
- bool unreadMessages;
- int highlightCount;
- int notificationCount;
+ int highlightCount = 0;
+ int notificationCount = 0;
members_map_t membersMap;
QList<User*> usersTyping;
QList<User*> membersLeft;
+ bool unreadMessages = false;
+ bool displayed = false;
+ QString lastDisplayedEventId;
QHash<const User*, QString> lastReadEventIds;
QString prevBatch;
QPointer<RoomMessagesJob> roomMessagesJob;
@@ -214,6 +215,9 @@ Room::Room(Connection* connection, QString id, JoinState initialJoinState)
// See "Accessing the Public Class" section in
// https://marcmutz.wordpress.com/translated-articles/pimp-my-pimpl-%E2%80%94-reloaded/
d->q = this;
+ connect(this, &Room::userAdded, this, &Room::memberListChanged);
+ connect(this, &Room::userRemoved, this, &Room::memberListChanged);
+ connect(this, &Room::memberRenamed, this, &Room::memberListChanged);
qCDebug(MAIN) << "New" << toCString(initialJoinState) << "Room:" << id;
}
@@ -413,6 +417,45 @@ Room::rev_iter_t Room::findInTimeline(const QString& evtId) const
return timelineEdge();
}
+bool Room::displayed() const
+{
+ return d->displayed;
+}
+
+void Room::setDisplayed(bool displayed)
+{
+ if (d->displayed == displayed)
+ return;
+
+ d->displayed = displayed;
+ emit displayedChanged(displayed);
+ if( displayed )
+ {
+ resetHighlightCount();
+ resetNotificationCount();
+ }
+}
+
+QString Room::lastDisplayedEventId() const
+{
+ return d->lastDisplayedEventId;
+}
+
+void Room::setLastDisplayedEventId(const QString& eventId)
+{
+ if (d->lastDisplayedEventId == eventId)
+ return;
+
+ d->lastDisplayedEventId = eventId;
+ emit lastDisplayedEventIdChanged();
+}
+
+void Room::setLastDisplayedEvent(TimelineItem::index_t index)
+{
+ Q_ASSERT(isValidIndex(index));
+ setLastDisplayedEventId(findInTimeline(index)->event()->id());
+}
+
Room::rev_iter_t Room::readMarker(const User* user) const
{
Q_ASSERT(user);
diff --git a/room.h b/room.h
index ac540fea..33514ac9 100644
--- a/room.h
+++ b/room.h
@@ -105,6 +105,13 @@ namespace QMatrixClient
Q_PROPERTY(QString canonicalAlias READ canonicalAlias NOTIFY namesChanged)
Q_PROPERTY(QString displayName READ displayName NOTIFY namesChanged)
Q_PROPERTY(QString topic READ topic NOTIFY topicChanged)
+ Q_PROPERTY(int timelineSize READ timelineSize NOTIFY addedMessages)
+ Q_PROPERTY(QStringList memberNames READ memberNames NOTIFY memberListChanged)
+ Q_PROPERTY(int memberCount READ memberCount NOTIFY memberListChanged)
+
+ Q_PROPERTY(bool displayed READ displayed WRITE setDisplayed NOTIFY displayedChanged)
+ Q_PROPERTY(QString lastDisplayedEventId READ lastDisplayedEventId WRITE setLastDisplayedEventId NOTIFY lastDisplayedEventIdChanged)
+
Q_PROPERTY(QString readMarkerEventId READ readMarkerEventId WRITE markMessagesAsRead NOTIFY readMarkerMoved)
public:
using Timeline = std::deque<TimelineItem>;
@@ -127,9 +134,9 @@ namespace QMatrixClient
QList<User*> membersLeft() const;
Q_INVOKABLE QList<User*> users() const;
- Q_INVOKABLE QStringList memberNames() const;
- Q_INVOKABLE int memberCount() const;
- Q_INVOKABLE int timelineSize() const;
+ QStringList memberNames() const;
+ int memberCount() const;
+ int timelineSize() const;
/**
* Returns a square room avatar with the given size and requests it
@@ -170,6 +177,11 @@ namespace QMatrixClient
rev_iter_t findInTimeline(TimelineItem::index_t index) const;
rev_iter_t findInTimeline(const QString& evtId) const;
+ bool displayed() const;
+ void setDisplayed(bool displayed = true);
+ QString lastDisplayedEventId() const;
+ void setLastDisplayedEventId(const QString& eventId);
+ void setLastDisplayedEvent(TimelineItem::index_t index);
rev_iter_t readMarker(const User* user) const;
rev_iter_t readMarker() const;
QString readMarkerEventId() const;
@@ -250,10 +262,16 @@ namespace QMatrixClient
void userAdded(User* user);
void userRemoved(User* user);
void memberRenamed(User* user);
+ void memberListChanged();
+
void joinStateChanged(JoinState oldState, JoinState newState);
void typingChanged();
+
void highlightCountChanged(Room* room);
void notificationCountChanged(Room* room);
+
+ void displayedChanged(bool displayed);
+ void lastDisplayedEventIdChanged();
void lastReadEventChanged(User* user);
void readMarkerMoved();
void unreadMessagesChanged(Room* room);