Disable settings when user doesnt have enough power level
This commit is contained in:
@@ -9,6 +9,11 @@ import Spectral.Setting 0.1
|
|||||||
Dialog {
|
Dialog {
|
||||||
property var room
|
property var room
|
||||||
|
|
||||||
|
readonly property bool canChangeAvatar: room.canSendState("m.room.avatar")
|
||||||
|
readonly property bool canChangeName: room.canSendState("m.room.name")
|
||||||
|
readonly property bool canChangeTopic: room.canSendState("m.room.topic")
|
||||||
|
readonly property bool canChangeCanonicalAlias: room.canSendState("m.room.canonical_alias")
|
||||||
|
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
width: 480
|
width: 480
|
||||||
|
|
||||||
@@ -36,6 +41,8 @@ Dialog {
|
|||||||
|
|
||||||
circular: true
|
circular: true
|
||||||
|
|
||||||
|
enabled: canChangeAvatar
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var fileDialog = openFileDialog.createObject(ApplicationWindow.overlay)
|
var fileDialog = openFileDialog.createObject(ApplicationWindow.overlay)
|
||||||
|
|
||||||
@@ -61,6 +68,8 @@ Dialog {
|
|||||||
|
|
||||||
text: room.name
|
text: room.name
|
||||||
placeholderText: "Room Name"
|
placeholderText: "Room Name"
|
||||||
|
|
||||||
|
enabled: canChangeName
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoTextField {
|
AutoTextField {
|
||||||
@@ -70,6 +79,8 @@ Dialog {
|
|||||||
|
|
||||||
text: room.topic
|
text: room.topic
|
||||||
placeholderText: "Room Topic"
|
placeholderText: "Room Topic"
|
||||||
|
|
||||||
|
enabled: canChangeTopic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -179,6 +190,8 @@ Dialog {
|
|||||||
Button {
|
Button {
|
||||||
Layout.alignment: Qt.AlignRight
|
Layout.alignment: Qt.AlignRight
|
||||||
|
|
||||||
|
visible: canChangeName || canChangeTopic
|
||||||
|
|
||||||
text: "Save"
|
text: "Save"
|
||||||
highlighted: true
|
highlighted: true
|
||||||
|
|
||||||
@@ -216,6 +229,8 @@ Dialog {
|
|||||||
|
|
||||||
id: canonicalAliasComboBox
|
id: canonicalAliasComboBox
|
||||||
|
|
||||||
|
enabled: canChangeCanonicalAlias
|
||||||
|
|
||||||
model: room.remoteAliases
|
model: room.remoteAliases
|
||||||
|
|
||||||
currentIndex: room.remoteAliases.indexOf(room.canonicalAlias)
|
currentIndex: room.remoteAliases.indexOf(room.canonicalAlias)
|
||||||
@@ -275,6 +290,42 @@ Dialog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
|
||||||
|
Label {
|
||||||
|
Layout.preferredWidth: 100
|
||||||
|
Layout.alignment: Qt.AlignTop
|
||||||
|
|
||||||
|
wrapMode: Label.Wrap
|
||||||
|
text: "Remote Aliases"
|
||||||
|
color: MPalette.lighter
|
||||||
|
}
|
||||||
|
|
||||||
|
ColumnLayout {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
|
||||||
|
spacing: 0
|
||||||
|
|
||||||
|
Repeater {
|
||||||
|
model: {
|
||||||
|
var localAliases = room.localAliases
|
||||||
|
var remoteAliases = room.remoteAliases
|
||||||
|
return remoteAliases.filter(n => !localAliases.includes(n))
|
||||||
|
}
|
||||||
|
|
||||||
|
delegate: Label {
|
||||||
|
width: parent.width
|
||||||
|
|
||||||
|
text: modelData
|
||||||
|
|
||||||
|
font.pixelSize: 12
|
||||||
|
color: MPalette.lighter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Submodule include/libQuotient updated: 16d6700950...d4034fb12b
@@ -21,6 +21,7 @@
|
|||||||
#include "events/reactionevent.h"
|
#include "events/reactionevent.h"
|
||||||
#include "events/roommessageevent.h"
|
#include "events/roommessageevent.h"
|
||||||
#include "events/typingevent.h"
|
#include "events/typingevent.h"
|
||||||
|
#include "events/roompowerlevelsevent.h"
|
||||||
#include "jobs/downloadfilejob.h"
|
#include "jobs/downloadfilejob.h"
|
||||||
#include "user.h"
|
#include "user.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
@@ -487,20 +488,32 @@ void SpectralRoom::postPlainMessage(const QString& text,
|
|||||||
if (isReply) {
|
if (isReply) {
|
||||||
const auto& replyEvt = **replyIt;
|
const auto& replyEvt = **replyIt;
|
||||||
|
|
||||||
QJsonObject json{{"msgtype", msgTypeToString(type)},
|
// clang-format off
|
||||||
{"body", "> <" + replyEvt.senderId() + "> " +
|
QJsonObject json{
|
||||||
eventToString(replyEvt) + "\n\n" + text},
|
{"msgtype", msgTypeToString(type)},
|
||||||
{"format", "org.matrix.custom.html"},
|
{"body", "> <" + replyEvt.senderId() + "> " + eventToString(replyEvt) + "\n\n" + text},
|
||||||
{"m.relates_to",
|
{"format", "org.matrix.custom.html"},
|
||||||
QJsonObject{{"m.in_reply_to",
|
{"m.relates_to",
|
||||||
QJsonObject{{"event_id", replyEventId}}}}},
|
{
|
||||||
{"formatted_body",
|
{"m.in_reply_to",
|
||||||
"<mx-reply><blockquote><a href=\"https://matrix.to/#/" +
|
{
|
||||||
id() + "/" + replyEventId +
|
{"event_id", replyEventId}
|
||||||
"\">In reply to</a> <a href=\"https://matrix.to/#/" +
|
}
|
||||||
replyEvt.senderId() + "\">" + replyEvt.senderId() +
|
}
|
||||||
"</a><br>" + eventToString(replyEvt, Qt::RichText) +
|
}
|
||||||
"</blockquote></mx-reply>" + text.toHtmlEscaped()}};
|
},
|
||||||
|
{"formatted_body",
|
||||||
|
"<mx-reply><blockquote><a href=\"https://matrix.to/#/" +
|
||||||
|
id() + "/" +
|
||||||
|
replyEventId +
|
||||||
|
"\">In reply to</a> <a href=\"https://matrix.to/#/" +
|
||||||
|
replyEvt.senderId() + "\">" + replyEvt.senderId() +
|
||||||
|
"</a><br>" + eventToString(replyEvt, Qt::RichText) +
|
||||||
|
"</blockquote></mx-reply>" + text
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
postJson("m.room.message", json);
|
postJson("m.room.message", json);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -521,20 +534,32 @@ void SpectralRoom::postHtmlMessage(const QString& text,
|
|||||||
if (isReply) {
|
if (isReply) {
|
||||||
const auto& replyEvt = **replyIt;
|
const auto& replyEvt = **replyIt;
|
||||||
|
|
||||||
QJsonObject json{{"msgtype", msgTypeToString(type)},
|
// clang-format off
|
||||||
{"body", "> <" + replyEvt.senderId() + "> " +
|
QJsonObject json{
|
||||||
eventToString(replyEvt) + "\n\n" + text},
|
{"msgtype", msgTypeToString(type)},
|
||||||
{"format", "org.matrix.custom.html"},
|
{"body", "> <" + replyEvt.senderId() + "> " + eventToString(replyEvt) + "\n\n" + text},
|
||||||
{"m.relates_to",
|
{"format", "org.matrix.custom.html"},
|
||||||
QJsonObject{{"m.in_reply_to",
|
{"m.relates_to",
|
||||||
QJsonObject{{"event_id", replyEventId}}}}},
|
{
|
||||||
{"formatted_body",
|
{"m.in_reply_to",
|
||||||
"<mx-reply><blockquote><a href=\"https://matrix.to/#/" +
|
{
|
||||||
id() + "/" + replyEventId +
|
{"event_id", replyEventId}
|
||||||
"\">In reply to</a> <a href=\"https://matrix.to/#/" +
|
}
|
||||||
replyEvt.senderId() + "\">" + replyEvt.senderId() +
|
}
|
||||||
"</a><br>" + eventToString(replyEvt, Qt::RichText) +
|
}
|
||||||
"</blockquote></mx-reply>" + html}};
|
},
|
||||||
|
{"formatted_body",
|
||||||
|
"<mx-reply><blockquote><a href=\"https://matrix.to/#/" +
|
||||||
|
id() + "/" +
|
||||||
|
replyEventId +
|
||||||
|
"\">In reply to</a> <a href=\"https://matrix.to/#/" +
|
||||||
|
replyEvt.senderId() + "\">" + replyEvt.senderId() +
|
||||||
|
"</a><br>" + eventToString(replyEvt, Qt::RichText) +
|
||||||
|
"</blockquote></mx-reply>" + html
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
postJson("m.room.message", json);
|
postJson("m.room.message", json);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -588,3 +613,19 @@ bool SpectralRoom::containsUser(QString userID) const {
|
|||||||
|
|
||||||
return Room::memberJoinState(u) != JoinState::Leave;
|
return Room::memberJoinState(u) != JoinState::Leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SpectralRoom::canSendEvent(const QString& eventType) const {
|
||||||
|
auto plEvent = getCurrentState<RoomPowerLevelsEvent>();
|
||||||
|
auto pl = plEvent->powerLevelForEvent(eventType);
|
||||||
|
auto currentPl = plEvent->powerLevelForUser(localUser()->id());
|
||||||
|
|
||||||
|
return currentPl >= pl;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SpectralRoom::canSendState(const QString& eventType) const {
|
||||||
|
auto plEvent = getCurrentState<RoomPowerLevelsEvent>();
|
||||||
|
auto pl = plEvent->powerLevelForState(eventType);
|
||||||
|
auto currentPl = plEvent->powerLevelForUser(localUser()->id());
|
||||||
|
|
||||||
|
return currentPl >= pl;
|
||||||
|
}
|
||||||
|
|||||||
@@ -75,6 +75,9 @@ class SpectralRoom : public Room {
|
|||||||
|
|
||||||
Q_INVOKABLE bool containsUser(QString userID) const;
|
Q_INVOKABLE bool containsUser(QString userID) const;
|
||||||
|
|
||||||
|
Q_INVOKABLE bool canSendEvent(const QString& eventType) const;
|
||||||
|
Q_INVOKABLE bool canSendState(const QString& eventType) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_cachedInput;
|
QString m_cachedInput;
|
||||||
QSet<const Quotient::RoomEvent*> highlights;
|
QSet<const Quotient::RoomEvent*> highlights;
|
||||||
|
|||||||
Reference in New Issue
Block a user