From 49a1098a2873def2375ed246467a95056deae2f4 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 18 Mar 2022 20:13:45 +0100 Subject: [PATCH] Can report group --- .../screens/authorized_group_page_screen.dart | 13 +++++++- .../group_sections/about_group_section.dart | 12 +++++++ lib/ui/screens/groups_list_screen.dart | 33 +++++++++++++++++-- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/lib/ui/screens/authorized_group_page_screen.dart b/lib/ui/screens/authorized_group_page_screen.dart index c3ab2ef..3a1ea2e 100644 --- a/lib/ui/screens/authorized_group_page_screen.dart +++ b/lib/ui/screens/authorized_group_page_screen.dart @@ -1,4 +1,8 @@ +import 'package:comunic/enums/report_target_type.dart'; import 'package:comunic/models/advanced_group_info.dart'; +import 'package:comunic/models/group.dart'; +import 'package:comunic/models/report_target.dart'; +import 'package:comunic/ui/dialogs/report_dialog.dart'; import 'package:comunic/ui/routes/main_route/main_route.dart'; import 'package:comunic/ui/screens/group_sections/about_group_section.dart'; import 'package:comunic/ui/screens/group_sections/forez_presence_section.dart'; @@ -65,7 +69,10 @@ class _AuthorizedGroupPageScreenState // About the group _GroupPageTab( - widget: (c) => AboutGroupSection(group: _group), + widget: (c) => AboutGroupSection( + group: _group, + onReportGroup: _reportGroup, + ), label: tr("About")!, ), @@ -197,6 +204,10 @@ class _AuthorizedGroupPageScreenState ), ); } + + /// Report group + void _reportGroup(Group g) => showReportDialog( + ctx: context, target: ReportTarget(ReportTargetType.Group, g.id)); } class _GroupPageTab { diff --git a/lib/ui/screens/group_sections/about_group_section.dart b/lib/ui/screens/group_sections/about_group_section.dart index d6ab37d..fa281d1 100644 --- a/lib/ui/screens/group_sections/about_group_section.dart +++ b/lib/ui/screens/group_sections/about_group_section.dart @@ -1,3 +1,4 @@ +import 'package:comunic/helpers/server_config_helper.dart'; import 'package:comunic/models/advanced_group_info.dart'; import 'package:comunic/models/group.dart'; import 'package:comunic/utils/date_utils.dart'; @@ -11,10 +12,12 @@ import 'package:url_launcher/url_launcher.dart'; class AboutGroupSection extends StatelessWidget { final AdvancedGroupInfo group; + final Function(Group) onReportGroup; const AboutGroupSection({ Key? key, required this.group, + required this.onReportGroup, }) : super(key: key); @override @@ -103,6 +106,15 @@ class AboutGroupSection extends StatelessWidget { subtitle: Text(tr("Forez special features enabled")!), ) : Container(), + // Report group + srvConfig!.isReportingEnabled + ? ListTile( + textColor: Colors.red, + leading: Icon(Icons.flag, color: Colors.red), + title: Text(tr("Report abuse")!), + onTap: () => onReportGroup(group), + ) + : Container(), ], ); } diff --git a/lib/ui/screens/groups_list_screen.dart b/lib/ui/screens/groups_list_screen.dart index 78c4637..ea1c554 100644 --- a/lib/ui/screens/groups_list_screen.dart +++ b/lib/ui/screens/groups_list_screen.dart @@ -1,6 +1,10 @@ +import 'package:comunic/enums/report_target_type.dart'; import 'package:comunic/helpers/groups_helper.dart'; +import 'package:comunic/helpers/server_config_helper.dart'; import 'package:comunic/lists/groups_list.dart'; import 'package:comunic/models/group.dart'; +import 'package:comunic/models/report_target.dart'; +import 'package:comunic/ui/dialogs/report_dialog.dart'; import 'package:comunic/ui/routes/main_route/main_route.dart'; import 'package:comunic/ui/widgets/group_icon_widget.dart'; import 'package:comunic/ui/widgets/group_membership_widget.dart'; @@ -70,9 +74,28 @@ class _GroupsListScreenState extends SafeState { group: g, onUpdated: () => _refreshIndicatorKey.currentState!.show(), ), - trailing: IconButton( - icon: Icon(Icons.delete), - onPressed: () => _deleteGroup(g)), + trailing: IntrinsicWidth( + child: Row( + children: [ + // Remove membership + IconButton( + icon: Icon(Icons.delete), + onPressed: () => _deleteGroup(g)), + + // Report button + srvConfig!.isReportingEnabled + ? IconButton( + visualDensity: VisualDensity.compact, + onPressed: () => _reportGroup(g), + icon: Icon( + Icons.flag, + size: 15.0, + ), + ) + : Container() + ], + ), + ), onTap: () => MainController.of(context)!.openGroup(g.id), )) .toList(), @@ -122,6 +145,10 @@ class _GroupsListScreenState extends SafeState { _refreshIndicatorKey.currentState!.show(); } + /// Report a group + void _reportGroup(Group g) => showReportDialog( + ctx: context, target: ReportTarget(ReportTargetType.Group, g.id)); + /// Add a group void _createGroup() async { try {