diff --git a/src/python/matrix_client.py b/src/python/matrix_client.py
index a8957a70..b2f0c247 100644
--- a/src/python/matrix_client.py
+++ b/src/python/matrix_client.py
@@ -7,6 +7,7 @@ import re
import traceback
from contextlib import suppress
from datetime import datetime
+from functools import partial
from pathlib import Path
from typing import (
Any, DefaultDict, Dict, List, NamedTuple, Optional, Set, Tuple, Type,
@@ -801,14 +802,17 @@ class MatrixClient(nio.AsyncClient):
except KeyError:
last_ev = None
- inviter = getattr(room, "inviter", "") or ""
- levels = room.power_levels
- our_level = levels.get_user_level(self.user_id)
+ inviter = getattr(room, "inviter", "") or ""
+ levels = room.power_levels
+ can_send_state = partial(levels.can_user_send_state, self.user_id)
+ can_send_msg = partial(levels.can_user_send_message, self.user_id)
self.models[Room, self.user_id][room.room_id] = Room(
room_id = room.room_id,
+ given_name = room.name,
display_name = room.display_name or "",
avatar_url = room.gen_avatar_url or "",
+ plain_topic = room.topic,
topic = HTML_FILTER.filter_inline(room.topic or ""),
inviter_id = inviter,
inviter_name = room.user_name(inviter) if inviter else "",
@@ -816,8 +820,18 @@ class MatrixClient(nio.AsyncClient):
(room.avatar_url(inviter) or "") if inviter else "",
left = left,
- can_invite = our_level >= levels.defaults.invite,
- can_send_messages = our_level >= levels.defaults.events_default,
+ encrypted = room.encrypted,
+ invite_required = room.join_rule == "invite",
+ guests_allowed = room.guest_access == "can_join",
+
+ can_invite = levels.can_user_invite(self.user),
+ can_send_messages = can_send_msg(),
+ can_set_name = can_send_state("m.room.name"),
+ can_set_topic = can_send_state("m.room.topic"),
+ can_set_avatar = can_send_state("m.room.avatar"),
+ can_set_encryption = can_send_state("m.room.encryption"),
+ can_set_join_rules = can_send_state("m.room.join_rules"),
+ can_set_guest_access = can_send_state("m.room.guest_access"),
last_event = last_ev,
)
diff --git a/src/python/models/items.py b/src/python/models/items.py
index 6e819d3a..a0d056d7 100644
--- a/src/python/models/items.py
+++ b/src/python/models/items.py
@@ -38,8 +38,10 @@ class Account(ModelItem):
@dataclass
class Room(ModelItem):
room_id: str = field()
+ given_name: str = ""
display_name: str = ""
avatar_url: str = ""
+ plain_topic: str = ""
topic: str = ""
inviter_id: str = ""
inviter_name: str = ""
@@ -47,8 +49,18 @@ class Room(ModelItem):
left: bool = False
typing_members: List[str] = field(default_factory=list)
- can_invite: bool = True
- can_send_messages: bool = True
+ encrypted: bool = False
+ invite_required: bool = True
+ guests_allowed: bool = True
+
+ can_invite: bool = False
+ can_send_messages: bool = False
+ can_set_name: bool = False
+ can_set_topic: bool = False
+ can_set_avatar: bool = False
+ can_set_encryption: bool = False
+ can_set_join_rules: bool = False
+ can_set_guest_access: bool = False
# Event.serialized
last_event: Optional[Dict[str, Any]] = field(default=None, repr=False)
diff --git a/src/qml/Chat/RoomPane/RoomPane.qml b/src/qml/Chat/RoomPane/RoomPane.qml
index 09a917a3..72043a86 100644
--- a/src/qml/Chat/RoomPane/RoomPane.qml
+++ b/src/qml/Chat/RoomPane/RoomPane.qml
@@ -1,4 +1,5 @@
import QtQuick 2.12
+import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import "../../Base"
@@ -43,19 +44,32 @@ HDrawer {
height: theme.baseElementsHeight
backgroundColor: "transparent"
icon.name: "room-view-" + modelData
- autoExclusive: true
- checked: modelData === "members"
- enabled: modelData === "members"
toolTip.text: qsTr(
modelData.charAt(0).toUpperCase() + modelData.slice(1)
)
+
+ autoExclusive: true
+ checked: swipeView.currentIndex === index
+ enabled: ["members", "settings"].includes(modelData)
+
+ onClicked: swipeView.currentIndex = index
}
}
}
- MemberView {
+ SwipeView {
+ id: swipeView
+ interactive: ! roomPane.collapsed
+ currentIndex: 4 // XXX
+
Layout.fillWidth: true
Layout.fillHeight: true
+
+ MemberView {}
+ Item {}
+ Item {}
+ Item {}
+ SettingsView {}
}
}
}
diff --git a/src/qml/Chat/RoomPane/SettingsView.qml b/src/qml/Chat/RoomPane/SettingsView.qml
new file mode 100644
index 00000000..fe8bd128
--- /dev/null
+++ b/src/qml/Chat/RoomPane/SettingsView.qml
@@ -0,0 +1,88 @@
+import QtQuick 2.12
+import QtQuick.Layouts 1.12
+import "../../Base"
+import "../../utils.js" as Utils
+
+// TODO: hide roompane until room is loaded & expand if too small
+
+HBox {
+ color: "transparent"
+ Component.onCompleted: Utils.debug(this) // XXX
+
+ HRoomAvatar {
+ id: avatar
+ displayName: chat.roomInfo.display_name
+ mxc: chat.roomInfo.avatar_url
+ // enabled: chat.roomInfo.can_set_avatar # put this in "change avatar"
+
+ Layout.fillWidth: true
+ Layout.preferredHeight: width
+ Layout.maximumWidth: 256 * theme.uiScale
+ }
+
+ HTextField {
+ id: nameField
+ placeholderText: qsTr("Room name")
+ maximumLength: 255
+ text: chat.roomInfo.given_name
+ enabled: chat.roomInfo.can_set_name
+
+ Layout.fillWidth: true
+ }
+
+ HScrollableTextArea {
+ id: topicField
+ placeholderText: qsTr("Room topic")
+ text: chat.roomInfo.plain_topic
+ enabled: chat.roomInfo.can_set_topic
+
+ Layout.fillWidth: true
+ }
+
+ HCheckBox {
+ id: encryptCheckBox
+ text: qsTr("Encrypt messages")
+ subtitle.text:
+ qsTr("Only you and those you trust will be able to read the " +
+ "conversation") +
+ `
` +
+ (
+ chat.roomInfo.encrypted ?
+ qsTr("Cannot be disabled") :
+ qsTr("Cannot be disabled later!")
+ ) +
+ ""
+ subtitle.textFormat: Text.StyledText
+ checked: chat.roomInfo.encrypted
+ enabled: chat.roomInfo.can_set_encryption && ! chat.roomInfo.encrypted
+
+ Layout.fillWidth: true
+ }
+
+ HCheckBox {
+ id: requireInviteCheckbox
+ text: qsTr("Require being invited")
+ subtitle.text: qsTr("Users will need an invite to join the room")
+ checked: chat.roomInfo.invite_required
+ enabled: chat.roomInfo.can_set_join_rules
+
+ Layout.fillWidth: true
+ }
+
+ HCheckBox {
+ text: qsTr("Forbid guests")
+ subtitle.text: qsTr("Users without an account won't be able to join")
+ checked: ! chat.roomInfo.guests_allowed
+ enabled: chat.roomInfo.can_set_guest_access
+
+ Layout.fillWidth: true
+ }
+
+ // HCheckBox { TODO
+ // text: qsTr("Make this room visible in the public room directory")
+ // checked: chat.roomInfo.published_in_directory
+
+ // Layout.fillWidth: true
+ // }
+
+}