some updates to add to space toggles
This commit is contained in:
parent
9c21ac3f8f
commit
11575b1a9a
4 changed files with 43 additions and 17 deletions
|
|
@ -194,6 +194,12 @@ class SettingsView extends StatelessWidget {
|
|||
Icons.chevron_right_outlined,
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.psychology_outlined),
|
||||
title: Text(L10n.of(context)!.learningSettings),
|
||||
onTap: () => context.go('/rooms/settings/learning'),
|
||||
trailing: const Icon(Icons.chevron_right_outlined),
|
||||
),
|
||||
// Pangea#
|
||||
ListTile(
|
||||
leading: const Icon(Icons.shield_outlined),
|
||||
|
|
|
|||
|
|
@ -123,11 +123,19 @@ extension ChildrenAndParentsRoomExtension on Room {
|
|||
|
||||
// Checks if has permissions to add child chat
|
||||
// Or whether potential child space is ancestor of this
|
||||
bool _canAddAsParentOf(Room? child) {
|
||||
if (child == null || !child.isSpace) {
|
||||
return _canIAddSpaceChild(child);
|
||||
}
|
||||
if (id == child.id) return false;
|
||||
return !child._allSpaceChildRoomIds.contains(id);
|
||||
bool _canAddAsParentOf(Room? child, {bool spaceMode = false}) {
|
||||
// don't add a room to itself
|
||||
if (id == child?.id) return false;
|
||||
spaceMode = child?.isSpace ?? spaceMode;
|
||||
|
||||
// get the bool for adding chats to spaces
|
||||
final bool canAddChild = _canIAddSpaceChild(child, spaceMode: spaceMode);
|
||||
if (!spaceMode) return canAddChild;
|
||||
|
||||
// if adding space to a space, check if the child is an ancestor
|
||||
// to prevent cycles
|
||||
final bool isCycle =
|
||||
child != null ? child._allSpaceChildRoomIds.contains(id) : false;
|
||||
return canAddChild && !isCycle;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,7 +109,9 @@ extension PangeaRoom on Room {
|
|||
|
||||
List<String> get allSpaceChildRoomIds => _allSpaceChildRoomIds;
|
||||
|
||||
bool canAddAsParentOf(Room? child) => _canAddAsParentOf(child);
|
||||
bool canAddAsParentOf(Room? child, {bool spaceMode = false}) {
|
||||
return _canAddAsParentOf(child, spaceMode: spaceMode);
|
||||
}
|
||||
|
||||
// class_and_exchange_settings
|
||||
|
||||
|
|
@ -262,8 +264,9 @@ extension PangeaRoom on Room {
|
|||
|
||||
bool get canDelete => _canDelete;
|
||||
|
||||
bool canIAddSpaceChild(Room? room, {bool spaceMode = false}) =>
|
||||
_canIAddSpaceChild(room, spaceMode: spaceMode);
|
||||
bool canIAddSpaceChild(Room? room, {bool spaceMode = false}) {
|
||||
return _canIAddSpaceChild(room, spaceMode: spaceMode);
|
||||
}
|
||||
|
||||
bool get canIAddSpaceParents => _canIAddSpaceParents;
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,19 @@ class AddToSpaceState extends State<AddToSpaceToggles> {
|
|||
|
||||
@override
|
||||
void initState() {
|
||||
initialize();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(AddToSpaceToggles oldWidget) {
|
||||
if (oldWidget.roomId != widget.roomId) {
|
||||
initialize();
|
||||
}
|
||||
super.didUpdateWidget(oldWidget);
|
||||
}
|
||||
|
||||
void initialize() {
|
||||
//if roomId is null, it means this widget is being used in the creation flow
|
||||
room = widget.roomId != null
|
||||
? Matrix.of(context).client.getRoomById(widget.roomId!)
|
||||
|
|
@ -92,7 +105,6 @@ class AddToSpaceState extends State<AddToSpaceToggles> {
|
|||
});
|
||||
|
||||
isOpen = widget.startOpen;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
Future<void> _addSingleSpace(String roomToAddId, Room newParent) async {
|
||||
|
|
@ -140,13 +152,10 @@ class AddToSpaceState extends State<AddToSpaceToggles> {
|
|||
|
||||
Widget getAddToSpaceToggleItem(int index) {
|
||||
final Room possibleParent = possibleParents[index];
|
||||
final bool canAdd = (room?.isSpace ?? false)
|
||||
// Room is space
|
||||
? possibleParent.isRoomAdmin &&
|
||||
room!.isRoomAdmin &&
|
||||
possibleParent.canAddAsParentOf(room)
|
||||
// Room is null or chat
|
||||
: possibleParent.canAddAsParentOf(room);
|
||||
final bool canAdd = possibleParent.canAddAsParentOf(
|
||||
room,
|
||||
spaceMode: widget.spaceMode,
|
||||
);
|
||||
|
||||
return Opacity(
|
||||
opacity: canAdd ? 1 : 0.5,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue