diff options
author | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2018-06-13 12:28:00 +0300 |
---|---|---|
committer | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2018-06-13 12:28:00 +0300 |
commit | 5d47cc3940076f6e7da4578d985253c869117f21 (patch) | |
tree | f851f52a57561787c2ba856d5d2d864825eea215 /src/Olm.cpp | |
parent | Add method to convert PendingMessage's to event types (diff) | |
download | nheko-5d47cc3940076f6e7da4578d985253c869117f21.tar.xz |
Add support for sending encrypted messages
Diffstat (limited to 'src/Olm.cpp')
-rw-r--r-- | src/Olm.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/Olm.cpp b/src/Olm.cpp index 769b0234..6e130277 100644 --- a/src/Olm.cpp +++ b/src/Olm.cpp @@ -136,4 +136,31 @@ handle_olm_normal_message(const std::string &, const std::string &, const OlmCip log::crypto()->warn("olm(1) not implemeted yet"); } +mtx::events::msg::Encrypted +encrypt_group_message(const std::string &room_id, + const std::string &device_id, + const std::string &body) +{ + using namespace mtx::events; + + // Always chech before for existence. + auto res = cache::client()->getOutboundMegolmSession(room_id); + auto payload = olm::client()->encrypt_group_message(res.session, body); + + // Prepare the m.room.encrypted event. + msg::Encrypted data; + data.ciphertext = std::string((char *)payload.data(), payload.size()); + data.sender_key = olm::client()->identity_keys().curve25519; + data.session_id = res.data.session_id; + data.device_id = device_id; + + auto message_index = olm_outbound_group_session_message_index(res.session); + log::crypto()->info("next message_index {}", message_index); + + // We need to re-pickle the session after we send a message to save the new message_index. + cache::client()->updateOutboundMegolmSession(room_id, message_index); + + return data; +} + } // namespace olm |