|
|
|
@ -5,26 +5,32 @@ import 'package:collection/collection.dart';
|
|
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|
|
|
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
|
|
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
|
import 'package:matrix/matrix.dart' as sdk;
|
|
|
|
|
import 'package:matrix/matrix.dart';
|
|
|
|
|
|
|
|
|
|
import 'package:fluffychat/pages/chat_list/chat_list.dart';
|
|
|
|
|
import 'package:fluffychat/config/app_config.dart';
|
|
|
|
|
import 'package:fluffychat/pages/chat_list/chat_list_item.dart';
|
|
|
|
|
import 'package:fluffychat/pages/chat_list/search_title.dart';
|
|
|
|
|
import 'package:fluffychat/pages/chat_list/utils/on_chat_tap.dart';
|
|
|
|
|
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
|
|
|
|
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
|
|
|
|
import 'package:fluffychat/utils/stream_extension.dart';
|
|
|
|
|
import 'package:fluffychat/widgets/avatar.dart';
|
|
|
|
|
import '../../utils/localized_exception_extension.dart';
|
|
|
|
|
import '../../widgets/matrix.dart';
|
|
|
|
|
import 'chat_list_header.dart';
|
|
|
|
|
import 'package:fluffychat/widgets/matrix.dart';
|
|
|
|
|
|
|
|
|
|
class SpaceView extends StatefulWidget {
|
|
|
|
|
final ChatListController controller;
|
|
|
|
|
final ScrollController scrollController;
|
|
|
|
|
const SpaceView(
|
|
|
|
|
this.controller, {
|
|
|
|
|
final String spaceId;
|
|
|
|
|
final void Function() onBack;
|
|
|
|
|
final void Function(String spaceId) toParentSpace;
|
|
|
|
|
final void Function(Room room) onChatTab;
|
|
|
|
|
final void Function(Room room) onChatContext;
|
|
|
|
|
final String? activeChat;
|
|
|
|
|
|
|
|
|
|
const SpaceView({
|
|
|
|
|
required this.spaceId,
|
|
|
|
|
required this.onBack,
|
|
|
|
|
required this.onChatTab,
|
|
|
|
|
required this.activeChat,
|
|
|
|
|
required this.toParentSpace,
|
|
|
|
|
required this.onChatContext,
|
|
|
|
|
super.key,
|
|
|
|
|
required this.scrollController,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@ -32,543 +38,449 @@ class SpaceView extends StatefulWidget {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _SpaceViewState extends State<SpaceView> {
|
|
|
|
|
static final Map<String, GetSpaceHierarchyResponse> _lastResponse = {};
|
|
|
|
|
|
|
|
|
|
String? prevBatch;
|
|
|
|
|
Object? error;
|
|
|
|
|
bool loading = false;
|
|
|
|
|
final List<SpaceRoomsChunk> _discoveredChildren = [];
|
|
|
|
|
final TextEditingController _filterController = TextEditingController();
|
|
|
|
|
String? _nextBatch;
|
|
|
|
|
bool _noMoreRooms = false;
|
|
|
|
|
bool _isLoading = false;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
loadHierarchy();
|
|
|
|
|
_loadHierarchy();
|
|
|
|
|
super.initState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _refresh() {
|
|
|
|
|
_lastResponse.remove(widget.controller.activeSpaceId);
|
|
|
|
|
loadHierarchy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<GetSpaceHierarchyResponse?> loadHierarchy([String? prevBatch]) async {
|
|
|
|
|
final activeSpaceId = widget.controller.activeSpaceId;
|
|
|
|
|
if (activeSpaceId == null) return null;
|
|
|
|
|
final client = Matrix.of(context).client;
|
|
|
|
|
|
|
|
|
|
final activeSpace = client.getRoomById(activeSpaceId);
|
|
|
|
|
await activeSpace?.postLoad();
|
|
|
|
|
void _loadHierarchy() async {
|
|
|
|
|
final room = Matrix.of(context).client.getRoomById(widget.spaceId);
|
|
|
|
|
if (room == null) return;
|
|
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
|
error = null;
|
|
|
|
|
loading = true;
|
|
|
|
|
_isLoading = true;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
final response = await client.getSpaceHierarchy(
|
|
|
|
|
activeSpaceId,
|
|
|
|
|
maxDepth: 1,
|
|
|
|
|
from: prevBatch,
|
|
|
|
|
final hierarchy = await room.client.getSpaceHierarchy(
|
|
|
|
|
widget.spaceId,
|
|
|
|
|
suggestedOnly: false,
|
|
|
|
|
maxDepth: 2,
|
|
|
|
|
from: _nextBatch,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (prevBatch != null) {
|
|
|
|
|
response.rooms.insertAll(0, _lastResponse[activeSpaceId]?.rooms ?? []);
|
|
|
|
|
}
|
|
|
|
|
setState(() {
|
|
|
|
|
_lastResponse[activeSpaceId] = response;
|
|
|
|
|
});
|
|
|
|
|
return _lastResponse[activeSpaceId]!;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
if (!mounted) return;
|
|
|
|
|
setState(() {
|
|
|
|
|
error = e;
|
|
|
|
|
_nextBatch = hierarchy.nextBatch;
|
|
|
|
|
if (hierarchy.nextBatch == null) {
|
|
|
|
|
_noMoreRooms = true;
|
|
|
|
|
}
|
|
|
|
|
_discoveredChildren.addAll(
|
|
|
|
|
hierarchy.rooms
|
|
|
|
|
.where((c) => room.client.getRoomById(c.roomId) == null),
|
|
|
|
|
);
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
});
|
|
|
|
|
rethrow;
|
|
|
|
|
} finally {
|
|
|
|
|
} catch (e, s) {
|
|
|
|
|
Logs().w('Unable to load hierarchy', e, s);
|
|
|
|
|
if (!mounted) return;
|
|
|
|
|
ScaffoldMessenger.of(context)
|
|
|
|
|
.showSnackBar(SnackBar(content: Text(e.toLocalizedString(context))));
|
|
|
|
|
setState(() {
|
|
|
|
|
loading = false;
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _onJoinSpaceChild(SpaceRoomsChunk spaceChild) async {
|
|
|
|
|
void _joinChildRoom(SpaceRoomsChunk item) 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) {
|
|
|
|
|
context.go('/rooms/${spaceChild.roomId}');
|
|
|
|
|
} else {
|
|
|
|
|
widget.controller.setActiveSpace(spaceChild.roomId);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
context.go('/rooms/${spaceChild.roomId}');
|
|
|
|
|
}
|
|
|
|
|
final space = client.getRoomById(widget.spaceId);
|
|
|
|
|
|
|
|
|
|
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>(
|
|
|
|
|
final consent = await showOkCancelAlertDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
title: spaceChild?.name ??
|
|
|
|
|
room?.getLocalizedDisplayname(
|
|
|
|
|
MatrixLocals(L10n.of(context)!),
|
|
|
|
|
),
|
|
|
|
|
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?.canChangeStateEvent(EventTypes.SpaceChild) ?? 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,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
title: item.name ?? item.canonicalAlias ?? L10n.of(context)!.emptyChat,
|
|
|
|
|
message: item.topic,
|
|
|
|
|
okLabel: L10n.of(context)!.joinRoom,
|
|
|
|
|
cancelLabel: L10n.of(context)!.cancel,
|
|
|
|
|
);
|
|
|
|
|
if (consent != OkCancelResult.ok) return;
|
|
|
|
|
if (!mounted) return;
|
|
|
|
|
|
|
|
|
|
await showFutureLoadingDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
future: () async {
|
|
|
|
|
await client.joinRoom(
|
|
|
|
|
item.roomId,
|
|
|
|
|
serverName: space?.spaceChildren
|
|
|
|
|
.firstWhereOrNull(
|
|
|
|
|
(child) => child.roomId == item.roomId,
|
|
|
|
|
)
|
|
|
|
|
?.via,
|
|
|
|
|
);
|
|
|
|
|
if (client.getRoomById(item.roomId) == null) {
|
|
|
|
|
// Wait for room actually appears in sync
|
|
|
|
|
await client.waitForRoomInSync(item.roomId, join: true);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
if (action == null) return;
|
|
|
|
|
if (!mounted) return;
|
|
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
|
_discoveredChildren.remove(item);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _onSpaceAction(SpaceActions action) async {
|
|
|
|
|
final space = Matrix.of(context).client.getRoomById(widget.spaceId);
|
|
|
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
|
case SpaceChildContextAction.join:
|
|
|
|
|
_onJoinSpaceChild(spaceChild!);
|
|
|
|
|
case SpaceActions.settings:
|
|
|
|
|
await space?.postLoad();
|
|
|
|
|
context.push('/rooms/${widget.spaceId}/details');
|
|
|
|
|
break;
|
|
|
|
|
case SpaceChildContextAction.leave:
|
|
|
|
|
await showFutureLoadingDialog(
|
|
|
|
|
case SpaceActions.invite:
|
|
|
|
|
await space?.postLoad();
|
|
|
|
|
context.push('/rooms/${widget.spaceId}/invite');
|
|
|
|
|
break;
|
|
|
|
|
case SpaceActions.leave:
|
|
|
|
|
final confirmed = await showOkCancelAlertDialog(
|
|
|
|
|
useRootNavigator: false,
|
|
|
|
|
context: context,
|
|
|
|
|
future: room!.leave,
|
|
|
|
|
title: L10n.of(context)!.areYouSure,
|
|
|
|
|
okLabel: L10n.of(context)!.ok,
|
|
|
|
|
cancelLabel: L10n.of(context)!.cancel,
|
|
|
|
|
message: L10n.of(context)!.archiveRoomDescription,
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
case SpaceChildContextAction.removeFromSpace:
|
|
|
|
|
await showFutureLoadingDialog(
|
|
|
|
|
if (!mounted) return;
|
|
|
|
|
if (confirmed != OkCancelResult.ok) return;
|
|
|
|
|
|
|
|
|
|
final success = await showFutureLoadingDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
future: () => activeSpace!.removeSpaceChild(spaceChild!.roomId),
|
|
|
|
|
future: () async => await space?.leave(),
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
if (!mounted) return;
|
|
|
|
|
if (success.error != null) return;
|
|
|
|
|
widget.onBack();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _addChatOrSubSpace() async {
|
|
|
|
|
final roomType = await showConfirmationDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
title: L10n.of(context)!.addChatOrSubSpace,
|
|
|
|
|
actions: [
|
|
|
|
|
AlertDialogAction(
|
|
|
|
|
key: AddRoomType.subspace,
|
|
|
|
|
label: L10n.of(context)!.createNewSpace,
|
|
|
|
|
),
|
|
|
|
|
AlertDialogAction(
|
|
|
|
|
key: AddRoomType.chat,
|
|
|
|
|
label: L10n.of(context)!.createGroup,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
if (roomType == null) return;
|
|
|
|
|
|
|
|
|
|
final names = await showTextInputDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
title: roomType == AddRoomType.subspace
|
|
|
|
|
? L10n.of(context)!.createNewSpace
|
|
|
|
|
: L10n.of(context)!.createGroup,
|
|
|
|
|
textFields: [
|
|
|
|
|
DialogTextField(
|
|
|
|
|
hintText: roomType == AddRoomType.subspace
|
|
|
|
|
? L10n.of(context)!.spaceName
|
|
|
|
|
: L10n.of(context)!.groupName,
|
|
|
|
|
minLines: 1,
|
|
|
|
|
maxLines: 1,
|
|
|
|
|
maxLength: 64,
|
|
|
|
|
validator: (text) {
|
|
|
|
|
if (text == null || text.isEmpty) {
|
|
|
|
|
return L10n.of(context)!.pleaseChoose;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
DialogTextField(
|
|
|
|
|
hintText: L10n.of(context)!.chatDescription,
|
|
|
|
|
minLines: 4,
|
|
|
|
|
maxLines: 8,
|
|
|
|
|
maxLength: 255,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
okLabel: L10n.of(context)!.create,
|
|
|
|
|
cancelLabel: L10n.of(context)!.cancel,
|
|
|
|
|
);
|
|
|
|
|
if (names == null) return;
|
|
|
|
|
final client = Matrix.of(context).client;
|
|
|
|
|
final result = await showFutureLoadingDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
future: () async {
|
|
|
|
|
late final String roomId;
|
|
|
|
|
final activeSpace = client.getRoomById(
|
|
|
|
|
widget.controller.activeSpaceId!,
|
|
|
|
|
)!;
|
|
|
|
|
|
|
|
|
|
if (roomType == AddRoomType.subspace) {
|
|
|
|
|
roomId = await client.createSpace(
|
|
|
|
|
name: names.first,
|
|
|
|
|
topic: names.last.isEmpty ? null : names.last,
|
|
|
|
|
visibility: activeSpace.joinRules == JoinRules.public
|
|
|
|
|
? sdk.Visibility.public
|
|
|
|
|
: sdk.Visibility.private,
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
roomId = await client.createGroupChat(
|
|
|
|
|
groupName: names.first,
|
|
|
|
|
initialState: names.length > 1 && names.last.isNotEmpty
|
|
|
|
|
? [
|
|
|
|
|
sdk.StateEvent(
|
|
|
|
|
type: sdk.EventTypes.RoomTopic,
|
|
|
|
|
content: {'topic': names.last},
|
|
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
: null,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
await activeSpace.setSpaceChild(roomId);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
if (result.error != null) return;
|
|
|
|
|
_refresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final client = Matrix.of(context).client;
|
|
|
|
|
final activeSpaceId = widget.controller.activeSpaceId;
|
|
|
|
|
final activeSpace = activeSpaceId == null
|
|
|
|
|
? null
|
|
|
|
|
: client.getRoomById(
|
|
|
|
|
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),
|
|
|
|
|
) &&
|
|
|
|
|
space
|
|
|
|
|
.getLocalizedDisplayname(MatrixLocals(L10n.of(context)!))
|
|
|
|
|
.toLowerCase()
|
|
|
|
|
.contains(
|
|
|
|
|
widget.controller.searchController.text.toLowerCase(),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
|
|
return SafeArea(
|
|
|
|
|
child: CustomScrollView(
|
|
|
|
|
controller: widget.scrollController,
|
|
|
|
|
slivers: [
|
|
|
|
|
ChatListHeader(controller: widget.controller),
|
|
|
|
|
SliverList(
|
|
|
|
|
delegate: SliverChildBuilderDelegate(
|
|
|
|
|
(context, i) {
|
|
|
|
|
final rootSpace = rootSpaces[i];
|
|
|
|
|
final displayname = rootSpace.getLocalizedDisplayname(
|
|
|
|
|
MatrixLocals(L10n.of(context)!),
|
|
|
|
|
);
|
|
|
|
|
return Material(
|
|
|
|
|
color: Theme.of(context).colorScheme.surface,
|
|
|
|
|
child: ListTile(
|
|
|
|
|
leading: Avatar(
|
|
|
|
|
mxContent: rootSpace.avatar,
|
|
|
|
|
name: displayname,
|
|
|
|
|
),
|
|
|
|
|
title: Text(
|
|
|
|
|
displayname,
|
|
|
|
|
maxLines: 1,
|
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
|
),
|
|
|
|
|
subtitle: Text(
|
|
|
|
|
L10n.of(context)!.numChats(
|
|
|
|
|
rootSpace.spaceChildren.length.toString(),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
onTap: () =>
|
|
|
|
|
widget.controller.setActiveSpace(rootSpace.id),
|
|
|
|
|
onLongPress: () =>
|
|
|
|
|
_onSpaceChildContextMenu(null, rootSpace),
|
|
|
|
|
trailing: const Icon(Icons.chevron_right_outlined),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
childCount: rootSpaces.length,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
final room = Matrix.of(context).client.getRoomById(widget.spaceId);
|
|
|
|
|
final displayname =
|
|
|
|
|
room?.getLocalizedDisplayname() ?? L10n.of(context)!.nothingFound;
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
leading: Center(
|
|
|
|
|
child: CloseButton(
|
|
|
|
|
onPressed: widget.onBack,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final parentSpace = allSpaces.firstWhereOrNull(
|
|
|
|
|
(space) =>
|
|
|
|
|
space.spaceChildren.any((child) => child.roomId == activeSpaceId),
|
|
|
|
|
);
|
|
|
|
|
return PopScope(
|
|
|
|
|
canPop: parentSpace == null,
|
|
|
|
|
onPopInvoked: (pop) async {
|
|
|
|
|
if (pop) return;
|
|
|
|
|
if (parentSpace != null) {
|
|
|
|
|
widget.controller.setActiveSpace(parentSpace.id);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
child: SafeArea(
|
|
|
|
|
child: CustomScrollView(
|
|
|
|
|
controller: widget.scrollController,
|
|
|
|
|
slivers: [
|
|
|
|
|
ChatListHeader(controller: widget.controller, globalSearch: false),
|
|
|
|
|
SliverAppBar(
|
|
|
|
|
automaticallyImplyLeading: false,
|
|
|
|
|
primary: false,
|
|
|
|
|
titleSpacing: 0,
|
|
|
|
|
title: ListTile(
|
|
|
|
|
leading: BackButton(
|
|
|
|
|
onPressed: () =>
|
|
|
|
|
widget.controller.setActiveSpace(parentSpace?.id),
|
|
|
|
|
titleSpacing: 0,
|
|
|
|
|
title: ListTile(
|
|
|
|
|
contentPadding: EdgeInsets.zero,
|
|
|
|
|
leading: Avatar(
|
|
|
|
|
mxContent: room?.avatar,
|
|
|
|
|
name: displayname,
|
|
|
|
|
borderRadius: BorderRadius.circular(AppConfig.borderRadius / 2),
|
|
|
|
|
),
|
|
|
|
|
title: Text(
|
|
|
|
|
displayname,
|
|
|
|
|
maxLines: 1,
|
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
|
),
|
|
|
|
|
subtitle: room == null
|
|
|
|
|
? null
|
|
|
|
|
: Text(
|
|
|
|
|
L10n.of(context)!.countChatsAndCountParticipants(
|
|
|
|
|
room.spaceChildren.length,
|
|
|
|
|
room.summary.mJoinedMemberCount ?? 1,
|
|
|
|
|
),
|
|
|
|
|
maxLines: 1,
|
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
|
),
|
|
|
|
|
title: Text(
|
|
|
|
|
parentSpace == null
|
|
|
|
|
? L10n.of(context)!.allSpaces
|
|
|
|
|
: parentSpace.getLocalizedDisplayname(
|
|
|
|
|
MatrixLocals(L10n.of(context)!),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
actions: [
|
|
|
|
|
PopupMenuButton<SpaceActions>(
|
|
|
|
|
onSelected: _onSpaceAction,
|
|
|
|
|
itemBuilder: (context) => [
|
|
|
|
|
PopupMenuItem(
|
|
|
|
|
value: SpaceActions.settings,
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
const Icon(Icons.settings_outlined),
|
|
|
|
|
const SizedBox(width: 12),
|
|
|
|
|
Text(L10n.of(context)!.settings),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
trailing: IconButton(
|
|
|
|
|
icon: loading
|
|
|
|
|
? const CircularProgressIndicator.adaptive(strokeWidth: 2)
|
|
|
|
|
: const Icon(Icons.refresh_outlined),
|
|
|
|
|
onPressed: loading ? null : _refresh,
|
|
|
|
|
),
|
|
|
|
|
PopupMenuItem(
|
|
|
|
|
value: SpaceActions.invite,
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
const Icon(Icons.person_add_outlined),
|
|
|
|
|
const SizedBox(width: 12),
|
|
|
|
|
Text(L10n.of(context)!.invite),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Builder(
|
|
|
|
|
builder: (context) {
|
|
|
|
|
final response = _lastResponse[activeSpaceId];
|
|
|
|
|
final error = this.error;
|
|
|
|
|
if (error != null) {
|
|
|
|
|
return SliverFillRemaining(
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
|
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),
|
|
|
|
|
PopupMenuItem(
|
|
|
|
|
value: SpaceActions.leave,
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
const Icon(Icons.delete_outlined),
|
|
|
|
|
const SizedBox(width: 12),
|
|
|
|
|
Text(L10n.of(context)!.leave),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
body: room == null
|
|
|
|
|
? const Center(
|
|
|
|
|
child: Icon(
|
|
|
|
|
Icons.search_outlined,
|
|
|
|
|
size: 80,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: StreamBuilder(
|
|
|
|
|
stream: room.client.onSync.stream
|
|
|
|
|
.where((s) => s.hasRoomUpdate)
|
|
|
|
|
.rateLimit(const Duration(seconds: 1)),
|
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
|
final joinedRooms = room.spaceChildren
|
|
|
|
|
.map((child) {
|
|
|
|
|
final roomId = child.roomId;
|
|
|
|
|
if (roomId == null) return null;
|
|
|
|
|
return room.client.getRoomById(roomId);
|
|
|
|
|
})
|
|
|
|
|
.whereType<Room>()
|
|
|
|
|
.where((room) => room.membership != Membership.leave)
|
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
|
|
// Sort rooms by last activity
|
|
|
|
|
joinedRooms.sort(
|
|
|
|
|
(b, a) => (a.lastEvent?.originServerTs ??
|
|
|
|
|
DateTime.fromMillisecondsSinceEpoch(0))
|
|
|
|
|
.compareTo(
|
|
|
|
|
b.lastEvent?.originServerTs ??
|
|
|
|
|
DateTime.fromMillisecondsSinceEpoch(0),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final joinedParents = room.spaceParents
|
|
|
|
|
.map((parent) {
|
|
|
|
|
final roomId = parent.roomId;
|
|
|
|
|
if (roomId == null) return null;
|
|
|
|
|
return room.client.getRoomById(roomId);
|
|
|
|
|
})
|
|
|
|
|
.whereType<Room>()
|
|
|
|
|
.toList();
|
|
|
|
|
final filter = _filterController.text.trim().toLowerCase();
|
|
|
|
|
return CustomScrollView(
|
|
|
|
|
slivers: [
|
|
|
|
|
SliverAppBar(
|
|
|
|
|
floating: true,
|
|
|
|
|
toolbarHeight: 72,
|
|
|
|
|
scrolledUnderElevation: 0,
|
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
|
automaticallyImplyLeading: false,
|
|
|
|
|
title: TextField(
|
|
|
|
|
controller: _filterController,
|
|
|
|
|
onChanged: (_) => setState(() {}),
|
|
|
|
|
textInputAction: TextInputAction.search,
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
fillColor:
|
|
|
|
|
Theme.of(context).colorScheme.secondaryContainer,
|
|
|
|
|
border: OutlineInputBorder(
|
|
|
|
|
borderSide: BorderSide.none,
|
|
|
|
|
borderRadius: BorderRadius.circular(99),
|
|
|
|
|
),
|
|
|
|
|
contentPadding: EdgeInsets.zero,
|
|
|
|
|
hintText: L10n.of(context)!.search,
|
|
|
|
|
hintStyle: TextStyle(
|
|
|
|
|
color: Theme.of(context)
|
|
|
|
|
.colorScheme
|
|
|
|
|
.onPrimaryContainer,
|
|
|
|
|
fontWeight: FontWeight.normal,
|
|
|
|
|
),
|
|
|
|
|
floatingLabelBehavior: FloatingLabelBehavior.never,
|
|
|
|
|
prefixIcon: IconButton(
|
|
|
|
|
onPressed: () {},
|
|
|
|
|
icon: Icon(
|
|
|
|
|
Icons.search_outlined,
|
|
|
|
|
color: Theme.of(context)
|
|
|
|
|
.colorScheme
|
|
|
|
|
.onPrimaryContainer,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (response == null) {
|
|
|
|
|
return SliverFillRemaining(
|
|
|
|
|
child: Center(
|
|
|
|
|
child: Text(L10n.of(context)!.loadingPleaseWait),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
final spaceChildren = response.rooms;
|
|
|
|
|
final canLoadMore = response.nextBatch != null;
|
|
|
|
|
return SliverList(
|
|
|
|
|
delegate: SliverChildBuilderDelegate(
|
|
|
|
|
(context, i) {
|
|
|
|
|
if (canLoadMore && i == spaceChildren.length) {
|
|
|
|
|
SliverList.builder(
|
|
|
|
|
itemCount: joinedParents.length,
|
|
|
|
|
itemBuilder: (context, i) {
|
|
|
|
|
final displayname =
|
|
|
|
|
joinedParents[i].getLocalizedDisplayname();
|
|
|
|
|
return Padding(
|
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
|
child: OutlinedButton.icon(
|
|
|
|
|
label: loading
|
|
|
|
|
? const LinearProgressIndicator()
|
|
|
|
|
: Text(L10n.of(context)!.loadMore),
|
|
|
|
|
icon: const Icon(Icons.chevron_right_outlined),
|
|
|
|
|
onPressed: loading
|
|
|
|
|
? null
|
|
|
|
|
: () {
|
|
|
|
|
loadHierarchy(response.nextBatch);
|
|
|
|
|
},
|
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
|
horizontal: 8,
|
|
|
|
|
vertical: 1,
|
|
|
|
|
),
|
|
|
|
|
child: Material(
|
|
|
|
|
borderRadius:
|
|
|
|
|
BorderRadius.circular(AppConfig.borderRadius),
|
|
|
|
|
clipBehavior: Clip.hardEdge,
|
|
|
|
|
child: ListTile(
|
|
|
|
|
minVerticalPadding: 0,
|
|
|
|
|
leading: Icon(
|
|
|
|
|
Icons.adaptive.arrow_back_outlined,
|
|
|
|
|
size: 16,
|
|
|
|
|
),
|
|
|
|
|
title: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Avatar(
|
|
|
|
|
mxContent: joinedParents[i].avatar,
|
|
|
|
|
name: displayname,
|
|
|
|
|
size: Avatar.defaultSize / 2,
|
|
|
|
|
borderRadius: BorderRadius.circular(
|
|
|
|
|
AppConfig.borderRadius / 4,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
|
Expanded(child: Text(displayname)),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
onTap: () =>
|
|
|
|
|
widget.toParentSpace(joinedParents[i].id),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
final spaceChild = spaceChildren[i];
|
|
|
|
|
final room = client.getRoomById(spaceChild.roomId);
|
|
|
|
|
if (room != null && !room.isSpace) {
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
SliverList.builder(
|
|
|
|
|
itemCount: joinedRooms.length + 1,
|
|
|
|
|
itemBuilder: (context, i) {
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
return SearchTitle(
|
|
|
|
|
title: L10n.of(context)!.joinedChats,
|
|
|
|
|
icon: const Icon(Icons.chat_outlined),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
i--;
|
|
|
|
|
final room = joinedRooms[i];
|
|
|
|
|
return ChatListItem(
|
|
|
|
|
room,
|
|
|
|
|
onLongPress: () =>
|
|
|
|
|
_onSpaceChildContextMenu(spaceChild, room),
|
|
|
|
|
activeChat: widget.controller.activeChat == room.id,
|
|
|
|
|
onTap: () => onChatTap(room, context),
|
|
|
|
|
filter: filter,
|
|
|
|
|
onTap: () => widget.onChatTab(room),
|
|
|
|
|
onLongPress: () => widget.onChatContext(room),
|
|
|
|
|
activeChat: widget.activeChat == room.id,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
final isSpace = spaceChild.roomType == 'm.space';
|
|
|
|
|
final topic = spaceChild.topic?.isEmpty ?? true
|
|
|
|
|
? null
|
|
|
|
|
: spaceChild.topic;
|
|
|
|
|
if (spaceChild.roomId == activeSpaceId) {
|
|
|
|
|
return Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
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,
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
SliverList.builder(
|
|
|
|
|
itemCount: _discoveredChildren.length + 2,
|
|
|
|
|
itemBuilder: (context, i) {
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
return SearchTitle(
|
|
|
|
|
title: L10n.of(context)!.discover,
|
|
|
|
|
icon: const Icon(Icons.explore_outlined),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
i--;
|
|
|
|
|
if (i == _discoveredChildren.length) {
|
|
|
|
|
if (_noMoreRooms) {
|
|
|
|
|
return Padding(
|
|
|
|
|
padding: const EdgeInsets.all(12.0),
|
|
|
|
|
child: Center(
|
|
|
|
|
child: Text(
|
|
|
|
|
L10n.of(context)!.noMoreChatsFound,
|
|
|
|
|
style: const TextStyle(fontSize: 13),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
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 Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
|
horizontal: 12.0,
|
|
|
|
|
vertical: 2.0,
|
|
|
|
|
),
|
|
|
|
|
if (activeSpace?.canChangeStateEvent(
|
|
|
|
|
EventTypes.SpaceChild,
|
|
|
|
|
) ==
|
|
|
|
|
true)
|
|
|
|
|
Material(
|
|
|
|
|
child: ListTile(
|
|
|
|
|
leading: const CircleAvatar(
|
|
|
|
|
child: Icon(Icons.group_add_outlined),
|
|
|
|
|
),
|
|
|
|
|
title:
|
|
|
|
|
Text(L10n.of(context)!.addChatOrSubSpace),
|
|
|
|
|
trailing:
|
|
|
|
|
const Icon(Icons.chevron_right_outlined),
|
|
|
|
|
onTap: _addChatOrSubSpace,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
final name = spaceChild.name ??
|
|
|
|
|
spaceChild.canonicalAlias ??
|
|
|
|
|
L10n.of(context)!.chat;
|
|
|
|
|
if (widget.controller.isSearchMode &&
|
|
|
|
|
!name.toLowerCase().contains(
|
|
|
|
|
widget.controller.searchController.text
|
|
|
|
|
.toLowerCase(),
|
|
|
|
|
)) {
|
|
|
|
|
return const SizedBox.shrink();
|
|
|
|
|
}
|
|
|
|
|
return Material(
|
|
|
|
|
child: ListTile(
|
|
|
|
|
leading: Avatar(
|
|
|
|
|
mxContent: spaceChild.avatarUrl,
|
|
|
|
|
name: spaceChild.name,
|
|
|
|
|
child: TextButton(
|
|
|
|
|
onPressed: _isLoading ? null : _loadHierarchy,
|
|
|
|
|
child: _isLoading
|
|
|
|
|
? LinearProgressIndicator(
|
|
|
|
|
borderRadius: BorderRadius.circular(
|
|
|
|
|
AppConfig.borderRadius,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: Text(L10n.of(context)!.loadMore),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
final item = _discoveredChildren[i];
|
|
|
|
|
final displayname = item.name ??
|
|
|
|
|
item.canonicalAlias ??
|
|
|
|
|
L10n.of(context)!.emptyChat;
|
|
|
|
|
if (!displayname.toLowerCase().contains(filter)) {
|
|
|
|
|
return const SizedBox.shrink();
|
|
|
|
|
}
|
|
|
|
|
return Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
|
horizontal: 8,
|
|
|
|
|
vertical: 1,
|
|
|
|
|
),
|
|
|
|
|
title: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Text(
|
|
|
|
|
name,
|
|
|
|
|
maxLines: 1,
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
child: Material(
|
|
|
|
|
borderRadius:
|
|
|
|
|
BorderRadius.circular(AppConfig.borderRadius),
|
|
|
|
|
clipBehavior: Clip.hardEdge,
|
|
|
|
|
child: ListTile(
|
|
|
|
|
onTap: () => _joinChildRoom(item),
|
|
|
|
|
leading: Avatar(
|
|
|
|
|
mxContent: item.avatarUrl,
|
|
|
|
|
name: displayname,
|
|
|
|
|
borderRadius: item.roomType == 'm.space'
|
|
|
|
|
? BorderRadius.circular(
|
|
|
|
|
AppConfig.borderRadius / 2,
|
|
|
|
|
)
|
|
|
|
|
: null,
|
|
|
|
|
),
|
|
|
|
|
title: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Text(
|
|
|
|
|
displayname,
|
|
|
|
|
maxLines: 1,
|
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
|
const Icon(Icons.add_circle_outline_outlined),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
subtitle: Text(
|
|
|
|
|
item.topic ??
|
|
|
|
|
L10n.of(context)!.countParticipants(
|
|
|
|
|
item.numJoinedMembers,
|
|
|
|
|
),
|
|
|
|
|
maxLines: 1,
|
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
|
),
|
|
|
|
|
if (!isSpace) ...[
|
|
|
|
|
const Icon(
|
|
|
|
|
Icons.people_outline,
|
|
|
|
|
size: 16,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 4),
|
|
|
|
|
Text(
|
|
|
|
|
spaceChild.numJoinedMembers.toString(),
|
|
|
|
|
style: const TextStyle(fontSize: 14),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
onTap: () => room?.isSpace == true
|
|
|
|
|
? widget.controller.setActiveSpace(room!.id)
|
|
|
|
|
: _onSpaceChildContextMenu(spaceChild, room),
|
|
|
|
|
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.onSurface,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
trailing: isSpace
|
|
|
|
|
? const Icon(Icons.chevron_right_outlined)
|
|
|
|
|
: null,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
childCount: spaceChildren.length + (canLoadMore ? 1 : 0),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum SpaceChildContextAction {
|
|
|
|
|
join,
|
|
|
|
|
enum SpaceActions {
|
|
|
|
|
settings,
|
|
|
|
|
invite,
|
|
|
|
|
leave,
|
|
|
|
|
removeFromSpace,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum AddRoomType { chat, subspace }
|
|
|
|
|