2021-04-24 09:29:17 +02:00
|
|
|
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
2021-05-23 13:11:55 +02:00
|
|
|
|
2021-06-18 10:29:48 +02:00
|
|
|
import 'package:matrix/matrix.dart';
|
2021-05-22 08:57:49 +02:00
|
|
|
import 'package:fluffychat/pages/permission_slider_dialog.dart';
|
2021-04-24 09:29:17 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|
|
|
|
|
|
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
2021-05-23 13:11:55 +02:00
|
|
|
import 'package:vrouter/vrouter.dart';
|
2021-04-24 09:29:17 +02:00
|
|
|
|
2021-05-22 09:08:23 +02:00
|
|
|
import 'views/user_bottom_sheet_view.dart';
|
2021-04-24 09:29:17 +02:00
|
|
|
|
|
|
|
class UserBottomSheet extends StatefulWidget {
|
|
|
|
final User user;
|
|
|
|
final Function onMention;
|
2021-05-01 10:04:44 +02:00
|
|
|
final BuildContext outerContext;
|
2021-04-24 09:29:17 +02:00
|
|
|
|
|
|
|
const UserBottomSheet({
|
|
|
|
Key key,
|
|
|
|
@required this.user,
|
2021-05-01 10:04:44 +02:00
|
|
|
@required this.outerContext,
|
2021-04-24 09:29:17 +02:00
|
|
|
this.onMention,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
UserBottomSheetController createState() => UserBottomSheetController();
|
|
|
|
}
|
|
|
|
|
|
|
|
class UserBottomSheetController extends State<UserBottomSheet> {
|
|
|
|
void participantAction(String action) async {
|
|
|
|
final Function _askConfirmation =
|
|
|
|
() async => (await showOkCancelAlertDialog(
|
2021-05-23 15:02:36 +02:00
|
|
|
useRootNavigator: false,
|
2021-04-24 09:29:17 +02:00
|
|
|
context: context,
|
|
|
|
title: L10n.of(context).areYouSure,
|
|
|
|
okLabel: L10n.of(context).yes,
|
|
|
|
cancelLabel: L10n.of(context).no,
|
|
|
|
) ==
|
|
|
|
OkCancelResult.ok);
|
|
|
|
switch (action) {
|
|
|
|
case 'mention':
|
|
|
|
Navigator.of(context, rootNavigator: false).pop();
|
|
|
|
widget.onMention();
|
|
|
|
break;
|
|
|
|
case 'ban':
|
|
|
|
if (await _askConfirmation()) {
|
|
|
|
await showFutureLoadingDialog(
|
|
|
|
context: context,
|
|
|
|
future: () => widget.user.ban(),
|
|
|
|
);
|
|
|
|
Navigator.of(context, rootNavigator: false).pop();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'unban':
|
|
|
|
if (await _askConfirmation()) {
|
|
|
|
await showFutureLoadingDialog(
|
|
|
|
context: context,
|
|
|
|
future: () => widget.user.unban(),
|
|
|
|
);
|
|
|
|
Navigator.of(context, rootNavigator: false).pop();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'kick':
|
|
|
|
if (await _askConfirmation()) {
|
|
|
|
await showFutureLoadingDialog(
|
|
|
|
context: context,
|
|
|
|
future: () => widget.user.kick(),
|
|
|
|
);
|
|
|
|
Navigator.of(context, rootNavigator: false).pop();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'permission':
|
|
|
|
final newPermission = await PermissionSliderDialog(
|
|
|
|
initialPermission: widget.user.powerLevel)
|
|
|
|
.show(context);
|
|
|
|
if (newPermission != null) {
|
|
|
|
if (newPermission == 100 && await _askConfirmation() == false) break;
|
|
|
|
await showFutureLoadingDialog(
|
|
|
|
context: context,
|
|
|
|
future: () => widget.user.setPower(newPermission),
|
|
|
|
);
|
|
|
|
Navigator.of(context, rootNavigator: false).pop();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'message':
|
|
|
|
final roomId = await widget.user.startDirectChat();
|
2021-07-08 17:10:20 +02:00
|
|
|
VRouter.of(widget.outerContext).to('/rooms/$roomId');
|
2021-05-01 10:04:44 +02:00
|
|
|
Navigator.of(context, rootNavigator: false).pop();
|
2021-04-24 09:29:17 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2021-05-22 09:13:47 +02:00
|
|
|
Widget build(BuildContext context) => UserBottomSheetView(this);
|
2021-04-24 09:29:17 +02:00
|
|
|
}
|