Add history visibiltiy room setting

Add setting for setting the history visibility.

Note this setting can only be read not set for Quotient version < 0.7 as there is no event definition for a history visibility state event and it doesn't seem worth creating one when not needed with Quotient 0.7.

BUG: 457840
This commit is contained in:
James Graham
2022-11-25 16:13:01 +00:00
parent 23548ef151
commit 054ad80d30
3 changed files with 86 additions and 0 deletions

View File

@@ -859,7 +859,15 @@ bool NeoChatRoom::canSendState(const QString &eventType) const
auto pl = plEvent->powerLevelForState(eventType);
auto currentPl = plEvent->powerLevelForUser(localUser()->id());
#ifndef QUOTIENT_07
if (eventType == "m.room.history_visibility") {
return false;
} else {
return currentPl >= pl;
}
#else
return currentPl >= pl;
#endif
}
bool NeoChatRoom::readMarkerLoaded() const
@@ -916,6 +924,32 @@ void NeoChatRoom::setJoinRule(const QString &joinRule)
// Not emitting joinRuleChanged() here, since that would override the change in the UI with the *current* value, which is not the *new* value.
}
QString NeoChatRoom::historyVisibility() const
{
#ifdef QUOTIENT_07
return currentState().get("m.room.history_visibility")->contentJson()["history_visibility"_ls].toString();
#else
return getCurrentState("m.room.history_visibility")->contentJson()["history_visibility"_ls].toString();
#endif
}
void NeoChatRoom::setHistoryVisibility(const QString &historyVisibilityRule)
{
if (!canSendState("m.room.history_visibility")) {
qWarning() << "Power level too low to set history visibility";
return;
}
#ifdef QUOTIENT_07
setState("m.room.history_visibility", "", QJsonObject{{"history_visibility", historyVisibilityRule}});
#else
qWarning() << "Quotient 0.7 required to set history visibility";
return;
#endif
// Not emitting historyVisibilityChanged() here, since that would override the change in the UI with the *current* value, which is not the *new* value.
}
QCoro::Task<void> NeoChatRoom::doDeleteMessagesByUser(const QString &user, QString reason)
{
QStringList events;

View File

@@ -48,6 +48,7 @@ class NeoChatRoom : public Quotient::Room
Q_PROPERTY(QDateTime lastActiveTime READ lastActiveTime NOTIFY lastActiveTimeChanged)
Q_PROPERTY(bool isInvite READ isInvite NOTIFY isInviteChanged)
Q_PROPERTY(QString joinRule READ joinRule WRITE setJoinRule NOTIFY joinRuleChanged)
Q_PROPERTY(QString historyVisibility READ historyVisibility WRITE setHistoryVisibility NOTIFY historyVisibilityChanged)
Q_PROPERTY(QString htmlSafeDisplayName READ htmlSafeDisplayName NOTIFY displayNameChanged)
Q_PROPERTY(PushNotificationState::State pushNotificationState MEMBER m_currentPushNotificationState WRITE setPushNotificationState NOTIFY
pushNotificationStateChanged)
@@ -112,6 +113,9 @@ public:
[[nodiscard]] QString joinRule() const;
void setJoinRule(const QString &joinRule);
[[nodiscard]] QString historyVisibility() const;
void setHistoryVisibility(const QString &historyVisibilityRule);
[[nodiscard]] bool hasFileUploading() const
{
return m_hasFileUploading;
@@ -258,6 +262,7 @@ Q_SIGNALS:
void chatBoxAttachmentPathChanged();
void canEncryptRoomChanged();
void joinRuleChanged();
void historyVisibilityChanged();
public Q_SLOTS:
void uploadFile(const QUrl &url, const QString &body = QString());

View File

@@ -58,6 +58,53 @@ Kirigami.ScrollablePage {
}
}
}
MobileForm.FormCard {
Layout.topMargin: Kirigami.Units.largeSpacing
Layout.fillWidth: true
contentItem: ColumnLayout {
spacing: 0
MobileForm.FormCardHeader {
title: i18nc("@option:check", "Message history visibility")
}
MobileForm.FormRadioDelegate {
text: i18nc("@option:check", "Anyone")
description: i18nc("@option:check", "Anyone, regardless of whether they have joined, can view history.")
checked: room.historyVisibility === "world_readable"
enabled: room.canSendState("m.room.history_visibility")
onCheckedChanged: if (checked) {
room.historyVisibility = "world_readable"
}
}
MobileForm.FormRadioDelegate {
text: i18nc("@option:check", "Members only")
description: i18nc("@option:check", "All members can view the entire message history, even before they joined.")
checked: room.historyVisibility === "shared"
enabled: room.canSendState("m.room.history_visibility")
onCheckedChanged: if (checked) {
room.historyVisibility = "shared"
}
}
MobileForm.FormRadioDelegate {
text: i18nc("@option:check", "Members only (since invite)")
description: i18nc("@option:check", "New members can view the message history from the point they were invited to the room.")
checked: room.historyVisibility === "invited"
enabled: room.canSendState("m.room.history_visibility")
onCheckedChanged: if (checked) {
room.historyVisibility = "invited"
}
}
MobileForm.FormRadioDelegate {
text: i18nc("@option:check", "Members only (since joining)")
description: i18nc("@option:check", "New members can view the message history from the point they joined the room.")
checked: room.historyVisibility === "joined"
enabled: room.canSendState("m.room.history_visibility")
onCheckedChanged: if (checked) {
room.historyVisibility = "joined"
}
}
}
}
}
footer: QQC2.ToolBar {