mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-21 18:50:47 +03:00
Allow viewing and changing the history visibility
This commit is contained in:
parent
3e56e4e578
commit
fa653bc078
3 changed files with 135 additions and 1 deletions
|
@ -377,6 +377,37 @@ ApplicationWindow {
|
|||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
@ -278,6 +299,20 @@ RoomSettings::canChangeAvatar() const
|
|||
return false;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
|
@ -457,6 +492,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)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue