From 7824c772346e13f26eb878ce6a945fbb707e2247 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Tue, 31 Oct 2023 16:38:15 +0100 Subject: Cleanup headers a bit more --- src/Cache.cpp | 30 ++++--- src/Cache.h | 7 +- src/Cache_p.h | 6 +- src/ChatPage.cpp | 8 +- src/ChatPage.h | 3 +- src/CombinedImagePackModel.cpp | 4 +- src/EventAccessors.cpp | 2 + src/EventAccessors.h | 8 +- src/GridImagePackModel.cpp | 3 +- src/ImagePackListModel.cpp | 4 +- src/MainWindow.cpp | 52 ----------- src/Utils.cpp | 137 ++++++++++++++++++++++++++-- src/Utils.h | 145 ++---------------------------- src/encryption/DeviceVerificationFlow.cpp | 30 +++++++ src/encryption/DeviceVerificationFlow.h | 32 +------ src/encryption/Olm.cpp | 16 ++-- src/encryption/SelfVerificationStatus.cpp | 2 +- src/timeline/InputBar.h | 2 +- 18 files changed, 224 insertions(+), 267 deletions(-) (limited to 'src') diff --git a/src/Cache.cpp b/src/Cache.cpp index 5367ee22..e6b7313e 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -463,14 +463,14 @@ fatalSecretError() } static QString -secretName(std::string name, bool internal) +secretName(std::string_view name, bool internal) { auto settings = UserSettings::instance(); return (internal ? "nheko." : "matrix.") + QString( QCryptographicHash::hash(settings->profile().toUtf8(), QCryptographicHash::Sha256) .toBase64()) + - "." + QString::fromStdString(name); + "." + QString::fromUtf8(name); } void @@ -560,7 +560,7 @@ Cache::loadSecretsFromStore( } std::optional -Cache::secret(const std::string &name_, bool internal) +Cache::secret(std::string_view name_, bool internal) { auto name = secretName(name_, internal); @@ -580,7 +580,7 @@ Cache::secret(const std::string &name_, bool internal) } void -Cache::storeSecret(const std::string &name_, const std::string &secret, bool internal) +Cache::storeSecret(std::string_view name_, const std::string &secret, bool internal) { auto name = secretName(name_, internal); @@ -592,11 +592,11 @@ Cache::storeSecret(const std::string &name_, const std::string &secret, bool int auto db_name = "secret." + name.toStdString(); syncStateDb_.put(txn, db_name, nlohmann::json(encrypted).dump()); txn.commit(); - emit secretChanged(name_); + emit secretChanged(std::string(name_)); } void -Cache::deleteSecret(const std::string &name_, bool internal) +Cache::deleteSecret(std::string_view name_, bool internal) { auto name = secretName(name_, internal); @@ -1631,10 +1631,10 @@ Cache::runMigrations() this->databaseReady_ = false; loadSecretsFromStore( { - {mtx::secret_storage::secrets::cross_signing_master, false}, - {mtx::secret_storage::secrets::cross_signing_self_signing, false}, - {mtx::secret_storage::secrets::cross_signing_user_signing, false}, - {mtx::secret_storage::secrets::megolm_backup_v1, false}, + {std::string(mtx::secret_storage::secrets::cross_signing_master), false}, + {std::string(mtx::secret_storage::secrets::cross_signing_self_signing), false}, + {std::string(mtx::secret_storage::secrets::cross_signing_user_signing), false}, + {std::string(mtx::secret_storage::secrets::megolm_backup_v1), false}, }, [this, count = 1](const std::string &name, bool internal, const std::string &value) mutable { @@ -6147,15 +6147,21 @@ restoreOlmAccount() } void -storeSecret(const std::string &name, const std::string &secret) +storeSecret(std::string_view name, const std::string &secret) { instance_->storeSecret(name, secret); } std::optional -secret(const std::string &name) +secret(std::string_view name) { return instance_->secret(name); } + +std::vector +getImagePacks(const std::string &room_id, std::optional stickers) +{ + return instance_->getImagePacks(room_id, stickers); +} } // namespace cache #define NHEKO_CACHE_GET_STATE_EVENT_DEFINITION(Content) \ diff --git a/src/Cache.h b/src/Cache.h index bed4938c..7c79881c 100644 --- a/src/Cache.h +++ b/src/Cache.h @@ -253,7 +253,10 @@ std::string restoreOlmAccount(); void -storeSecret(const std::string &name, const std::string &secret); +storeSecret(std::string_view name, const std::string &secret); std::optional -secret(const std::string &name); +secret(std::string_view name); + +std::vector +getImagePacks(const std::string &room_id, std::optional stickers); } diff --git a/src/Cache_p.h b/src/Cache_p.h index d1316ae5..24ea2939 100644 --- a/src/Cache_p.h +++ b/src/Cache_p.h @@ -291,9 +291,9 @@ public: void deleteBackupVersion(); std::optional backupVersion(); - void storeSecret(const std::string &name, const std::string &secret, bool internal = false); - void deleteSecret(const std::string &name, bool internal = false); - std::optional secret(const std::string &name, bool internal = false); + void storeSecret(std::string_view name, const std::string &secret, bool internal = false); + void deleteSecret(std::string_view name, bool internal = false); + std::optional secret(std::string_view name, bool internal = false); std::string pickleSecret(); diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index 03144faf..b756f486 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -778,7 +778,9 @@ ChatPage::handleSyncResponse(const mtx::responses::Sync &res, const std::string nhlog::net()->debug("sync completed: {}", res.next_batch); // Ensure that we have enough one-time keys available. - ensureOneTimeKeyCount(res.device_one_time_keys_count, res.device_unused_fallback_key_types); + std::map counts{res.device_one_time_keys_count.begin(), + res.device_one_time_keys_count.end()}; + ensureOneTimeKeyCount(counts, res.device_unused_fallback_key_types); std::optional oldIgnoredUsers; if (auto ignoreEv = std::ranges::find_if( @@ -1194,7 +1196,7 @@ ChatPage::verifyOneTimeKeyCountAfterStartup() return; } - std::map key_counts; + std::map key_counts; std::uint64_t count = 0; if (auto c = res.one_time_key_counts.find(mtx::crypto::SIGNED_CURVE25519); c == res.one_time_key_counts.end()) { @@ -1215,7 +1217,7 @@ ChatPage::verifyOneTimeKeyCountAfterStartup() } void -ChatPage::ensureOneTimeKeyCount(const std::map &counts, +ChatPage::ensureOneTimeKeyCount(const std::map &counts, const std::optional> &unused_fallback_keys) { if (auto count = counts.find(mtx::crypto::SIGNED_CURVE25519); count != counts.end()) { diff --git a/src/ChatPage.h b/src/ChatPage.h index 1e1da049..13621b23 100644 --- a/src/ChatPage.h +++ b/src/ChatPage.h @@ -6,7 +6,6 @@ #include #include -#include #include #include @@ -191,7 +190,7 @@ private: void tryInitialSync(); void trySync(); void verifyOneTimeKeyCountAfterStartup(); - void ensureOneTimeKeyCount(const std::map &counts, + void ensureOneTimeKeyCount(const std::map &counts, const std::optional> &fallback_keys); void removeOldFallbackKey(); void getProfileInfo(); diff --git a/src/CombinedImagePackModel.cpp b/src/CombinedImagePackModel.cpp index 23fb50f1..c4a09847 100644 --- a/src/CombinedImagePackModel.cpp +++ b/src/CombinedImagePackModel.cpp @@ -4,7 +4,7 @@ #include "CombinedImagePackModel.h" -#include "Cache_p.h" +#include "Cache.h" #include "CompletionModelRoles.h" #include "emoji/Provider.h" @@ -12,7 +12,7 @@ CombinedImagePackModel::CombinedImagePackModel(const std::string &roomId, QObjec : QAbstractListModel(parent) , room_id(roomId) { - auto packs = cache::client()->getImagePacks(room_id, false); + auto packs = cache::getImagePacks(room_id, false); for (const auto &pack : packs) { QString packname = diff --git a/src/EventAccessors.cpp b/src/EventAccessors.cpp index 8cb09a1d..ca730a75 100644 --- a/src/EventAccessors.cpp +++ b/src/EventAccessors.cpp @@ -10,6 +10,8 @@ #include #include +#include + namespace { struct IsStateEvent diff --git a/src/EventAccessors.h b/src/EventAccessors.h index 78484e91..4128f681 100644 --- a/src/EventAccessors.h +++ b/src/EventAccessors.h @@ -9,7 +9,13 @@ #include #include -#include +#include +#include + +namespace mtx::events::collections { +struct TimelineEvents; +struct StateEvents; +} namespace nheko { struct nonesuch diff --git a/src/GridImagePackModel.cpp b/src/GridImagePackModel.cpp index cfd014f0..4dbe6af3 100644 --- a/src/GridImagePackModel.cpp +++ b/src/GridImagePackModel.cpp @@ -10,7 +10,6 @@ #include #include "Cache.h" -#include "Cache_p.h" #include "emoji/Provider.h" QString @@ -102,7 +101,7 @@ GridImagePackModel::GridImagePackModel(const std::string &roomId, bool stickers, } } - auto originalPacks = cache::client()->getImagePacks(room_id, stickers); + auto originalPacks = cache::getImagePacks(room_id, stickers); for (auto &pack : originalPacks) { PackDesc newPack{}; diff --git a/src/ImagePackListModel.cpp b/src/ImagePackListModel.cpp index 4cf807a9..94b319f2 100644 --- a/src/ImagePackListModel.cpp +++ b/src/ImagePackListModel.cpp @@ -6,14 +6,14 @@ #include -#include "Cache_p.h" +#include "Cache.h" #include "SingleImagePackModel.h" ImagePackListModel::ImagePackListModel(const std::string &roomId, QObject *parent) : QAbstractListModel(parent) , room_id(roomId) { - auto packs_ = cache::client()->getImagePacks(room_id, std::nullopt); + auto packs_ = cache::getImagePacks(room_id, std::nullopt); packs.reserve(packs_.size()); for (const auto &pack : packs_) { diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 1a0b1e96..e25619cd 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -101,58 +101,6 @@ MainWindow::MainWindow(QWindow *parent) void MainWindow::registerQmlTypes() { - // qmlRegisterUncreatableType( - // "im.nheko", - // 1, - // 0, - // "DeviceVerificationFlow", - // QStringLiteral("Can't create verification flow from QML!")); - // qmlRegisterUncreatableType( - // "im.nheko", - // 1, - // 0, - // "UserProfileModel", - // QStringLiteral("UserProfile needs to be instantiated on the C++ side")); - // qmlRegisterUncreatableType( - // "im.nheko", - // 1, - // 0, - // "MemberList", - // QStringLiteral("MemberList needs to be instantiated on the C++ side")); - // qmlRegisterUncreatableType( - // "im.nheko", - // 1, - // 0, - // "RoomSettingsModel", - // QStringLiteral("Room Settings needs to be instantiated on the C++ side")); - // qmlRegisterUncreatableType( - // "im.nheko", 1, 0, "Room", QStringLiteral("Room needs to be instantiated on the C++ side")); - // qmlRegisterUncreatableType( - // "im.nheko", - // 1, - // 0, - // "ImagePackListModel", - // QStringLiteral("ImagePackListModel needs to be instantiated on the C++ side")); - // qmlRegisterUncreatableType( - // "im.nheko", - // 1, - // 0, - // "SingleImagePackModel", - // QStringLiteral("SingleImagePackModel needs to be instantiated on the C++ side")); - // qmlRegisterUncreatableType( - // "im.nheko", - // 1, - // 0, - // "InviteesModel", - // QStringLiteral("InviteesModel needs to be instantiated on the C++ side")); - - // qmlRegisterUncreatableMetaObject(emoji::staticMetaObject, - // "im.nheko.EmojiModel", - // 1, - // 0, - // "EmojiCategory", - // QStringLiteral("Error: Only enums")); - imgProvider = new MxcImageProvider(); engine()->addImageProvider(QStringLiteral("MxcImage"), imgProvider); engine()->addImageProvider(QStringLiteral("colorimage"), new ColorImageProvider()); diff --git a/src/Utils.cpp b/src/Utils.cpp index 7a487101..8d372763 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -40,6 +40,133 @@ #include "MatrixClient.h" #include "UserSettingsPage.h" +//! Match widgets/events with a description message. +namespace { +template +QString +messageDescription(const QString &username = QString(), + const QString &body = QString(), + const bool isLocal = false) +{ + using Audio = mtx::events::RoomEvent; + using Emote = mtx::events::RoomEvent; + using File = mtx::events::RoomEvent; + using Image = mtx::events::RoomEvent; + using Notice = mtx::events::RoomEvent; + using Sticker = mtx::events::Sticker; + using Text = mtx::events::RoomEvent; + using Unknown = mtx::events::RoomEvent; + using Video = mtx::events::RoomEvent; + using ElementEffect = mtx::events::RoomEvent; + using CallInvite = mtx::events::RoomEvent; + using CallAnswer = mtx::events::RoomEvent; + using CallHangUp = mtx::events::RoomEvent; + using CallReject = mtx::events::RoomEvent; + using Encrypted = mtx::events::EncryptedEvent; + + if (std::is_same::value) { + if (isLocal) + return QCoreApplication::translate("message-description sent:", + "You sent an audio clip"); + else + return QCoreApplication::translate("message-description sent:", "%1 sent an audio clip") + .arg(username); + } else if (std::is_same::value) { + if (isLocal) + return QCoreApplication::translate("message-description sent:", "You sent an image"); + else + return QCoreApplication::translate("message-description sent:", "%1 sent an image") + .arg(username); + } else if (std::is_same::value) { + if (isLocal) + return QCoreApplication::translate("message-description sent:", "You sent a file"); + else + return QCoreApplication::translate("message-description sent:", "%1 sent a file") + .arg(username); + } else if (std::is_same::value) { + if (isLocal) + return QCoreApplication::translate("message-description sent:", "You sent a video"); + else + return QCoreApplication::translate("message-description sent:", "%1 sent a video") + .arg(username); + } else if (std::is_same::value) { + if (isLocal) + return QCoreApplication::translate("message-description sent:", "You sent a sticker"); + else + return QCoreApplication::translate("message-description sent:", "%1 sent a sticker") + .arg(username); + } else if (std::is_same::value) { + if (isLocal) + return QCoreApplication::translate("message-description sent:", + "You sent a notification"); + else + return QCoreApplication::translate("message-description sent:", + "%1 sent a notification") + .arg(username); + } else if (std::is_same::value || std::is_same::value) { + if (isLocal) + return QCoreApplication::translate("message-description sent:", "You: %1").arg(body); + else + return QCoreApplication::translate("message-description sent:", "%1: %2") + .arg(username, body); + } else if (std::is_same::value) { + if (body.isEmpty()) { + // TODO: what is the best way to handle this? + if (isLocal) + return QCoreApplication::translate("message-description sent:", + "You sent a chat effect"); + else + return QCoreApplication::translate("message-description sent:", + "%1 sent a chat effect") + .arg(username); + } else { + if (isLocal) + return QCoreApplication::translate("message-description sent:", "You: %1") + .arg(body); + else + return QCoreApplication::translate("message-description sent:", "%1: %2") + .arg(username, body); + } + } else if (std::is_same::value) { + return QStringLiteral("* %1 %2").arg(username, body); + } else if (std::is_same::value) { + if (isLocal) + return QCoreApplication::translate("message-description sent:", + "You sent an encrypted message"); + else + return QCoreApplication::translate("message-description sent:", + "%1 sent an encrypted message") + .arg(username); + } else if (std::is_same::value) { + if (isLocal) + return QCoreApplication::translate("message-description sent:", "You placed a call"); + else + return QCoreApplication::translate("message-description sent:", "%1 placed a call") + .arg(username); + } else if (std::is_same::value) { + if (isLocal) + return QCoreApplication::translate("message-description sent:", "You answered a call"); + else + return QCoreApplication::translate("message-description sent:", "%1 answered a call") + .arg(username); + } else if (std::is_same::value) { + if (isLocal) + return QCoreApplication::translate("message-description sent:", "You ended a call"); + else + return QCoreApplication::translate("message-description sent:", "%1 ended a call") + .arg(username); + } else if (std::is_same::value) { + if (isLocal) + return QCoreApplication::translate("message-description sent:", "You rejected a call"); + else + return QCoreApplication::translate("message-description sent:", "%1 rejected a call") + .arg(username); + } else { + return QCoreApplication::translate("utils", "Unknown Message Type"); + } +} +} + template static DescInfo createDescriptionInfo(const Event &event, const QString &localUser, const QString &displayName) @@ -56,7 +183,7 @@ createDescriptionInfo(const Event &event, const QString &localUser, const QStrin return DescInfo{ QString::fromStdString(msg.event_id), sender, - utils::messageDescription(username, QString::fromStdString(body), sender == localUser), + messageDescription(username, QString::fromStdString(body), sender == localUser), utils::descriptiveTime(ts), msg.origin_server_ts, ts}; @@ -389,13 +516,9 @@ utils::mxcToHttp(const QUrl &url, const QString &server, int port) } QString -utils::humanReadableFingerprint(const std::string &ed25519) -{ - return humanReadableFingerprint(QString::fromStdString(ed25519)); -} -QString -utils::humanReadableFingerprint(const QString &ed25519) +utils::humanReadableFingerprint(const std::string &ed25519_) { + auto ed25519 = QString::fromStdString(ed25519_); QString fingerprint; for (int i = 0; i < ed25519.length(); i = i + 4) { fingerprint.append(QStringView(ed25519).mid(i, 4)); diff --git a/src/Utils.h b/src/Utils.h index 2c75cb5c..7f844627 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -5,14 +5,14 @@ #pragma once #include -#include #include #include -#include -#include -#include +#include -#include +namespace mtx::events::collections { +struct TimelineEvents; +struct StateEvents; +} struct DescInfo; @@ -85,131 +85,6 @@ firstChar(const QString &input); QString humanReadableFileSize(uint64_t bytes); -//! Match widgets/events with a description message. -template -QString -messageDescription(const QString &username = QString(), - const QString &body = QString(), - const bool isLocal = false) -{ - using Audio = mtx::events::RoomEvent; - using Emote = mtx::events::RoomEvent; - using File = mtx::events::RoomEvent; - using Image = mtx::events::RoomEvent; - using Notice = mtx::events::RoomEvent; - using Sticker = mtx::events::Sticker; - using Text = mtx::events::RoomEvent; - using Unknown = mtx::events::RoomEvent; - using Video = mtx::events::RoomEvent; - using ElementEffect = mtx::events::RoomEvent; - using CallInvite = mtx::events::RoomEvent; - using CallAnswer = mtx::events::RoomEvent; - using CallHangUp = mtx::events::RoomEvent; - using CallReject = mtx::events::RoomEvent; - using Encrypted = mtx::events::EncryptedEvent; - - if (std::is_same::value) { - if (isLocal) - return QCoreApplication::translate("message-description sent:", - "You sent an audio clip"); - else - return QCoreApplication::translate("message-description sent:", "%1 sent an audio clip") - .arg(username); - } else if (std::is_same::value) { - if (isLocal) - return QCoreApplication::translate("message-description sent:", "You sent an image"); - else - return QCoreApplication::translate("message-description sent:", "%1 sent an image") - .arg(username); - } else if (std::is_same::value) { - if (isLocal) - return QCoreApplication::translate("message-description sent:", "You sent a file"); - else - return QCoreApplication::translate("message-description sent:", "%1 sent a file") - .arg(username); - } else if (std::is_same::value) { - if (isLocal) - return QCoreApplication::translate("message-description sent:", "You sent a video"); - else - return QCoreApplication::translate("message-description sent:", "%1 sent a video") - .arg(username); - } else if (std::is_same::value) { - if (isLocal) - return QCoreApplication::translate("message-description sent:", "You sent a sticker"); - else - return QCoreApplication::translate("message-description sent:", "%1 sent a sticker") - .arg(username); - } else if (std::is_same::value) { - if (isLocal) - return QCoreApplication::translate("message-description sent:", - "You sent a notification"); - else - return QCoreApplication::translate("message-description sent:", - "%1 sent a notification") - .arg(username); - } else if (std::is_same::value || std::is_same::value) { - if (isLocal) - return QCoreApplication::translate("message-description sent:", "You: %1").arg(body); - else - return QCoreApplication::translate("message-description sent:", "%1: %2") - .arg(username, body); - } else if (std::is_same::value) { - if (body.isEmpty()) { - // TODO: what is the best way to handle this? - if (isLocal) - return QCoreApplication::translate("message-description sent:", - "You sent a chat effect"); - else - return QCoreApplication::translate("message-description sent:", - "%1 sent a chat effect") - .arg(username); - } else { - if (isLocal) - return QCoreApplication::translate("message-description sent:", "You: %1") - .arg(body); - else - return QCoreApplication::translate("message-description sent:", "%1: %2") - .arg(username, body); - } - } else if (std::is_same::value) { - return QStringLiteral("* %1 %2").arg(username, body); - } else if (std::is_same::value) { - if (isLocal) - return QCoreApplication::translate("message-description sent:", - "You sent an encrypted message"); - else - return QCoreApplication::translate("message-description sent:", - "%1 sent an encrypted message") - .arg(username); - } else if (std::is_same::value) { - if (isLocal) - return QCoreApplication::translate("message-description sent:", "You placed a call"); - else - return QCoreApplication::translate("message-description sent:", "%1 placed a call") - .arg(username); - } else if (std::is_same::value) { - if (isLocal) - return QCoreApplication::translate("message-description sent:", "You answered a call"); - else - return QCoreApplication::translate("message-description sent:", "%1 answered a call") - .arg(username); - } else if (std::is_same::value) { - if (isLocal) - return QCoreApplication::translate("message-description sent:", "You ended a call"); - else - return QCoreApplication::translate("message-description sent:", "%1 ended a call") - .arg(username); - } else if (std::is_same::value) { - if (isLocal) - return QCoreApplication::translate("message-description sent:", "You rejected a call"); - else - return QCoreApplication::translate("message-description sent:", "%1 rejected a call") - .arg(username); - } else { - return QCoreApplication::translate("utils", "Unknown Message Type"); - } -} - //! Scale down an image to fit to the given width & height limitations. QPixmap scaleDown(uint64_t maxWidth, uint64_t maxHeight, const QPixmap &source); @@ -227,13 +102,6 @@ erase_if(ContainerT &items, const PredicateT &predicate) } } -template -QString -message_body(const mtx::events::collections::TimelineEvents &event) -{ - return QString::fromStdString(std::get(event).content.body); -} - //! Calculate the Levenshtein distance between two strings with character skipping. int levenshtein_distance(const std::string &s1, const std::string &s2); @@ -249,9 +117,6 @@ mxcToHttp(const QUrl &url, const QString &server, int port); QString humanReadableFingerprint(const std::string &ed25519); -QString -humanReadableFingerprint(const QString &ed25519); - //! Retrieve the message body taking into account the `formatted_body` field. //! If the `format` of the message is not supported we fallback to `body`. template diff --git a/src/encryption/DeviceVerificationFlow.cpp b/src/encryption/DeviceVerificationFlow.cpp index f0c7ed52..8c7204be 100644 --- a/src/encryption/DeviceVerificationFlow.cpp +++ b/src/encryption/DeviceVerificationFlow.cpp @@ -944,3 +944,33 @@ DeviceVerificationFlow::InitiateDeviceVerification(QObject *parent_, return flow; } +template +void +DeviceVerificationFlow::send(T msg) +{ + if (this->type == DeviceVerificationFlow::Type::ToDevice) { + mtx::requests::ToDeviceMessages body; + msg.transaction_id = this->transaction_id; + for (const auto &d : deviceIds) + body[this->toClient][d.toStdString()] = msg; + + http::client()->send_to_device( + http::client()->generate_txn_id(), body, [](mtx::http::RequestErr err) { + if (err) + nhlog::net()->warn("failed to send verification to_device message: {} {}", + err->matrix_error.error, + static_cast(err->status_code)); + }); + } else if (this->type == DeviceVerificationFlow::Type::RoomMsg && model_) { + if constexpr (!std::is_same_v) { + msg.relations.relations.push_back(this->relation); + // Set synthesized to surpress the nheko relation extensions + msg.relations.synthesized = true; + } + (model_)->sendMessageEvent(msg, mtx::events::to_device_content_to_type); + } + + nhlog::net()->debug("Sent verification step: {} in state: {}", + mtx::events::to_string(mtx::events::to_device_content_to_type), + state().toStdString()); +} diff --git a/src/encryption/DeviceVerificationFlow.h b/src/encryption/DeviceVerificationFlow.h index 6b1776e0..e64eab96 100644 --- a/src/encryption/DeviceVerificationFlow.h +++ b/src/encryption/DeviceVerificationFlow.h @@ -7,13 +7,14 @@ #include #include +#include #include "CacheCryptoStructs.h" #include "Logging.h" #include "MatrixClient.h" -#include "timeline/TimelineModel.h" class QTimer; +class TimelineModel; using sas_ptr = std::unique_ptr; @@ -230,32 +231,5 @@ private: bool keySent = false, macSent = false, acceptSent = false, startSent = false; template - void send(T msg) - { - if (this->type == DeviceVerificationFlow::Type::ToDevice) { - mtx::requests::ToDeviceMessages body; - msg.transaction_id = this->transaction_id; - for (const auto &d : deviceIds) - body[this->toClient][d.toStdString()] = msg; - - http::client()->send_to_device( - http::client()->generate_txn_id(), body, [](mtx::http::RequestErr err) { - if (err) - nhlog::net()->warn("failed to send verification to_device message: {} {}", - err->matrix_error.error, - static_cast(err->status_code)); - }); - } else if (this->type == DeviceVerificationFlow::Type::RoomMsg && model_) { - if constexpr (!std::is_same_v) { - msg.relations.relations.push_back(this->relation); - // Set synthesized to surpress the nheko relation extensions - msg.relations.synthesized = true; - } - (model_)->sendMessageEvent(msg, mtx::events::to_device_content_to_type); - } - - nhlog::net()->debug("Sent verification step: {} in state: {}", - mtx::events::to_string(mtx::events::to_device_content_to_type), - state().toStdString()); - } + void send(T msg); }; diff --git a/src/encryption/Olm.cpp b/src/encryption/Olm.cpp index aaa7e43f..0352d8d3 100644 --- a/src/encryption/Olm.cpp +++ b/src/encryption/Olm.cpp @@ -1665,10 +1665,10 @@ request_cross_signing_keys() }); }; - request(mtx::secret_storage::secrets::cross_signing_master); - request(mtx::secret_storage::secrets::cross_signing_self_signing); - request(mtx::secret_storage::secrets::cross_signing_user_signing); - request(mtx::secret_storage::secrets::megolm_backup_v1); + request(std::string(mtx::secret_storage::secrets::cross_signing_master)); + request(std::string(mtx::secret_storage::secrets::cross_signing_self_signing)); + request(std::string(mtx::secret_storage::secrets::cross_signing_user_signing)); + request(std::string(mtx::secret_storage::secrets::megolm_backup_v1)); } namespace { @@ -1725,22 +1725,22 @@ download_cross_signing_keys() if (backup_key && !backup_key->encrypted.empty()) secrets[backup_key->encrypted.begin()->first] - [secrets::megolm_backup_v1] = + [std::string(secrets::megolm_backup_v1)] = backup_key->encrypted.begin()->second; if (master_key && !master_key->encrypted.empty()) secrets[master_key->encrypted.begin()->first] - [secrets::cross_signing_master] = + [std::string(secrets::cross_signing_master)] = master_key->encrypted.begin()->second; if (self_signing_key && !self_signing_key->encrypted.empty()) secrets[self_signing_key->encrypted.begin()->first] - [secrets::cross_signing_self_signing] = + [std::string(secrets::cross_signing_self_signing)] = self_signing_key->encrypted.begin()->second; if (user_signing_key && !user_signing_key->encrypted.empty()) secrets[user_signing_key->encrypted.begin()->first] - [secrets::cross_signing_user_signing] = + [std::string(secrets::cross_signing_user_signing)] = user_signing_key->encrypted.begin()->second; for (const auto &[key, secret_] : secrets) diff --git a/src/encryption/SelfVerificationStatus.cpp b/src/encryption/SelfVerificationStatus.cpp index 8981244d..29711716 100644 --- a/src/encryption/SelfVerificationStatus.cpp +++ b/src/encryption/SelfVerificationStatus.cpp @@ -110,7 +110,7 @@ SelfVerificationStatus::setupCrosssigning(bool useSSSS, http::client()->set_secret_storage_default_key(ssss->keyDescription.name, [](mtx::http::RequestErr) {}); - auto uploadSecret = [ssss](const std::string &key_name, const std::string &secret) { + auto uploadSecret = [ssss](std::string_view key_name, const std::string &secret) { mtx::secret_storage::Secret s; s.encrypted[ssss->keyDescription.name] = mtx::crypto::encrypt(secret, ssss->privateKey, key_name); diff --git a/src/timeline/InputBar.h b/src/timeline/InputBar.h index 3cd65524..b15377fc 100644 --- a/src/timeline/InputBar.h +++ b/src/timeline/InputBar.h @@ -18,7 +18,7 @@ #include #include -#include +#include class TimelineModel; class CombinedImagePackModel; -- cgit 1.4.1