diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2022-03-29 04:50:25 +0200 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2022-03-29 20:51:18 +0200 |
commit | 6d1416fb6ec7e64a765af652ea3b21722ec12be3 (patch) | |
tree | e5a7f21a13cb9aa7e4a737dd52c243da78622300 /src/ui | |
parent | expose options better (diff) | |
download | nheko-6d1416fb6ec7e64a765af652ea3b21722ec12be3.tar.xz |
Add backend for new room creation dialogs
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/NhekoGlobalObject.cpp | 31 | ||||
-rw-r--r-- | src/ui/NhekoGlobalObject.h | 3 | ||||
-rw-r--r-- | src/ui/UserProfile.cpp | 13 | ||||
-rw-r--r-- | src/ui/UserProfile.h | 1 |
4 files changed, 40 insertions, 8 deletions
diff --git a/src/ui/NhekoGlobalObject.cpp b/src/ui/NhekoGlobalObject.cpp index 3abcdf08..2e1aadf0 100644 --- a/src/ui/NhekoGlobalObject.cpp +++ b/src/ui/NhekoGlobalObject.cpp @@ -13,7 +13,6 @@ #include "Cache_p.h" #include "ChatPage.h" #include "Logging.h" -#include "MainWindow.h" #include "UserSettingsPage.h" #include "Utils.h" #include "voip/WebRTCSession.h" @@ -129,8 +128,32 @@ Nheko::logout() const } void -Nheko::openCreateRoomDialog() const +Nheko::createRoom(QString name, QString topic, QString aliasLocalpart, bool isEncrypted, int preset) { - MainWindow::instance()->openCreateRoomDialog( - [](const mtx::requests::CreateRoom &req) { ChatPage::instance()->createRoom(req); }); + mtx::requests::CreateRoom req; + + switch (preset) { + case 1: + req.preset = mtx::requests::Preset::PublicChat; + break; + case 2: + req.preset = mtx::requests::Preset::TrustedPrivateChat; + break; + case 0: + default: + req.preset = mtx::requests::Preset::PrivateChat; + } + + req.name = name.toStdString(); + req.topic = topic.toStdString(); + req.room_alias_name = aliasLocalpart.toStdString(); + + if (isEncrypted) { + mtx::events::StrippedEvent<mtx::events::state::Encryption> enc; + enc.type = mtx::events::EventType::RoomEncryption; + enc.content.algorithm = mtx::crypto::MEGOLM_ALGO; + req.initial_state.emplace_back(std::move(enc)); + } + + emit ChatPage::instance()->createRoom(req); } diff --git a/src/ui/NhekoGlobalObject.h b/src/ui/NhekoGlobalObject.h index 24493873..1139cf31 100644 --- a/src/ui/NhekoGlobalObject.h +++ b/src/ui/NhekoGlobalObject.h @@ -52,7 +52,8 @@ public: Q_INVOKABLE void setStatusMessage(QString msg) const; Q_INVOKABLE void showUserSettingsPage() const; Q_INVOKABLE void logout() const; - Q_INVOKABLE void openCreateRoomDialog() const; + Q_INVOKABLE void + createRoom(QString name, QString topic, QString aliasLocalpart, bool isEncrypted, int preset); public slots: void updateUserProfile(); diff --git a/src/ui/UserProfile.cpp b/src/ui/UserProfile.cpp index 898b56fd..db50b050 100644 --- a/src/ui/UserProfile.cpp +++ b/src/ui/UserProfile.cpp @@ -53,6 +53,9 @@ UserProfile::UserProfile(QString roomid, emit verificationStatiChanged(); }); + connect(this, &UserProfile::devicesChanged, [this]() { + nhlog::net()->critical("Device list: {}", deviceList_.rowCount()); + }); fetchDeviceList(this->userid_); } @@ -187,7 +190,6 @@ UserProfile::fetchDeviceList(const QString &userID) nhlog::net()->warn("failed to query device keys: {},{}", mtx::errors::to_string(err->matrix_error.errcode), static_cast<int>(err->status_code)); - return; } // Ensure local key cache is up to date @@ -201,7 +203,6 @@ UserProfile::fetchDeviceList(const QString &userID) nhlog::net()->warn("failed to query device keys: {},{}", mtx::errors::to_string(err->matrix_error.errcode), static_cast<int>(err->status_code)); - return; } emit verificationStatiChanged(); @@ -313,9 +314,15 @@ UserProfile::kickUser() } void +UserProfile::startChat(bool encryption) +{ + ChatPage::instance()->startChat(this->userid_, encryption); +} + +void UserProfile::startChat() { - ChatPage::instance()->startChat(this->userid_); + ChatPage::instance()->startChat(this->userid_, std::nullopt); } void diff --git a/src/ui/UserProfile.h b/src/ui/UserProfile.h index 0f03e537..4652a72e 100644 --- a/src/ui/UserProfile.h +++ b/src/ui/UserProfile.h @@ -143,6 +143,7 @@ public: // Q_INVOKABLE void ignoreUser(); Q_INVOKABLE void kickUser(); Q_INVOKABLE void startChat(); + Q_INVOKABLE void startChat(bool encryptionEnabled); Q_INVOKABLE void changeUsername(QString username); Q_INVOKABLE void changeDeviceName(QString deviceID, QString deviceName); Q_INVOKABLE void changeAvatar(); |