1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-21 20:39:22 +00:00

Can report conversation

This commit is contained in:
Pierre HUBERT 2022-03-18 19:11:06 +01:00
parent e80232931e
commit 1bd7840be6
2 changed files with 39 additions and 15 deletions

View File

@ -1,6 +1,7 @@
import 'dart:math'; import 'dart:math';
import 'package:comunic/enums/load_error_level.dart'; import 'package:comunic/enums/load_error_level.dart';
import 'package:comunic/enums/report_target_type.dart';
import 'package:comunic/helpers/conversations_helper.dart'; import 'package:comunic/helpers/conversations_helper.dart';
import 'package:comunic/helpers/events_helper.dart'; import 'package:comunic/helpers/events_helper.dart';
import 'package:comunic/helpers/groups_helper.dart'; import 'package:comunic/helpers/groups_helper.dart';
@ -9,6 +10,8 @@ import 'package:comunic/lists/conversations_list.dart';
import 'package:comunic/lists/groups_list.dart'; import 'package:comunic/lists/groups_list.dart';
import 'package:comunic/lists/users_list.dart'; import 'package:comunic/lists/users_list.dart';
import 'package:comunic/models/conversation.dart'; import 'package:comunic/models/conversation.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/routes/main_route/main_route.dart';
import 'package:comunic/ui/screens/create_conversation_screen.dart'; import 'package:comunic/ui/screens/create_conversation_screen.dart';
import 'package:comunic/ui/tiles/conversation_tile.dart'; import 'package:comunic/ui/tiles/conversation_tile.dart';
@ -160,6 +163,11 @@ class _ConversationScreenState extends SafeState<ConversationsListScreen> {
_loadConversationsList(false); _loadConversationsList(false);
} }
/// Handle conversation report request
void _reportConversation(Conversation conversation) => showReportDialog(
ctx: context,
target: ReportTarget(ReportTargetType.Conversation, conversation.id!));
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (_error == LoadErrorLevel.MAJOR) return _buildErrorCard(); if (_error == LoadErrorLevel.MAJOR) return _buildErrorCard();
@ -201,6 +209,7 @@ class _ConversationScreenState extends SafeState<ConversationsListScreen> {
}, },
onRequestUpdate: _updateConversation, onRequestUpdate: _updateConversation,
onRequestLeave: _requestLeaveConversation, onRequestLeave: _requestLeaveConversation,
onReport: _reportConversation,
); );
}, },
itemCount: max(_list!.length, 1), itemCount: max(_list!.length, 1),

View File

@ -1,4 +1,5 @@
import 'package:comunic/helpers/conversations_helper.dart'; import 'package:comunic/helpers/conversations_helper.dart';
import 'package:comunic/helpers/server_config_helper.dart';
import 'package:comunic/lists/groups_list.dart'; import 'package:comunic/lists/groups_list.dart';
import 'package:comunic/lists/users_list.dart'; import 'package:comunic/lists/users_list.dart';
import 'package:comunic/models/config.dart'; import 'package:comunic/models/config.dart';
@ -18,7 +19,7 @@ typedef OpenConversationCallback = void Function(Conversation);
typedef RequestLeaveConversationCallback = void Function(Conversation); typedef RequestLeaveConversationCallback = void Function(Conversation);
typedef RequestUpdateConversationCallback = void Function(Conversation); typedef RequestUpdateConversationCallback = void Function(Conversation);
enum _PopupMenuChoices { UPDATE, LEAVE } enum _PopupMenuChoices { UPDATE, LEAVE, REPORT }
class ConversationTile extends StatelessWidget { class ConversationTile extends StatelessWidget {
final Conversation conversation; final Conversation conversation;
@ -27,6 +28,7 @@ class ConversationTile extends StatelessWidget {
final OpenConversationCallback onOpen; final OpenConversationCallback onOpen;
final RequestUpdateConversationCallback onRequestUpdate; final RequestUpdateConversationCallback onRequestUpdate;
final RequestLeaveConversationCallback onRequestLeave; final RequestLeaveConversationCallback onRequestLeave;
final Function(Conversation) onReport;
const ConversationTile({ const ConversationTile({
Key? key, Key? key,
@ -36,7 +38,8 @@ class ConversationTile extends StatelessWidget {
required this.onOpen, required this.onOpen,
required this.onRequestUpdate, required this.onRequestUpdate,
required this.onRequestLeave, required this.onRequestLeave,
}) : super(key: key); required this.onReport,
}) : super(key: key);
_buildSubInformation(IconData icon, String content) { _buildSubInformation(IconData icon, String content) {
return Row( return Row(
@ -116,18 +119,26 @@ class ConversationTile extends StatelessWidget {
onLongPressOpenMenu: (position) { onLongPressOpenMenu: (position) {
showMenu<_PopupMenuChoices>( showMenu<_PopupMenuChoices>(
context: context, context: context,
position: position, position: position,
items: [ items: [
PopupMenuItem( PopupMenuItem(
child: Text(tr("Update")!), child: Text(tr("Update")!),
value: _PopupMenuChoices.UPDATE, value: _PopupMenuChoices.UPDATE,
), ),
PopupMenuItem( PopupMenuItem(
child: Text(tr("Leave")!), child: Text(tr("Leave")!),
value: _PopupMenuChoices.LEAVE, value: _PopupMenuChoices.LEAVE,
) )
]).then(_conversationMenuCallback); ]..addAll(srvConfig!.isReportingEnabled
? [
PopupMenuItem(
child: Text(tr("Report")!),
value: _PopupMenuChoices.REPORT,
)
]
: []))
.then(_conversationMenuCallback);
}, },
); );
@ -158,7 +169,11 @@ class ConversationTile extends StatelessWidget {
onRequestLeave(conversation); onRequestLeave(conversation);
break; break;
default: case _PopupMenuChoices.REPORT:
onReport(conversation);
break;
case null:
break; break;
} }
} }