diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2023-07-06 20:13:39 +0200 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2023-07-06 20:13:39 +0200 |
commit | 5f8e80cd84710520e86e1c526b444e756742867e (patch) | |
tree | 74463fb1ddd979a1deb63b05f04cba01271ae9fa /src | |
parent | Prevent redactions of ACL and Create events, since Synapse prevents redaction... (diff) | |
download | nheko-5f8e80cd84710520e86e1c526b444e756742867e.tar.xz |
Fix event expiration not always stopping properly and redacting some wrong state events
Diffstat (limited to 'src')
-rw-r--r-- | src/Utils.cpp | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/src/Utils.cpp b/src/Utils.cpp index 9001bd2d..20c6f7d1 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -1642,6 +1642,7 @@ utils::removeExpiredEvents() std::string filter; std::string currentRoom; + bool firstMessagesCall = true; std::uint64_t currentRoomCount = 0; std::string currentRoomPrevToken; std::set<std::pair<std::string, std::string>> currentRoomStateEvents; @@ -1685,6 +1686,13 @@ utils::removeExpiredEvents() } }); } else if (!state->currentRoom.empty()) { + if (state->currentRoomPrevToken.empty() && !state->firstMessagesCall) { + nhlog::net()->info("Finished room {}", state->currentRoom); + state->currentRoom.clear(); + next(std::move(state)); + return; + } + mtx::http::MessagesOpts opts{}; opts.dir = mtx::http::PaginationDirection::Backwards; opts.from = state->currentRoomPrevToken; @@ -1692,17 +1700,21 @@ utils::removeExpiredEvents() opts.filter = state->filter; opts.room_id = state->currentRoom; + state->firstMessagesCall = false; + http::client()->messages( opts, [state = std::move(state)](const mtx::responses::Messages &msgs, mtx::http::RequestErr error) mutable { - if (error || msgs.chunk.empty()) { + if (error) { + // skip success handler + nhlog::net()->info( + "Finished room {} with error {}", state->currentRoom, *error); state->currentRoom.clear(); - state->currentRoomCount = 0; + } else if (msgs.chunk.empty()) { state->currentRoomPrevToken.clear(); } else { - if (!msgs.end.empty()) - state->currentRoomPrevToken = msgs.end; + state->currentRoomPrevToken = msgs.end; auto now = (uint64_t)QDateTime::currentMSecsSinceEpoch(); auto us = http::client()->user_id().to_string(); @@ -1775,13 +1787,6 @@ utils::removeExpiredEvents() } } - if (msgs.end.empty() && state->currentRoomRedactionQueue.empty()) { - state->currentRoom.clear(); - state->currentRoomCount = 0; - state->currentRoomPrevToken.clear(); - state->currentRoomStateEvents.clear(); - } - next(std::move(state)); }); } else if (!state->roomsToUpdate.empty()) { @@ -1795,6 +1800,12 @@ utils::removeExpiredEvents() state->currentRoom = room; state->currentExpiry = state->globalExpiry->content; } + state->firstMessagesCall = true; + state->currentRoomCount = 0; + state->currentRoomPrevToken = ""; + state->currentRoomRedactionQueue.clear(); + state->currentRoomStateEvents.clear(); + state->roomsToUpdate.pop_back(); next(std::move(state)); } else { |