mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-12-24 14:32:37 +01:00
fix: errors in space hierarchy
- fix suggestions of joined rooms - fix missing spaces when parent not joined Signed-off-by: TheOneWithTheBraid <the-one@with-the-braid.cf>
This commit is contained in:
parent
aaf6610ff4
commit
1ce0cb3749
@ -142,6 +142,7 @@
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"allSuggestedRoomsJoined": "You joined all suggested rooms",
|
||||
"askVerificationRequest": "Accept this verification request from {username}?",
|
||||
"@askVerificationRequest": {
|
||||
"type": "text",
|
||||
|
@ -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),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -62,6 +62,7 @@ class _SpacesHierarchyProposalsState extends State<SpacesHierarchyProposals> {
|
||||
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<SpacesHierarchyProposals> {
|
||||
// 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<SpacesHierarchyProposals> {
|
||||
),
|
||||
onTap: _refreshRooms,
|
||||
),
|
||||
if (rooms.isEmpty && thereWereRooms)
|
||||
ListTile(
|
||||
leading: const Icon(Icons.info),
|
||||
title: Text(L10n.of(context)!.allSuggestedRoomsJoined),
|
||||
),
|
||||
...rooms.map(
|
||||
(e) => RecommendedRoomListItem(
|
||||
room: e,
|
||||
|
Loading…
Reference in New Issue
Block a user