From 1ce0cb3749b46a85419b60e8f8e824eeac213d28 Mon Sep 17 00:00:00 2001 From: TheOneWithTheBraid Date: Tue, 2 Aug 2022 16:02:03 +0200 Subject: [PATCH] fix: errors in space hierarchy - fix suggestions of joined rooms - fix missing spaces when parent not joined Signed-off-by: TheOneWithTheBraid --- assets/l10n/intl_en.arb | 1 + lib/pages/chat_list/spaces_drawer.dart | 26 ++++++++++++++----- .../chat_list/spaces_hierarchy_proposal.dart | 12 +++++++-- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index fc0170ba..62707c14 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -142,6 +142,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,