diff --git a/Quotient/connection.cpp b/Quotient/connection.cpp index 2071dfe73..433e3f6c5 100644 --- a/Quotient/connection.cpp +++ b/Quotient/connection.cpp @@ -378,7 +378,6 @@ QFuture Connection::Private::setupPicklingKey() default: qWarning(E2EE) << "Error loading pickling key - please fix your keychain:" << readJob->errorString(); - //TODO: We probably want to fail entirely here. } return {}; }) @@ -583,6 +582,7 @@ void Connection::sync(int timeout) auto result = (*d->cryptoMachine)->has_pending_backup_key(); if (!result->has_error()) { if (result->value()) { + //TODO only if backup is not already initialized d->initializeExistingBackup(); } @@ -592,8 +592,7 @@ void Connection::sync(int timeout) auto request = requestResult->value(); if (request->has_request()) { //TODO make sure that this is only run once simultaneously - auto transaction_id = request->transaction_id(); - callApi(stringFromRust(request->version()), fromJson>(jsonFromRust(request->rooms()))).onResult([this, transaction_id](const auto& job){ + callApi(stringFromRust(request->version()), fromJson>(jsonFromRust(request->rooms()))).onResult([this, transaction_id = request->transaction_id()](const auto& job){ (*d->cryptoMachine)->mark_keys_backup_as_sent(bytesToRust(job->rawData()), transaction_id); }); } @@ -714,11 +713,13 @@ void Connection::Private::processOutgoingRequests() (*cryptoMachine)->mark_keys_upload_as_sent(bytesToRust(job->rawData()), stringToRust(id)); }).QFuture::then([](auto){})); } else if (type == 1) { // Keys query - futures.append(q->callApi(fromJson>(jsonFromRust(request.keys_query_device_keys())), request.keys_query_timeout() /*TODO check correctness*/).then([id, this](const auto &job){ + auto timeout = request.keys_query_timeout(); + futures.append(q->callApi(fromJson>(jsonFromRust(request.keys_query_device_keys())), timeout > 0 ? timeout : std::optional()).then([id, this](const auto &job){ (*cryptoMachine)->mark_keys_query_as_sent(bytesToRust(job->rawData()), stringToRust(id)); }).QFuture::then([](auto){})); } else if (type == 2) { // keys claim - futures.append(q->callApi(fromJson>>(jsonFromRust(request.keys_claim_one_time_keys())), std::nullopt /*TODO: timeout */).then([id, this](const auto& job){ + auto timeout = request.keys_claim_timeout(); + futures.append(q->callApi(fromJson>>(jsonFromRust(request.keys_claim_one_time_keys())), timeout > 0 ? timeout : std::optional()).then([id, this](const auto& job){ (*cryptoMachine)->mark_keys_claim_as_sent(bytesToRust(job->rawData()), stringToRust(id)); }).QFuture::then([](auto){})); } else if (type == 3) { // to device @@ -735,7 +736,7 @@ void Connection::Private::processOutgoingRequests() auto transactionId = stringFromRust(request.room_msg_txn_id()); //TODO: this is wrong (content <-> full), but i also think we don't need it json[u"unsigned"_s] = QJsonObject { {u"transaction_id"_s, transactionId} }; //TODO: make Room::postJson return a future, then also append to the outer future - auto actualTransactionId = room->postJson(stringFromRust(request.room_msg_matrix_type()), json); + auto actualTransactionId = room->postJson(stringFromRust(request.room_msg_matrix_type()), json)->transactionId(); connectUntil(room, &Room::messageSent, q, [this, actualTransactionId, id](const auto& txnId, const auto &event) { if (txnId != actualTransactionId) { return false; @@ -2211,7 +2212,7 @@ void Connection::Private::requestUserVerification(KeyVerificationSession* sessio qWarning() << stringFromRust(request->error_string()); return; } - auto transactionId = session->room()->postJson(u"m.room.message"_s, jsonFromRust(request->value())); + auto transactionId = session->room()->postJson(u"m.room.message"_s, jsonFromRust(request->value()))->transactionId(); connectUntil(session->room(), &Room::pendingEventAboutToMerge, q, [this, transactionId, session](const auto &event) { if (event->transactionId() != transactionId) { return false; diff --git a/Quotient/crypto-sdk/src/lib.rs b/Quotient/crypto-sdk/src/lib.rs index 7bb800c88..ba9acd010 100644 --- a/Quotient/crypto-sdk/src/lib.rs +++ b/Quotient/crypto-sdk/src/lib.rs @@ -225,6 +225,7 @@ mod ffi { fn keys_upload_fallback_keys(self: &OutgoingRequest) -> String; fn keys_query_device_keys(self: &OutgoingRequest) -> String; fn keys_query_timeout(self: &OutgoingRequest) -> usize; + fn keys_claim_timeout(self: &OutgoingRequest) -> usize; fn keys_claim_one_time_keys(self: &OutgoingRequest) -> String; fn to_device_event_type(self: &OutgoingRequest) -> String; fn to_device_messages(self: &OutgoingRequest) -> String; diff --git a/Quotient/crypto-sdk/src/request.rs b/Quotient/crypto-sdk/src/request.rs index 3b6943706..fbeda3810 100644 --- a/Quotient/crypto-sdk/src/request.rs +++ b/Quotient/crypto-sdk/src/request.rs @@ -192,6 +192,17 @@ impl OutgoingRequest { } } + pub(crate) fn keys_claim_timeout(&self) -> usize { + if let OutgoingRequests::KeysClaim(request) = self.0.request() { + request + .timeout + .unwrap_or(Duration::from_millis(0)) + .as_millis() as usize + } else { + panic!() + } + } + pub(crate) fn keys_claim_one_time_keys(&self) -> String { if let OutgoingRequests::KeysClaim(request) = self.0.request() { serde_json::to_string(&request.one_time_keys).unwrap() diff --git a/Quotient/room.cpp b/Quotient/room.cpp index 40ef952c5..6f1a97f5d 100644 --- a/Quotient/room.cpp +++ b/Quotient/room.cpp @@ -2110,9 +2110,9 @@ const PendingEventItem& Room::post(RoomEventPtr event) return d->sendEvent(std::move(event)); } -QString Room::postJson(const QString& matrixType, const QJsonObject& eventContent) +const PendingEventItem& Room::postJson(const QString& matrixType, const QJsonObject& eventContent) { - return d->sendEvent(loadEvent(matrixType, eventContent))->transactionId(); + return d->sendEvent(loadEvent(matrixType, eventContent)); } SetRoomStateWithKeyJob* Room::setState(const StateEvent& evt) diff --git a/Quotient/room.h b/Quotient/room.h index 0248821f0..7fa2f1f1c 100644 --- a/Quotient/room.h +++ b/Quotient/room.h @@ -767,7 +767,7 @@ public Q_SLOTS: */ [[deprecated("Use post() instead")]] QString postEvent(RoomEvent* event); - QString postJson(const QString& matrixType, const QJsonObject& eventContent); + const PendingEventItem& postJson(const QString& matrixType, const QJsonObject& eventContent); QString retryMessage(const QString& txnId); void discardMessage(const QString& txnId);