diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-11-19 09:22:27 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-11-19 09:22:27 +0900 |
commit | e1fdb33a4161b29d6df590ccea339d361d9fc4e8 (patch) | |
tree | 730a6efb2a2987454855cfe01719e93004c67d1b /lib | |
parent | 06998c1406aab9943b62d6facb36cdee1cf52115 (diff) | |
download | libquotient-e1fdb33a4161b29d6df590ccea339d361d9fc4e8.tar.gz libquotient-e1fdb33a4161b29d6df590ccea339d361d9fc4e8.zip |
Don't cache empty events; prepare for lazy-loading
These two are intermingled in Room::addHistoricalMessageEvents because
processing empty events found in a historical batch is no different from
discovering (not lazy-loaded) members.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/room.cpp | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/lib/room.cpp b/lib/room.cpp index 5faff271..656788cb 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -1784,14 +1784,25 @@ void Room::Private::addHistoricalMessageEvents(RoomEvents&& events) const auto timelineSize = timeline.size(); dropDuplicateEvents(events); - RoomEventsRange normalEvents { - events.begin(), events.end() //remove_if(events.begin(), events.end(), isRedaction) - }; - if (normalEvents.empty()) + if (events.empty()) return; - emit q->aboutToAddHistoricalMessages(normalEvents); - const auto insertedSize = moveEventsToTimeline(normalEvents, Older); + // In case of lazy-loading new members may be loaded with historical + // messages. Also, the cache doesn't store events with empty content; + // so when such events show up in the timeline they should be properly + // incorporated. + for (const auto& eptr: events) + { + const auto& e = *eptr; + if (e.isStateEvent() && + !currentState.contains({e.matrixType(), e.stateKey()})) + { + q->processStateEvent(e); + } + } + + emit q->aboutToAddHistoricalMessages(events); + const auto insertedSize = moveEventsToTimeline(events, Older); const auto from = timeline.crend() - insertedSize; qCDebug(MAIN) << "Room" << displayname << "received" << insertedSize @@ -2085,7 +2096,15 @@ QJsonObject Room::Private::toJson() const for (const auto* evt: currentState) { Q_ASSERT(evt->isStateEvent()); - stateEvents.append(evt->fullJson()); + if ((evt->isRedacted() && !is<RoomMemberEvent>(*evt)) || + evt->contentJson().isEmpty()) + continue; + + auto json = evt->fullJson(); + auto unsignedJson = evt->unsignedJson(); + unsignedJson.remove(QStringLiteral("prev_content")); + json[UnsignedKeyL] = unsignedJson; + stateEvents.append(json); } const auto stateObjName = joinState == JoinState::Invite ? @@ -2098,7 +2117,10 @@ QJsonObject Room::Private::toJson() const { QJsonArray accountDataEvents; for (const auto& e: accountData) - accountDataEvents.append(e.second->fullJson()); + { + if (!e.second->contentJson().isEmpty()) + accountDataEvents.append(e.second->fullJson()); + } result.insert(QStringLiteral("account_data"), QJsonObject {{ QStringLiteral("events"), accountDataEvents }}); } |