diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4b4ad05c5..2890e3fef 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -146,6 +146,7 @@ if(ANDROID) "zoom-out" "image-rotate-left-symbolic" "image-rotate-right-symbolic" + "channel-insecure-symbolic" ) else() target_link_libraries(neochat PUBLIC Qt::Widgets KF5::KIOWidgets) diff --git a/src/neochatroom.cpp b/src/neochatroom.cpp index 5f674d946..87e32e473 100644 --- a/src/neochatroom.cpp +++ b/src/neochatroom.cpp @@ -67,6 +67,7 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS connect(this, &Room::displaynameChanged, this, &NeoChatRoom::displayNameChanged); connectSingleShot(this, &Room::baseStateLoaded, this, [this]() { + Q_EMIT canEncryptRoomChanged(); if (this->joinState() != JoinState::Invite) { return; } @@ -80,6 +81,9 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS } NotificationsManager::instance().postInviteNotification(this, htmlSafeDisplayName(), htmlSafeMemberName(senderId), avatar_image); }); + connect(this, &Room::changed, this, [this] { + Q_EMIT canEncryptRoomChanged(); + }); } void NeoChatRoom::uploadFile(const QUrl &url, const QString &body) @@ -1165,3 +1169,13 @@ void NeoChatRoom::setSavedText(const QString &savedText) { m_savedText = savedText; } + +bool NeoChatRoom::canEncryptRoom() const +{ +#ifdef QUOTIENT_07 +#ifdef Quotient_E2EE_ENABLED + return !usesEncryption() && canSendState("m.room.encryption"); +#endif +#endif + return false; +} diff --git a/src/neochatroom.h b/src/neochatroom.h index 07aaa7ab2..f54569916 100644 --- a/src/neochatroom.h +++ b/src/neochatroom.h @@ -61,6 +61,7 @@ class NeoChatRoom : public Quotient::Room Q_PROPERTY(NeoChatUser *chatBoxEditUser READ chatBoxEditUser NOTIFY chatBoxEditIdChanged) Q_PROPERTY(QString chatBoxEditMessage READ chatBoxEditMessage NOTIFY chatBoxEditIdChanged) Q_PROPERTY(QString chatBoxAttachmentPath READ chatBoxAttachmentPath WRITE setChatBoxAttachmentPath NOTIFY chatBoxAttachmentPathChanged) + Q_PROPERTY(bool canEncryptRoom READ canEncryptRoom NOTIFY canEncryptRoomChanged) public: enum MessageType { @@ -189,6 +190,8 @@ public: QString savedText() const; void setSavedText(const QString &savedText); + bool canEncryptRoom() const; + #ifndef QUOTIENT_07 Q_INVOKABLE QString htmlSafeMemberName(const QString &userId) const { @@ -241,6 +244,7 @@ Q_SIGNALS: void chatBoxReplyIdChanged(); void chatBoxEditIdChanged(); void chatBoxAttachmentPathChanged(); + void canEncryptRoomChanged(); public Q_SLOTS: void uploadFile(const QUrl &url, const QString &body = QString()); diff --git a/src/qml/Panel/RoomDrawer.qml b/src/qml/Panel/RoomDrawer.qml index dfef71993..d8202e1bf 100644 --- a/src/qml/Panel/RoomDrawer.qml +++ b/src/qml/Panel/RoomDrawer.qml @@ -126,6 +126,22 @@ Kirigami.OverlayDrawer { text: favouriteButton.text } } + ToolButton { + id: encryptButton + + Layout.alignment: Qt.AlignRight + icon.name: 'channel-insecure-symbolic' + enabled: roomDrawer.room.canEncryptRoom + visible: !roomDrawer.room.usesEncryption && Controller.encryptionSupported + text: i18n("Enable encryption") + display: AbstractButton.IconOnly + + onClicked: roomDrawer.room.activateEncryption() + + ToolTip { + text: encryptButton.text + } + } ToolButton { id: settingsButton