From b472fc355dc5ce70391ca2b9bc8da35b973ae3a3 Mon Sep 17 00:00:00 2001
From: Alexey Rusakov <Kitsune-Ral@users.sf.net>
Date: Mon, 8 Nov 2021 21:03:37 +0100
Subject: Room: lastLocalReadReceipt(), localReadReceiptMarker()

To simplify retrieval of the local m.read receipt and the marker for it.
---
 lib/room.cpp | 10 ++++++++++
 lib/room.h   | 16 ++++++++++++++--
 2 files changed, 24 insertions(+), 2 deletions(-)

(limited to 'lib')

diff --git a/lib/room.cpp b/lib/room.cpp
index ee76a85c..273a5753 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -1014,6 +1014,16 @@ ReadReceipt Room::lastReadReceipt(const QString& userId) const
     return d->lastReadReceipts.value(userId);
 }
 
+ReadReceipt Room::lastLocalReadReceipt() const
+{
+    return d->lastReadReceipts.value(localUser()->id());
+}
+
+Room::rev_iter_t Room::localReadReceiptMarker() const
+{
+    return findInTimeline(lastLocalReadReceipt().eventId);
+}
+
 QString Room::lastFullyReadEventId() const { return d->fullyReadUntilEventId; }
 
 Room::rev_iter_t Room::fullyReadMarker() const
diff --git a/lib/room.h b/lib/room.h
index 24025a88..d94de51c 100644
--- a/lib/room.h
+++ b/lib/room.h
@@ -400,8 +400,7 @@ public:
     //!
     //! See the documentation for the single-argument overload.
     //! \sa fullyReadMarker
-    [[deprecated("Use lastReadReceipt() to get m.read receipt or"
-                 " fullyReadMarker() to get m.fully_read marker")]] //
+    [[deprecated("Use localReadReceiptMarker() or fullyReadMarker()")]] //
     rev_iter_t readMarker() const;
     //! \brief Get the event id for the local user's fully-read marker
     //! \deprecated Use lastFullyReadEventId instead
@@ -420,6 +419,19 @@ public:
     //! \sa usersAtEventId
     ReadReceipt lastReadReceipt(const QString& userId) const;
 
+    //! \brief Get the latest read receipt from the local user
+    //!
+    //! This is a shortcut for <tt>lastReadReceipt(localUserId)</tt>.
+    //! \sa lastReadReceipt
+    ReadReceipt lastLocalReadReceipt() const;
+
+    //! \brief Find the timeline item the local read receipt is at
+    //!
+    //! This is a shortcut for \code
+    //! room->findInTimeline(room->lastLocalReadReceipt().eventId);
+    //! \endcode
+    rev_iter_t localReadReceiptMarker() const;
+
     //! \brief Get the latest event id marked as fully read
     //!
     //! This can be either the event id pointed to by the actual latest
-- 
cgit v1.2.3