Skip to content

Commit

Permalink
TW-1734: Add button “Remove from group” when open chat info
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev authored and hoangdat committed May 3, 2024
1 parent 480c959 commit cde1bc3
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 34 deletions.
11 changes: 10 additions & 1 deletion assets/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -3050,5 +3050,14 @@
"leaveGroupSubtitle": "This group will still remain after you left",
"leaveChatFailed": "Failed to leave the chat",
"invalidLoginToken": "Invalid login token",
"copiedPublicKeyToClipboard": "Copied public key to clipboard."
"copiedPublicKeyToClipboard": "Copied public key to clipboard.",
"removeFromGroup": "Remove from group",
"removeUser": "Remove User",
"removeReason": "Remove {user} from the group",
"@removeReason": {
"type": "text",
"placeholders": {
"user": {}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ class ParticipantListItem extends StatelessWidget {
onNewChatOpen: () {
dialogContext.pop();
},
onUpdatedMembers: onUpdatedMembers,
),
],
),
Expand Down
99 changes: 98 additions & 1 deletion lib/pages/profile_info/profile_info_body/profile_info_body.dart
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@
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';
import 'package:fluffychat/di/global/get_it_initializer.dart';
import 'package:fluffychat/domain/app_state/contact/lookup_match_contact_state.dart';
import 'package:fluffychat/domain/usecase/contacts/lookup_match_contact_interactor.dart';
import 'package:fluffychat/pages/profile_info/profile_info_body/profile_info_body_view.dart';
import 'package:fluffychat/pages/profile_info/profile_info_body/profile_info_body_view_style.dart';
import 'package:fluffychat/presentation/enum/profile_info/profile_info_body_enum.dart';
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/platform_infos.dart';
import 'package:fluffychat/utils/twake_snackbar.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:linagora_design_flutter/linagora_design_flutter.dart';

import 'package:matrix/matrix.dart';

class ProfileInfoBody extends StatefulWidget {
const ProfileInfoBody({
required this.user,
this.onNewChatOpen,
this.onUpdatedMembers,
Key? key,
}) : super(key: key);

final User? user;

final void Function()? onNewChatOpen;
final VoidCallback? onNewChatOpen;

final VoidCallback? onUpdatedMembers;

@override
State<ProfileInfoBody> createState() => ProfileInfoBodyController();
Expand Down Expand Up @@ -121,6 +131,93 @@ class ProfileInfoBodyController extends State<ProfileInfoBody> {
}
}

void leaveFromChat() 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,
);
return;
}
Navigator.of(context).pop();
widget.onUpdatedMembers?.call();
}
}

List<ProfileInfoActions> profileInfoActions() {
return [
ProfileInfoActions.sendMessage,
ProfileInfoActions.removeFromGroup,
];
}

void handleActions(ProfileInfoActions action) {
switch (action) {
case ProfileInfoActions.sendMessage:
openNewChat();
break;
case ProfileInfoActions.removeFromGroup:
leaveFromChat();
break;
default:
break;
}
}

Widget buildProfileInfoActions(BuildContext context) {
return Column(
children: profileInfoActions().map((action) {
return Column(
children: [
Divider(
thickness: ProfileInfoBodyViewStyle.bigDividerThickness,
color: LinagoraSysColors.material().surface,
),
Padding(
padding: ProfileInfoBodyViewStyle.actionItemPadding,
child: Row(
children: [
Expanded(
child: TextButton.icon(
onPressed: () => handleActions(action),
icon: action.icon(),
label: Row(
children: [
Expanded(
child: Text(
action.label(context),
style: action.textStyle(context),
overflow: TextOverflow.ellipsis,
),
),
],
),
),
),
],
),
),
],
);
}).toList(),
);
}

@override
void initState() {
lookupMatchContactAction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import 'package:fluffychat/pages/profile_info/profile_info_body/profile_info_con
import 'package:fluffychat/pages/profile_info/profile_info_body/profile_info_header.dart';
import 'package:flutter/material.dart';

import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:linagora_design_flutter/colors/linagora_sys_colors.dart';

class ProfileInfoBodyView extends StatelessWidget {
const ProfileInfoBodyView({
required this.controller,
Expand Down Expand Up @@ -36,34 +33,9 @@ class ProfileInfoBodyView extends StatelessWidget {
),
),
if (!controller.isOwnProfile) ...[
Divider(
thickness: ProfileInfoBodyViewStyle.bigDividerThickness,
color: LinagoraSysColors.material().surface,
),
Padding(
padding: ProfileInfoBodyViewStyle.newChatButtonPadding,
child: Row(
children: [
Expanded(
child: TextButton.icon(
onPressed: () => controller.openNewChat(),
icon: const Icon(Icons.chat_outlined),
label: L10n.of(context)?.newChat != null
? Row(
children: [
Expanded(
child: Text(
L10n.of(context)!.sendMessage,
overflow: TextOverflow.ellipsis,
),
),
],
)
: const SizedBox.shrink(),
),
),
],
),
padding: ProfileInfoBodyViewStyle.actionsPadding,
child: controller.buildProfileInfoActions(context),
),
] else
const SizedBox(height: 16),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ class ProfileInfoBodyViewStyle {

static const double bigDividerThickness = 4;

static const EdgeInsetsGeometry newChatButtonPadding = EdgeInsets.only(
bottom: 16.0,
static const EdgeInsetsGeometry actionItemPadding = EdgeInsets.only(
left: 16.0,
right: 16.0,
);

static const EdgeInsetsGeometry actionsPadding = EdgeInsets.only(
bottom: 16.0,
);

static const EdgeInsetsGeometry copiableRowPadding = EdgeInsets.symmetric(
horizontal: 16.0,
vertical: 8,
Expand Down
42 changes: 42 additions & 0 deletions lib/presentation/enum/profile_info/profile_info_body_enum.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:linagora_design_flutter/linagora_design_flutter.dart';

enum ProfileInfoActions {
sendMessage,
removeFromGroup;

String label(BuildContext context) {
switch (this) {
case ProfileInfoActions.sendMessage:
return L10n.of(context)!.sendMessage;
case ProfileInfoActions.removeFromGroup:
return L10n.of(context)!.removeFromGroup;
}
}

TextStyle textStyle(BuildContext context) {
switch (this) {
case ProfileInfoActions.sendMessage:
return Theme.of(context).textTheme.titleMedium!.copyWith(
color: LinagoraSysColors.material().primary,
);
case ProfileInfoActions.removeFromGroup:
return Theme.of(context).textTheme.titleMedium!.copyWith(
color: LinagoraSysColors.material().error,
);
}
}

Icon icon() {
switch (this) {
case ProfileInfoActions.sendMessage:
return const Icon(Icons.chat_outlined);
case ProfileInfoActions.removeFromGroup:
return Icon(
Icons.logout_outlined,
color: LinagoraSysColors.material().error,
);
}
}
}

0 comments on commit cde1bc3

Please sign in to comment.