|
|
|
@ -14,6 +14,7 @@ import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
|
|
|
|
import 'package:fluffychat/widgets/avatar.dart';
|
|
|
|
|
import '../../utils/localized_exception_extension.dart';
|
|
|
|
|
import '../../widgets/matrix.dart';
|
|
|
|
|
import 'chat_list_header.dart';
|
|
|
|
|
|
|
|
|
|
class SpaceView extends StatefulWidget {
|
|
|
|
|
final ChatListController controller;
|
|
|
|
@ -154,36 +155,44 @@ class _SpaceViewState extends State<SpaceView> {
|
|
|
|
|
)
|
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
|
|
return ListView.builder(
|
|
|
|
|
itemCount: rootSpaces.length,
|
|
|
|
|
return CustomScrollView(
|
|
|
|
|
controller: widget.scrollController,
|
|
|
|
|
itemBuilder: (context, i) {
|
|
|
|
|
final rootSpace = rootSpaces[i];
|
|
|
|
|
final displayname = rootSpace.getLocalizedDisplayname(
|
|
|
|
|
MatrixLocals(L10n.of(context)!),
|
|
|
|
|
);
|
|
|
|
|
return Material(
|
|
|
|
|
color: Theme.of(context).colorScheme.background,
|
|
|
|
|
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),
|
|
|
|
|
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.background,
|
|
|
|
|
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,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return FutureBuilder<GetSpaceHierarchyResponse>(
|
|
|
|
@ -208,7 +217,16 @@ class _SpaceViewState extends State<SpaceView> {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (response == null) {
|
|
|
|
|
return const Center(child: CircularProgressIndicator.adaptive());
|
|
|
|
|
return CustomScrollView(
|
|
|
|
|
slivers: [
|
|
|
|
|
ChatListHeader(controller: widget.controller),
|
|
|
|
|
const SliverFillRemaining(
|
|
|
|
|
child: Center(
|
|
|
|
|
child: CircularProgressIndicator.adaptive(),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
final parentSpace = allSpaces.firstWhereOrNull(
|
|
|
|
|
(space) =>
|
|
|
|
@ -224,125 +242,139 @@ class _SpaceViewState extends State<SpaceView> {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
child: ListView.builder(
|
|
|
|
|
itemCount: spaceChildren.length + 1 + (canLoadMore ? 1 : 0),
|
|
|
|
|
child: CustomScrollView(
|
|
|
|
|
controller: widget.scrollController,
|
|
|
|
|
itemBuilder: (context, i) {
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
return ListTile(
|
|
|
|
|
leading: BackButton(
|
|
|
|
|
onPressed: () =>
|
|
|
|
|
widget.controller.setActiveSpace(parentSpace?.id),
|
|
|
|
|
),
|
|
|
|
|
title: Text(
|
|
|
|
|
parentSpace == null
|
|
|
|
|
? L10n.of(context)!.allSpaces
|
|
|
|
|
: parentSpace.getLocalizedDisplayname(
|
|
|
|
|
MatrixLocals(L10n.of(context)!),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
trailing: IconButton(
|
|
|
|
|
icon: snapshot.connectionState != ConnectionState.done
|
|
|
|
|
? const CircularProgressIndicator.adaptive()
|
|
|
|
|
: const Icon(Icons.refresh_outlined),
|
|
|
|
|
onPressed: snapshot.connectionState != ConnectionState.done
|
|
|
|
|
slivers: [
|
|
|
|
|
ChatListHeader(controller: widget.controller),
|
|
|
|
|
SliverList(
|
|
|
|
|
delegate: SliverChildBuilderDelegate(
|
|
|
|
|
(context, i) {
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
return ListTile(
|
|
|
|
|
leading: BackButton(
|
|
|
|
|
onPressed: () =>
|
|
|
|
|
widget.controller.setActiveSpace(parentSpace?.id),
|
|
|
|
|
),
|
|
|
|
|
title: Text(
|
|
|
|
|
parentSpace == null
|
|
|
|
|
? L10n.of(context)!.allSpaces
|
|
|
|
|
: parentSpace.getLocalizedDisplayname(
|
|
|
|
|
MatrixLocals(L10n.of(context)!),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
trailing: IconButton(
|
|
|
|
|
icon: snapshot.connectionState != ConnectionState.done
|
|
|
|
|
? const CircularProgressIndicator.adaptive()
|
|
|
|
|
: const Icon(Icons.refresh_outlined),
|
|
|
|
|
onPressed:
|
|
|
|
|
snapshot.connectionState != ConnectionState.done
|
|
|
|
|
? null
|
|
|
|
|
: _refresh,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
i--;
|
|
|
|
|
if (canLoadMore && i == spaceChildren.length) {
|
|
|
|
|
return ListTile(
|
|
|
|
|
title: Text(L10n.of(context)!.loadMore),
|
|
|
|
|
trailing: const Icon(Icons.chevron_right_outlined),
|
|
|
|
|
onTap: () {
|
|
|
|
|
prevBatch = response.nextBatch;
|
|
|
|
|
_refresh();
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
final spaceChild = spaceChildren[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
|
|
|
|
|
: _refresh,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
i--;
|
|
|
|
|
if (canLoadMore && i == spaceChildren.length) {
|
|
|
|
|
return ListTile(
|
|
|
|
|
title: Text(L10n.of(context)!.loadMore),
|
|
|
|
|
trailing: const Icon(Icons.chevron_right_outlined),
|
|
|
|
|
onTap: () {
|
|
|
|
|
prevBatch = response.nextBatch;
|
|
|
|
|
_refresh();
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
final spaceChild = spaceChildren[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.topic;
|
|
|
|
|
if (spaceChild.roomId == activeSpaceId) {
|
|
|
|
|
return SearchTitle(
|
|
|
|
|
title: spaceChild.name ??
|
|
|
|
|
spaceChild.canonicalAlias ??
|
|
|
|
|
L10n.of(context)!.chat,
|
|
|
|
|
maxLines: 1,
|
|
|
|
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
|
|
|
|
'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,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
if (!isSpace) ...[
|
|
|
|
|
const Icon(
|
|
|
|
|
Icons.people_outline,
|
|
|
|
|
size: 16,
|
|
|
|
|
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),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
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,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
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,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
childCount: spaceChildren.length + 1 + (canLoadMore ? 1 : 0),
|
|
|
|
|
),
|
|
|
|
|
trailing:
|
|
|
|
|
isSpace ? const Icon(Icons.chevron_right_outlined) : null,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|