You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
2.6 KiB
Dart
98 lines
2.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|
import 'package:matrix/matrix.dart';
|
|
|
|
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
|
import 'package:fluffychat/widgets/adaptive_dialogs/show_modal_action_popup.dart';
|
|
import 'package:fluffychat/widgets/future_loading_dialog.dart';
|
|
import '../../widgets/matrix.dart';
|
|
import 'settings_notifications_view.dart';
|
|
|
|
class SettingsNotifications extends StatefulWidget {
|
|
const SettingsNotifications({super.key});
|
|
|
|
@override
|
|
SettingsNotificationsController createState() =>
|
|
SettingsNotificationsController();
|
|
}
|
|
|
|
class SettingsNotificationsController extends State<SettingsNotifications> {
|
|
bool isLoading = false;
|
|
|
|
void onPusherTap(Pusher pusher) async {
|
|
final delete = await showModalActionPopup<bool>(
|
|
context: context,
|
|
title: pusher.deviceDisplayName,
|
|
message: '${pusher.appDisplayName} (${pusher.appId})',
|
|
cancelLabel: L10n.of(context).cancel,
|
|
actions: [
|
|
AdaptiveModalAction(
|
|
label: L10n.of(context).delete,
|
|
isDestructive: true,
|
|
value: true,
|
|
),
|
|
],
|
|
);
|
|
if (delete != true) return;
|
|
|
|
final success = await showFutureLoadingDialog(
|
|
context: context,
|
|
future: () => Matrix.of(context).client.deletePusher(
|
|
PusherId(
|
|
appId: pusher.appId,
|
|
pushkey: pusher.pushkey,
|
|
),
|
|
),
|
|
);
|
|
|
|
if (success.error != null) return;
|
|
|
|
setState(() {
|
|
pusherFuture = null;
|
|
});
|
|
}
|
|
|
|
Future<List<Pusher>?>? pusherFuture;
|
|
|
|
void togglePushRule(PushRuleKind kind, PushRule pushRule) async {
|
|
setState(() {
|
|
isLoading = true;
|
|
});
|
|
try {
|
|
final updateFromSync = Matrix.of(context)
|
|
.client
|
|
.onSync
|
|
.stream
|
|
.where(
|
|
(syncUpdate) =>
|
|
syncUpdate.accountData?.any(
|
|
(accountData) => accountData.type == 'm.push_rules',
|
|
) ??
|
|
false,
|
|
)
|
|
.first;
|
|
await Matrix.of(context).client.setPushRuleEnabled(
|
|
kind,
|
|
pushRule.ruleId,
|
|
!pushRule.enabled,
|
|
);
|
|
await updateFromSync;
|
|
} catch (e, s) {
|
|
Logs().w('Unable to toggle push rule', e, s);
|
|
if (!mounted) return;
|
|
ScaffoldMessenger.of(context)
|
|
.showSnackBar(SnackBar(content: Text(e.toLocalizedString(context))));
|
|
} finally {
|
|
if (mounted) {
|
|
setState(() {
|
|
isLoading = false;
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) => SettingsNotificationsView(this);
|
|
}
|