Disable composer/upload button when no permission

This commit is contained in:
miruka 2019-12-11 13:53:22 -04:00
parent c2b7b458f9
commit c4ee77ca15
6 changed files with 55 additions and 8 deletions

View File

@ -57,6 +57,7 @@
- UI - UI
- Scrollable popup - Scrollable popup
- HDrawer snapping
- Make theme error/etc text colors more like name colors - Make theme error/etc text colors more like name colors
- In account settings, display name field text should be colored - In account settings, display name field text should be colored
- Way to open context menus without a right mouse button - Way to open context menus without a right mouse button
@ -103,7 +104,6 @@
- Server selection - Server selection
- Register/Reset for AddAccount page - Register/Reset for AddAccount page
- Prevent using the composer if no permission (power levels)
- Prevent using an alias if that user is not in the room or no permission - Prevent using an alias if that user is not in the room or no permission
- Spinner when loading past room events - Spinner when loading past room events

View File

@ -803,6 +803,7 @@ class MatrixClient(nio.AsyncClient):
inviter = getattr(room, "inviter", "") or "" inviter = getattr(room, "inviter", "") or ""
levels = room.power_levels levels = room.power_levels
our_level = levels.get_user_level(self.user_id)
self.models[Room, self.user_id][room.room_id] = Room( self.models[Room, self.user_id][room.room_id] = Room(
room_id = room.room_id, room_id = room.room_id,
@ -815,8 +816,8 @@ class MatrixClient(nio.AsyncClient):
(room.avatar_url(inviter) or "") if inviter else "", (room.avatar_url(inviter) or "") if inviter else "",
left = left, left = left,
can_invite = can_invite = our_level >= levels.defaults.invite,
levels.users.get(self.user_id, 0) >= levels.defaults.invite, can_send_messages = our_level >= levels.defaults.events_default,
last_event = last_ev, last_event = last_ev,
) )

View File

@ -48,6 +48,7 @@ class Room(ModelItem):
typing_members: List[str] = field(default_factory=list) typing_members: List[str] = field(default_factory=list)
can_invite: bool = True can_invite: bool = True
can_send_messages: bool = True
# Event.serialized # Event.serialized
last_event: Optional[Dict[str, Any]] = field(default=None, repr=False) last_event: Optional[Dict[str, Any]] = field(default=None, repr=False)

View File

@ -1,3 +1,4 @@
import QtQuick 2.12 import QtQuick 2.12
import QtQuick.Controls 2.12 import QtQuick.Controls 2.12
@ -23,13 +24,17 @@ ScrollView {
property alias backgroundColor: textAreaBackground.color property alias backgroundColor: textAreaBackground.color
property alias placeholderText: textArea.placeholderText property alias placeholderText: textArea.placeholderText
property alias text: textArea.text property alias placeholderTextColor: textArea.placeholderTextColor
property alias area: textArea property alias area: textArea
property alias text: textArea.text
property string disabledText: ""
property string disabledTextColor: theme.controls.textArea.disabledText
property var focusItemOnTab: null property var focusItemOnTab: null
TextArea { TextArea {
id: textArea id: textArea
enabled: parent.enabled
leftPadding: theme.spacing leftPadding: theme.spacing
rightPadding: leftPadding rightPadding: leftPadding
topPadding: theme.spacing / 1.5 topPadding: theme.spacing / 1.5
@ -45,6 +50,7 @@ ScrollView {
placeholderTextColor: theme.controls.textArea.placeholderText placeholderTextColor: theme.controls.textArea.placeholderText
color: theme.controls.textArea.text color: theme.controls.textArea.text
background: Rectangle { background: Rectangle {
id: textAreaBackground id: textAreaBackground
color: theme.controls.textArea.background color: theme.controls.textArea.background
@ -57,5 +63,37 @@ ScrollView {
KeyNavigation.priority: KeyNavigation.BeforeItem KeyNavigation.priority: KeyNavigation.BeforeItem
KeyNavigation.tab: focusItemOnTab KeyNavigation.tab: focusItemOnTab
Binding on color {
value: "transparent"
when: ! textArea.enabled
}
Binding on placeholderTextColor {
value: "transparent"
when: ! textArea.enabled
}
Behavior on color { HColorAnimation {} }
Behavior on placeholderTextColor { HColorAnimation {} }
HLabel {
anchors.fill: parent
visible: opacity > 0
opacity: parent.enabled ? 0 : 1
color: disabledTextColor
text: disabledText
leftPadding: parent.leftPadding
rightPadding: parent.rightPadding
topPadding: parent.topPadding
bottomPadding: parent.bottomPadding
wrapMode: parent.wrapMode
font.family: parent.font.family
font.pixelSize: parent.font.pixelSize
Behavior on opacity { HOpacityAnimator {} }
}
} }
} }

View File

@ -68,7 +68,11 @@ Rectangle {
saveName: "composer" saveName: "composer"
saveId: [chat.roomId, writingUserId] saveId: [chat.roomId, writingUserId]
enabled: chat.roomInfo.can_send_messages
disabledText:
qsTr("You do not have permission to post in this room")
placeholderText: qsTr("Type a message...") placeholderText: qsTr("Type a message...")
backgroundColor: "transparent" backgroundColor: "transparent"
area.tabStopDistance: 4 * 4 // 4 spaces area.tabStopDistance: 4 * 4 // 4 spaces
area.focus: true area.focus: true
@ -209,6 +213,7 @@ Rectangle {
} }
HButton { HButton {
enabled: chat.roomInfo.can_send_messages
icon.name: "upload-file" icon.name: "upload-file"
backgroundColor: theme.chat.composer.uploadButton.background backgroundColor: theme.chat.composer.uploadButton.background
toolTip.text: qsTr("Send files") toolTip.text: qsTr("Send files")

View File

@ -171,11 +171,13 @@ controls:
color text: colors.text color text: colors.text
color focusedText: colors.text color focusedText: colors.text
color placeholderText: colors.dimText color placeholderText: colors.dimText
color disabledText: colors.dimText
textArea: textArea:
color background: colors.inputBackground color background: colors.inputBackground
color text: colors.text color text: colors.text
color placeholderText: controls.textField.placeholderText color placeholderText: controls.textField.placeholderText
color disabledText: controls.textField.disabledText
toolTip: toolTip:
int delay: 500 int delay: 500