aboutsummaryrefslogtreecommitdiff
path: root/room.h
diff options
context:
space:
mode:
authorKitsuneRal <Kitsune-Ral@users.sf.net>2016-11-25 23:34:22 +0900
committerGitHub <noreply@github.com>2016-11-25 23:34:22 +0900
commit8113e61fec79b60be5c534af0d1b19e92d970e67 (patch)
tree0dbb26337b623266948c4b917d5c0f95795a8adc /room.h
parentf84b3afb1e7c4662bdda55b9cf8e871083350937 (diff)
parent8b69437b14021b23c208b27857d139bd2c2bb186 (diff)
downloadlibquotient-8113e61fec79b60be5c534af0d1b19e92d970e67.tar.gz
libquotient-8113e61fec79b60be5c534af0d1b19e92d970e67.zip
Merge pull request #48 from Fxrh/kitsune-unread-messages-in-lib
Unread messages implementation in the library
Diffstat (limited to 'room.h')
-rw-r--r--room.h46
1 files changed, 36 insertions, 10 deletions
diff --git a/room.h b/room.h
index 637c93f2..7cfd4c00 100644
--- a/room.h
+++ b/room.h
@@ -31,10 +31,12 @@ namespace QMatrixClient
class Event;
class Connection;
class User;
+ class MemberSorter;
class Room: public QObject
{
Q_OBJECT
+ Q_PROPERTY(QString readMarkerEventId READ readMarkerEventId WRITE markMessagesAsRead NOTIFY readMarkerPromoted)
public:
using Timeline = Owning<Events>;
@@ -68,27 +70,31 @@ namespace QMatrixClient
Q_INVOKABLE void updateData(SyncRoomData& data );
Q_INVOKABLE void setJoinState( JoinState state );
- Q_INVOKABLE QString lastReadEvent(User* user);
+ Q_INVOKABLE QString lastReadEvent(User* user) const;
+ QString readMarkerEventId() const;
/**
- * @brief Mark the message at the iterator as read
+ * @brief Mark the event with uptoEventId as read
*
- * Marks the message at the iterator as read; also posts a read
- * receipt to the server either for this message or, if it's from
- * the local user, for the nearest non-local message before.
+ * Finds in the timeline and marks as read the event with
+ * the specified id; also posts a read receipt to the server either
+ * for this message or, if it's from the local user, for
+ * the nearest non-local message before.
*/
- Q_INVOKABLE void markMessagesAsRead(Timeline::const_iterator last);
+ Q_INVOKABLE void markMessagesAsRead(QString uptoEventId);
/**
- * @brief Mark the most recent message in the timeline as read
- *
- * This effectively marks everything in the room as read.
+ * @brief Mark the whole room timeline as read
*/
Q_INVOKABLE void markMessagesAsRead();
+ Q_INVOKABLE bool hasUnreadMessages();
+
Q_INVOKABLE int notificationCount() const;
Q_INVOKABLE void resetNotificationCount();
Q_INVOKABLE int highlightCount() const;
Q_INVOKABLE void resetHighlightCount();
+ MemberSorter memberSorter() const;
+
public slots:
void getPreviousContent();
void userRenamed(User* user, QString oldName);
@@ -115,6 +121,8 @@ namespace QMatrixClient
void highlightCountChanged(Room* room);
void notificationCountChanged(Room* room);
void lastReadEventChanged(User* user);
+ void readMarkerPromoted();
+ void unreadMessagesChanged(Room* room);
protected:
Connection* connection() const;
@@ -123,7 +131,7 @@ namespace QMatrixClient
virtual void processStateEvents(const Events& events);
virtual void processEphemeralEvent(Event* event);
- bool promoteReadMarker(User* user, QString eventId);
+ Timeline::const_iterator promoteReadMarker(User* u, QString eventId);
private:
class Private;
@@ -134,4 +142,22 @@ namespace QMatrixClient
void setLastReadEvent(User* user, QString eventId);
};
+
+ class MemberSorter
+ {
+ public:
+ MemberSorter(const Room* r) : room(r) { }
+
+ bool operator()(User* u1, User* u2) const;
+
+ template <typename ContT>
+ typename ContT::size_type lowerBoundIndex(const ContT& c,
+ typename ContT::value_type v) const
+ {
+ return std::lower_bound(c.begin(), c.end(), v, *this) - c.begin();
+ }
+
+ private:
+ const Room* room;
+ };
}