aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-07-09 14:45:24 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-07-09 14:45:24 +0900
commit5bdfd6545c2c116c9260750cbc46ddc37eb455ef (patch)
treec8804cefed2ba15a57efefb7803680cb7a9cce5e
parent3002c73eebb9a7bb6eb03b9c6ac31bc232ff595b (diff)
downloadlibquotient-5bdfd6545c2c116c9260750cbc46ddc37eb455ef.tar.gz
libquotient-5bdfd6545c2c116c9260750cbc46ddc37eb455ef.zip
Room: Revert from visit() to a combination of ifs and eventCasts
Easier to read, and also easier compiler diagnostics if things go wrong. Still using visit() for state events processing though - it maintains that all lambdas return some value.
-rw-r--r--lib/room.cpp146
1 files changed, 73 insertions, 73 deletions
diff --git a/lib/room.cpp b/lib/room.cpp
index dc9f5ccc..06a0a380 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -1530,92 +1530,92 @@ bool Room::processStateEvent(const RoomEvent& e)
void Room::processEphemeralEvent(EventPtr&& event)
{
QElapsedTimer et; et.start();
- visit(*event
- , [this,et] (const TypingEvent& evt) {
- d->usersTyping.clear();
- for( const QString& userId: qAsConst(evt.users()) )
+ if (auto* evt = eventCast<TypingEvent>(event))
+ {
+ d->usersTyping.clear();
+ for( const QString& userId: qAsConst(evt->users()) )
+ {
+ auto u = user(userId);
+ if (memberJoinState(u) == JoinState::Join)
+ d->usersTyping.append(u);
+ }
+ if (!evt->users().isEmpty())
+ qCDebug(PROFILER) << "*** Room::processEphemeralEvent(typing):"
+ << evt->users().size() << "users," << et;
+ emit typingChanged();
+ }
+ if (auto* evt = eventCast<ReceiptEvent>(event))
+ {
+ for( const auto &p: qAsConst(evt->eventsWithReceipts()) )
+ {
{
- auto u = user(userId);
- if (memberJoinState(u) == JoinState::Join)
- d->usersTyping.append(u);
+ if (p.receipts.size() == 1)
+ qCDebug(EPHEMERAL) << "Marking" << p.evtId
+ << "as read for" << p.receipts[0].userId;
+ else
+ qCDebug(EPHEMERAL) << "Marking" << p.evtId
+ << "as read for" << p.receipts.size() << "users";
}
- if (!evt.users().isEmpty())
- qCDebug(PROFILER) << "*** Room::processEphemeralEvent(typing):"
- << evt.users().size() << "users," << et;
- emit typingChanged();
- }
- , [this,et] (const ReceiptEvent& evt) {
- for( const auto &p: qAsConst(evt.eventsWithReceipts()) )
+ const auto newMarker = findInTimeline(p.evtId);
+ if (newMarker != timelineEdge())
{
+ for( const Receipt& r: p.receipts )
{
- if (p.receipts.size() == 1)
- qCDebug(EPHEMERAL) << "Marking" << p.evtId
- << "as read for" << p.receipts[0].userId;
- else
- qCDebug(EPHEMERAL) << "Marking" << p.evtId
- << "as read for" << p.receipts.size() << "users";
+ if (r.userId == connection()->userId())
+ continue; // FIXME, #185
+ auto u = user(r.userId);
+ if (memberJoinState(u) == JoinState::Join)
+ d->promoteReadMarker(u, newMarker);
}
- const auto newMarker = findInTimeline(p.evtId);
- if (newMarker != timelineEdge())
- {
- for( const Receipt& r: p.receipts )
- {
- if (r.userId == connection()->userId())
- continue; // FIXME, #185
- auto u = user(r.userId);
- if (memberJoinState(u) == JoinState::Join)
- d->promoteReadMarker(u, newMarker);
- }
- } else
+ } else
+ {
+ qCDebug(EPHEMERAL) << "Event" << p.evtId
+ << "not found; saving read receipts anyway";
+ // If the event is not found (most likely, because it's too old
+ // and hasn't been fetched from the server yet), but there is
+ // a previous marker for a user, keep the previous marker.
+ // Otherwise, blindly store the event id for this user.
+ for( const Receipt& r: p.receipts )
{
- qCDebug(EPHEMERAL) << "Event" << p.evtId
- << "not found; saving read receipts anyway";
- // If the event is not found (most likely, because it's too old
- // and hasn't been fetched from the server yet), but there is
- // a previous marker for a user, keep the previous marker.
- // Otherwise, blindly store the event id for this user.
- for( const Receipt& r: p.receipts )
- {
- if (r.userId == connection()->userId())
- continue; // FIXME, #185
- auto u = user(r.userId);
- if (memberJoinState(u) == JoinState::Join &&
- readMarker(u) == timelineEdge())
- d->setLastReadEvent(u, p.evtId);
- }
+ if (r.userId == connection()->userId())
+ continue; // FIXME, #185
+ auto u = user(r.userId);
+ if (memberJoinState(u) == JoinState::Join &&
+ readMarker(u) == timelineEdge())
+ d->setLastReadEvent(u, p.evtId);
}
}
- if (!evt.eventsWithReceipts().isEmpty())
- qCDebug(PROFILER) << "*** Room::processEphemeralEvent(receipts):"
- << evt.eventsWithReceipts().size()
- << "events with receipts," << et;
}
- );
+ if (!evt->eventsWithReceipts().isEmpty())
+ qCDebug(PROFILER) << "*** Room::processEphemeralEvent(receipts):"
+ << evt->eventsWithReceipts().size()
+ << "events with receipts," << et;
+ }
}
void Room::processAccountDataEvent(EventPtr&& event)
{
- visit(*event
- , [this] (const TagEvent& evt) {
- auto newTags = evt.tags();
- if (newTags == d->tags)
- return;
- d->tags = newTags;
- qCDebug(MAIN) << "Room" << id() << "is tagged with:"
- << tagNames().join(", ");
- emit tagsChanged();
- }
- , [this] (const ReadMarkerEvent& evt) {
- auto readEventId = evt.event_id();
- qCDebug(MAIN) << "Server-side read marker at" << readEventId;
- d->serverReadMarker = readEventId;
- const auto newMarker = findInTimeline(readEventId);
- if (newMarker != timelineEdge())
- d->markMessagesAsRead(newMarker);
- else
- d->setLastReadEvent(localUser(), readEventId);
- }
- );
+ if (auto* evt = eventCast<TagEvent>(event))
+ {
+ auto newTags = evt->tags();
+ if (newTags == d->tags)
+ return;
+ d->tags = newTags;
+ qCDebug(MAIN) << "Room" << id() << "is tagged with:"
+ << tagNames().join(", ");
+ emit tagsChanged();
+ }
+ if (auto* evt = eventCast<ReadMarkerEvent>(event))
+ {
+ auto readEventId = evt->event_id();
+ qCDebug(MAIN) << "Server-side read marker at" << readEventId;
+ d->serverReadMarker = readEventId;
+ const auto newMarker = findInTimeline(readEventId);
+ if (newMarker != timelineEdge())
+ d->markMessagesAsRead(newMarker);
+ else
+ d->setLastReadEvent(localUser(), readEventId);
+ }
// For all account data events
auto& currentData = d->accountData[event->matrixType()];
// A polymorphic event-specific comparison might be a bit more