feat: New navigation design
parent
32cc2415b3
commit
e71dabca6e
@ -1,85 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|
||||||
import 'package:vrouter/vrouter.dart';
|
|
||||||
|
|
||||||
import 'package:fluffychat/pages/chat_list/chat_list.dart';
|
|
||||||
import 'package:fluffychat/pages/chat_list/spaces_drawer.dart';
|
|
||||||
import 'package:fluffychat/utils/fluffy_share.dart';
|
|
||||||
import 'package:fluffychat/widgets/avatar.dart';
|
|
||||||
import 'package:fluffychat/widgets/matrix.dart';
|
|
||||||
import '../../config/app_config.dart';
|
|
||||||
|
|
||||||
class ChatListDrawer extends StatelessWidget {
|
|
||||||
final ChatListController controller;
|
|
||||||
const ChatListDrawer(this.controller, {Key? key}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) => Drawer(
|
|
||||||
child: SafeArea(
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
ListTile(
|
|
||||||
leading: const CircleAvatar(
|
|
||||||
radius: Avatar.defaultSize / 2,
|
|
||||||
backgroundImage: AssetImage('assets/logo.png'),
|
|
||||||
),
|
|
||||||
title: Text(AppConfig.applicationName),
|
|
||||||
trailing: Icon(
|
|
||||||
Icons.adaptive.share_outlined,
|
|
||||||
color: Theme.of(context).colorScheme.onBackground,
|
|
||||||
),
|
|
||||||
onTap: () {
|
|
||||||
Scaffold.of(context).closeDrawer();
|
|
||||||
FluffyShare.share(
|
|
||||||
L10n.of(context)!.inviteText(
|
|
||||||
Matrix.of(context).client.userID!,
|
|
||||||
'https://matrix.to/#/${Matrix.of(context).client.userID}?client=im.fluffychat'),
|
|
||||||
context);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const Divider(thickness: 1),
|
|
||||||
Expanded(
|
|
||||||
child: SpacesDrawer(
|
|
||||||
controller: controller,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const Divider(thickness: 1),
|
|
||||||
ListTile(
|
|
||||||
leading: Icon(
|
|
||||||
Icons.group_add_outlined,
|
|
||||||
color: Theme.of(context).colorScheme.onBackground,
|
|
||||||
),
|
|
||||||
title: Text(L10n.of(context)!.createNewGroup),
|
|
||||||
onTap: () {
|
|
||||||
Scaffold.of(context).closeDrawer();
|
|
||||||
VRouter.of(context).to('/newgroup');
|
|
||||||
},
|
|
||||||
),
|
|
||||||
ListTile(
|
|
||||||
leading: Icon(
|
|
||||||
Icons.group_work_outlined,
|
|
||||||
color: Theme.of(context).colorScheme.onBackground,
|
|
||||||
),
|
|
||||||
title: Text(L10n.of(context)!.createNewSpace),
|
|
||||||
onTap: () {
|
|
||||||
Scaffold.of(context).closeDrawer();
|
|
||||||
VRouter.of(context).to('/newspace');
|
|
||||||
},
|
|
||||||
),
|
|
||||||
ListTile(
|
|
||||||
leading: Icon(
|
|
||||||
Icons.settings_outlined,
|
|
||||||
color: Theme.of(context).colorScheme.onBackground,
|
|
||||||
),
|
|
||||||
title: Text(L10n.of(context)!.settings),
|
|
||||||
onTap: () {
|
|
||||||
Scaffold.of(context).closeDrawer();
|
|
||||||
VRouter.of(context).to('/settings');
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,119 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|
||||||
import 'package:matrix/matrix.dart';
|
|
||||||
|
|
||||||
import 'package:fluffychat/pages/chat_list/spaces_hierarchy_proposal.dart';
|
|
||||||
import 'package:fluffychat/widgets/avatar.dart';
|
|
||||||
import 'package:fluffychat/widgets/public_room_bottom_sheet.dart';
|
|
||||||
|
|
||||||
class RecommendedRoomListItem extends StatelessWidget {
|
|
||||||
final SpaceRoomsChunk room;
|
|
||||||
final VoidCallback onRoomJoined;
|
|
||||||
|
|
||||||
const RecommendedRoomListItem({
|
|
||||||
Key? key,
|
|
||||||
required this.room,
|
|
||||||
required this.onRoomJoined,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final leading = Avatar(
|
|
||||||
mxContent: room.avatarUrl,
|
|
||||||
name: room.name,
|
|
||||||
);
|
|
||||||
final title = Row(
|
|
||||||
children: <Widget>[
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
room.name ?? '',
|
|
||||||
maxLines: 1,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
softWrap: false,
|
|
||||||
style: TextStyle(
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: Theme.of(context).textTheme.bodyText1!.color,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
// number of joined users
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(left: 4.0),
|
|
||||||
child: Text.rich(
|
|
||||||
TextSpan(children: [
|
|
||||||
WidgetSpan(
|
|
||||||
child: Tooltip(
|
|
||||||
message: L10n.of(context)!
|
|
||||||
.numberRoomMembers(room.numJoinedMembers),
|
|
||||||
child: const Icon(
|
|
||||||
Icons.people_outlined,
|
|
||||||
size: 20,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
alignment: PlaceholderAlignment.middle,
|
|
||||||
baseline: TextBaseline.alphabetic),
|
|
||||||
TextSpan(text: ' ${room.numJoinedMembers}')
|
|
||||||
]),
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 13,
|
|
||||||
color: Theme.of(context).textTheme.bodyText2!.color,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
final subtitle = room.topic != null
|
|
||||||
? Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: <Widget>[
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
room.topic!,
|
|
||||||
softWrap: false,
|
|
||||||
maxLines: 1,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
style: TextStyle(
|
|
||||||
color: Theme.of(context).textTheme.bodyText2!.color,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
: null;
|
|
||||||
void handler() => showModalBottomSheet(
|
|
||||||
context: context,
|
|
||||||
builder: (c) => PublicRoomBottomSheet(
|
|
||||||
outerContext: context,
|
|
||||||
chunk: room,
|
|
||||||
onRoomJoined: onRoomJoined,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
if (room.roomType == 'm.space') {
|
|
||||||
return Material(
|
|
||||||
color: Colors.transparent,
|
|
||||||
child: ExpansionTile(
|
|
||||||
leading: leading,
|
|
||||||
title: title,
|
|
||||||
subtitle: subtitle,
|
|
||||||
onExpansionChanged: (open) {
|
|
||||||
if (!open) handler();
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
SpacesHierarchyProposals(space: room.roomId),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return Material(
|
|
||||||
color: Colors.transparent,
|
|
||||||
child: ListTile(
|
|
||||||
leading: leading,
|
|
||||||
title: title,
|
|
||||||
subtitle: subtitle,
|
|
||||||
onTap: handler,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,309 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||||
|
import 'package:collection/collection.dart';
|
||||||
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||||
|
import 'package:matrix/matrix.dart';
|
||||||
|
import 'package:vrouter/vrouter.dart';
|
||||||
|
|
||||||
|
import 'package:fluffychat/config/themes.dart';
|
||||||
|
import 'package:fluffychat/pages/chat_list/chat_list.dart';
|
||||||
|
import 'package:fluffychat/pages/chat_list/chat_list_item.dart';
|
||||||
|
import 'package:fluffychat/pages/chat_list/search_title.dart';
|
||||||
|
import 'package:fluffychat/widgets/avatar.dart';
|
||||||
|
import '../../utils/localized_exception_extension.dart';
|
||||||
|
import '../../widgets/matrix.dart';
|
||||||
|
|
||||||
|
class SpaceView extends StatefulWidget {
|
||||||
|
final ChatListController controller;
|
||||||
|
final ScrollController scrollController;
|
||||||
|
const SpaceView(
|
||||||
|
this.controller, {
|
||||||
|
Key? key,
|
||||||
|
required this.scrollController,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<SpaceView> createState() => _SpaceViewState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SpaceViewState extends State<SpaceView> {
|
||||||
|
static final Map<String, Future<GetSpaceHierarchyResponse>> _requests = {};
|
||||||
|
|
||||||
|
void _refresh() {
|
||||||
|
setState(() {
|
||||||
|
_requests.remove(widget.controller.activeSpaceId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<GetSpaceHierarchyResponse> getFuture(String activeSpaceId) =>
|
||||||
|
_requests[activeSpaceId] ??=
|
||||||
|
Matrix.of(context).client.getSpaceHierarchy(activeSpaceId);
|
||||||
|
|
||||||
|
void _onJoinSpaceChild(SpaceRoomsChunk spaceChild) async {
|
||||||
|
final client = Matrix.of(context).client;
|
||||||
|
final space = client.getRoomById(widget.controller.activeSpaceId!);
|
||||||
|
if (client.getRoomById(spaceChild.roomId) == null) {
|
||||||
|
final result = await showFutureLoadingDialog(
|
||||||
|
context: context,
|
||||||
|
future: () async {
|
||||||
|
await client.joinRoom(spaceChild.roomId,
|
||||||
|
serverName: space?.spaceChildren
|
||||||
|
.firstWhereOrNull(
|
||||||
|
(child) => child.roomId == spaceChild.roomId)
|
||||||
|
?.via);
|
||||||
|
if (client.getRoomById(spaceChild.roomId) == null) {
|
||||||
|
// Wait for room actually appears in sync
|
||||||
|
await client.waitForRoomInSync(spaceChild.roomId, join: true);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (result.error != null) return;
|
||||||
|
_refresh();
|
||||||
|
}
|
||||||
|
if (spaceChild.roomType == 'm.space') {
|
||||||
|
if (spaceChild.roomId == widget.controller.activeSpaceId) {
|
||||||
|
VRouter.of(context).toSegments(['spaces', spaceChild.roomId]);
|
||||||
|
} else {
|
||||||
|
widget.controller.setActiveSpace(spaceChild.roomId);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
VRouter.of(context).toSegments(['rooms', spaceChild.roomId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onSpaceChildContextMenu(
|
||||||
|
[SpaceRoomsChunk? spaceChild, Room? room]) async {
|
||||||
|
final client = Matrix.of(context).client;
|
||||||
|
final activeSpaceId = widget.controller.activeSpaceId;
|
||||||
|
final activeSpace =
|
||||||
|
activeSpaceId == null ? null : client.getRoomById(activeSpaceId);
|
||||||
|
final action = await showModalActionSheet<SpaceChildContextAction>(
|
||||||
|
context: context,
|
||||||
|
title: spaceChild?.name ?? room?.displayname,
|
||||||
|
message: spaceChild?.topic ?? room?.topic,
|
||||||
|
actions: [
|
||||||
|
if (room == null)
|
||||||
|
SheetAction(
|
||||||
|
key: SpaceChildContextAction.join,
|
||||||
|
label: L10n.of(context)!.joinRoom,
|
||||||
|
icon: Icons.send_outlined,
|
||||||
|
),
|
||||||
|
if (spaceChild != null && (activeSpace?.canSendDefaultStates ?? false))
|
||||||
|
SheetAction(
|
||||||
|
key: SpaceChildContextAction.removeFromSpace,
|
||||||
|
label: L10n.of(context)!.removeFromSpace,
|
||||||
|
icon: Icons.delete_sweep_outlined,
|
||||||
|
),
|
||||||
|
if (room != null)
|
||||||
|
SheetAction(
|
||||||
|
key: SpaceChildContextAction.leave,
|
||||||
|
label: L10n.of(context)!.leave,
|
||||||
|
icon: Icons.delete_outlined,
|
||||||
|
isDestructiveAction: true,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
if (action == null) return;
|
||||||
|
|
||||||
|
switch (action) {
|
||||||
|
case SpaceChildContextAction.join:
|
||||||
|
_onJoinSpaceChild(spaceChild!);
|
||||||
|
break;
|
||||||
|
case SpaceChildContextAction.leave:
|
||||||
|
await showFutureLoadingDialog(
|
||||||
|
context: context,
|
||||||
|
future: room!.leave,
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case SpaceChildContextAction.removeFromSpace:
|
||||||
|
await showFutureLoadingDialog(
|
||||||
|
context: context,
|
||||||
|
future: () => activeSpace!.removeSpaceChild(spaceChild!.roomId),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final client = Matrix.of(context).client;
|
||||||
|
final activeSpaceId = widget.controller.activeSpaceId;
|
||||||
|
final allSpaces = client.rooms.where((room) => room.isSpace);
|
||||||
|
if (activeSpaceId == null) {
|
||||||
|
final rootSpaces = allSpaces
|
||||||
|
.where(
|
||||||
|
(space) => !allSpaces.any(
|
||||||
|
(parentSpace) => parentSpace.spaceChildren
|
||||||
|
.any((child) => child.roomId == space.id),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
return ListView.builder(
|
||||||
|
itemCount: rootSpaces.length,
|
||||||
|
controller: widget.scrollController,
|
||||||
|
itemBuilder: (context, i) => ListTile(
|
||||||
|
leading: Avatar(
|
||||||
|
mxContent: rootSpaces[i].avatar,
|
||||||
|
name: rootSpaces[i].displayname,
|
||||||
|
),
|
||||||
|
title: Text(
|
||||||
|
rootSpaces[i].displayname,
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
subtitle: Text('${rootSpaces[i].spaceChildren.length} Chats'),
|
||||||
|
onTap: () => widget.controller.setActiveSpace(rootSpaces[i].id),
|
||||||
|
onLongPress: () => _onSpaceChildContextMenu(null, rootSpaces[i]),
|
||||||
|
trailing: const Icon(Icons.chevron_right_outlined),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return FutureBuilder<GetSpaceHierarchyResponse>(
|
||||||
|
future: getFuture(activeSpaceId),
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
final response = snapshot.data;
|
||||||
|
final error = snapshot.error;
|
||||||
|
if (error != null) {
|
||||||
|
return Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
child: Text(error.toLocalizedString(context)),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
onPressed: _refresh,
|
||||||
|
icon: const Icon(Icons.refresh_outlined),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (response == null) {
|
||||||
|
return const Center(child: CircularProgressIndicator.adaptive());
|
||||||
|
}
|
||||||
|
final parentSpace = allSpaces.firstWhereOrNull((space) => space
|
||||||
|
.spaceChildren
|
||||||
|
.any((child) => child.roomId == activeSpaceId));
|
||||||
|
return ListView.builder(
|
||||||
|
itemCount: response.rooms.length + 1,
|
||||||
|
controller: widget.scrollController,
|
||||||
|
itemBuilder: (context, i) {
|
||||||
|
if (i == 0) {
|
||||||
|
return ListTile(
|
||||||
|
leading: FluffyThemes.isColumnMode(context) &&
|
||||||
|
parentSpace == null
|
||||||
|
? null
|
||||||
|
: BackButton(
|
||||||
|
onPressed: () => widget.controller
|
||||||
|
.setActiveSpace(parentSpace?.id),
|
||||||
|
),
|
||||||
|
title: Text(parentSpace == null
|
||||||
|
? FluffyThemes.isColumnMode(context)
|
||||||
|
? L10n.of(context)!.showSpaces
|
||||||
|
: L10n.of(context)!.allSpaces
|
||||||
|
: parentSpace.displayname),
|
||||||
|
trailing: IconButton(
|
||||||
|
icon: snapshot.connectionState != ConnectionState.done
|
||||||
|
? const CircularProgressIndicator.adaptive()
|
||||||
|
: const Icon(Icons.refresh_outlined),
|
||||||
|
onPressed:
|
||||||
|
snapshot.connectionState != ConnectionState.done
|
||||||
|
? null
|
||||||
|
: _refresh,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
i--;
|
||||||
|
final spaceChild = response.rooms[i];
|
||||||
|
final room = client.getRoomById(spaceChild.roomId);
|
||||||
|
if (room != null && !room.isSpace) {
|
||||||
|
return ChatListItem(
|
||||||
|
room,
|
||||||
|
onLongPress: () =>
|
||||||
|
_onSpaceChildContextMenu(spaceChild, room),
|
||||||
|
activeChat: widget.controller.activeChat == room.id,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
final isSpace = spaceChild.roomType == 'm.space';
|
||||||
|
final topic =
|
||||||
|
spaceChild.topic?.isEmpty ?? true ? null : spaceChild.topic;
|
||||||
|
if (spaceChild.roomId == activeSpaceId) {
|
||||||
|
return SearchTitle(
|
||||||
|
title:
|
||||||
|
spaceChild.name ?? spaceChild.canonicalAlias ?? 'Space',
|
||||||
|
icon: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 10.0),
|
||||||
|
child: Avatar(
|
||||||
|
size: 24,
|
||||||
|
mxContent: spaceChild.avatarUrl,
|
||||||
|
name: spaceChild.name,
|
||||||
|
fontSize: 9,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
color: Theme.of(context)
|
||||||
|
.colorScheme
|
||||||
|
.secondaryContainer
|
||||||
|
.withAlpha(128),
|
||||||
|
trailing: const Padding(
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||||
|
child: Icon(Icons.edit_outlined),
|
||||||
|
),
|
||||||
|
onTap: () => _onJoinSpaceChild(spaceChild),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return ListTile(
|
||||||
|
leading: Avatar(
|
||||||
|
mxContent: spaceChild.avatarUrl,
|
||||||
|
name: spaceChild.name,
|
||||||
|
),
|
||||||
|
title: Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
spaceChild.name ??
|
||||||
|
spaceChild.canonicalAlias ??
|
||||||
|
L10n.of(context)!.chat,
|
||||||
|
maxLines: 1,
|
||||||
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (!isSpace) ...[
|
||||||
|
const Icon(
|
||||||
|
Icons.people_outline,
|
||||||
|
size: 16,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
Text(
|
||||||
|
spaceChild.numJoinedMembers.toString(),
|
||||||
|
style: const TextStyle(fontSize: 14),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
onTap: () => _onJoinSpaceChild(spaceChild),
|
||||||
|
onLongPress: () => _onSpaceChildContextMenu(spaceChild, room),
|
||||||
|
subtitle: Text(
|
||||||
|
topic ??
|
||||||
|
(isSpace
|
||||||
|
? L10n.of(context)!.enterSpace
|
||||||
|
: L10n.of(context)!.enterRoom),
|
||||||
|
maxLines: 1,
|
||||||
|
style: TextStyle(
|
||||||
|
color: Theme.of(context).colorScheme.onBackground),
|
||||||
|
),
|
||||||
|
trailing:
|
||||||
|
isSpace ? const Icon(Icons.chevron_right_outlined) : null,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum SpaceChildContextAction {
|
||||||
|
join,
|
||||||
|
leave,
|
||||||
|
removeFromSpace,
|
||||||
|
}
|
@ -1,190 +0,0 @@
|
|||||||
import 'dart:convert';
|
|
||||||
|
|
||||||
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';
|
|
||||||
import 'package:fluffychat/widgets/avatar.dart';
|
|
||||||
import 'package:fluffychat/widgets/matrix.dart';
|
|
||||||
import 'chat_list.dart';
|
|
||||||
import 'spaces_drawer_entry.dart';
|
|
||||||
|
|
||||||
class SpacesDrawer extends StatelessWidget {
|
|
||||||
final ChatListController controller;
|
|
||||||
|
|
||||||
const SpacesDrawer({Key? key, required this.controller}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final spaceEntries = controller.spacesEntries
|
|
||||||
.map((e) => SpacesEntryMaybeChildren.buildIfTopLevel(
|
|
||||||
e, controller.spacesEntries))
|
|
||||||
.whereNotNull()
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
final childSpaceIds = <String>{};
|
|
||||||
|
|
||||||
final spacesHierarchy = <SpacesEntryMaybeChildren>[];
|
|
||||||
|
|
||||||
final matrix = Matrix.of(context);
|
|
||||||
for (final entry in spaceEntries) {
|
|
||||||
if (entry.spacesEntry is SpaceSpacesEntry) {
|
|
||||||
final space = entry.spacesEntry.getSpace(context);
|
|
||||||
if (space != null && space.spaceChildren.isNotEmpty) {
|
|
||||||
final children = space.spaceChildren;
|
|
||||||
// computing the children space entries
|
|
||||||
final childrenSpaceEntries = spaceEntries.where((element) {
|
|
||||||
// current ID
|
|
||||||
final id = element.spacesEntry.getSpace(context)?.id;
|
|
||||||
|
|
||||||
// comparing against the supposed IDs of the children and checking
|
|
||||||
// whether the room is already joined
|
|
||||||
return children.any(
|
|
||||||
(child) =>
|
|
||||||
child.roomId == id &&
|
|
||||||
matrix.client.rooms
|
|
||||||
.any((joinedRoom) => child.roomId == joinedRoom.id),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
childSpaceIds.addAll(childrenSpaceEntries
|
|
||||||
.map((e) => e.spacesEntry.getSpace(context)?.id)
|
|
||||||
.whereNotNull());
|
|
||||||
entry.children.addAll(childrenSpaceEntries);
|
|
||||||
spacesHierarchy.add(entry);
|
|
||||||
} else {
|
|
||||||
// don't add rooms with parent space apart from those where the
|
|
||||||
// parent space is not joined
|
|
||||||
if (space?.hasNotJoinedParentSpace() ?? false) {
|
|
||||||
spacesHierarchy.add(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
spacesHierarchy.add(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
spacesHierarchy.removeWhere((element) =>
|
|
||||||
childSpaceIds.contains(element.spacesEntry.getSpace(context)?.id));
|
|
||||||
|
|
||||||
return ListView.builder(
|
|
||||||
itemCount: spacesHierarchy.length + 1,
|
|
||||||
itemBuilder: (context, i) {
|
|
||||||
if (i == spacesHierarchy.length) {
|
|
||||||
return ListTile(
|
|
||||||
leading: CircleAvatar(
|
|
||||||
radius: Avatar.defaultSize / 2,
|
|
||||||
backgroundColor: Theme.of(context).colorScheme.secondary,
|
|
||||||
foregroundColor: Theme.of(context).colorScheme.onSecondary,
|
|
||||||
child: const Icon(
|
|
||||||
Icons.archive_outlined,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
title: Text(L10n.of(context)!.archive),
|
|
||||||
onTap: () {
|
|
||||||
Scaffold.of(context).closeDrawer();
|
|
||||||
VRouter.of(context).to('/archive');
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
final space = spacesHierarchy[i];
|
|
||||||
return SpacesDrawerEntry(
|
|
||||||
entry: space,
|
|
||||||
controller: controller,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class SpacesEntryMaybeChildren {
|
|
||||||
final SpacesEntry spacesEntry;
|
|
||||||
|
|
||||||
final Set<SpacesEntryMaybeChildren> children;
|
|
||||||
|
|
||||||
const SpacesEntryMaybeChildren(this.spacesEntry, [this.children = const {}]);
|
|
||||||
|
|
||||||
static SpacesEntryMaybeChildren? buildIfTopLevel(
|
|
||||||
SpacesEntry entry, List<SpacesEntry> allEntries,
|
|
||||||
[String? parent]) {
|
|
||||||
if (entry is SpaceSpacesEntry) {
|
|
||||||
final room = entry.space;
|
|
||||||
// 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;
|
|
||||||
} else {
|
|
||||||
final children = allEntries
|
|
||||||
.where((element) =>
|
|
||||||
element is SpaceSpacesEntry &&
|
|
||||||
element.space.spaceParents.any((parent) =>
|
|
||||||
parent.roomId == room.id /*&& (parent.canonical ?? true)*/))
|
|
||||||
.toList();
|
|
||||||
return SpacesEntryMaybeChildren(
|
|
||||||
entry,
|
|
||||||
children
|
|
||||||
.map((e) => buildIfTopLevel(e, allEntries, room.id))
|
|
||||||
.whereNotNull()
|
|
||||||
.toSet());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return SpacesEntryMaybeChildren(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isActiveOfChild(ChatListController controller) =>
|
|
||||||
spacesEntry == controller.activeSpacesEntry ||
|
|
||||||
children.any(
|
|
||||||
(element) => element.isActiveOfChild(controller),
|
|
||||||
);
|
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => {
|
|
||||||
'entry': spacesEntry is SpaceSpacesEntry
|
|
||||||
? (spacesEntry as SpaceSpacesEntry).space.id
|
|
||||||
: spacesEntry.runtimeType.toString(),
|
|
||||||
if (spacesEntry is SpaceSpacesEntry)
|
|
||||||
'rawSpaceParents': (spacesEntry as SpaceSpacesEntry)
|
|
||||||
.space
|
|
||||||
.spaceParents
|
|
||||||
.map((e) =>
|
|
||||||
{'roomId': e.roomId, 'canonical': e.canonical, 'via': e.via})
|
|
||||||
.toList(),
|
|
||||||
if (spacesEntry is SpaceSpacesEntry)
|
|
||||||
'rawSpaceChildren': (spacesEntry as SpaceSpacesEntry)
|
|
||||||
.space
|
|
||||||
.spaceChildren
|
|
||||||
.map(
|
|
||||||
(e) => {
|
|
||||||
'roomId': e.roomId,
|
|
||||||
'suggested': e.suggested,
|
|
||||||
'via': e.via,
|
|
||||||
'order': e.order
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.toList(),
|
|
||||||
'children': children.map((e) => e.toJson()).toList(),
|
|
||||||
};
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toString() {
|
|
||||||
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),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,98 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|
||||||
|
|
||||||
import 'package:fluffychat/pages/chat_list/chat_list.dart';
|
|
||||||
import 'package:fluffychat/pages/chat_list/spaces_drawer.dart';
|
|
||||||
import 'package:fluffychat/utils/space_navigator.dart';
|
|
||||||
import 'package:fluffychat/widgets/avatar.dart';
|
|
||||||
|
|
||||||
class SpacesDrawerEntry extends StatelessWidget {
|
|
||||||
final SpacesEntryMaybeChildren entry;
|
|
||||||
final ChatListController controller;
|
|
||||||
|
|
||||||
const SpacesDrawerEntry(
|
|
||||||
{Key? key, required this.entry, required this.controller})
|
|
||||||
: super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final space = entry.spacesEntry;
|
|
||||||
final room = space.getSpace(context);
|
|
||||||
|
|
||||||
final active = controller.activeSpacesEntry == entry.spacesEntry;
|
|
||||||
final leading = room == null
|
|
||||||
? CircleAvatar(
|
|
||||||
radius: Avatar.defaultSize / 2,
|
|
||||||
backgroundColor: Theme.of(context).colorScheme.secondary,
|
|
||||||
foregroundColor: Theme.of(context).colorScheme.onSecondary,
|
|
||||||
child: space.getIcon(active),
|
|
||||||
)
|
|
||||||
: Avatar(
|
|
||||||
mxContent: room.avatar,
|
|
||||||
name: space.getName(context),
|
|
||||||
);
|
|
||||||
final title = Text(
|
|
||||||
space.getName(context),
|
|
||||||
maxLines: 1,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
);
|
|
||||||
final subtitle = room?.topic.isEmpty ?? true
|
|
||||||
? null
|
|
||||||
: Tooltip(
|
|
||||||
message: room!.topic,
|
|
||||||
child: Text(
|
|
||||||
room.topic.replaceAll('\n', ' '),
|
|
||||||
softWrap: false,
|
|
||||||
overflow: TextOverflow.fade,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
void onTap() {
|
|
||||||
SpaceNavigator.navigateToSpace(space.routeHandle);
|
|
||||||
Scaffold.of(context).closeDrawer();
|
|
||||||
}
|
|
||||||
|
|
||||||
final trailing = room != null
|
|
||||||
? SizedBox(
|
|
||||||
width: 32,
|
|
||||||
child: IconButton(
|
|
||||||
splashRadius: 24,
|
|
||||||
icon: const Icon(Icons.edit_outlined),
|
|
||||||
tooltip: L10n.of(context)!.edit,
|
|
||||||
onPressed: () => controller.editSpace(context, room.id),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: const Icon(Icons.arrow_forward_ios_outlined);
|
|
||||||
|
|
||||||
if (entry.children.isEmpty) {
|
|
||||||
return ListTile(
|
|
||||||
selected: active,
|
|
||||||
leading: leading,
|
|
||||||
title: title,
|
|
||||||
subtitle: subtitle,
|
|
||||||
onTap: onTap,
|
|
||||||
trailing: trailing,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return ExpansionTile(
|
|
||||||
leading: leading,
|
|
||||||
initiallyExpanded:
|
|
||||||
entry.children.any((element) => entry.isActiveOfChild(controller)),
|
|
||||||
title: GestureDetector(
|
|
||||||
onTap: onTap,
|
|
||||||
child: Row(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
mainAxisSize: MainAxisSize.max,
|
|
||||||
children: [
|
|
||||||
Expanded(child: title),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
trailing
|
|
||||||
]),
|
|
||||||
),
|
|
||||||
children: entry.children
|
|
||||||
.map((e) => SpacesDrawerEntry(entry: e, controller: controller))
|
|
||||||
.toList(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,240 +0,0 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|
||||||
import 'package:matrix/matrix.dart';
|
|
||||||
|
|
||||||
import 'package:fluffychat/config/app_config.dart';
|
|
||||||
import 'package:fluffychat/utils/matrix_sdk_extensions.dart/client_stories_extension.dart';
|
|
||||||
import '../../widgets/matrix.dart';
|
|
||||||
|
|
||||||
// This is not necessarily a Space, but an abstract categorization of a room.
|
|
||||||
// More to the point, it's a selectable entry that *could* be a Space.
|
|
||||||
// Note that view code is in spaces_bottom_bar.dart because of type-specific UI.
|
|
||||||
// So only really generic functions (so far, anything ChatList cares about) go here.
|
|
||||||
// If getRoom returns something non-null, then it gets the avatar and such of a Space.
|
|
||||||
// Otherwise it gets to look like All Rooms. Future work impending.
|
|
||||||
abstract class SpacesEntry {
|
|
||||||
const SpacesEntry();
|
|
||||||
|
|
||||||
// Gets the (translated) name of this entry.
|
|
||||||
String getName(BuildContext context);
|
|
||||||
|
|
||||||
// Gets an icon for this entry (avoided if a space is given)
|
|
||||||
Icon getIcon(bool active) => active
|
|
||||||
? const Icon(CupertinoIcons.chat_bubble_2_fill)
|
|
||||||
: const Icon(CupertinoIcons.chat_bubble_2);
|
|
||||||
|
|
||||||
// If this is a specific Room, returns the space Room for various purposes.
|
|
||||||
Room? getSpace(BuildContext context) => null;
|
|
||||||
|
|
||||||
// Gets a list of rooms - this is done as part of _ChatListViewBodyState to get the full list of rooms visible from this SpacesEntry.
|
|
||||||
List<Room> getRooms(BuildContext context);
|
|
||||||
|
|
||||||
// Checks that this entry is still valid.
|
|
||||||
bool stillValid(BuildContext context) => true;
|
|
||||||
|
|
||||||
// Returns true if the Stories header should be shown.
|
|
||||||
bool shouldShowStoriesHeader(BuildContext context) => false;
|
|
||||||
|
|
||||||
String? get routeHandle;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Common room validity checks
|
|
||||||
bool _roomCheckCommon(Room room, BuildContext context) {
|
|
||||||
if (room.isSpace && room.membership == Membership.join && !room.isUnread) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (room.getState(EventTypes.RoomCreate)?.content.tryGet<String>('type') ==
|
|
||||||
ClientStoriesExtension.storiesRoomType) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _roomInsideSpace(Room room, Room space) {
|
|
||||||
if (space.spaceChildren.any((child) => child.roomId == room.id)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (room.spaceParents.any((parent) => parent.roomId == space.id)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// "All rooms" entry.
|
|
||||||
class AllRoomsSpacesEntry extends SpacesEntry {
|
|
||||||
static final AllRoomsSpacesEntry _value = AllRoomsSpacesEntry._();
|
|
||||||
|
|
||||||
AllRoomsSpacesEntry._();
|
|
||||||
|
|
||||||
factory AllRoomsSpacesEntry() {
|
|
||||||
return _value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
String getName(BuildContext context) => L10n.of(context)!.allChats;
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Room> getRooms(BuildContext context) {
|
|
||||||
return Matrix.of(context)
|
|
||||||
.client
|
|
||||||
.rooms
|
|
||||||
.where((room) => _roomCheckCommon(room, context))
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
final String? routeHandle = null;
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool shouldShowStoriesHeader(BuildContext context) => true;
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator ==(Object other) {
|
|
||||||
return runtimeType == other.runtimeType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode => runtimeType.hashCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
// "Direct Chats" entry.
|
|
||||||
class DirectChatsSpacesEntry extends SpacesEntry {
|
|
||||||
static final DirectChatsSpacesEntry _value = DirectChatsSpacesEntry._();
|
|
||||||
|
|
||||||
DirectChatsSpacesEntry._();
|
|
||||||
|
|
||||||
factory DirectChatsSpacesEntry() {
|
|
||||||
return _value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
String getName(BuildContext context) => L10n.of(context)!.directChats;
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Room> getRooms(BuildContext context) {
|
|
||||||
return Matrix.of(context)
|
|
||||||
.client
|
|
||||||
.rooms
|
|
||||||
.where((room) => room.isDirectChat && _roomCheckCommon(room, context))
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
final String? routeHandle = null;
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool shouldShowStoriesHeader(BuildContext context) => true;
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator ==(Object other) {
|
|
||||||
return runtimeType == other.runtimeType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode => runtimeType.hashCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
// "Groups" entry.
|
|
||||||
class GroupsSpacesEntry extends SpacesEntry {
|
|
||||||
static final GroupsSpacesEntry _value = GroupsSpacesEntry._();
|
|
||||||
|
|
||||||
GroupsSpacesEntry._();
|
|
||||||
|
|
||||||
factory GroupsSpacesEntry() {
|
|
||||||
return _value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
String getName(BuildContext context) => L10n.of(context)!.groups;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Icon getIcon(bool active) =>
|
|
||||||
active ? const Icon(Icons.group) : const Icon(Icons.group_outlined);
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Room> getRooms(BuildContext context) {
|
|
||||||
final rooms = Matrix.of(context).client.rooms;
|
|
||||||
// Needs to match ChatList's definition of a space.
|
|
||||||
final spaces = rooms.where((room) => room.isSpace).toList();
|
|
||||||
return rooms
|
|
||||||
.where((room) =>
|
|
||||||
(!room.isDirectChat) &&
|
|
||||||
_roomCheckCommon(room, context) &&
|
|
||||||
separatedGroup(room, spaces))
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
final String? routeHandle = 'groups';
|
|
||||||
|
|
||||||
bool separatedGroup(Room room, List<Room> spaces) {
|
|
||||||
return !spaces.any((space) => _roomInsideSpace(room, space));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator ==(Object other) {
|
|
||||||
return runtimeType == other.runtimeType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode => runtimeType.hashCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
// All rooms associated with a specific space.
|
|
||||||
class SpaceSpacesEntry extends SpacesEntry {
|
|
||||||
final Room space;
|
|
||||||
|
|
||||||
const SpaceSpacesEntry(this.space);
|
|
||||||
|
|
||||||
@override
|
|
||||||
String getName(BuildContext context) => space.displayname;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Room? getSpace(BuildContext context) => space;
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Room> getRooms(BuildContext context) {
|
|
||||||
return Matrix.of(context)
|
|
||||||
.client
|
|
||||||
.rooms
|
|
||||||
.where((room) => roomCheck(room, context))
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool roomCheck(Room room, BuildContext context) {
|
|
||||||
if (!_roomCheckCommon(room, context)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (_roomInsideSpace(room, space)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (AppConfig.showDirectChatsInSpaces) {
|
|
||||||
if (room.isDirectChat &&
|
|
||||||
room.summary.mHeroes != null &&
|
|
||||||
room.summary.mHeroes!.any((userId) {
|
|
||||||
final user = space.getState(EventTypes.RoomMember, userId)?.asUser;
|
|
||||||
return user != null && user.membership == Membership.join;
|
|
||||||
})) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool stillValid(BuildContext context) =>
|
|
||||||
Matrix.of(context).client.getRoomById(space.id) != null;
|
|
||||||
|
|
||||||
@override
|
|
||||||
String? get routeHandle => space.id;
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator ==(Object other) {
|
|
||||||
return hashCode == other.hashCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode => space.id.hashCode;
|
|
||||||
}
|
|
@ -1,156 +0,0 @@
|
|||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'package:animations/animations.dart';
|
|
||||||
import 'package:async/async.dart';
|
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|
||||||
import 'package:matrix/matrix.dart';
|
|
||||||
|
|
||||||
import 'package:fluffychat/pages/chat_list/search_title.dart';
|
|
||||||
import 'package:fluffychat/widgets/matrix.dart';
|
|
||||||
import 'recommended_room_list_item.dart';
|
|
||||||
|
|
||||||
class SpacesHierarchyProposals extends StatefulWidget {
|
|
||||||
static final Map<String, AsyncCache<GetSpaceHierarchyResponse?>> _cache = {};
|
|
||||||
|
|
||||||
final String? space;
|
|
||||||
final String? query;
|
|
||||||
|
|
||||||
const SpacesHierarchyProposals({
|
|
||||||
Key? key,
|
|
||||||
required this.space,
|
|
||||||
this.query,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<SpacesHierarchyProposals> createState() =>
|
|
||||||
_SpacesHierarchyProposalsState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _SpacesHierarchyProposalsState extends State<SpacesHierarchyProposals> {
|
|
||||||
@override
|
|
||||||
void didUpdateWidget(covariant SpacesHierarchyProposals oldWidget) {
|
|
||||||
if (oldWidget.space != widget.space || oldWidget.query != widget.query) {
|
|
||||||
setState(() {});
|
|
||||||
}
|
|
||||||
super.didUpdateWidget(oldWidget);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
// check for recommended rooms in case the active space is a [SpaceSpacesEntry]
|
|
||||||
if (widget.space != null) {
|
|
||||||
final client = Matrix.of(context).client;
|
|
||||||
|
|
||||||
final cache = SpacesHierarchyProposals._cache[widget.space!] ??=
|
|
||||||
AsyncCache<GetSpaceHierarchyResponse?>(const Duration(minutes: 15));
|
|
||||||
|
|
||||||
/// additionally saving the future's state in the completer in order to
|
|
||||||
/// display the loading indicator when refreshing as a [FutureBuilder] is
|
|
||||||
/// a [StatefulWidget].
|
|
||||||
final completer = Completer();
|
|
||||||
final future = cache.fetch(() => client.getSpaceHierarchy(
|
|
||||||
widget.space!,
|
|
||||||
suggestedOnly: true,
|
|
||||||
maxDepth: 1,
|
|
||||||
));
|
|
||||||
future.then(completer.complete);
|
|
||||||
|
|
||||||
return FutureBuilder<GetSpaceHierarchyResponse?>(
|
|
||||||
future: future,
|
|
||||||
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 &&
|
|
||||||
// filtering in case a query is given
|
|
||||||
(widget.query != null
|
|
||||||
? (element.name?.contains(widget.query!) ?? false) ||
|
|
||||||
(element.topic?.contains(widget.query!) ?? false)
|
|
||||||
// in case not, just leave it...
|
|
||||||
: true) &&
|
|
||||||
client.rooms
|
|
||||||
.every((knownRoom) => element.roomId != knownRoom.id),
|
|
||||||
);
|
|
||||||
if (rooms.isEmpty && !thereWereRooms) {
|
|
||||||
child = const ListTile(key: ValueKey(false));
|
|
||||||
}
|
|
||||||
child = Column(
|
|
||||||
key: ValueKey(widget.space),
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
SearchTitle(
|
|
||||||
title: L10n.of(context)!.suggestedRooms,
|
|
||||||
icon: const Icon(Icons.auto_awesome_outlined),
|
|
||||||
trailing: completer.isCompleted
|
|
||||||
? const Icon(
|
|
||||||
Icons.refresh_outlined,
|
|
||||||
size: 16,
|
|
||||||
)
|
|
||||||
: const SizedBox(
|
|
||||||
width: 16,
|
|
||||||
height: 16,
|
|
||||||
child: CircularProgressIndicator.adaptive(
|
|
||||||
strokeWidth: 1,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onTap: _refreshRooms,
|
|
||||||
),
|
|
||||||
if (rooms.isEmpty && thereWereRooms)
|
|
||||||
ListTile(
|
|
||||||
leading: const Icon(Icons.info),
|
|
||||||
title: Text(L10n.of(context)!.allSuggestedRoomsJoined),
|
|
||||||
),
|
|
||||||
...rooms.map(
|
|
||||||
(e) => RecommendedRoomListItem(
|
|
||||||
room: e,
|
|
||||||
onRoomJoined: _refreshRooms,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
child = Column(
|
|
||||||
key: const ValueKey(null),
|
|
||||||
children: [
|
|
||||||
if (!snapshot.hasError) const LinearProgressIndicator(),
|
|
||||||
const ListTile(),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return PageTransitionSwitcher(
|
|
||||||
// prevent the animation from re-building on dependency change
|
|
||||||
key: ValueKey(widget.space),
|
|
||||||
transitionBuilder: (
|
|
||||||
Widget child,
|
|
||||||
Animation<double> primaryAnimation,
|
|
||||||
Animation<double> secondaryAnimation,
|
|
||||||
) {
|
|
||||||
return SharedAxisTransition(
|
|
||||||
animation: primaryAnimation,
|
|
||||||
secondaryAnimation: secondaryAnimation,
|
|
||||||
transitionType: SharedAxisTransitionType.scaled,
|
|
||||||
fillColor: Colors.transparent,
|
|
||||||
child: child,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
layoutBuilder: (children) => Stack(
|
|
||||||
alignment: Alignment.topCenter,
|
|
||||||
children: children,
|
|
||||||
),
|
|
||||||
child: child,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return Container();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _refreshRooms() => setState(
|
|
||||||
() => SpacesHierarchyProposals._cache[widget.space!]!.invalidate(),
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
/// this is a workaround to allow navigation of spaces out from any widget.
|
|
||||||
/// Reason is that we have no reliable way to listen on *query* changes of
|
|
||||||
/// VRouter.
|
|
||||||
///
|
|
||||||
/// Time wasted: 3h
|
|
||||||
abstract class SpaceNavigator {
|
|
||||||
const SpaceNavigator._();
|
|
||||||
|
|
||||||
// TODO(TheOneWithTheBraid): adjust routing table in order to represent spaces
|
|
||||||
// ... in any present path
|
|
||||||
static final routeObserver = RouteObserver();
|
|
||||||
|
|
||||||
static final StreamController<String?> _controller =
|
|
||||||
StreamController.broadcast();
|
|
||||||
|
|
||||||
static Stream<String?> get stream => _controller.stream;
|
|
||||||
|
|
||||||
static void navigateToSpace(String? spaceId) => _controller.add(spaceId);
|
|
||||||
}
|
|
Loading…
Reference in New Issue