diff --git a/TODO.md b/TODO.md index 9a059527..74a4ca8f 100644 --- a/TODO.md +++ b/TODO.md @@ -57,6 +57,7 @@ - UI - Scrollable popup + - HDrawer snapping - Make theme error/etc text colors more like name colors - In account settings, display name field text should be colored - Way to open context menus without a right mouse button @@ -103,8 +104,7 @@ - Server selection - 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 - Theming diff --git a/src/python/matrix_client.py b/src/python/matrix_client.py index a68eb109..27438b2f 100644 --- a/src/python/matrix_client.py +++ b/src/python/matrix_client.py @@ -801,8 +801,9 @@ class MatrixClient(nio.AsyncClient): except KeyError: last_ev = None - inviter = getattr(room, "inviter", "") or "" - levels = room.power_levels + inviter = getattr(room, "inviter", "") or "" + levels = room.power_levels + our_level = levels.get_user_level(self.user_id) self.models[Room, self.user_id][room.room_id] = Room( room_id = room.room_id, @@ -815,8 +816,8 @@ class MatrixClient(nio.AsyncClient): (room.avatar_url(inviter) or "") if inviter else "", left = left, - can_invite = - levels.users.get(self.user_id, 0) >= levels.defaults.invite, + can_invite = our_level >= levels.defaults.invite, + can_send_messages = our_level >= levels.defaults.events_default, last_event = last_ev, ) diff --git a/src/python/models/items.py b/src/python/models/items.py index 4790251e..9f6fdbd7 100644 --- a/src/python/models/items.py +++ b/src/python/models/items.py @@ -47,7 +47,8 @@ class Room(ModelItem): left: bool = False typing_members: List[str] = field(default_factory=list) - can_invite: bool = True + can_invite: bool = True + can_send_messages: bool = True # Event.serialized last_event: Optional[Dict[str, Any]] = field(default=None, repr=False) diff --git a/src/qml/Base/HScrollableTextArea.qml b/src/qml/Base/HScrollableTextArea.qml index a8d63197..0b1d9830 100644 --- a/src/qml/Base/HScrollableTextArea.qml +++ b/src/qml/Base/HScrollableTextArea.qml @@ -1,3 +1,4 @@ + import QtQuick 2.12 import QtQuick.Controls 2.12 @@ -23,13 +24,17 @@ ScrollView { property alias backgroundColor: textAreaBackground.color property alias placeholderText: textArea.placeholderText - property alias text: textArea.text + property alias placeholderTextColor: textArea.placeholderTextColor property alias area: textArea + property alias text: textArea.text + property string disabledText: "" + property string disabledTextColor: theme.controls.textArea.disabledText property var focusItemOnTab: null TextArea { id: textArea + enabled: parent.enabled leftPadding: theme.spacing rightPadding: leftPadding topPadding: theme.spacing / 1.5 @@ -45,6 +50,7 @@ ScrollView { placeholderTextColor: theme.controls.textArea.placeholderText color: theme.controls.textArea.text + background: Rectangle { id: textAreaBackground color: theme.controls.textArea.background @@ -57,5 +63,37 @@ ScrollView { KeyNavigation.priority: KeyNavigation.BeforeItem 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 {} } + } } } diff --git a/src/qml/Chat/Composer.qml b/src/qml/Chat/Composer.qml index 41bf522e..3a696a60 100644 --- a/src/qml/Chat/Composer.qml +++ b/src/qml/Chat/Composer.qml @@ -68,7 +68,11 @@ Rectangle { saveName: "composer" 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...") + backgroundColor: "transparent" area.tabStopDistance: 4 * 4 // 4 spaces area.focus: true @@ -209,6 +213,7 @@ Rectangle { } HButton { + enabled: chat.roomInfo.can_send_messages icon.name: "upload-file" backgroundColor: theme.chat.composer.uploadButton.background toolTip.text: qsTr("Send files") diff --git a/src/themes/Default.qpl b/src/themes/Default.qpl index 51ae63f5..938acb3b 100644 --- a/src/themes/Default.qpl +++ b/src/themes/Default.qpl @@ -171,11 +171,13 @@ controls: color text: colors.text color focusedText: colors.text color placeholderText: colors.dimText + color disabledText: colors.dimText textArea: color background: colors.inputBackground color text: colors.text color placeholderText: controls.textField.placeholderText + color disabledText: controls.textField.disabledText toolTip: int delay: 500