diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index 46b60ef5..b706f625 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -144,6 +144,7 @@ "type": "text", "placeholders": {} }, + "allSuggestedRoomsJoined": "You joined all suggested rooms", "askVerificationRequest": "Accept this verification request from {username}?", "@askVerificationRequest": { "type": "text", diff --git a/lib/pages/chat_list/spaces_drawer.dart b/lib/pages/chat_list/spaces_drawer.dart index e61202c4..b2dd5c19 100644 --- a/lib/pages/chat_list/spaces_drawer.dart +++ b/lib/pages/chat_list/spaces_drawer.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import 'package:collection/collection.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; +import 'package:matrix/matrix.dart'; import 'package:vrouter/vrouter.dart'; import 'package:fluffychat/pages/chat_list/spaces_entry.dart'; @@ -55,7 +56,9 @@ class SpacesDrawer extends StatelessWidget { entry.children.addAll(childrenSpaceEntries); spacesHierarchy.add(entry); } else { - if (space?.spaceParents.isEmpty ?? false) { + // don't add rooms with parent space apart from those where the + // parent space is not joined + if (space?.hasNotJoinedParentSpace() ?? false) { spacesHierarchy.add(entry); } } @@ -67,10 +70,6 @@ class SpacesDrawer extends StatelessWidget { spacesHierarchy.removeWhere((element) => childSpaceIds.contains(element.spacesEntry.getSpace(context)?.id)); - // final spacesHierarchy = spaceEntries; - - // TODO(TheOeWithTheBraid): wait for space hierarchy https://gitlab.com/famedly/company/frontend/libraries/matrix_api_lite/-/merge_requests/58 - return ListView.builder( itemCount: spacesHierarchy.length + 1, itemBuilder: (context, i) { @@ -113,7 +112,11 @@ class SpacesEntryMaybeChildren { [String? parent]) { if (entry is SpaceSpacesEntry) { final room = entry.space; - if ((parent == null && room.spaceParents.isNotEmpty) || + // don't add rooms with parent space apart from those where the + // parent space is not joined + if ((parent == null && + room.spaceParents.isNotEmpty && + room.hasNotJoinedParentSpace()) || (parent != null && !room.spaceParents.any((element) => element.roomId == parent))) { return null; @@ -174,3 +177,14 @@ class SpacesEntryMaybeChildren { return jsonEncode(toJson()); } } + +extension on Room { + bool hasNotJoinedParentSpace() { + return (spaceParents.isEmpty || + spaceParents.none( + (p0) => + (p0.canonical ?? true) && + client.rooms.map((e) => e.id).contains(p0.roomId), + )); + } +} diff --git a/lib/pages/chat_list/spaces_hierarchy_proposal.dart b/lib/pages/chat_list/spaces_hierarchy_proposal.dart index cccfdd80..65574283 100644 --- a/lib/pages/chat_list/spaces_hierarchy_proposal.dart +++ b/lib/pages/chat_list/spaces_hierarchy_proposal.dart @@ -62,6 +62,7 @@ class _SpacesHierarchyProposalsState extends State { builder: (context, snapshot) { Widget child; if (snapshot.hasData) { + final thereWereRooms = snapshot.data!.rooms.isNotEmpty; final rooms = snapshot.data!.rooms.where( (element) => element.roomId != widget.space && @@ -72,9 +73,11 @@ class _SpacesHierarchyProposalsState extends State { // in case not, just leave it... : true) && client.rooms - .any((knownRoom) => element.roomId != knownRoom.id), + .every((knownRoom) => element.roomId != knownRoom.id), ); - if (rooms.isEmpty) child = const ListTile(key: ValueKey(false)); + if (rooms.isEmpty && !thereWereRooms) { + child = const ListTile(key: ValueKey(false)); + } child = Column( key: ValueKey(widget.space), mainAxisSize: MainAxisSize.min, @@ -96,6 +99,11 @@ class _SpacesHierarchyProposalsState extends State { ), onTap: _refreshRooms, ), + if (rooms.isEmpty && thereWereRooms) + ListTile( + leading: const Icon(Icons.info), + title: Text(L10n.of(context)!.allSuggestedRoomsJoined), + ), ...rooms.map( (e) => RecommendedRoomListItem( room: e,