mirror of
				https://gitlab.com/famedly/fluffychat.git
				synced 2025-11-03 22:07:23 +01:00 
			
		
		
		
	feat: Implement deleting pushers in app
This commit is contained in:
		
							parent
							
								
									839711bb9b
								
							
						
					
					
						commit
						534c84db7d
					
				@ -1,5 +1,6 @@
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
 | 
			
		||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
 | 
			
		||||
import 'package:collection/collection.dart' show IterableExtension;
 | 
			
		||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
 | 
			
		||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
 | 
			
		||||
@ -94,6 +95,40 @@ class SettingsNotificationsController extends State<SettingsNotifications> {
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void onPusherTap(Pusher pusher) async {
 | 
			
		||||
    final delete = await showModalActionSheet<bool>(
 | 
			
		||||
      context: context,
 | 
			
		||||
      title: pusher.deviceDisplayName,
 | 
			
		||||
      message: '${pusher.appDisplayName} (${pusher.appId})',
 | 
			
		||||
      actions: [
 | 
			
		||||
        SheetAction(
 | 
			
		||||
          label: L10n.of(context)!.delete,
 | 
			
		||||
          isDestructiveAction: true,
 | 
			
		||||
          key: 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;
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) => SettingsNotificationsView(this);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -77,7 +77,8 @@ class SettingsNotificationsView extends StatelessWidget {
 | 
			
		||||
                    ),
 | 
			
		||||
                  ),
 | 
			
		||||
                  FutureBuilder<List<Pusher>?>(
 | 
			
		||||
                    future: Matrix.of(context).client.getPushers(),
 | 
			
		||||
                    future: controller.pusherFuture ??=
 | 
			
		||||
                        Matrix.of(context).client.getPushers(),
 | 
			
		||||
                    builder: (context, snapshot) {
 | 
			
		||||
                      if (snapshot.hasError) {
 | 
			
		||||
                        Center(
 | 
			
		||||
@ -100,6 +101,7 @@ class SettingsNotificationsView extends StatelessWidget {
 | 
			
		||||
                          title: Text(
 | 
			
		||||
                              '${pushers[i].appDisplayName} - ${pushers[i].appId}'),
 | 
			
		||||
                          subtitle: Text(pushers[i].data.url.toString()),
 | 
			
		||||
                          onTap: () => controller.onPusherTap(pushers[i]),
 | 
			
		||||
                        ),
 | 
			
		||||
                      );
 | 
			
		||||
                    },
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user