Disable settings when user doesnt have enough power level
This commit is contained in:
@@ -9,6 +9,11 @@ import Spectral.Setting 0.1
|
||||
Dialog {
|
||||
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
|
||||
width: 480
|
||||
|
||||
@@ -36,6 +41,8 @@ Dialog {
|
||||
|
||||
circular: true
|
||||
|
||||
enabled: canChangeAvatar
|
||||
|
||||
onClicked: {
|
||||
var fileDialog = openFileDialog.createObject(ApplicationWindow.overlay)
|
||||
|
||||
@@ -61,6 +68,8 @@ Dialog {
|
||||
|
||||
text: room.name
|
||||
placeholderText: "Room Name"
|
||||
|
||||
enabled: canChangeName
|
||||
}
|
||||
|
||||
AutoTextField {
|
||||
@@ -70,6 +79,8 @@ Dialog {
|
||||
|
||||
text: room.topic
|
||||
placeholderText: "Room Topic"
|
||||
|
||||
enabled: canChangeTopic
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -179,6 +190,8 @@ Dialog {
|
||||
Button {
|
||||
Layout.alignment: Qt.AlignRight
|
||||
|
||||
visible: canChangeName || canChangeTopic
|
||||
|
||||
text: "Save"
|
||||
highlighted: true
|
||||
|
||||
@@ -216,6 +229,8 @@ Dialog {
|
||||
|
||||
id: canonicalAliasComboBox
|
||||
|
||||
enabled: canChangeCanonicalAlias
|
||||
|
||||
model: room.remoteAliases
|
||||
|
||||
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/roommessageevent.h"
|
||||
#include "events/typingevent.h"
|
||||
#include "events/roompowerlevelsevent.h"
|
||||
#include "jobs/downloadfilejob.h"
|
||||
#include "user.h"
|
||||
#include "utils.h"
|
||||
@@ -487,20 +488,32 @@ void SpectralRoom::postPlainMessage(const QString& text,
|
||||
if (isReply) {
|
||||
const auto& replyEvt = **replyIt;
|
||||
|
||||
QJsonObject json{{"msgtype", msgTypeToString(type)},
|
||||
{"body", "> <" + replyEvt.senderId() + "> " +
|
||||
eventToString(replyEvt) + "\n\n" + text},
|
||||
{"format", "org.matrix.custom.html"},
|
||||
{"m.relates_to",
|
||||
QJsonObject{{"m.in_reply_to",
|
||||
QJsonObject{{"event_id", replyEventId}}}}},
|
||||
{"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.toHtmlEscaped()}};
|
||||
// clang-format off
|
||||
QJsonObject json{
|
||||
{"msgtype", msgTypeToString(type)},
|
||||
{"body", "> <" + replyEvt.senderId() + "> " + eventToString(replyEvt) + "\n\n" + text},
|
||||
{"format", "org.matrix.custom.html"},
|
||||
{"m.relates_to",
|
||||
{
|
||||
{"m.in_reply_to",
|
||||
{
|
||||
{"event_id", replyEventId}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{"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);
|
||||
|
||||
return;
|
||||
@@ -521,20 +534,32 @@ void SpectralRoom::postHtmlMessage(const QString& text,
|
||||
if (isReply) {
|
||||
const auto& replyEvt = **replyIt;
|
||||
|
||||
QJsonObject json{{"msgtype", msgTypeToString(type)},
|
||||
{"body", "> <" + replyEvt.senderId() + "> " +
|
||||
eventToString(replyEvt) + "\n\n" + text},
|
||||
{"format", "org.matrix.custom.html"},
|
||||
{"m.relates_to",
|
||||
QJsonObject{{"m.in_reply_to",
|
||||
QJsonObject{{"event_id", replyEventId}}}}},
|
||||
{"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 off
|
||||
QJsonObject json{
|
||||
{"msgtype", msgTypeToString(type)},
|
||||
{"body", "> <" + replyEvt.senderId() + "> " + eventToString(replyEvt) + "\n\n" + text},
|
||||
{"format", "org.matrix.custom.html"},
|
||||
{"m.relates_to",
|
||||
{
|
||||
{"m.in_reply_to",
|
||||
{
|
||||
{"event_id", replyEventId}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{"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);
|
||||
|
||||
return;
|
||||
@@ -588,3 +613,19 @@ bool SpectralRoom::containsUser(QString userID) const {
|
||||
|
||||
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 canSendEvent(const QString& eventType) const;
|
||||
Q_INVOKABLE bool canSendState(const QString& eventType) const;
|
||||
|
||||
private:
|
||||
QString m_cachedInput;
|
||||
QSet<const Quotient::RoomEvent*> highlights;
|
||||
|
||||
Reference in New Issue
Block a user