mirror of
				https://gitlab.com/famedly/fluffychat.git
				synced 2025-11-03 22:07:23 +01:00 
			
		
		
		
	refactor: MVC settings 3pid
This commit is contained in:
		
							parent
							
								
									b008d56fcc
								
							
						
					
					
						commit
						6bfe7b292a
					
				@ -19,7 +19,7 @@ import 'package:fluffychat/views/new_group.dart';
 | 
			
		||||
import 'package:fluffychat/views/new_private_chat.dart';
 | 
			
		||||
import 'package:fluffychat/views/search.dart';
 | 
			
		||||
import 'package:fluffychat/views/ui/settings_ui.dart';
 | 
			
		||||
import 'package:fluffychat/views/ui/settings_3pid_ui.dart';
 | 
			
		||||
import 'package:fluffychat/views/settings_3pid.dart';
 | 
			
		||||
import 'package:fluffychat/views/device_settings.dart';
 | 
			
		||||
import 'package:fluffychat/views/ui/settings_emotes_ui.dart';
 | 
			
		||||
import 'package:fluffychat/views/ui/settings_ignore_list_ui.dart';
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										90
									
								
								lib/views/settings_3pid.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										90
									
								
								lib/views/settings_3pid.dart
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,90 @@
 | 
			
		||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
 | 
			
		||||
import 'package:famedlysdk/famedlysdk.dart';
 | 
			
		||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
 | 
			
		||||
import 'package:fluffychat/views/widgets/matrix.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
 | 
			
		||||
 | 
			
		||||
import 'ui/settings_3pid_ui.dart';
 | 
			
		||||
 | 
			
		||||
class Settings3Pid extends StatefulWidget {
 | 
			
		||||
  static int sendAttempt = 0;
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Settings3PidController createState() => Settings3PidController();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class Settings3PidController extends State<Settings3Pid> {
 | 
			
		||||
  void add3PidAction() async {
 | 
			
		||||
    final input = await showTextInputDialog(
 | 
			
		||||
      context: context,
 | 
			
		||||
      title: L10n.of(context).enterAnEmailAddress,
 | 
			
		||||
      okLabel: L10n.of(context).ok,
 | 
			
		||||
      cancelLabel: L10n.of(context).cancel,
 | 
			
		||||
      useRootNavigator: false,
 | 
			
		||||
      textFields: [
 | 
			
		||||
        DialogTextField(
 | 
			
		||||
          hintText: L10n.of(context).enterAnEmailAddress,
 | 
			
		||||
          keyboardType: TextInputType.emailAddress,
 | 
			
		||||
        ),
 | 
			
		||||
      ],
 | 
			
		||||
    );
 | 
			
		||||
    if (input == null) return;
 | 
			
		||||
    final clientSecret = DateTime.now().millisecondsSinceEpoch.toString();
 | 
			
		||||
    final response = await showFutureLoadingDialog(
 | 
			
		||||
      context: context,
 | 
			
		||||
      future: () => Matrix.of(context).client.requestEmailToken(
 | 
			
		||||
            input.single,
 | 
			
		||||
            clientSecret,
 | 
			
		||||
            Settings3Pid.sendAttempt++,
 | 
			
		||||
          ),
 | 
			
		||||
    );
 | 
			
		||||
    if (response.error != null) return;
 | 
			
		||||
    final ok = await showOkAlertDialog(
 | 
			
		||||
      context: context,
 | 
			
		||||
      title: L10n.of(context).weSentYouAnEmail,
 | 
			
		||||
      message: L10n.of(context).pleaseClickOnLink,
 | 
			
		||||
      okLabel: L10n.of(context).iHaveClickedOnLink,
 | 
			
		||||
      useRootNavigator: false,
 | 
			
		||||
    );
 | 
			
		||||
    if (ok == null) return;
 | 
			
		||||
    final success = await showFutureLoadingDialog(
 | 
			
		||||
      context: context,
 | 
			
		||||
      future: () => Matrix.of(context).client.uiaRequestBackground(
 | 
			
		||||
            (auth) => Matrix.of(context).client.addThirdPartyIdentifier(
 | 
			
		||||
                  clientSecret,
 | 
			
		||||
                  response.result.sid,
 | 
			
		||||
                  auth: auth,
 | 
			
		||||
                ),
 | 
			
		||||
          ),
 | 
			
		||||
    );
 | 
			
		||||
    if (success.error != null) return;
 | 
			
		||||
    setState(() => request = null);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Future<List<ThirdPartyIdentifier>> request;
 | 
			
		||||
 | 
			
		||||
  void delete3Pid(ThirdPartyIdentifier identifier) async {
 | 
			
		||||
    if (await showOkCancelAlertDialog(
 | 
			
		||||
          context: context,
 | 
			
		||||
          title: L10n.of(context).areYouSure,
 | 
			
		||||
          okLabel: L10n.of(context).yes,
 | 
			
		||||
          cancelLabel: L10n.of(context).cancel,
 | 
			
		||||
          useRootNavigator: false,
 | 
			
		||||
        ) !=
 | 
			
		||||
        OkCancelResult.ok) {
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    final success = await showFutureLoadingDialog(
 | 
			
		||||
        context: context,
 | 
			
		||||
        future: () => Matrix.of(context).client.deleteThirdPartyIdentifier(
 | 
			
		||||
              identifier.address,
 | 
			
		||||
              identifier.medium,
 | 
			
		||||
            ));
 | 
			
		||||
    if (success.error != null) return;
 | 
			
		||||
    setState(() => request = null);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) => Settings3PidUI(this);
 | 
			
		||||
}
 | 
			
		||||
@ -1,93 +1,19 @@
 | 
			
		||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
 | 
			
		||||
import 'package:famedlysdk/famedlysdk.dart';
 | 
			
		||||
import 'package:fluffychat/views/settings_3pid.dart';
 | 
			
		||||
import 'package:fluffychat/views/widgets/max_width_body.dart';
 | 
			
		||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
 | 
			
		||||
import 'package:fluffychat/views/widgets/matrix.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
 | 
			
		||||
 | 
			
		||||
class Settings3Pid extends StatefulWidget {
 | 
			
		||||
  static int sendAttempt = 0;
 | 
			
		||||
class Settings3PidUI extends StatelessWidget {
 | 
			
		||||
  final Settings3PidController controller;
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  _Settings3PidState createState() => _Settings3PidState();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class _Settings3PidState extends State<Settings3Pid> {
 | 
			
		||||
  void _add3PidAction(BuildContext context) async {
 | 
			
		||||
    final input = await showTextInputDialog(
 | 
			
		||||
      context: context,
 | 
			
		||||
      title: L10n.of(context).enterAnEmailAddress,
 | 
			
		||||
      okLabel: L10n.of(context).ok,
 | 
			
		||||
      cancelLabel: L10n.of(context).cancel,
 | 
			
		||||
      useRootNavigator: false,
 | 
			
		||||
      textFields: [
 | 
			
		||||
        DialogTextField(
 | 
			
		||||
          hintText: L10n.of(context).enterAnEmailAddress,
 | 
			
		||||
          keyboardType: TextInputType.emailAddress,
 | 
			
		||||
        ),
 | 
			
		||||
      ],
 | 
			
		||||
    );
 | 
			
		||||
    if (input == null) return;
 | 
			
		||||
    final clientSecret = DateTime.now().millisecondsSinceEpoch.toString();
 | 
			
		||||
    final response = await showFutureLoadingDialog(
 | 
			
		||||
      context: context,
 | 
			
		||||
      future: () => Matrix.of(context).client.requestEmailToken(
 | 
			
		||||
            input.single,
 | 
			
		||||
            clientSecret,
 | 
			
		||||
            Settings3Pid.sendAttempt++,
 | 
			
		||||
          ),
 | 
			
		||||
    );
 | 
			
		||||
    if (response.error != null) return;
 | 
			
		||||
    final ok = await showOkAlertDialog(
 | 
			
		||||
      context: context,
 | 
			
		||||
      title: L10n.of(context).weSentYouAnEmail,
 | 
			
		||||
      message: L10n.of(context).pleaseClickOnLink,
 | 
			
		||||
      okLabel: L10n.of(context).iHaveClickedOnLink,
 | 
			
		||||
      useRootNavigator: false,
 | 
			
		||||
    );
 | 
			
		||||
    if (ok == null) return;
 | 
			
		||||
    final success = await showFutureLoadingDialog(
 | 
			
		||||
      context: context,
 | 
			
		||||
      future: () => Matrix.of(context).client.uiaRequestBackground(
 | 
			
		||||
            (auth) => Matrix.of(context).client.addThirdPartyIdentifier(
 | 
			
		||||
                  clientSecret,
 | 
			
		||||
                  response.result.sid,
 | 
			
		||||
                  auth: auth,
 | 
			
		||||
                ),
 | 
			
		||||
          ),
 | 
			
		||||
    );
 | 
			
		||||
    if (success.error != null) return;
 | 
			
		||||
    setState(() => _request = null);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Future<List<ThirdPartyIdentifier>> _request;
 | 
			
		||||
 | 
			
		||||
  void _delete3Pid(
 | 
			
		||||
      BuildContext context, ThirdPartyIdentifier identifier) async {
 | 
			
		||||
    if (await showOkCancelAlertDialog(
 | 
			
		||||
          context: context,
 | 
			
		||||
          title: L10n.of(context).areYouSure,
 | 
			
		||||
          okLabel: L10n.of(context).yes,
 | 
			
		||||
          cancelLabel: L10n.of(context).cancel,
 | 
			
		||||
          useRootNavigator: false,
 | 
			
		||||
        ) !=
 | 
			
		||||
        OkCancelResult.ok) {
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    final success = await showFutureLoadingDialog(
 | 
			
		||||
        context: context,
 | 
			
		||||
        future: () => Matrix.of(context).client.deleteThirdPartyIdentifier(
 | 
			
		||||
              identifier.address,
 | 
			
		||||
              identifier.medium,
 | 
			
		||||
            ));
 | 
			
		||||
    if (success.error != null) return;
 | 
			
		||||
    setState(() => _request = null);
 | 
			
		||||
  }
 | 
			
		||||
  const Settings3PidUI(this.controller, {Key key}) : super(key: key);
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    _request ??= Matrix.of(context).client.requestThirdPartyIdentifiers();
 | 
			
		||||
    controller.request ??=
 | 
			
		||||
        Matrix.of(context).client.requestThirdPartyIdentifiers();
 | 
			
		||||
    return Scaffold(
 | 
			
		||||
      appBar: AppBar(
 | 
			
		||||
        leading: BackButton(),
 | 
			
		||||
@ -95,14 +21,14 @@ class _Settings3PidState extends State<Settings3Pid> {
 | 
			
		||||
        actions: [
 | 
			
		||||
          IconButton(
 | 
			
		||||
            icon: Icon(Icons.add_outlined),
 | 
			
		||||
            onPressed: () => _add3PidAction(context),
 | 
			
		||||
            onPressed: controller.add3PidAction,
 | 
			
		||||
            tooltip: L10n.of(context).addEmail,
 | 
			
		||||
          )
 | 
			
		||||
        ],
 | 
			
		||||
      ),
 | 
			
		||||
      body: MaxWidthBody(
 | 
			
		||||
        child: FutureBuilder<List<ThirdPartyIdentifier>>(
 | 
			
		||||
          future: _request,
 | 
			
		||||
          future: controller.request,
 | 
			
		||||
          builder: (BuildContext context,
 | 
			
		||||
              AsyncSnapshot<List<ThirdPartyIdentifier>> snapshot) {
 | 
			
		||||
            if (snapshot.hasError) {
 | 
			
		||||
@ -152,7 +78,7 @@ class _Settings3PidState extends State<Settings3Pid> {
 | 
			
		||||
                        tooltip: L10n.of(context).delete,
 | 
			
		||||
                        icon: Icon(Icons.delete_forever_outlined),
 | 
			
		||||
                        color: Colors.red,
 | 
			
		||||
                        onPressed: () => _delete3Pid(context, identifier[i]),
 | 
			
		||||
                        onPressed: () => controller.delete3Pid(identifier[i]),
 | 
			
		||||
                      ),
 | 
			
		||||
                    ),
 | 
			
		||||
                  ),
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user