mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-11-28 07:19:32 +01:00
Merge branch 'krille/make-verification-in-dialogs' into 'main'
refactor: Make verification in dialogs See merge request ChristianPauly/fluffychat-flutter!295
This commit is contained in:
commit
01a05b3a9d
@ -1,40 +1,28 @@
|
||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:famedlysdk/encryption.dart';
|
||||
import 'package:famedlysdk/matrix_api.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import '../avatar.dart';
|
||||
import 'simple_dialogs.dart';
|
||||
import '../../utils/string_color.dart';
|
||||
|
||||
import '../components/adaptive_page_layout.dart';
|
||||
import '../components/avatar.dart';
|
||||
import '../components/dialogs/simple_dialogs.dart';
|
||||
import '../utils/string_color.dart';
|
||||
import 'chat_list.dart';
|
||||
class KeyVerificationDialog extends StatefulWidget {
|
||||
Future<void> show(BuildContext context) => PlatformInfos.isCupertinoStyle
|
||||
? showCupertinoDialog(context: context, builder: (context) => this)
|
||||
: showDialog(context: context, builder: (context) => this);
|
||||
|
||||
class KeyVerificationView extends StatelessWidget {
|
||||
final KeyVerification request;
|
||||
|
||||
KeyVerificationView({this.request});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AdaptivePageLayout(
|
||||
primaryPage: FocusPage.SECOND,
|
||||
firstScaffold: ChatList(),
|
||||
secondScaffold: KeyVerificationPage(request: request),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class KeyVerificationPage extends StatefulWidget {
|
||||
final KeyVerification request;
|
||||
|
||||
KeyVerificationPage({this.request});
|
||||
KeyVerificationDialog({this.request});
|
||||
|
||||
@override
|
||||
_KeyVerificationPageState createState() => _KeyVerificationPageState();
|
||||
}
|
||||
|
||||
class _KeyVerificationPageState extends State<KeyVerificationPage> {
|
||||
class _KeyVerificationPageState extends State<KeyVerificationDialog> {
|
||||
void Function() originalOnUpdate;
|
||||
|
||||
@override
|
||||
@ -133,20 +121,14 @@ class _KeyVerificationPageState extends State<KeyVerificationPage> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
),
|
||||
);
|
||||
buttons.add(RaisedButton(
|
||||
color: Theme.of(context).primaryColor,
|
||||
elevation: 5,
|
||||
textColor: Colors.white,
|
||||
buttons.add(_AdaptiveFlatButton(
|
||||
child: Text(L10n.of(context).submit),
|
||||
onPressed: () {
|
||||
input = textEditingController.text;
|
||||
checkInput();
|
||||
},
|
||||
));
|
||||
buttons.add(RaisedButton(
|
||||
textColor: Theme.of(context).primaryColor,
|
||||
elevation: 5,
|
||||
color: Colors.white,
|
||||
buttons.add(_AdaptiveFlatButton(
|
||||
child: Text(L10n.of(context).skip),
|
||||
onPressed: () => widget.request.openSSSS(skip: true),
|
||||
));
|
||||
@ -158,17 +140,11 @@ class _KeyVerificationPageState extends State<KeyVerificationPage> {
|
||||
style: TextStyle(fontSize: 20)),
|
||||
margin: EdgeInsets.only(left: 8.0, right: 8.0),
|
||||
);
|
||||
buttons.add(RaisedButton(
|
||||
color: Theme.of(context).primaryColor,
|
||||
elevation: 5,
|
||||
textColor: Colors.white,
|
||||
buttons.add(_AdaptiveFlatButton(
|
||||
child: Text(L10n.of(context).accept),
|
||||
onPressed: () => widget.request.acceptVerification(),
|
||||
));
|
||||
buttons.add(RaisedButton(
|
||||
textColor: Theme.of(context).primaryColor,
|
||||
elevation: 5,
|
||||
color: Colors.white,
|
||||
buttons.add(_AdaptiveFlatButton(
|
||||
child: Text(L10n.of(context).reject),
|
||||
onPressed: () {
|
||||
widget.request.rejectVerification().then((_) {
|
||||
@ -180,7 +156,9 @@ class _KeyVerificationPageState extends State<KeyVerificationPage> {
|
||||
case KeyVerificationState.waitingAccept:
|
||||
body = Column(
|
||||
children: <Widget>[
|
||||
CircularProgressIndicator(),
|
||||
PlatformInfos.isCupertinoStyle
|
||||
? CupertinoActivityIndicator()
|
||||
: CircularProgressIndicator(),
|
||||
SizedBox(height: 10),
|
||||
Text(
|
||||
L10n.of(context).waitingPartnerAcceptRequest,
|
||||
@ -214,7 +192,7 @@ class _KeyVerificationPageState extends State<KeyVerificationPage> {
|
||||
Center(
|
||||
child: Text(
|
||||
compareText,
|
||||
style: TextStyle(fontSize: 20),
|
||||
style: TextStyle(fontSize: 16),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
@ -226,23 +204,12 @@ class _KeyVerificationPageState extends State<KeyVerificationPage> {
|
||||
],
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
);
|
||||
buttons.add(RaisedButton(
|
||||
color: Theme.of(context).primaryColor,
|
||||
elevation: 7,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
textColor: Colors.white,
|
||||
buttons.add(_AdaptiveFlatButton(
|
||||
child: Text(L10n.of(context).theyMatch),
|
||||
onPressed: () => widget.request.acceptSas(),
|
||||
));
|
||||
buttons.add(RaisedButton(
|
||||
textColor: Theme.of(context).primaryColor,
|
||||
elevation: 7,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
color: Colors.white,
|
||||
buttons.add(_AdaptiveFlatButton(
|
||||
textColor: Colors.red,
|
||||
child: Text(L10n.of(context).theyDontMatch),
|
||||
onPressed: () => widget.request.rejectSas(),
|
||||
));
|
||||
@ -253,7 +220,9 @@ class _KeyVerificationPageState extends State<KeyVerificationPage> {
|
||||
: L10n.of(context).waitingPartnerNumbers;
|
||||
body = Column(
|
||||
children: <Widget>[
|
||||
CircularProgressIndicator(),
|
||||
PlatformInfos.isCupertinoStyle
|
||||
? CupertinoActivityIndicator()
|
||||
: CircularProgressIndicator(),
|
||||
SizedBox(height: 10),
|
||||
Text(
|
||||
acceptText,
|
||||
@ -275,13 +244,7 @@ class _KeyVerificationPageState extends State<KeyVerificationPage> {
|
||||
],
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
);
|
||||
buttons.add(RaisedButton(
|
||||
color: Theme.of(context).primaryColor,
|
||||
elevation: 7,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
textColor: Colors.white,
|
||||
buttons.add(_AdaptiveFlatButton(
|
||||
child: Text(L10n.of(context).close),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
));
|
||||
@ -298,13 +261,7 @@ class _KeyVerificationPageState extends State<KeyVerificationPage> {
|
||||
],
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
);
|
||||
buttons.add(RaisedButton(
|
||||
color: Theme.of(context).primaryColor,
|
||||
elevation: 7,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
textColor: Colors.white,
|
||||
buttons.add(FlatButton(
|
||||
child: Text(L10n.of(context).close),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
));
|
||||
@ -328,52 +285,59 @@ class _KeyVerificationPageState extends State<KeyVerificationPage> {
|
||||
style: TextStyle(color: Theme.of(context).textTheme.caption.color)),
|
||||
);
|
||||
}
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: ListTile(
|
||||
leading: Avatar(profile?.avatarUrl, otherName),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
subtitle: Text(L10n.of(context).verifyTitle, maxLines: 1),
|
||||
title: Row(
|
||||
children: <Widget>[
|
||||
Text(
|
||||
otherName,
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
color: otherName.color,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
if (otherName != widget.request.userId)
|
||||
Text(
|
||||
' - ' + widget.request.userId,
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
fontStyle: FontStyle.italic,
|
||||
),
|
||||
),
|
||||
],
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
final userNameTitle = Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
otherName,
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
color: otherName.color,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
elevation: 0,
|
||||
),
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: body,
|
||||
),
|
||||
),
|
||||
if (otherName != widget.request.userId)
|
||||
Text(
|
||||
' - ' + widget.request.userId,
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
fontStyle: FontStyle.italic,
|
||||
),
|
||||
if (bottom != null) bottom,
|
||||
],
|
||||
),
|
||||
),
|
||||
persistentFooterButtons: buttons.isEmpty ? null : buttons,
|
||||
),
|
||||
],
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
);
|
||||
final title = PlatformInfos.isCupertinoStyle
|
||||
? Text(L10n.of(context).verifyTitle)
|
||||
: ListTile(
|
||||
leading: Avatar(profile?.avatarUrl, otherName),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
subtitle: Text(L10n.of(context).verifyTitle, maxLines: 1),
|
||||
title: userNameTitle,
|
||||
);
|
||||
final content = Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (PlatformInfos.isCupertinoStyle) ...{
|
||||
SizedBox(height: 8),
|
||||
Center(child: userNameTitle),
|
||||
SizedBox(height: 12),
|
||||
},
|
||||
body,
|
||||
if (bottom != null) bottom,
|
||||
],
|
||||
);
|
||||
if (PlatformInfos.isCupertinoStyle) {
|
||||
return CupertinoAlertDialog(
|
||||
title: title,
|
||||
content: content,
|
||||
actions: buttons,
|
||||
);
|
||||
}
|
||||
return AlertDialog(
|
||||
title: title,
|
||||
content: content,
|
||||
actions: buttons,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -395,3 +359,32 @@ class _Emoji extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _AdaptiveFlatButton extends StatelessWidget {
|
||||
final Widget child;
|
||||
final Color textColor;
|
||||
final Function onPressed;
|
||||
|
||||
const _AdaptiveFlatButton({
|
||||
Key key,
|
||||
this.child,
|
||||
this.textColor,
|
||||
this.onPressed,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (PlatformInfos.isCupertinoStyle) {
|
||||
return CupertinoDialogAction(
|
||||
child: child,
|
||||
onPressed: onPressed,
|
||||
textStyle: textColor != null ? TextStyle(color: textColor) : null,
|
||||
);
|
||||
}
|
||||
return FlatButton(
|
||||
child: child,
|
||||
textColor: textColor,
|
||||
onPressed: onPressed,
|
||||
);
|
||||
}
|
||||
}
|
@ -20,10 +20,9 @@ import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:dbus/dbus.dart';
|
||||
import 'package:desktop_notifications/desktop_notifications.dart';*/
|
||||
|
||||
import '../utils/app_route.dart';
|
||||
import '../utils/beautify_string_extension.dart';
|
||||
import '../utils/famedlysdk_store.dart';
|
||||
import '../views/key_verification.dart';
|
||||
import 'dialogs/key_verification_dialog.dart';
|
||||
import '../utils/platform_infos.dart';
|
||||
import '../config/app_config.dart';
|
||||
import '../config/setting_keys.dart';
|
||||
@ -324,12 +323,7 @@ class MatrixState extends State<Matrix> {
|
||||
request.onUpdate = null;
|
||||
hidPopup = true;
|
||||
await request.acceptVerification();
|
||||
await Navigator.of(context).push(
|
||||
AppRoute.defaultRoute(
|
||||
context,
|
||||
KeyVerificationView(request: request),
|
||||
),
|
||||
);
|
||||
await KeyVerificationDialog(request: request).show(context);
|
||||
} else {
|
||||
request.onUpdate = null;
|
||||
hidPopup = true;
|
||||
|
@ -3,10 +3,9 @@ import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/components/audio_player.dart';
|
||||
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
|
||||
import 'package:fluffychat/components/image_bubble.dart';
|
||||
import 'package:fluffychat/utils/app_route.dart';
|
||||
import 'package:fluffychat/utils/event_extension.dart';
|
||||
import 'package:fluffychat/utils/matrix_locals.dart';
|
||||
import 'package:fluffychat/views/key_verification.dart';
|
||||
import 'package:fluffychat/components/dialogs/key_verification_dialog.dart';
|
||||
import 'package:flushbar/flushbar_helper.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
@ -53,12 +52,7 @@ class MessageContent extends StatelessWidget {
|
||||
timeline.cancelSubscriptions();
|
||||
}
|
||||
};
|
||||
await Navigator.of(context).push(
|
||||
AppRoute.defaultRoute(
|
||||
context,
|
||||
KeyVerificationView(request: req),
|
||||
),
|
||||
);
|
||||
await KeyVerificationDialog(request: req).show(context);
|
||||
} else {
|
||||
final success = await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
||||
event.requestKey(),
|
||||
|
@ -13,7 +13,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import '../utils/presence_extension.dart';
|
||||
import 'dialogs/simple_dialogs.dart';
|
||||
import 'matrix.dart';
|
||||
import '../views/key_verification.dart';
|
||||
import 'dialogs/key_verification_dialog.dart';
|
||||
import '../utils/app_route.dart';
|
||||
|
||||
class UserBottomSheet extends StatelessWidget {
|
||||
@ -88,12 +88,7 @@ class UserBottomSheet extends StatelessWidget {
|
||||
void _verifyAction(BuildContext context) async {
|
||||
final client = Matrix.of(context).client;
|
||||
final req = await client.userDeviceKeys[user.id].startVerification();
|
||||
await Navigator.of(context).push(
|
||||
AppRoute.defaultRoute(
|
||||
context,
|
||||
KeyVerificationView(request: req),
|
||||
),
|
||||
);
|
||||
await KeyVerificationDialog(request: req).show(context);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -5,6 +5,9 @@ import 'package:flutter/foundation.dart';
|
||||
abstract class PlatformInfos {
|
||||
static bool get isWeb => kIsWeb;
|
||||
|
||||
static bool get isCupertinoStyle =>
|
||||
!kIsWeb && (Platform.isIOS || Platform.isMacOS);
|
||||
|
||||
static bool get isMobile => !kIsWeb && (Platform.isAndroid || Platform.isIOS);
|
||||
|
||||
/// For desktops which don't support ChachedNetworkImage yet
|
||||
|
@ -9,8 +9,7 @@ import 'package:fluffychat/views/chat_list.dart';
|
||||
import 'package:flushbar/flushbar_helper.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import '../utils/app_route.dart';
|
||||
import 'key_verification.dart';
|
||||
import '../components/dialogs/key_verification_dialog.dart';
|
||||
|
||||
class ChatEncryptionSettingsView extends StatelessWidget {
|
||||
final String id;
|
||||
@ -55,12 +54,7 @@ class _ChatEncryptionSettingsState extends State<ChatEncryptionSettings> {
|
||||
setState(() => null);
|
||||
}
|
||||
};
|
||||
await Navigator.of(context).push(
|
||||
AppRoute.defaultRoute(
|
||||
context,
|
||||
KeyVerificationView(request: req),
|
||||
),
|
||||
);
|
||||
await KeyVerificationDialog(request: req).show(context);
|
||||
break;
|
||||
case 'verify_manual':
|
||||
if (await showOkCancelAlertDialog(
|
||||
@ -83,12 +77,7 @@ class _ChatEncryptionSettingsState extends State<ChatEncryptionSettings> {
|
||||
setState(() => null);
|
||||
}
|
||||
};
|
||||
await Navigator.of(context).push(
|
||||
AppRoute.defaultRoute(
|
||||
context,
|
||||
KeyVerificationView(request: req),
|
||||
),
|
||||
);
|
||||
await KeyVerificationDialog(request: req).show(context);
|
||||
break;
|
||||
case 'block':
|
||||
if (key.directVerified) {
|
||||
|
Loading…
Reference in New Issue
Block a user