mirror of
https://github.com/krille-chan/fluffychat
synced 2024-09-21 00:55:14 +00:00
chore: Follow up fixes spaces
This commit is contained in:
parent
92fa413156
commit
f1a495b8cd
2 changed files with 24 additions and 7 deletions
|
@ -48,6 +48,7 @@ class ChatListView extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final client = Matrix.of(context).client;
|
||||||
return StreamBuilder<Object?>(
|
return StreamBuilder<Object?>(
|
||||||
stream: Matrix.of(context).onShareContentChanged.stream,
|
stream: Matrix.of(context).onShareContentChanged.stream,
|
||||||
builder: (_, __) {
|
builder: (_, __) {
|
||||||
|
@ -61,9 +62,9 @@ class ChatListView extends StatelessWidget {
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
if (FluffyThemes.isColumnMode(context) &&
|
if (FluffyThemes.isColumnMode(context) &&
|
||||||
FluffyThemes.getDisplayNavigationRail(context)) ...[
|
FluffyThemes.getDisplayNavigationRail(context) &&
|
||||||
|
controller.waitForFirstSync) ...[
|
||||||
Builder(builder: (context) {
|
Builder(builder: (context) {
|
||||||
final client = Matrix.of(context).client;
|
|
||||||
final allSpaces = client.rooms.where((room) => room.isSpace);
|
final allSpaces = client.rooms.where((room) => room.isSpace);
|
||||||
final rootSpaces = allSpaces
|
final rootSpaces = allSpaces
|
||||||
.where(
|
.where(
|
||||||
|
@ -74,6 +75,7 @@ class ChatListView extends StatelessWidget {
|
||||||
)
|
)
|
||||||
.toList();
|
.toList();
|
||||||
final destinations = getNavigationDestinations(context);
|
final destinations = getNavigationDestinations(context);
|
||||||
|
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
width: 64,
|
width: 64,
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
|
|
|
@ -30,6 +30,8 @@ class SpaceView extends StatefulWidget {
|
||||||
class _SpaceViewState extends State<SpaceView> {
|
class _SpaceViewState extends State<SpaceView> {
|
||||||
static final Map<String, Future<GetSpaceHierarchyResponse>> _requests = {};
|
static final Map<String, Future<GetSpaceHierarchyResponse>> _requests = {};
|
||||||
|
|
||||||
|
String? prevBatch;
|
||||||
|
|
||||||
void _refresh() {
|
void _refresh() {
|
||||||
setState(() {
|
setState(() {
|
||||||
_requests.remove(widget.controller.activeSpaceId);
|
_requests.remove(widget.controller.activeSpaceId);
|
||||||
|
@ -37,8 +39,11 @@ class _SpaceViewState extends State<SpaceView> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<GetSpaceHierarchyResponse> getFuture(String activeSpaceId) =>
|
Future<GetSpaceHierarchyResponse> getFuture(String activeSpaceId) =>
|
||||||
_requests[activeSpaceId] ??=
|
_requests[activeSpaceId] ??= Matrix.of(context).client.getSpaceHierarchy(
|
||||||
Matrix.of(context).client.getSpaceHierarchy(activeSpaceId);
|
activeSpaceId,
|
||||||
|
maxDepth: 1,
|
||||||
|
from: prevBatch,
|
||||||
|
);
|
||||||
|
|
||||||
void _onJoinSpaceChild(SpaceRoomsChunk spaceChild) async {
|
void _onJoinSpaceChild(SpaceRoomsChunk spaceChild) async {
|
||||||
final client = Matrix.of(context).client;
|
final client = Matrix.of(context).client;
|
||||||
|
@ -186,10 +191,10 @@ class _SpaceViewState extends State<SpaceView> {
|
||||||
final parentSpace = allSpaces.firstWhereOrNull((space) => space
|
final parentSpace = allSpaces.firstWhereOrNull((space) => space
|
||||||
.spaceChildren
|
.spaceChildren
|
||||||
.any((child) => child.roomId == activeSpaceId));
|
.any((child) => child.roomId == activeSpaceId));
|
||||||
final spaceChildren = response.rooms
|
final spaceChildren = response.rooms;
|
||||||
..sort((a, b) => a.roomType == 'm.space' ? -1 : 1);
|
final canLoadMore = response.nextBatch != null;
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
itemCount: spaceChildren.length + 1,
|
itemCount: spaceChildren.length + 1 + (canLoadMore ? 1 : 0),
|
||||||
controller: widget.scrollController,
|
controller: widget.scrollController,
|
||||||
itemBuilder: (context, i) {
|
itemBuilder: (context, i) {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
|
@ -213,6 +218,16 @@ class _SpaceViewState extends State<SpaceView> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
i--;
|
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 spaceChild = spaceChildren[i];
|
||||||
final room = client.getRoomById(spaceChild.roomId);
|
final room = client.getRoomById(spaceChild.roomId);
|
||||||
if (room != null && !room.isSpace) {
|
if (room != null && !room.isSpace) {
|
||||||
|
|
Loading…
Reference in a new issue