mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-12-29 01:22:37 +01:00
fix: Load spaces on app start
This commit is contained in:
parent
7167d0ace6
commit
a5f1925f03
@ -49,7 +49,10 @@ class ChatListController extends State<ChatList> {
|
||||
StreamSubscription _intentUriStreamSubscription;
|
||||
|
||||
String _activeSpaceId;
|
||||
String get activeSpaceId => _activeSpaceId;
|
||||
String get activeSpaceId =>
|
||||
Matrix.of(context).client.getRoomById(_activeSpaceId) == null
|
||||
? null
|
||||
: _activeSpaceId;
|
||||
final ScrollController scrollController = ScrollController();
|
||||
bool scrolledToTop = true;
|
||||
|
||||
@ -160,11 +163,9 @@ class ChatListController extends State<ChatList> {
|
||||
@override
|
||||
void initState() {
|
||||
_initReceiveSharingIntent();
|
||||
WidgetsBinding.instance.addPostFrameCallback(
|
||||
(_) => waitForFirstSync.then((_) => checkBootstrap()),
|
||||
);
|
||||
|
||||
scrollController.addListener(_onScroll);
|
||||
waitForFirstSync = _waitForFirstSync();
|
||||
_waitForFirstSync();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@ -433,7 +434,7 @@ class ChatListController extends State<ChatList> {
|
||||
Matrix.of(context).client.getRoomById(roomId).pushRuleState ==
|
||||
PushRuleState.notify);
|
||||
|
||||
Future<void> waitForFirstSync;
|
||||
bool waitForFirstSync = false;
|
||||
|
||||
Future<void> _waitForFirstSync() async {
|
||||
final client = Matrix.of(context).client;
|
||||
@ -452,7 +453,11 @@ class ChatListController extends State<ChatList> {
|
||||
await space.requestParticipants();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
setState(() {
|
||||
waitForFirstSync = true;
|
||||
});
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => checkBootstrap());
|
||||
return;
|
||||
}
|
||||
|
||||
void cancelAction() {
|
||||
|
@ -221,10 +221,9 @@ class _ChatListViewBody extends StatelessWidget {
|
||||
.where((s) => s.hasRoomUpdate)
|
||||
.rateLimit(const Duration(seconds: 1)),
|
||||
builder: (context, snapshot) {
|
||||
return FutureBuilder<void>(
|
||||
future: controller.waitForFirstSync,
|
||||
builder: (BuildContext context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
return Builder(
|
||||
builder: (context) {
|
||||
if (controller.waitForFirstSync) {
|
||||
final rooms = Matrix.of(context)
|
||||
.client
|
||||
.rooms
|
||||
|
@ -6,6 +6,7 @@ import 'package:salomon_bottom_bar/salomon_bottom_bar.dart';
|
||||
|
||||
import 'package:fluffychat/pages/chat_list/chat_list.dart';
|
||||
import 'package:fluffychat/widgets/avatar.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
||||
class SpacesBottomBar extends StatelessWidget {
|
||||
final ChatListController controller;
|
||||
@ -21,42 +22,50 @@ class SpacesBottomBar extends StatelessWidget {
|
||||
return Material(
|
||||
color: Theme.of(context).appBarTheme.backgroundColor,
|
||||
elevation: 6,
|
||||
child: SalomonBottomBar(
|
||||
itemPadding: const EdgeInsets.all(8),
|
||||
currentIndex: currentIndex,
|
||||
onTap: (i) => controller.setActiveSpaceId(
|
||||
context,
|
||||
i == 0 ? null : controller.spaces[i - 1].id,
|
||||
),
|
||||
selectedItemColor: Theme.of(context).colorScheme.primary,
|
||||
items: [
|
||||
SalomonBottomBarItem(
|
||||
icon: const Icon(CupertinoIcons.chat_bubble_2),
|
||||
activeIcon: const Icon(CupertinoIcons.chat_bubble_2_fill),
|
||||
title: Text(L10n.of(context).allChats),
|
||||
),
|
||||
...controller.spaces
|
||||
.map((space) => SalomonBottomBarItem(
|
||||
icon: InkWell(
|
||||
borderRadius: BorderRadius.circular(28),
|
||||
onTap: () => controller.setActiveSpaceId(
|
||||
context,
|
||||
space.id,
|
||||
),
|
||||
onLongPress: () =>
|
||||
controller.editSpace(context, space.id),
|
||||
child: Avatar(
|
||||
space.avatar,
|
||||
space.displayname,
|
||||
size: 24,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
title: Text(space.displayname),
|
||||
))
|
||||
.toList(),
|
||||
],
|
||||
),
|
||||
child: StreamBuilder<Object>(
|
||||
stream: Matrix.of(context).client.onSync.stream.where((sync) =>
|
||||
(sync.rooms?.join?.values?.any((r) =>
|
||||
r.state?.any((s) => s.type.startsWith('m.space'))) ??
|
||||
false) ||
|
||||
(sync.rooms?.leave?.isNotEmpty ?? false)),
|
||||
builder: (context, snapshot) {
|
||||
return SalomonBottomBar(
|
||||
itemPadding: const EdgeInsets.all(8),
|
||||
currentIndex: currentIndex,
|
||||
onTap: (i) => controller.setActiveSpaceId(
|
||||
context,
|
||||
i == 0 ? null : controller.spaces[i - 1].id,
|
||||
),
|
||||
selectedItemColor: Theme.of(context).colorScheme.primary,
|
||||
items: [
|
||||
SalomonBottomBarItem(
|
||||
icon: const Icon(CupertinoIcons.chat_bubble_2),
|
||||
activeIcon: const Icon(CupertinoIcons.chat_bubble_2_fill),
|
||||
title: Text(L10n.of(context).allChats),
|
||||
),
|
||||
...controller.spaces
|
||||
.map((space) => SalomonBottomBarItem(
|
||||
icon: InkWell(
|
||||
borderRadius: BorderRadius.circular(28),
|
||||
onTap: () => controller.setActiveSpaceId(
|
||||
context,
|
||||
space.id,
|
||||
),
|
||||
onLongPress: () =>
|
||||
controller.editSpace(context, space.id),
|
||||
child: Avatar(
|
||||
space.avatar,
|
||||
space.displayname,
|
||||
size: 24,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
title: Text(space.displayname),
|
||||
))
|
||||
.toList(),
|
||||
],
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user