mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-12-01 22:58:49 +03:00
Also request keys from own devices
This commit is contained in:
parent
1f9215a5be
commit
7eb0c4e09c
1 changed files with 26 additions and 22 deletions
34
src/Olm.cpp
34
src/Olm.cpp
|
@ -317,22 +317,25 @@ send_key_request_for(const std::string &room_id,
|
||||||
using namespace mtx::events;
|
using namespace mtx::events;
|
||||||
|
|
||||||
nhlog::crypto()->debug("sending key request: {}", json(e).dump(2));
|
nhlog::crypto()->debug("sending key request: {}", json(e).dump(2));
|
||||||
auto payload = json{{"action", "request"},
|
|
||||||
{"request_id", http::client()->generate_txn_id()},
|
|
||||||
{"requesting_device_id", http::client()->device_id()},
|
|
||||||
{"body",
|
|
||||||
{{"algorithm", MEGOLM_ALGO},
|
|
||||||
{"room_id", room_id},
|
|
||||||
{"sender_key", e.content.sender_key},
|
|
||||||
{"session_id", e.content.session_id}}}};
|
|
||||||
|
|
||||||
json body;
|
mtx::events::msg::KeyRequest request;
|
||||||
body["messages"][e.sender] = json::object();
|
request.action = mtx::events::msg::RequestAction::Request;
|
||||||
body["messages"][e.sender][e.content.device_id] = payload;
|
request.algorithm = MEGOLM_ALGO;
|
||||||
|
request.room_id = room_id;
|
||||||
|
request.sender_key = e.content.sender_key;
|
||||||
|
request.session_id = e.content.session_id;
|
||||||
|
request.request_id = "key_request." + http::client()->generate_txn_id();
|
||||||
|
request.requesting_device_id = http::client()->device_id();
|
||||||
|
|
||||||
nhlog::crypto()->debug("m.room_key_request: {}", body.dump(2));
|
nhlog::crypto()->debug("m.room_key_request: {}", json(request).dump(2));
|
||||||
|
|
||||||
http::client()->send_to_device("m.room_key_request", body, [e](mtx::http::RequestErr err) {
|
std::map<mtx::identifiers::User, std::map<std::string, decltype(request)>> body;
|
||||||
|
body[mtx::identifiers::parse<mtx::identifiers::User>(e.sender)][e.content.device_id] =
|
||||||
|
request;
|
||||||
|
body[http::client()->user_id()]["*"] = request;
|
||||||
|
|
||||||
|
http::client()->send_to_device(
|
||||||
|
http::client()->generate_txn_id(), body, [e](mtx::http::RequestErr err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
nhlog::net()->warn("failed to send "
|
nhlog::net()->warn("failed to send "
|
||||||
"send_to_device "
|
"send_to_device "
|
||||||
|
@ -340,8 +343,9 @@ send_key_request_for(const std::string &room_id,
|
||||||
err->matrix_error.error);
|
err->matrix_error.error);
|
||||||
}
|
}
|
||||||
|
|
||||||
nhlog::net()->info(
|
nhlog::net()->info("m.room_key_request sent to {}:{} and your own devices",
|
||||||
"m.room_key_request sent to {}:{}", e.sender, e.content.device_id);
|
e.sender,
|
||||||
|
e.content.device_id);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue