Clean up key requests + autoreload

This commit is contained in:
Nicolas Werner 2020-10-20 19:46:37 +02:00
parent 983690c94f
commit cea7f4574f
11 changed files with 84 additions and 56 deletions

View file

@ -212,6 +212,28 @@ EventStore::clearTimeline()
emit endResetModel();
}
void
EventStore::receivedSessionKey(const std::string &session_id)
{
if (!pending_key_requests.count(session_id))
return;
auto request = pending_key_requests.at(session_id);
pending_key_requests.erase(session_id);
olm::send_key_request_for(request.events.front(), request.request_id, true);
for (const auto &e : request.events) {
auto idx = idToIndex(e.event_id);
if (idx) {
decryptedEvents_.remove({room_id_, e.event_id});
events_by_id_.remove({room_id_, e.event_id});
events_.remove({room_id_, toInternalIdx(*idx)});
emit dataChanged(*idx, *idx);
}
}
}
void
EventStore::handleSync(const mtx::responses::Timeline &events)
{
@ -294,18 +316,6 @@ EventStore::handleSync(const mtx::responses::Timeline &events)
*d_event)) {
handle_room_verification(*d_event);
}
// else {
// // only the key.verification.ready sent by localuser's other
// device
// // is of significance as it is used for detecting accepted request
// if (std::get_if<mtx::events::RoomEvent<
// mtx::events::msg::KeyVerificationReady>>(d_event)) {
// auto msg = std::get_if<mtx::events::RoomEvent<
// mtx::events::msg::KeyVerificationReady>>(d_event);
// ChatPage::instance()->receivedDeviceVerificationReady(
// msg->content);
// }
//}
}
}
}
@ -501,7 +511,7 @@ EventStore::decryptEvent(const IdIndex &idx,
if (decryptionResult.error) {
switch (*decryptionResult.error) {
case olm::DecryptionErrorCode::MissingSession:
case olm::DecryptionErrorCode::MissingSession: {
dummy.content.body =
tr("-- Encrypted Event (No keys found for decryption) --",
"Placeholder, when the message was not decrypted yet or can't be "
@ -512,8 +522,21 @@ EventStore::decryptEvent(const IdIndex &idx,
index.session_id,
e.sender);
// TODO: Check if this actually works and look in key backup
olm::send_key_request_for(room_id_, e);
auto copy = e;
copy.room_id = room_id_;
if (pending_key_requests.count(e.content.session_id)) {
pending_key_requests.at(e.content.session_id)
.events.push_back(copy);
} else {
PendingKeyRequests request;
request.request_id =
"key_request." + http::client()->generate_txn_id();
request.events.push_back(copy);
olm::send_key_request_for(copy, request.request_id);
pending_key_requests[e.content.session_id] = request;
}
break;
}
case olm::DecryptionErrorCode::DbError:
nhlog::db()->critical(
"failed to retrieve megolm session with index ({}, {}, {})",