Skip to content

Commit

Permalink
Merge pull request #1409 from krille-chan/krille/unverified-banner
Browse files Browse the repository at this point in the history
feat: Display warning banner on unverified devices
  • Loading branch information
krille-chan authored Oct 12, 2024
2 parents f49a653 + d8acd92 commit 38283d2
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 2 deletions.
4 changes: 3 additions & 1 deletion assets/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2786,5 +2786,7 @@
"placeholders": {
"seconds": {}
}
}
},
"oneOfYourDevicesIsNotVerified": "One of your devices is not verified",
"noticeChatBackupDeviceVerification": "Note: When you connect all your devices to the chat backup, they are automatically verified."
}
3 changes: 3 additions & 0 deletions lib/config/themes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ abstract class FluffyThemes {
borderRadius: BorderRadius.circular(AppConfig.borderRadius / 2),
),
),
snackBarTheme: const SnackBarThemeData(
behavior: SnackBarBehavior.floating,
),
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
backgroundColor: colorScheme.secondaryContainer,
Expand Down
28 changes: 28 additions & 0 deletions lib/pages/chat_list/chat_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,7 @@ class ChatListController extends State<ChatList>
bool waitForFirstSync = false;

Future<void> _waitForFirstSync() async {
final router = GoRouter.of(context);
final client = Matrix.of(context).client;
await client.roomsLoading;
await client.accountDataLoading;
Expand All @@ -840,6 +841,33 @@ class ChatListController extends State<ChatList>
setState(() {
waitForFirstSync = true;
});

if (client.userDeviceKeys[client.userID!]?.deviceKeys.values
.any((device) => !device.verified && !device.blocked) ??
false) {
late final ScaffoldFeatureController controller;
final theme = Theme.of(context);
controller = ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
duration: const Duration(seconds: 15),
backgroundColor: theme.colorScheme.errorContainer,
content: Text(
L10n.of(context).oneOfYourDevicesIsNotVerified,
style: TextStyle(
color: theme.colorScheme.onErrorContainer,
),
),
action: SnackBarAction(
onPressed: () {
controller.close();
router.go('/rooms/settings/devices');
},
textColor: theme.colorScheme.onErrorContainer,
label: L10n.of(context).settings,
),
),
);
}
}

void cancelAction() {
Expand Down
22 changes: 22 additions & 0 deletions lib/pages/device_settings/device_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,28 @@ class DevicesSettingsController extends State<DevicesSettings> {
bool loadingDeletingDevices = false;
String? errorDeletingDevices;

bool? chatBackupEnabled;

@override
void initState() {
_checkChatBackup();
super.initState();
}

void _checkChatBackup() async {
final client = Matrix.of(context).client;
if (client.encryption?.keyManager.enabled == true) {
if (await client.encryption?.keyManager.isCached() == false ||
await client.encryption?.crossSigning.isCached() == false ||
client.isUnknownSession && !mounted) {
setState(() {
chatBackupEnabled = false;
});
return;
}
}
}

void removeDevicesAction(List<Device> devices) async {
if (await showOkCancelAlertDialog(
context: context,
Expand Down
13 changes: 13 additions & 0 deletions lib/pages/device_settings/device_settings_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ class DevicesSettingsView extends StatelessWidget {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
if (controller.chatBackupEnabled == false)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: ListTile(
leading: const CircleAvatar(
child: Icon(Icons.info_outlined),
),
subtitle: Text(
L10n.of(context)
.noticeChatBackupDeviceVerification,
),
),
),
if (controller.thisDevice != null) ...[
Container(
padding: const EdgeInsets.symmetric(
Expand Down
5 changes: 4 additions & 1 deletion lib/widgets/fluffy_chat_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ class FluffyChatApp extends StatelessWidget {

// Router must be outside of build method so that hot reload does not reset
// the current path.
static final GoRouter router = GoRouter(routes: AppRoutes.routes);
static final GoRouter router = GoRouter(
routes: AppRoutes.routes,
debugLogDiagnostics: true,
);

@override
Widget build(BuildContext context) {
Expand Down

0 comments on commit 38283d2

Please sign in to comment.