Initial commit
Some checks failed
Main Deploy Workflow / deploy_web (push) Has been cancelled
Main Deploy Workflow / deploy_playstore_internal (push) Has been cancelled
Close stale issues and PRs / stale (push) Has been cancelled

This commit is contained in:
2026-09-11 15:59:56 -03:00
commit 0037b0b9cf
651 changed files with 199705 additions and 0 deletions

View File

@@ -0,0 +1,166 @@
// SPDX-FileCopyrightText: 2019-Present Christian Kußowski
// SPDX-FileCopyrightText: 2019-Present Contributors to FluffyChat
//
// SPDX-License-Identifier: AGPL-3.0-or-later
import 'package:tatchat/config/setting_keys.dart';
import 'package:tatchat/l10n/l10n.dart';
import 'package:tatchat/widgets/adaptive_dialogs/show_ok_cancel_alert_dialog.dart';
import 'package:tatchat/widgets/adaptive_dialogs/show_text_input_dialog.dart';
import 'package:tatchat/widgets/app_lock.dart';
import 'package:tatchat/widgets/future_loading_dialog.dart';
import 'package:tatchat/widgets/matrix.dart';
import 'package:local_auth/local_auth.dart';
import 'package:material_ui/material_ui.dart';
import 'package:matrix/matrix.dart';
import 'settings_security_view.dart';
class SettingsSecurity extends StatefulWidget {
const SettingsSecurity({super.key});
@override
SettingsSecurityController createState() => SettingsSecurityController();
}
class SettingsSecurityController extends State<SettingsSecurity> {
Future<void> toggleBiometrics() async {
AppLock.of(context).showLockScreen();
final oldState = AppLock.of(context).useBiometrics;
final actionStr = oldState
? L10n.of(context).disableBiometrics
: L10n.of(context).enableBiometrics;
final consent = await showOkCancelAlertDialog(
context: context,
title: actionStr,
message: L10n.of(context).biometricsDescription,
okLabel: actionStr,
cancelLabel: L10n.of(context).cancel,
isDestructive: true,
);
if (consent != OkCancelResult.ok) return;
if (!mounted) return;
if (!oldState) {
final localAuth = LocalAuthentication();
final unlocked = await localAuth.authenticate(
localizedReason: actionStr,
biometricOnly: true,
);
if (!unlocked) return;
if (!mounted) return;
}
await AppLock.of(context).changeUseBiometrics(!oldState);
setState(() {});
}
Future<void> disableAppLockAction() async {
AppLock.of(context).showLockScreen();
final consent = await showOkCancelAlertDialog(
context: context,
title: L10n.of(context).disableAppLock,
message: L10n.of(context).disableAppLockAreYouSure,
okLabel: L10n.of(context).disableAppLock,
cancelLabel: L10n.of(context).cancel,
isDestructive: true,
);
if (consent != OkCancelResult.ok) return;
if (!mounted) return;
await AppLock.of(context).changePincode(null);
if (!mounted) return;
setState(() {});
}
Future<void> setAppLockAction() async {
await AppLock.of(context).changeUseBiometrics(false);
if (!mounted) return;
final l10n = L10n.of(context);
if (AppLock.of(context).isActive) {
AppLock.of(context).showLockScreen();
}
final newLock = await showTextInputDialog(
useRootNavigator: false,
context: context,
title: l10n.pleaseChooseAPasscode,
message: l10n.pleaseEnter6Digits,
cancelLabel: l10n.cancel,
validator: (text) {
if (text.length == 6 && int.tryParse(text)! >= 0) {
return null;
}
return l10n.pleaseEnter6Digits;
},
keyboardType: TextInputType.number,
obscureText: true,
maxLines: 1,
minLines: 1,
maxLength: 6,
);
if (newLock != null) {
if (!mounted) return;
await AppLock.of(context).changePincode(newLock);
setState(() {});
}
}
Future<void> deleteAccountAction() async {
final l10n = L10n.of(context);
final matrix = Matrix.of(context);
if (await showOkCancelAlertDialog(
useRootNavigator: false,
context: context,
title: l10n.warning,
message: l10n.deactivateAccountWarning,
okLabel: l10n.ok,
cancelLabel: l10n.cancel,
isDestructive: true,
) ==
OkCancelResult.cancel) {
return;
}
if (!mounted) return;
final supposedMxid = matrix.client.userID!;
final mxid = await showTextInputDialog(
useRootNavigator: false,
context: context,
title: l10n.confirmMatrixId,
validator: (text) =>
text == supposedMxid ? null : l10n.supposedMxid(supposedMxid),
isDestructive: true,
okLabel: l10n.delete,
cancelLabel: l10n.cancel,
);
if (mxid == null || mxid.isEmpty || mxid != supposedMxid) {
return;
}
if (!mounted) return;
final resp = await showFutureLoadingDialog(
context: context,
delay: false,
future: () => matrix.client.uiaRequestBackground<IdServerUnbindResult?>(
(auth) => matrix.client.deactivateAccount(auth: auth, erase: true),
),
);
if (!resp.isError) {
if (!mounted) return;
await showFutureLoadingDialog(
context: context,
future: () => matrix.client.logout(),
);
}
}
Future<void> dehydrateAction() => Matrix.of(context).dehydrateAction(context);
Future<void> changeShareKeysWith(ShareKeysWith? shareKeysWith) async {
if (shareKeysWith == null) return;
AppSettings.shareKeysWith.setItem(shareKeysWith.name);
Matrix.of(context).client.shareKeysWith = shareKeysWith;
setState(() {});
}
@override
Widget build(BuildContext context) => SettingsSecurityView(this);
}

View File

@@ -0,0 +1,253 @@
// SPDX-FileCopyrightText: 2019-Present Christian Kußowski
// SPDX-FileCopyrightText: 2019-Present Contributors to FluffyChat
//
// SPDX-License-Identifier: AGPL-3.0-or-later
import 'package:tatchat/config/app_config.dart';
import 'package:tatchat/config/setting_keys.dart';
import 'package:tatchat/config/themes.dart';
import 'package:tatchat/l10n/l10n.dart';
import 'package:tatchat/utils/beautify_string_extension.dart';
import 'package:tatchat/utils/platform_infos.dart';
import 'package:tatchat/widgets/app_lock.dart';
import 'package:tatchat/widgets/layouts/max_width_body.dart';
import 'package:tatchat/widgets/matrix.dart';
import 'package:tatchat/widgets/settings_switch_list_tile.dart';
import 'package:go_router/go_router.dart';
import 'package:local_auth/local_auth.dart';
import 'package:material_ui/material_ui.dart';
import 'package:matrix/matrix.dart';
import 'settings_security.dart';
class SettingsSecurityView extends StatelessWidget {
final SettingsSecurityController controller;
const SettingsSecurityView(this.controller, {super.key});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final client = Matrix.of(context).client;
final publicMasterKey =
client.userDeviceKeys[client.userID]?.masterKey?.publicKey;
return Scaffold(
appBar: AppBar(
title: Text(L10n.of(context).security),
automaticallyImplyLeading: !FluffyThemes.isColumnMode(context),
centerTitle: FluffyThemes.isColumnMode(context),
),
body: ListTileTheme(
iconColor: theme.colorScheme.onSurface,
child: MaxWidthBody(
child: FutureBuilder(
future: Matrix.of(
context,
).client.getCapabilities().timeout(const Duration(seconds: 10)),
builder: (context, snapshot) {
final capabilities = snapshot.data;
final error = snapshot.error;
if (error == null && capabilities == null) {
return const Center(
child: Padding(
padding: EdgeInsets.all(16.0),
child: CircularProgressIndicator.adaptive(strokeWidth: 2),
),
);
}
return Column(
children: [
ListTile(
title: Text(
L10n.of(context).privacy,
style: TextStyle(
color: theme.colorScheme.secondary,
fontWeight: FontWeight.bold,
),
),
),
SettingsSwitchListTile.adaptive(
title: L10n.of(context).sendTypingNotifications,
subtitle: L10n.of(
context,
).sendTypingNotificationsDescription,
setting: AppSettings.sendTypingNotifications,
),
SettingsSwitchListTile.adaptive(
title: L10n.of(context).sendReadReceipts,
subtitle: L10n.of(context).sendReadReceiptsDescription,
setting: AppSettings.sendPublicReadReceipts,
),
SettingsSwitchListTile.adaptive(
title: L10n.of(context).shareCrashReports,
subtitle: L10n.of(context).shareCrashReportsDescription,
setting: AppSettings.autoSendErrorReports,
defaultValue: false,
),
ListTile(
trailing: const Icon(Icons.chevron_right_outlined),
title: Text(L10n.of(context).blockedUsers),
subtitle: Text(
L10n.of(context).thereAreCountUsersBlocked(
Matrix.of(context).client.ignoredUsers.length,
),
),
onTap: () =>
context.go('/rooms/settings/security/ignorelist'),
),
if (PlatformInfos.supportsAppLock) ...[
Divider(color: theme.dividerColor),
ListTile(
title: Text(
L10n.of(context).appLock,
style: TextStyle(
color: theme.colorScheme.secondary,
fontWeight: FontWeight.bold,
),
),
subtitle: Text(L10n.of(context).appLockDescription),
),
SwitchListTile.adaptive(
value: AppLock.of(context).isActive,
title: Text(L10n.of(context).useAppLock),
onChanged: (active) => active
? controller.setAppLockAction()
: controller.disableAppLockAction(),
),
if (AppLock.of(context).isActive) ...[
FutureBuilder(
future: LocalAuthentication().canCheckBiometrics,
builder: (context, snapshot) {
if (snapshot.data != true) return SizedBox.shrink();
return SwitchListTile.adaptive(
value: AppLock.of(context).useBiometrics,
onChanged: (_) => controller.toggleBiometrics(),
title: Text(L10n.of(context).unlockWithBiometrics),
);
},
),
ListTile(
trailing: const Icon(Icons.lock_reset_outlined),
title: Text(L10n.of(context).resetPin),
onTap: controller.setAppLockAction,
),
],
],
Divider(color: theme.dividerColor),
ListTile(
title: Text(
L10n.of(context).shareKeysWith,
style: TextStyle(
color: theme.colorScheme.secondary,
fontWeight: FontWeight.bold,
),
),
subtitle: Text(L10n.of(context).shareKeysWithDescription),
),
ListTile(
title: Material(
borderRadius: BorderRadius.circular(
AppConfig.borderRadius / 2,
),
color: theme.colorScheme.onInverseSurface,
child: DropdownButton<ShareKeysWith>(
isExpanded: true,
padding: const EdgeInsets.symmetric(horizontal: 8.0),
borderRadius: BorderRadius.circular(
AppConfig.borderRadius / 2,
),
underline: const SizedBox.shrink(),
value: Matrix.of(context).client.shareKeysWith,
items: ShareKeysWith.values
.map(
(share) => DropdownMenuItem(
value: share,
child: Text(share.localized(L10n.of(context))),
),
)
.toList(),
onChanged: controller.changeShareKeysWith,
),
),
),
Divider(color: theme.dividerColor),
ListTile(
title: Text(
L10n.of(context).account,
style: TextStyle(
color: theme.colorScheme.secondary,
fontWeight: FontWeight.bold,
),
),
),
if (publicMasterKey != null)
ListTile(
title: Text(L10n.of(context).yourPublicKey),
leading: const Icon(Icons.verified_user_outlined),
subtitle: SelectableText(
publicMasterKey.beautified,
style: const TextStyle(fontFamily: 'RobotoMono'),
),
),
ListTile(
title: Text(L10n.of(context).deviceIdentityKey),
leading: const Icon(Icons.mobile_friendly_outlined),
subtitle: SelectableText(
Matrix.of(context).client.fingerprintKey.beautified,
style: const TextStyle(fontFamily: 'RobotoMono'),
),
),
if (capabilities?.mChangePassword?.enabled != false ||
error != null)
ListTile(
leading: const Icon(Icons.password_outlined),
trailing: const Icon(Icons.chevron_right_outlined),
title: Text(L10n.of(context).changePassword),
onTap: () =>
context.go('/rooms/settings/security/password'),
),
Divider(color: theme.dividerColor),
ListTile(
iconColor: Colors.orange,
leading: const Icon(Icons.delete_sweep_outlined),
title: Text(
L10n.of(context).dehydrate,
style: const TextStyle(color: Colors.orange),
),
onTap: controller.dehydrateAction,
),
ListTile(
iconColor: Colors.red,
leading: const Icon(Icons.delete_outlined),
title: Text(
L10n.of(context).deleteAccount,
style: const TextStyle(color: Colors.red),
),
onTap: controller.deleteAccountAction,
),
],
);
},
),
),
),
);
}
}
extension on ShareKeysWith {
String localized(L10n l10n) {
switch (this) {
case ShareKeysWith.all:
return l10n.allDevices;
case ShareKeysWith.crossVerifiedIfEnabled:
return l10n.crossVerifiedDevicesIfEnabled;
case ShareKeysWith.crossVerified:
return l10n.crossVerifiedDevices;
case ShareKeysWith.directlyVerifiedOnly:
return l10n.verifiedDevicesOnly;
}
}
}