diff options
-rw-r--r-- | resources/qml/dialogs/RoomSettings.qml | 31 | ||||
-rw-r--r-- | src/ui/RoomSettings.cpp | 81 | ||||
-rw-r--r-- | src/ui/RoomSettings.h | 24 |
3 files changed, 135 insertions, 1 deletions
diff --git a/resources/qml/dialogs/RoomSettings.qml b/resources/qml/dialogs/RoomSettings.qml index 1f011bf1..a2400722 100644 --- a/resources/qml/dialogs/RoomSettings.qml +++ b/resources/qml/dialogs/RoomSettings.qml @@ -378,6 +378,37 @@ ApplicationWindow { } Label { + text: qsTr("History visibility") + Layout.fillWidth: true + color: palette.text + } + + ComboBox { + id: visComboBox + model: [qsTr("Readable to anyone without joining the room"), qsTr("Past messages visible to all current members"), qsTr("Only visible to members who were invited or joined when the message was sent"), qsTr("Only visible to members who were joined when the message was sent")] + currentIndex: roomSettings.historyVisibility + onActivated: { + roomSettings.changeHistoryVisibility(index); + } + Layout.fillWidth: true + WheelHandler{} // suppress scrolling changing values + enabled: roomSettings.canChangeHistoryVisibility + + delegate: ItemDelegate { + text: modelData + width: implicitWidth + highlighted: visComboBox.highlightedIndex === index + ToolTip.text: modelData + ToolTip.visible: hovered + ToolTip.delay: Nheko.tooltipDelay + } + + ToolTip.text: displayText + ToolTip.visible: hovered + ToolTip.delay: Nheko.tooltipDelay + } + + Label { text: qsTr("Encryption") color: palette.text } diff --git a/src/ui/RoomSettings.cpp b/src/ui/RoomSettings.cpp index 97c7cd61..769f2c8d 100644 --- a/src/ui/RoomSettings.cpp +++ b/src/ui/RoomSettings.cpp @@ -74,6 +74,11 @@ RoomSettings::RoomSettings(QString roomid, QObject *parent) guestRules_ = info_.guest_access ? AccessState::CanJoin : AccessState::Forbidden; emit accessJoinRulesChanged(); + if (auto ev = cache::client()->getStateEvent<mtx::events::state::HistoryVisibility>( + roomid_.toStdString())) { + this->historyVisibility_ = ev->content.history_visibility; + } + this->allowedRoomsModel = new RoomSettingsAllowedRoomsModel(this); } @@ -151,6 +156,22 @@ RoomSettings::notifications() return notifications_; } +RoomSettings::Visibility +RoomSettings::historyVisibility() const +{ + switch (this->historyVisibility_) { + case mtx::events::state::Visibility::WorldReadable: + return WorldReadable; + case mtx::events::state::Visibility::Joined: + return Joined; + case mtx::events::state::Visibility::Invited: + return Invited; + case mtx::events::state::Visibility::Shared: + return Shared; + } + return Shared; +} + bool RoomSettings::privateAccess() const { @@ -279,6 +300,20 @@ RoomSettings::canChangeAvatar() const } bool +RoomSettings::canChangeHistoryVisibility() const +{ + try { + return cache::hasEnoughPowerLevel({EventType::RoomHistoryVisibility}, + roomid_.toStdString(), + utils::localUser().toStdString()); + } catch (const lmdb::error &e) { + nhlog::db()->warn("lmdb error: {}", e.what()); + } + + return false; +} + +bool RoomSettings::isEncryptionEnabled() const { return usesEncryption_; @@ -458,6 +493,52 @@ RoomSettings::changeName(const QString &name) } void +RoomSettings::changeHistoryVisibility(Visibility value) +{ + auto tempVis = mtx::events::state::Visibility::Shared; + + switch (value) { + case WorldReadable: + tempVis = mtx::events::state::Visibility::WorldReadable; + break; + case Joined: + tempVis = mtx::events::state::Visibility::Joined; + break; + case Invited: + tempVis = mtx::events::state::Visibility::Invited; + break; + case Shared: + tempVis = mtx::events::state::Visibility::Shared; + break; + default: + return; + } + + using namespace mtx::events; + auto proxy = std::make_shared<ThreadProxy>(); + connect(proxy.get(), &ThreadProxy::eventSent, this, [this, tempVis]() { + this->historyVisibility_ = tempVis; + emit historyVisibilityChanged(); + }); + connect(proxy.get(), &ThreadProxy::error, this, &RoomSettings::displayError); + + state::HistoryVisibility body; + body.history_visibility = tempVis; + + http::client()->send_state_event( + roomid_.toStdString(), + body, + [proxy](const mtx::responses::EventId &, mtx::http::RequestErr err) { + if (err) { + emit proxy->error(QString::fromStdString(err->matrix_error.error)); + return; + } + + emit proxy->eventSent(); + }); +} + +void RoomSettings::changeTopic(const QString &topic) { // Check if the values are changed from the originals. diff --git a/src/ui/RoomSettings.h b/src/ui/RoomSettings.h index f8d0857c..cf3ac032 100644 --- a/src/ui/RoomSettings.h +++ b/src/ui/RoomSettings.h @@ -6,6 +6,7 @@ #include <QAbstractListModel> #include <QObject> +#include <QQmlEngine> #include <QSet> #include <QString> @@ -13,6 +14,7 @@ #include <mtx/events/event_type.hpp> #include <mtx/events/guest_access.hpp> +#include <mtx/events/history_visibility.hpp> #include "CacheStructs.h" @@ -26,6 +28,7 @@ signals: void error(const QString &msg); void nameEventSent(const QString &); void topicEventSent(const QString &); + void eventSent(); void stopLoading(); }; @@ -78,6 +81,8 @@ class RoomSettings final : public QObject Q_PROPERTY(QString roomAvatarUrl READ roomAvatarUrl NOTIFY avatarUrlChanged) Q_PROPERTY(int memberCount READ memberCount CONSTANT) Q_PROPERTY(int notifications READ notifications NOTIFY notificationsChanged) + Q_PROPERTY(Visibility historyVisibility READ historyVisibility WRITE changeHistoryVisibility + NOTIFY historyVisibilityChanged) Q_PROPERTY(bool privateAccess READ privateAccess NOTIFY accessJoinRulesChanged) Q_PROPERTY(bool guestAccess READ guestAccess NOTIFY accessJoinRulesChanged) Q_PROPERTY(bool knockingEnabled READ knockingEnabled NOTIFY accessJoinRulesChanged) @@ -87,6 +92,7 @@ class RoomSettings final : public QObject Q_PROPERTY(bool canChangeJoinRules READ canChangeJoinRules CONSTANT) Q_PROPERTY(bool canChangeName READ canChangeName CONSTANT) Q_PROPERTY(bool canChangeTopic READ canChangeTopic CONSTANT) + Q_PROPERTY(bool canChangeHistoryVisibility READ canChangeHistoryVisibility CONSTANT) Q_PROPERTY(bool isEncryptionEnabled READ isEncryptionEnabled NOTIFY encryptionChanged) Q_PROPERTY(bool supportsKnocking READ supportsKnocking CONSTANT) Q_PROPERTY(bool supportsRestricted READ supportsRestricted CONSTANT) @@ -98,6 +104,16 @@ class RoomSettings final : public QObject bool allowedRoomsModified READ allowedRoomsModified NOTIFY allowedRoomsModifiedChanged) public: + // match mtx::events::state::Visibility + enum Visibility + { + WorldReadable, + Shared, + Invited, + Joined, + }; + Q_ENUM(Visibility) + RoomSettings(QString roomid, QObject *parent = nullptr); QString roomId() const; @@ -122,6 +138,7 @@ public: bool canChangeTopic() const; //! Whether the user has enough power level to send m.room.avatar event. bool canChangeAvatar() const; + bool canChangeHistoryVisibility() const; bool isEncryptionEnabled() const; bool supportsKnocking() const; bool supportsRestricted() const; @@ -130,6 +147,9 @@ public: void setAllowedRooms(QStringList rooms); bool allowedRoomsModified() const { return allowedRoomsModified_; } + Visibility historyVisibility() const; + Q_INVOKABLE void changeHistoryVisibility(Visibility visibility); + Q_INVOKABLE void enableEncryption(); Q_INVOKABLE void updateAvatar(); Q_INVOKABLE void changeAccessRules(bool private_, @@ -153,6 +173,7 @@ signals: void allowedRoomsChanged(); void displayError(const QString &errorMessage); void allowedRoomsModifiedChanged(); + void historyVisibilityChanged(); public slots: void stopLoading(); @@ -173,7 +194,8 @@ private: int notifications_ = 0; mtx::events::state::JoinRules accessRules_; - mtx::events::state::AccessState guestRules_ = mtx::events::state::AccessState::Forbidden; + mtx::events::state::Visibility historyVisibility_ = mtx::events::state::Visibility::Shared; + mtx::events::state::AccessState guestRules_ = mtx::events::state::AccessState::Forbidden; RoomSettingsAllowedRoomsModel *allowedRoomsModel; }; |