diff --git a/lib/pages/chat_list.dart b/lib/pages/chat_list.dart index 9f9667f5..054f7de4 100644 --- a/lib/pages/chat_list.dart +++ b/lib/pages/chat_list.dart @@ -154,6 +154,18 @@ class ChatListController extends State { @override void initState() { _initReceiveSharingIntent(); + WidgetsBinding.instance.addPostFrameCallback((_) async { + if (!Matrix.of(context).client.encryptionEnabled) return; + final crossSigning = await crossSigningCachedFuture; + final needsBootstrap = + Matrix.of(context).client.encryption?.crossSigning?.enabled == + false || + crossSigning == false; + final isUnknownSession = Matrix.of(context).client.isUnknownSession; + if (needsBootstrap || isUnknownSession) { + firstRunBootstrapAction(); + } + }); super.initState(); } diff --git a/lib/pages/views/chat_list_view.dart b/lib/pages/views/chat_list_view.dart index 059f7a9d..e0b88d17 100644 --- a/lib/pages/views/chat_list_view.dart +++ b/lib/pages/views/chat_list_view.dart @@ -180,148 +180,7 @@ class ChatListView extends StatelessWidget { ), body: Column(children: [ ConnectionStatusHeader(), - Expanded( - child: StreamBuilder( - stream: Matrix.of(context) - .client - .onSync - .stream - .where((s) => s.hasRoomUpdate) - .rateLimit(Duration(seconds: 1)), - builder: (context, snapshot) { - return FutureBuilder( - future: controller.waitForFirstSync(), - builder: (BuildContext context, snapshot) { - if (Matrix.of(context).client.prevBatch != null) { - final rooms = List.from( - Matrix.of(context).client.rooms) - .where((r) => !r.isSpace) - .toList(); - if (controller.activeSpaceId != null) { - rooms.removeWhere((room) => !room.spaceParents - .any((parent) => - parent.roomId == - controller.activeSpaceId)); - } - rooms.removeWhere( - (room) => room.lastEvent == null); - if (rooms.isEmpty) { - return Column( - mainAxisAlignment: MainAxisAlignment.center, - mainAxisSize: MainAxisSize.min, - children: [ - Icon( - Icons.maps_ugc_outlined, - size: 80, - color: Colors.grey, - ), - Center( - child: Text( - L10n.of(context).startYourFirstChat, - textAlign: TextAlign.start, - style: TextStyle( - color: Colors.grey, - fontSize: 16, - ), - ), - ), - ], - ); - } - final totalCount = rooms.length + 1; - return ListView.builder( - itemCount: totalCount, - itemBuilder: (BuildContext context, int i) { - if (i == 0) { - return FutureBuilder( - future: - controller.crossSigningCachedFuture, - builder: (context, snapshot) { - final needsBootstrap = - Matrix.of(context) - .client - .encryption - ?.crossSigning - ?.enabled == - false || - snapshot.data == false; - final isUnknownSession = - Matrix.of(context) - .client - .isUnknownSession; - final displayHeader = - needsBootstrap || - isUnknownSession; - if (!displayHeader || - controller.hideChatBackupBanner) { - return Container(); - } - return Material( - color: Theme.of(context) - .secondaryHeaderColor, - child: ListTile( - leading: CircleAvatar( - backgroundColor: Theme.of( - context) - .scaffoldBackgroundColor, - foregroundColor: - Theme.of(context) - .colorScheme - .secondaryVariant, - child: Icon(Icons.cloud), - ), - trailing: IconButton( - icon: Icon(Icons.close), - onPressed: controller - .hideChatBackupBannerAction, - ), - title: Text( - L10n.of(context).chatBackup), - subtitle: Text(L10n.of(context) - .enableChatBackup), - onTap: controller - .firstRunBootstrapAction, - ), - ); - }); - } - i--; - return ChatListItem( - rooms[i], - selected: controller.selectedRoomIds - .contains(rooms[i].id), - onTap: selectMode == SelectMode.select - ? () => controller - .toggleSelection(rooms[i].id) - : null, - onLongPress: () => - controller.toggleSelection(rooms[i].id), - activeChat: - controller.activeChat == rooms[i].id, - ); - }, - ); - } else { - return Center( - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Image.asset( - 'assets/private_chat_wallpaper.png', - width: 100, - ), - Text( - L10n.of(context).yourChatsAreBeingSynced, - textAlign: TextAlign.center, - ), - ], - ), - ); - } - }, - ); - }), - ), + Expanded(child: _ChatListViewBody(controller)), ]), floatingActionButton: selectMode == SelectMode.normal ? FloatingActionButton( @@ -375,6 +234,91 @@ class ChatListView extends StatelessWidget { } } +class _ChatListViewBody extends StatelessWidget { + final ChatListController controller; + const _ChatListViewBody(this.controller, {Key key}) : super(key: key); + + @override + Widget build(BuildContext context) => StreamBuilder( + stream: Matrix.of(context) + .client + .onSync + .stream + .where((s) => s.hasRoomUpdate) + .rateLimit(Duration(seconds: 1)), + builder: (context, snapshot) { + return FutureBuilder( + future: controller.waitForFirstSync(), + builder: (BuildContext context, snapshot) { + if (Matrix.of(context).client.prevBatch != null) { + final rooms = List.from(Matrix.of(context).client.rooms) + .where((r) => !r.isSpace) + .toList(); + if (controller.activeSpaceId != null) { + rooms.removeWhere((room) => !room.spaceParents.any( + (parent) => parent.roomId == controller.activeSpaceId)); + } + rooms.removeWhere((room) => room.lastEvent == null); + if (rooms.isEmpty) { + return Column( + mainAxisAlignment: MainAxisAlignment.center, + mainAxisSize: MainAxisSize.min, + children: [ + Icon( + Icons.maps_ugc_outlined, + size: 80, + color: Colors.grey, + ), + Center( + child: Text( + L10n.of(context).startYourFirstChat, + textAlign: TextAlign.start, + style: TextStyle( + color: Colors.grey, + fontSize: 16, + ), + ), + ), + ], + ); + } + final totalCount = rooms.length; + return ListView.builder( + itemCount: totalCount, + itemBuilder: (BuildContext context, int i) { + return ChatListItem( + rooms[i], + selected: controller.selectedRoomIds.contains(rooms[i].id), + onTap: controller.selectMode == SelectMode.select + ? () => controller.toggleSelection(rooms[i].id) + : null, + onLongPress: () => controller.toggleSelection(rooms[i].id), + activeChat: controller.activeChat == rooms[i].id, + ); + }, + ); + } else { + return Center( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Image.asset( + 'assets/private_chat_wallpaper.png', + width: 100, + ), + Text( + L10n.of(context).yourChatsAreBeingSynced, + textAlign: TextAlign.center, + ), + ], + ), + ); + } + }, + ); + }); +} + enum ChatListPopupMenuItemActions { createGroup, createSpace,