diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2023-06-24 01:04:54 +0200 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2023-06-24 01:04:54 +0200 |
commit | fa653bc078ca80508b5de27ac02c77980dda4c45 (patch) | |
tree | 6e46f203e41eb592870e4ab9a8409ec0db1af04f /src | |
parent | Bump arm job count (diff) | |
download | nheko-fa653bc078ca80508b5de27ac02c77980dda4c45.tar.xz |
Allow viewing and changing the history visibility
Diffstat (limited to 'src')
-rw-r--r-- | src/ui/RoomSettings.cpp | 81 | ||||
-rw-r--r-- | src/ui/RoomSettings.h | 24 |
2 files changed, 104 insertions, 1 deletions
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; }; |