design: Move chat backup header to settings

This commit is contained in:
Christian Pauly 2022-08-28 13:34:57 +02:00
parent 8e04f4cc73
commit c40bdc3a6d
4 changed files with 65 additions and 86 deletions

View File

@ -211,19 +211,6 @@ class ChatListController extends State<ChatList>
}
final selectedRoomIds = <String>{};
bool? crossSigningCached;
bool showChatBackupBanner = false;
void firstRunBootstrapAction() async {
setState(() {
showChatBackupBanner = false;
});
await BootstrapDialog(
client: Matrix.of(context).client,
).show(context);
VRouter.of(context).to('/rooms');
}
String? get activeChat => VRouter.of(context).pathParameters['roomid'];
@ -314,24 +301,6 @@ class ChatListController extends State<ChatList>
super.initState();
}
void checkBootstrap() async {
if (!Matrix.of(context).client.encryptionEnabled) return;
await Matrix.of(context).client.accountDataLoading;
await Matrix.of(context).client.userDeviceKeysLoading;
final crossSigning =
await Matrix.of(context).client.encryption?.crossSigning.isCached() ??
false;
final needsBootstrap =
Matrix.of(context).client.encryption?.crossSigning.enabled == false ||
crossSigning == false;
final isUnknownSession = Matrix.of(context).client.isUnknownSession;
if (needsBootstrap || isUnknownSession) {
setState(() {
showChatBackupBanner = true;
});
}
}
@override
void dispose() {
_intentDataStreamSubscription?.cancel();
@ -538,7 +507,17 @@ class ChatListController extends State<ChatList>
await client.accountDataLoading;
if (client.prevBatch == null) {
await client.onSync.stream.first;
// Display first login bootstrap if enabled
if (client.encryption?.keyManager.enabled == true) {
if (await client.encryption?.keyManager.isCached() == false ||
await client.encryption?.crossSigning.isCached() == false ||
client.isUnknownSession) {
await BootstrapDialog(client: client).show(context);
}
}
}
// Load space members to display DM rooms
final spaceId = activeSpaceId;
if (spaceId != null) {
@ -553,7 +532,6 @@ class ChatListController extends State<ChatList>
setState(() {
waitForFirstSync = true;
});
WidgetsBinding.instance.addPostFrameCallback((_) => checkBootstrap());
return;
}

View File

@ -146,44 +146,6 @@ class _ChatListViewBodyState extends State<ChatListViewBody> {
StoriesHeader(
filter: widget.controller.searchController.text,
),
AnimatedContainer(
height: !widget.controller.isSearchMode &&
widget.controller.showChatBackupBanner
? 54
: 0,
duration: const Duration(milliseconds: 300),
clipBehavior: Clip.hardEdge,
curve: Curves.bounceInOut,
decoration: const BoxDecoration(),
child: Material(
color: Theme.of(context).colorScheme.surface,
child: ListTile(
leading: CircleAvatar(
radius: Avatar.defaultSize / 2,
backgroundColor:
Theme.of(context).colorScheme.surfaceVariant,
foregroundColor:
Theme.of(context).colorScheme.onSurfaceVariant,
child: const Icon(Icons.enhanced_encryption_outlined),
),
title: Text(
(Matrix.of(context)
.client
.encryption
?.keyManager
.enabled ==
true)
? L10n.of(context)!.unlockOldMessages
: L10n.of(context)!.enableAutoBackups,
style: TextStyle(
color: Theme.of(context).colorScheme.onSurface,
),
),
trailing: const Icon(Icons.chevron_right_outlined),
onTap: widget.controller.firstRunBootstrapAction,
),
),
),
AnimatedContainer(
height: widget.controller.isTorBrowser ? 64 : 0,
duration: const Duration(milliseconds: 300),

View File

@ -11,6 +11,7 @@ import 'package:matrix/matrix.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import '../../widgets/matrix.dart';
import '../bootstrap/bootstrap_dialog.dart';
import 'settings_view.dart';
class Settings extends StatefulWidget {
@ -21,10 +22,6 @@ class Settings extends StatefulWidget {
}
class SettingsController extends State<Settings> {
Future<bool>? crossSigningCachedFuture;
bool? crossSigningCached;
Future<bool>? megolmBackupCachedFuture;
bool? megolmBackupCached;
Future<dynamic>? profileFuture;
Profile? profile;
bool profileUpdated = false;
@ -106,6 +103,43 @@ class SettingsController extends State<Settings> {
}
}
@override
void initState() {
WidgetsBinding.instance.addPostFrameCallback((_) => checkBootstrap());
super.initState();
}
void checkBootstrap() async {
final client = Matrix.of(context).client;
if (!client.encryptionEnabled) return;
await client.accountDataLoading;
await client.userDeviceKeysLoading;
if (client.prevBatch == null) {
await client.onSync.stream.first;
}
final crossSigning =
await client.encryption?.crossSigning.isCached() ?? false;
final needsBootstrap =
await client.encryption?.keyManager.isCached() == false ||
client.encryption?.crossSigning.enabled == false ||
crossSigning == false;
final isUnknownSession = client.isUnknownSession;
setState(() {
showChatBackupBanner = needsBootstrap || isUnknownSession;
});
}
bool? crossSigningCached;
bool showChatBackupBanner = false;
void firstRunBootstrapAction() async {
await BootstrapDialog(
client: Matrix.of(context).client,
).show(context);
checkBootstrap();
}
@override
Widget build(BuildContext context) {
final client = Matrix.of(context).client;
@ -119,18 +153,6 @@ class SettingsController extends State<Settings> {
if (mounted) setState(() => profile = p);
return p;
});
if (client.encryption != null) {
crossSigningCachedFuture ??=
client.encryption?.crossSigning.isCached().then((c) {
if (mounted) setState(() => crossSigningCached = c);
return c;
});
megolmBackupCachedFuture ??=
client.encryption?.keyManager.isCached().then((c) {
if (mounted) setState(() => megolmBackupCached = c);
return c;
});
}
return SettingsView(this);
}
}

View File

@ -39,6 +39,23 @@ class SettingsView extends StatelessWidget {
iconColor: Theme.of(context).colorScheme.onBackground,
child: ListView(
children: <Widget>[
AnimatedContainer(
height: controller.showChatBackupBanner ? 54 : 0,
duration: const Duration(milliseconds: 300),
clipBehavior: Clip.hardEdge,
curve: Curves.bounceInOut,
decoration: const BoxDecoration(),
child: ListTile(
leading: const Icon(Icons.backup_outlined),
title: Text(L10n.of(context)!.enableAutoBackups),
trailing: const Icon(
Icons.warning_outlined,
color: Colors.orange,
),
onTap: controller.firstRunBootstrapAction,
),
),
const Divider(thickness: 1),
ListTile(
leading: const Icon(Icons.format_paint_outlined),
title: Text(L10n.of(context)!.changeTheme),