fix: normalize space chat count copy (#1829)

This commit is contained in:
ggurdin 2025-02-17 17:03:00 -05:00 committed by GitHub
parent beb0e91c07
commit 8176d691bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 51 deletions

View file

@ -309,7 +309,10 @@ class ChatListItem extends StatelessWidget {
child: room.isSpace && room.membership == Membership.join
? Text(
L10n.of(context).countChatsAndCountParticipants(
room.spaceChildren.length.toString(),
// #Pangea
// room.spaceChildren.length.toString(),
room.spaceChildCount.toString(),
// Pangea#
(room.summary.mJoinedMemberCount ?? 1)
.toString(),
),

View file

@ -547,8 +547,7 @@ class _SpaceViewState extends State<SpaceView> {
L10n.of(context).countChatsAndCountParticipants(
// #Pangea
// room.spaceChildren.length,
(_discoveredChildren?.length ?? 0) +
(joinedRooms?.length ?? 0),
room.spaceChildCount.toString(),
// Pangea#
room.summary.mJoinedMemberCount ?? 1,
),

View file

@ -1,54 +1,6 @@
part of "pangea_room_extension.dart";
extension ChildrenAndParentsRoomExtension on Room {
//note this only will return rooms that the user has joined or been invited to
List<Room> get joinedChildren {
if (!isSpace) return [];
return spaceChildren
.where((child) => child.roomId != null)
.map(
(child) => client.getRoomById(child.roomId!),
)
.where((child) => child != null)
.cast<Room>()
.where(
(child) => child.membership == Membership.join,
)
.toList();
}
Future<List<Room>> getChildRooms() async {
final List<Room> children = [];
for (final child in spaceChildren) {
if (child.roomId == null) continue;
final Room? room = client.getRoomById(child.roomId!);
if (room != null) {
children.add(room);
}
}
return children;
}
//resolve somehow if multiple rooms have the state?
//check logic
Room? firstParentWithState(String stateType) {
if (![PangeaEventTypes.languageSettings, PangeaEventTypes.rules]
.contains(stateType)) {
return null;
}
for (final parent in pangeaSpaceParents) {
if (parent.getState(stateType) != null) {
return parent;
}
}
for (final parent in pangeaSpaceParents) {
final parentFirstRoom = parent.firstParentWithState(stateType);
if (parentFirstRoom != null) return parentFirstRoom;
}
return null;
}
List<Room> get pangeaSpaceParents => client.rooms
.where(
(r) => r.isSpace,
@ -119,6 +71,15 @@ extension ChildrenAndParentsRoomExtension on Room {
}
return suggestionStatus;
}
/// The number of child rooms to display for a given space.
int get spaceChildCount => client.rooms
.where(
(r) => spaceChildren.any(
(child) => r.id == child.roomId && !r.isAnalyticsRoom,
),
)
.length;
}
class NestedSpaceError extends Error {