Skip to content
Snippets Groups Projects
Verified Commit 5f8e80cd authored by Nicolas Werner's avatar Nicolas Werner
Browse files

Fix event expiration not always stopping properly and redacting some wrong state events

parent 6c180a5c
No related branches found
No related tags found
No related merge requests found
...@@ -1642,6 +1642,7 @@ utils::removeExpiredEvents() ...@@ -1642,6 +1642,7 @@ utils::removeExpiredEvents()
std::string filter; std::string filter;
std::string currentRoom; std::string currentRoom;
bool firstMessagesCall = true;
std::uint64_t currentRoomCount = 0; std::uint64_t currentRoomCount = 0;
std::string currentRoomPrevToken; std::string currentRoomPrevToken;
std::set<std::pair<std::string, std::string>> currentRoomStateEvents; std::set<std::pair<std::string, std::string>> currentRoomStateEvents;
...@@ -1685,6 +1686,13 @@ utils::removeExpiredEvents() ...@@ -1685,6 +1686,13 @@ utils::removeExpiredEvents()
} }
}); });
} else if (!state->currentRoom.empty()) { } 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{}; mtx::http::MessagesOpts opts{};
opts.dir = mtx::http::PaginationDirection::Backwards; opts.dir = mtx::http::PaginationDirection::Backwards;
opts.from = state->currentRoomPrevToken; opts.from = state->currentRoomPrevToken;
...@@ -1692,17 +1700,21 @@ utils::removeExpiredEvents() ...@@ -1692,17 +1700,21 @@ utils::removeExpiredEvents()
opts.filter = state->filter; opts.filter = state->filter;
opts.room_id = state->currentRoom; opts.room_id = state->currentRoom;
state->firstMessagesCall = false;
http::client()->messages( http::client()->messages(
opts, opts,
[state = std::move(state)](const mtx::responses::Messages &msgs, [state = std::move(state)](const mtx::responses::Messages &msgs,
mtx::http::RequestErr error) mutable { 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->currentRoom.clear();
state->currentRoomCount = 0; } else if (msgs.chunk.empty()) {
state->currentRoomPrevToken.clear(); state->currentRoomPrevToken.clear();
} else { } else {
if (!msgs.end.empty()) state->currentRoomPrevToken = msgs.end;
state->currentRoomPrevToken = msgs.end;
auto now = (uint64_t)QDateTime::currentMSecsSinceEpoch(); auto now = (uint64_t)QDateTime::currentMSecsSinceEpoch();
auto us = http::client()->user_id().to_string(); auto us = http::client()->user_id().to_string();
...@@ -1775,13 +1787,6 @@ utils::removeExpiredEvents() ...@@ -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)); next(std::move(state));
}); });
} else if (!state->roomsToUpdate.empty()) { } else if (!state->roomsToUpdate.empty()) {
...@@ -1795,6 +1800,12 @@ utils::removeExpiredEvents() ...@@ -1795,6 +1800,12 @@ utils::removeExpiredEvents()
state->currentRoom = room; state->currentRoom = room;
state->currentExpiry = state->globalExpiry->content; state->currentExpiry = state->globalExpiry->content;
} }
state->firstMessagesCall = true;
state->currentRoomCount = 0;
state->currentRoomPrevToken = "";
state->currentRoomRedactionQueue.clear();
state->currentRoomStateEvents.clear();
state->roomsToUpdate.pop_back(); state->roomsToUpdate.pop_back();
next(std::move(state)); next(std::move(state));
} else { } else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment