aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/room.cpp22
-rw-r--r--lib/room.h11
2 files changed, 27 insertions, 6 deletions
diff --git a/lib/room.cpp b/lib/room.cpp
index 088d1d8e..fd4add3b 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -170,6 +170,9 @@ class Room::Private
void renameMember(User* u, QString oldName);
void removeMemberFromMap(const QString& username, User* u);
+ /// A point in the timeline corresponding to baseState
+ rev_iter_t timelineBase() const { return q->findInTimeline(-1); }
+
void getPreviousContent(int limit = 10);
template <typename EventT>
@@ -525,11 +528,21 @@ int Room::unreadCount() const
return d->unreadMessages;
}
-Room::rev_iter_t Room::timelineEdge() const
+Room::rev_iter_t Room::historyEdge() const
{
return d->timeline.crend();
}
+Room::Timeline::const_iterator Room::syncEdge() const
+{
+ return d->timeline.cend();
+}
+
+Room::rev_iter_t Room::timelineEdge() const
+{
+ return historyEdge();
+}
+
TimelineItem::index_t Room::minTimelineIndex() const
{
return d->timeline.empty() ? 0 : d->timeline.front().index();
@@ -1018,8 +1031,9 @@ Room::Timeline::difference_type Room::Private::moveEventsToTimeline(
{
Q_ASSERT(!events.empty());
// Historical messages arrive in newest-to-oldest order, so the process for
- // them is symmetric to the one for new messages.
- auto index = timeline.empty() ? -int(placement) :
+ // them is almost symmetric to the one for new messages. New messages get
+ // appended from index 0; old messages go backwards from index -1.
+ auto index = timeline.empty() ? -((placement+1)/2) /* 1 -> -1; -1 -> 0 */ :
placement == Older ? timeline.front().index() :
timeline.back().index();
auto baseIndex = index;
@@ -1040,7 +1054,7 @@ Room::Timeline::difference_type Room::Private::moveEventsToTimeline(
eventsIndex.insert(eId, index);
Q_ASSERT(q->findInTimeline(eId)->event()->id() == eId);
}
- const auto insertedSize = (index - baseIndex) * int(placement);
+ const auto insertedSize = (index - baseIndex) * placement;
Q_ASSERT(insertedSize == int(events.size()));
return insertedSize;
}
diff --git a/lib/room.h b/lib/room.h
index a9ed9647..0a0eb878 100644
--- a/lib/room.h
+++ b/lib/room.h
@@ -177,9 +177,16 @@ namespace QMatrixClient
const Timeline& messageEvents() const;
const PendingEvents& pendingEvents() const;
/**
- * A convenience method returning the read marker to
- * the before-oldest message
+ * A convenience method returning the read marker to the position
+ * before the "oldest" event; same as messageEvents().crend()
*/
+ rev_iter_t historyEdge() const;
+ /**
+ * A convenience method returning the iterator beyond the latest
+ * arrived event; same as messageEvents().cend()
+ */
+ Timeline::const_iterator syncEdge() const;
+ /// \deprecated Use historyEdge instead
rev_iter_t timelineEdge() const;
Q_INVOKABLE TimelineItem::index_t minTimelineIndex() const;
Q_INVOKABLE TimelineItem::index_t maxTimelineIndex() const;