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