diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-11-11 15:33:03 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-11-14 21:55:50 +0900 |
commit | 2a72a0ad0f8b4a0d24c9c2262917ff658ca5fec4 (patch) | |
tree | 30c365e04589a988e5042bfe1603935513fa4a84 /lib | |
parent | 6ca6dde46b9c72fc8833bc6fb81614fb705424f2 (diff) | |
download | libquotient-2a72a0ad0f8b4a0d24c9c2262917ff658ca5fec4.tar.gz libquotient-2a72a0ad0f8b4a0d24c9c2262917ff658ca5fec4.zip |
Room: historyEdge(), syncEdge, Private::timelineBase()
Also: make moveEventsToTimeline() always put historical events from
position -1 rather than 0 so that Private::baseState could always
correspond to the before-0 position.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/room.cpp | 22 | ||||
-rw-r--r-- | lib/room.h | 11 |
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; } @@ -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; |