Skip to content

Commit

Permalink
TW-1734: Update remove from group on mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev authored and hoangdat committed May 3, 2024
1 parent dd56f31 commit fb4df71
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class ParticipantListItem extends StatelessWidget {
builder: (ctx) => ProfileInfoPage(
roomId: member.room.id,
userId: member.id,
onUpdatedMembers: onUpdatedMembers,
),
),
);
Expand All @@ -126,6 +127,7 @@ class ParticipantListItem extends StatelessWidget {
return ProfileInfoPage(
roomId: member.room.id,
userId: member.id,
onUpdatedMembers: onUpdatedMembers,
onNewChatOpen: () {
dialogContext.pop();
},
Expand Down
52 changes: 26 additions & 26 deletions lib/pages/profile_info/profile_info_body/profile_info_body.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:async';

import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:dartz/dartz.dart' hide State;
import 'package:fluffychat/app_state/failure.dart';
import 'package:fluffychat/app_state/success.dart';
Expand All @@ -13,6 +12,7 @@ import 'package:fluffychat/presentation/enum/profile_info/profile_info_body_enum
import 'package:fluffychat/presentation/model/presentation_contact_constant.dart';
import 'package:fluffychat/presentation/model/search/presentation_search.dart';
import 'package:fluffychat/utils/dialog/twake_dialog.dart';
import 'package:fluffychat/utils/dialog/warning_dialog.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/utils/twake_snackbar.dart';
import 'package:fluffychat/widgets/matrix.dart';
Expand Down Expand Up @@ -131,32 +131,32 @@ class ProfileInfoBodyController extends State<ProfileInfoBody> {
}
}

void leaveFromChat() async {
Future<void> removeFromGroupChat() async {
if (user == null) return;
if (await showOkCancelAlertDialog(
useRootNavigator: false,
context: context,
title: L10n.of(context)!.removeUser,
okLabel: L10n.of(context)!.remove,
cancelLabel: L10n.of(context)!.cancel,
message: L10n.of(context)!.removeReason(
user?.displayName ?? '',
),
) ==
OkCancelResult.ok) {
final result = await TwakeDialog.showFutureLoadingDialogFullScreen(
future: () => user!.kick(),
);
if (result.error != null) {
TwakeSnackBar.show(
context,
result.error!.message,
WarningDialog.showCancelable(
context,
message: L10n.of(context)!.removeReason(
user?.displayName ?? '',
),
title: L10n.of(context)!.removeUser,
acceptText: L10n.of(context)!.remove,
cancelText: L10n.of(context)!.cancel,
acceptTextColor: LinagoraSysColors.material().error,
onAccept: () async {
WarningDialog.hideWarningDialog(context);
final result = await TwakeDialog.showFutureLoadingDialogFullScreen(
future: () => user!.kick(),
);
return;
}
Navigator.of(context).pop();
widget.onUpdatedMembers?.call();
}
if (result.error != null) {
TwakeSnackBar.show(
context,
result.error!.message,
);
return;
}
widget.onUpdatedMembers?.call();
},
);
}

List<ProfileInfoActions> profileInfoActions() {
Expand All @@ -172,7 +172,7 @@ class ProfileInfoBodyController extends State<ProfileInfoBody> {
openNewChat();
break;
case ProfileInfoActions.removeFromGroup:
leaveFromChat();
removeFromGroupChat();
break;
default:
break;
Expand Down
7 changes: 6 additions & 1 deletion lib/pages/profile_info/profile_info_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ class ProfileInfoPage extends StatefulWidget {
required this.roomId,
required this.userId,
this.onNewChatOpen,
this.onUpdatedMembers,
});

final String roomId;
final String userId;
final void Function()? onNewChatOpen;
final VoidCallback? onUpdatedMembers;

@override
State<ProfileInfoPage> createState() => ProfileInfoPageState();
Expand All @@ -25,5 +27,8 @@ class ProfileInfoPageState extends State<ProfileInfoPage> {
User? get user => room?.unsafeGetUserFromMemoryOrFallback(widget.userId);

@override
Widget build(BuildContext context) => ProfileInfoView(this);
Widget build(BuildContext context) => ProfileInfoView(
this,
onUpdatedMembers: widget.onUpdatedMembers,
);
}
4 changes: 4 additions & 0 deletions lib/pages/profile_info/profile_info_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ class ProfileInfoView extends StatelessWidget {
const ProfileInfoView(
this.controller, {
super.key,
this.onUpdatedMembers,
});

final ProfileInfoPageState controller;

final VoidCallback? onUpdatedMembers;

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down Expand Up @@ -58,6 +61,7 @@ class ProfileInfoView extends StatelessWidget {
body: ProfileInfoBody(
user: controller.user,
onNewChatOpen: controller.widget.onNewChatOpen,
onUpdatedMembers: onUpdatedMembers,
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class SettingsSecurityController extends State<SettingsSecurity> {
file.result?.downloadFile(context);
}

void copyPublicKey() {
Future<void> copyPublicKey() async {
Clipboard.setData(
ClipboardData(text: Matrix.of(context).client.fingerprintKey.beautified),
);
Expand Down
4 changes: 4 additions & 0 deletions lib/utils/dialog/warning_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ class WarningDialog {
String? title,
String? message,
String? acceptText,
Color? acceptTextColor,
OnAcceptButton? onAccept,
String? cancelText,
Color? cancelTextColor,
OnAcceptButton? onCancel,
}) {
showDialog(
Expand All @@ -40,13 +42,15 @@ class WarningDialog {
actions: [
DialogAction(
text: cancelText ?? L10n.of(context)!.cancel,
textColor: cancelTextColor,
onPressed: () {
Navigator.pop(context);
onCancel?.call();
},
),
DialogAction(
text: acceptText ?? L10n.of(context)!.ok,
textColor: acceptTextColor,
onPressed: () {
Navigator.pop(context);
onAccept?.call();
Expand Down
6 changes: 5 additions & 1 deletion lib/utils/warning_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,19 @@ class WarningDialogWidget extends StatelessWidget {

class DialogAction {
final String text;
final Color? textColor;
final VoidCallback? onPressed;

DialogAction({
required this.text,
this.onPressed,
this.textColor,
});
}

class _WarningTextButton extends StatelessWidget {
final DialogAction action;

const _WarningTextButton({
required this.action,
});
Expand All @@ -85,7 +88,8 @@ class _WarningTextButton extends StatelessWidget {
child: Text(
action.text,
style: Theme.of(context).textTheme.labelLarge?.copyWith(
color: Theme.of(context).colorScheme.primary,
color:
action.textColor ?? Theme.of(context).colorScheme.primary,
),
),
),
Expand Down

0 comments on commit fb4df71

Please sign in to comment.