From cd61509f751d7ff3022385b141263abeefa2fa0a Mon Sep 17 00:00:00 2001 From: Henry-Hiles Date: Fri, 26 Dec 2025 17:56:21 -0500 Subject: [PATCH] Add reporting functionality --- README.md | 2 +- lib/widgets/chat_page/chat_box.dart | 2 +- lib/widgets/chat_page/room_chat.dart | 32 +++++++++++++++++++ lib/widgets/chat_page/room_menu.dart | 48 ++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 36982c2..40abd70 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ A simple and user-friendly Matrix client made with Flutter and the Matrix Dart S - [ ] Threads - [ ] Profile popouts - [x] Copy link to [room, space] -- [ ] Reporting +- [x] Reporting - [ ] Notifications using UnifiedPush - [ ] Group calls using [MSC4195](https://github.com/matrix-org/matrix-spec-proposals/pull/4195) - [ ] Invites diff --git a/lib/widgets/chat_page/chat_box.dart b/lib/widgets/chat_page/chat_box.dart index a702690..92c44fc 100644 --- a/lib/widgets/chat_page/chat_box.dart +++ b/lib/widgets/chat_page/chat_box.dart @@ -54,7 +54,7 @@ class ChatBox extends HookConsumerWidget { return KeyEventResult.ignored; }, - ); + )..requestFocus(); final style = TextStyle( color: theme.colorScheme.primary, diff --git a/lib/widgets/chat_page/room_chat.dart b/lib/widgets/chat_page/room_chat.dart index 1297b64..a95af30 100644 --- a/lib/widgets/chat_page/room_chat.dart +++ b/lib/widgets/chat_page/room_chat.dart @@ -35,6 +35,7 @@ class RoomChat extends HookConsumerWidget { final replyToMessage = useState(null); final memberListOpened = useState(showMembersByDefault); final theme = Theme.of(context); + final danger = theme.colorScheme.error; return ref .watch(SelectedRoomController.provider) @@ -120,6 +121,37 @@ class RoomChat extends HookConsumerWidget { title: Text("Delete"), ), ), + PopupMenuItem( + onTap: () => showDialog( + context: context, + builder: (context) => AlertDialog( + title: Text("Report"), + content: Text( + "Report this message to your server administrators, who can take action like banning that user or blocking that server from federating.", + ), + actions: [ + TextButton( + onPressed: Navigator.of(context).pop, + child: Text("Cancel"), + ), + TextButton( + onPressed: () { + room.roomData.client.reportEvent( + room.roomData.id, + message.id, + ); + Navigator.of(context).pop(); + }, + child: Text("Report"), + ), + ], + ), + ), + child: ListTile( + leading: Icon(Icons.report, color: danger), + title: Text("Report", style: TextStyle(color: danger)), + ), + ), ]; return Scaffold( diff --git a/lib/widgets/chat_page/room_menu.dart b/lib/widgets/chat_page/room_menu.dart index 82b7133..c5fa322 100644 --- a/lib/widgets/chat_page/room_menu.dart +++ b/lib/widgets/chat_page/room_menu.dart @@ -1,6 +1,8 @@ import "package:clipboard/clipboard.dart"; import "package:flutter/material.dart"; +import "package:flutter_hooks/flutter_hooks.dart"; import "package:matrix/matrix.dart"; +import "package:nexus/widgets/form_text_input.dart"; class RoomMenu extends StatelessWidget { final Room room; @@ -51,6 +53,52 @@ class RoomMenu extends StatelessWidget { title: Text("Leave", style: TextStyle(color: danger)), ), ), + PopupMenuItem( + onTap: () => showDialog( + context: context, + builder: (context) => HookBuilder( + builder: (_) { + final reasonController = useTextEditingController(); + return AlertDialog( + title: Text("Report"), + content: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Text( + "Report this room to your server administrators, who can take action like banning this room.", + ), + + SizedBox(height: 12), + FormTextInput( + required: false, + capitalize: true, + controller: reasonController, + title: "Reason for deletion (optional)", + ), + ], + ), + actions: [ + TextButton( + onPressed: Navigator.of(context).pop, + child: Text("Cancel"), + ), + TextButton( + onPressed: () { + room.client.reportRoom(room.id, reasonController.text); + Navigator.of(context).pop(); + }, + child: Text("Report"), + ), + ], + ); + }, + ), + ), + child: ListTile( + leading: Icon(Icons.report, color: danger), + title: Text("Report", style: TextStyle(color: danger)), + ), + ), ], ); }