aboutsummaryrefslogtreecommitdiff
path: root/lib/room.cpp
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2021-07-24 21:06:13 +0200
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2021-08-10 08:10:31 +0200
commit5276e4321c6b3348fc5b1d3d16f93131d9676e76 (patch)
treef3dbe61209c8dc5e86c992bddbef83a0c71110bc /lib/room.cpp
parent5d9443fccf2d336f16d6beacb5e1775c79123c02 (diff)
downloadlibquotient-5276e4321c6b3348fc5b1d3d16f93131d9676e76.tar.gz
libquotient-5276e4321c6b3348fc5b1d3d16f93131d9676e76.zip
Room::Private::sync/historyEdge()
Move Room::sync/historyEdge() implementation to Room::Private, so that internal logic could use the same readable shortcuts without q-> prefixes, instead of timeline.crend() and timeline.cend() that are much less readable.
Diffstat (limited to 'lib/room.cpp')
-rw-r--r--lib/room.cpp39
1 files changed, 19 insertions, 20 deletions
diff --git a/lib/room.cpp b/lib/room.cpp
index 47a0ec94..9fe70678 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -101,8 +101,8 @@ public:
UnorderedMap<StateEventKey, StateEventPtr> baseState;
/// State event stubs - events without content, just type and state key
static decltype(baseState) stubbedState;
- /// The state of the room at timeline position after-maxTimelineIndex()
- /// \sa Room::syncEdge
+ /// The state of the room at syncEdge()
+ /// \sa syncEdge
QHash<StateEventKey, const StateEventBase*> currentState;
/// Servers with aliases for this room except the one of the local user
/// \sa Room::remoteAliases
@@ -198,6 +198,8 @@ public:
/// A point in the timeline corresponding to baseState
rev_iter_t timelineBase() const { return q->findInTimeline(-1); }
+ rev_iter_t historyEdge() const { return timeline.crend(); }
+ Timeline::const_iterator syncEdge() const { return timeline.cend(); }
void getPreviousContent(int limit = 10, const QString &filter = {});
@@ -638,7 +640,7 @@ void Room::Private::updateUnreadCount(const rev_iter_t& from,
// unreadMessages and might need to promote the read marker further
// over local-origin messages.
auto readMarker = q->readMarker();
- if (readMarker == timeline.crend() && q->allHistoryLoaded())
+ if (readMarker == historyEdge() && q->allHistoryLoaded())
--readMarker; // Read marker not found in the timeline, initialise it
if (readMarker >= from && readMarker < to) {
promoteReadMarker(q->localUser(), readMarker, true);
@@ -682,7 +684,7 @@ Room::Changes Room::Private::promoteReadMarker(User* u,
// iterators
return Change::NoChange;
- Q_ASSERT(newMarker < timeline.crend());
+ Q_ASSERT(newMarker < historyEdge());
// Try to auto-promote the read marker over the user's own messages
// (switch to direct iterators for that).
@@ -697,7 +699,7 @@ Room::Changes Room::Private::promoteReadMarker(User* u,
QElapsedTimer et;
et.start();
unreadMessages =
- int(count_if(eagerMarker, timeline.cend(),
+ int(count_if(eagerMarker, syncEdge(),
[this](const auto& ti) { return isEventNotable(ti); }));
if (et.nsecsElapsed() > profilerMinNsecs() / 10)
qCDebug(PROFILER) << "Recounting unread messages took" << et;
@@ -771,12 +773,9 @@ bool Room::hasUnreadMessages() const { return unreadCount() >= 0; }
int Room::unreadCount() const { return d->unreadMessages; }
-Room::rev_iter_t Room::historyEdge() const { return d->timeline.crend(); }
+Room::rev_iter_t Room::historyEdge() const { return d->historyEdge(); }
-Room::Timeline::const_iterator Room::syncEdge() const
-{
- return d->timeline.cend();
-}
+Room::Timeline::const_iterator Room::syncEdge() const { return d->syncEdge(); }
TimelineItem::index_t Room::minTimelineIndex() const
{
@@ -855,7 +854,7 @@ void Room::Private::getAllMembers()
// the full members list was requested.
if (!timeline.empty())
for (auto it = q->findInTimeline(nextIndex).base();
- it != timeline.cend(); ++it)
+ it != syncEdge(); ++it)
if (is<RoomMemberEvent>(**it))
roomChanges |= q->processStateEvent(**it);
if (roomChanges & MembersChange)
@@ -2357,7 +2356,7 @@ Room::Changes Room::Private::addNewMessageEvents(RoomEvents&& events)
emit q->aboutToAddNewMessages(eventsSpan);
auto insertedSize = moveEventsToTimeline(eventsSpan, Newer);
totalInserted += insertedSize;
- auto firstInserted = timeline.cend() - insertedSize;
+ auto firstInserted = syncEdge() - insertedSize;
q->onAddNewTimelineEvents(firstInserted);
emit q->addedMessages(firstInserted->index(),
timeline.back().index());
@@ -2387,20 +2386,20 @@ Room::Changes Room::Private::addNewMessageEvents(RoomEvents&& events)
unsyncedEvents.erase(unsyncedEvents.begin() + pendingEvtIdx);
if (auto insertedSize = moveEventsToTimeline({ remoteEcho, it }, Newer)) {
totalInserted += insertedSize;
- q->onAddNewTimelineEvents(timeline.cend() - insertedSize);
+ q->onAddNewTimelineEvents(syncEdge() - insertedSize);
}
emit q->pendingEventMerged();
}
// Events merged and transferred from `events` to `timeline` now.
- const auto from = timeline.cend() - totalInserted;
+ const auto from = syncEdge() - totalInserted;
if (q->supportsCalls())
- for (auto it = from; it != timeline.cend(); ++it)
+ for (auto it = from; it != syncEdge(); ++it)
if (const auto* evt = it->viewAs<CallEventBase>())
emit q->callEvent(q, evt);
if (totalInserted > 0) {
- for (auto it = from; it != timeline.cend(); ++it) {
+ for (auto it = from; it != syncEdge(); ++it) {
if (const auto* reaction = it->viewAs<ReactionEvent>()) {
const auto& relation = reaction->relation();
relations[{ relation.eventId, relation.type }] << reaction;
@@ -2420,7 +2419,7 @@ Room::Changes Room::Private::addNewMessageEvents(RoomEvents&& events)
// the new message events.
if (const auto senderId = (*from)->senderId(); !senderId.isEmpty()) {
auto* const firstWriter = q->user(senderId);
- if (q->readMarker(firstWriter) != timeline.crend()) {
+ if (q->readMarker(firstWriter) != historyEdge()) {
roomChanges |=
promoteReadMarker(firstWriter, rev_iter_t(from) - 1);
qCDebug(MESSAGES)
@@ -2461,14 +2460,14 @@ void Room::Private::addHistoricalMessageEvents(RoomEvents&& events)
emit q->aboutToAddHistoricalMessages(events);
const auto insertedSize = moveEventsToTimeline(events, Older);
- const auto from = timeline.crend() - insertedSize;
+ const auto from = historyEdge() - insertedSize;
qCDebug(STATE) << "Room" << displayname << "received" << insertedSize
<< "past events; the oldest event is now" << timeline.front();
q->onAddHistoricalTimelineEvents(from);
emit q->addedMessages(timeline.front().index(), from->index());
- for (auto it = from; it != timeline.crend(); ++it) {
+ for (auto it = from; it != historyEdge(); ++it) {
if (const auto* reaction = it->viewAs<ReactionEvent>()) {
const auto& relation = reaction->relation();
relations[{ relation.eventId, relation.type }] << reaction;
@@ -2476,7 +2475,7 @@ void Room::Private::addHistoricalMessageEvents(RoomEvents&& events)
}
}
if (from <= q->readMarker())
- updateUnreadCount(from, timeline.crend());
+ updateUnreadCount(from, historyEdge());
Q_ASSERT(timeline.size() == timelineSize + insertedSize);
if (insertedSize > 9 || et.nsecsElapsed() >= profilerMinNsecs())