Implement (read-only for now) room settings
This commit is contained in:
parent
f8d5260fd7
commit
d240de702f
@ -7,6 +7,7 @@ import re
|
|||||||
import traceback
|
import traceback
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from functools import partial
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import (
|
from typing import (
|
||||||
Any, DefaultDict, Dict, List, NamedTuple, Optional, Set, Tuple, Type,
|
Any, DefaultDict, Dict, List, NamedTuple, Optional, Set, Tuple, Type,
|
||||||
@ -801,14 +802,17 @@ class MatrixClient(nio.AsyncClient):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
last_ev = None
|
last_ev = None
|
||||||
|
|
||||||
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)
|
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(
|
self.models[Room, self.user_id][room.room_id] = Room(
|
||||||
room_id = room.room_id,
|
room_id = room.room_id,
|
||||||
|
given_name = room.name,
|
||||||
display_name = room.display_name or "",
|
display_name = room.display_name or "",
|
||||||
avatar_url = room.gen_avatar_url or "",
|
avatar_url = room.gen_avatar_url or "",
|
||||||
|
plain_topic = room.topic,
|
||||||
topic = HTML_FILTER.filter_inline(room.topic or ""),
|
topic = HTML_FILTER.filter_inline(room.topic or ""),
|
||||||
inviter_id = inviter,
|
inviter_id = inviter,
|
||||||
inviter_name = room.user_name(inviter) if inviter else "",
|
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 "",
|
(room.avatar_url(inviter) or "") if inviter else "",
|
||||||
left = left,
|
left = left,
|
||||||
|
|
||||||
can_invite = our_level >= levels.defaults.invite,
|
encrypted = room.encrypted,
|
||||||
can_send_messages = our_level >= levels.defaults.events_default,
|
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,
|
last_event = last_ev,
|
||||||
)
|
)
|
||||||
|
@ -38,8 +38,10 @@ class Account(ModelItem):
|
|||||||
@dataclass
|
@dataclass
|
||||||
class Room(ModelItem):
|
class Room(ModelItem):
|
||||||
room_id: str = field()
|
room_id: str = field()
|
||||||
|
given_name: str = ""
|
||||||
display_name: str = ""
|
display_name: str = ""
|
||||||
avatar_url: str = ""
|
avatar_url: str = ""
|
||||||
|
plain_topic: str = ""
|
||||||
topic: str = ""
|
topic: str = ""
|
||||||
inviter_id: str = ""
|
inviter_id: str = ""
|
||||||
inviter_name: str = ""
|
inviter_name: str = ""
|
||||||
@ -47,8 +49,18 @@ class Room(ModelItem):
|
|||||||
left: bool = False
|
left: bool = False
|
||||||
typing_members: List[str] = field(default_factory=list)
|
typing_members: List[str] = field(default_factory=list)
|
||||||
|
|
||||||
can_invite: bool = True
|
encrypted: bool = False
|
||||||
can_send_messages: bool = True
|
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
|
# Event.serialized
|
||||||
last_event: Optional[Dict[str, Any]] = field(default=None, repr=False)
|
last_event: Optional[Dict[str, Any]] = field(default=None, repr=False)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import QtQuick 2.12
|
import QtQuick 2.12
|
||||||
|
import QtQuick.Controls 2.12
|
||||||
import QtQuick.Layouts 1.12
|
import QtQuick.Layouts 1.12
|
||||||
import "../../Base"
|
import "../../Base"
|
||||||
|
|
||||||
@ -43,19 +44,32 @@ HDrawer {
|
|||||||
height: theme.baseElementsHeight
|
height: theme.baseElementsHeight
|
||||||
backgroundColor: "transparent"
|
backgroundColor: "transparent"
|
||||||
icon.name: "room-view-" + modelData
|
icon.name: "room-view-" + modelData
|
||||||
autoExclusive: true
|
|
||||||
checked: modelData === "members"
|
|
||||||
enabled: modelData === "members"
|
|
||||||
toolTip.text: qsTr(
|
toolTip.text: qsTr(
|
||||||
modelData.charAt(0).toUpperCase() + modelData.slice(1)
|
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.fillWidth: true
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
|
|
||||||
|
MemberView {}
|
||||||
|
Item {}
|
||||||
|
Item {}
|
||||||
|
Item {}
|
||||||
|
SettingsView {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
88
src/qml/Chat/RoomPane/SettingsView.qml
Normal file
88
src/qml/Chat/RoomPane/SettingsView.qml
Normal file
@ -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") +
|
||||||
|
`<br><font color="${theme.colors.middleBackground}">` +
|
||||||
|
(
|
||||||
|
chat.roomInfo.encrypted ?
|
||||||
|
qsTr("Cannot be disabled") :
|
||||||
|
qsTr("Cannot be disabled later!")
|
||||||
|
) +
|
||||||
|
"</font>"
|
||||||
|
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
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user