Add button to encrypt room

This commit is contained in:
Tobias Fella
2022-10-27 20:56:29 +02:00
parent 82ec92b209
commit 4e6aca9a4e
4 changed files with 35 additions and 0 deletions

View File

@@ -146,6 +146,7 @@ if(ANDROID)
"zoom-out" "zoom-out"
"image-rotate-left-symbolic" "image-rotate-left-symbolic"
"image-rotate-right-symbolic" "image-rotate-right-symbolic"
"channel-insecure-symbolic"
) )
else() else()
target_link_libraries(neochat PUBLIC Qt::Widgets KF5::KIOWidgets) target_link_libraries(neochat PUBLIC Qt::Widgets KF5::KIOWidgets)

View File

@@ -67,6 +67,7 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS
connect(this, &Room::displaynameChanged, this, &NeoChatRoom::displayNameChanged); connect(this, &Room::displaynameChanged, this, &NeoChatRoom::displayNameChanged);
connectSingleShot(this, &Room::baseStateLoaded, this, [this]() { connectSingleShot(this, &Room::baseStateLoaded, this, [this]() {
Q_EMIT canEncryptRoomChanged();
if (this->joinState() != JoinState::Invite) { if (this->joinState() != JoinState::Invite) {
return; return;
} }
@@ -80,6 +81,9 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS
} }
NotificationsManager::instance().postInviteNotification(this, htmlSafeDisplayName(), htmlSafeMemberName(senderId), avatar_image); 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) void NeoChatRoom::uploadFile(const QUrl &url, const QString &body)
@@ -1165,3 +1169,13 @@ void NeoChatRoom::setSavedText(const QString &savedText)
{ {
m_savedText = 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;
}

View File

@@ -61,6 +61,7 @@ class NeoChatRoom : public Quotient::Room
Q_PROPERTY(NeoChatUser *chatBoxEditUser READ chatBoxEditUser NOTIFY chatBoxEditIdChanged) Q_PROPERTY(NeoChatUser *chatBoxEditUser READ chatBoxEditUser NOTIFY chatBoxEditIdChanged)
Q_PROPERTY(QString chatBoxEditMessage READ chatBoxEditMessage NOTIFY chatBoxEditIdChanged) Q_PROPERTY(QString chatBoxEditMessage READ chatBoxEditMessage NOTIFY chatBoxEditIdChanged)
Q_PROPERTY(QString chatBoxAttachmentPath READ chatBoxAttachmentPath WRITE setChatBoxAttachmentPath NOTIFY chatBoxAttachmentPathChanged) Q_PROPERTY(QString chatBoxAttachmentPath READ chatBoxAttachmentPath WRITE setChatBoxAttachmentPath NOTIFY chatBoxAttachmentPathChanged)
Q_PROPERTY(bool canEncryptRoom READ canEncryptRoom NOTIFY canEncryptRoomChanged)
public: public:
enum MessageType { enum MessageType {
@@ -189,6 +190,8 @@ public:
QString savedText() const; QString savedText() const;
void setSavedText(const QString &savedText); void setSavedText(const QString &savedText);
bool canEncryptRoom() const;
#ifndef QUOTIENT_07 #ifndef QUOTIENT_07
Q_INVOKABLE QString htmlSafeMemberName(const QString &userId) const Q_INVOKABLE QString htmlSafeMemberName(const QString &userId) const
{ {
@@ -241,6 +244,7 @@ Q_SIGNALS:
void chatBoxReplyIdChanged(); void chatBoxReplyIdChanged();
void chatBoxEditIdChanged(); void chatBoxEditIdChanged();
void chatBoxAttachmentPathChanged(); void chatBoxAttachmentPathChanged();
void canEncryptRoomChanged();
public Q_SLOTS: public Q_SLOTS:
void uploadFile(const QUrl &url, const QString &body = QString()); void uploadFile(const QUrl &url, const QString &body = QString());

View File

@@ -126,6 +126,22 @@ Kirigami.OverlayDrawer {
text: favouriteButton.text 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 { ToolButton {
id: settingsButton id: settingsButton