Skip to content

Commit

Permalink
TODO----
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Fella committed Dec 30, 2024
1 parent 0d30215 commit e9c79e0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
30 changes: 26 additions & 4 deletions Quotient/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "room.h"
#include "settings.h"
#include "user.h"
#include "events/roommemberevent.h"

#include "csapi/account-data.h"
#include "csapi/cross_signing.h"
Expand Down Expand Up @@ -1962,23 +1963,44 @@ QFuture<void> Connection::shareRoomKey(Room* room)
auto result = promise.future();
promise.start();

auto visibilityString = room->currentState().get("m.room.history_visibility"_L1)->contentJson()["history_visibility"_L1].toString();
int visibility = 0;
if (visibilityString == u"joined"_s) {
visibility = 1;
} else if (visibilityString == u"shared"_s) {
visibility = 2;
} else if (visibilityString == u"world_readable"_s) {
visibility = 3;
}

rust::Vec<rust::String> ids;
for (const auto& id : room->joinedMemberIds()) { //TODO + invited
for (const auto& id : room->joinedMemberIds()) {
ids.push_back(stringToRust(id));
}

if (visibility == 0 || visibility == 3) {
// FIXME: Make this more efficient once we properly track invited users
for (const auto& event : room->currentState().eventsOfType(u"m.room.member"_s)) {
if (auto memberEvent = eventCast<const RoomMemberEvent>(event)) {
if (memberEvent->isInvite()) {
ids.push_back(stringToRust(memberEvent->stateKey()));
}
}
}
}

auto missingResult = (*d->cryptoMachine)->get_missing_sessions(ids);
if (missingResult->has_error()) {
qWarning() << stringFromRust(missingResult->error_string());
return {};
}
auto missing = missingResult->request();
auto id = missing->id();
callApi<ClaimKeysJob>(fromJson<QHash<UserId, QHash<QString, QString>>>(jsonFromRust(missing->one_time_keys()))).then([this, id, room, ids, p = std::move(promise)](const auto& job) mutable {
callApi<ClaimKeysJob>(fromJson<QHash<UserId, QHash<QString, QString>>>(jsonFromRust(missing->one_time_keys()))).then([this, visibility, id, room, ids, p = std::move(promise)](const auto& job) mutable {
(*d->cryptoMachine)->mark_keys_claim_as_sent(bytesToRust(job->rawData()), id);
//TODO: Wire up visibility + only_trusted
//TODO: if only_trusted, we do somehow need to send keys for verification sessions?
auto requestsResult = (*d->cryptoMachine)->share_room_key(stringToRust(room->id()), ids, false, 1);

auto requestsResult = (*d->cryptoMachine)->share_room_key(stringToRust(room->id()), ids, d->onlyEncryptForTrusted, visibility);
if (requestsResult->has_error()) {
qWarning() << stringFromRust(requestsResult->error_string());
return;
Expand Down
1 change: 1 addition & 0 deletions Quotient/connection_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Q_DECL_HIDDEN Quotient::Connection::Private {
bool lazyLoading = false;

bool isHandlingOutgoing = false;
bool onlyEncryptForTrusted = false;

//! \brief Check the homeserver and resolve it if needed, before connecting
//!
Expand Down

0 comments on commit e9c79e0

Please sign in to comment.