From 9f0bcd5523eb8ceb5813c1d9347601f6e5e5b548 Mon Sep 17 00:00:00 2001 From: krille-chan Date: Sun, 5 Nov 2023 10:09:02 +0100 Subject: [PATCH] fix: Remove failed to sent events --- lib/pages/chat/chat.dart | 19 +++++++++++++++ lib/pages/chat/chat_input_row.dart | 38 ++++++++++++++++++++++-------- lib/pages/chat/chat_view.dart | 27 +++++++++++---------- 3 files changed, 61 insertions(+), 23 deletions(-) diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index eef437bf..ecdb20af 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -772,6 +772,24 @@ class ChatController extends State { ); } + void deleteErrorEventsAction() async { + try { + if (selectedEvents.any((event) => event.status != EventStatus.error)) { + throw Exception( + 'Tried to delete failed to send events but one event is not failed to sent', + ); + } + for (final event in selectedEvents) { + await event.remove(); + } + } catch (e, s) { + ErrorReporter( + context, + 'Error while delete error events action', + ).onErrorCallback(e, s); + } + } + void redactEventsAction() async { final reasonInput = selectedEvents.any((event) => event.status.isSent) ? await showTextInputDialog( @@ -832,6 +850,7 @@ class ChatController extends State { if (isArchived) return false; final clients = Matrix.of(context).currentBundle; for (final event in selectedEvents) { + if (!event.status.isSent) return false; if (event.canRedact == false && !(clients!.any((cl) => event.senderId == cl!.userID))) return false; } diff --git a/lib/pages/chat/chat_input_row.dart b/lib/pages/chat/chat_input_row.dart index c7401d0d..6f5fe428 100644 --- a/lib/pages/chat/chat_input_row.dart +++ b/lib/pages/chat/chat_input_row.dart @@ -30,18 +30,36 @@ class ChatInputRow extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: controller.selectMode ? [ - SizedBox( - height: 56, - child: TextButton( - onPressed: controller.forwardEventsAction, - child: Row( - children: [ - const Icon(Icons.keyboard_arrow_left_outlined), - Text(L10n.of(context)!.forward), - ], + if (controller.selectedEvents + .every((event) => event.status == EventStatus.error)) + SizedBox( + height: 56, + child: TextButton( + style: TextButton.styleFrom( + foregroundColor: Theme.of(context).colorScheme.error, + ), + onPressed: controller.deleteErrorEventsAction, + child: Row( + children: [ + const Icon(Icons.delete), + Text(L10n.of(context)!.delete), + ], + ), + ), + ) + else + SizedBox( + height: 56, + child: TextButton( + onPressed: controller.forwardEventsAction, + child: Row( + children: [ + const Icon(Icons.keyboard_arrow_left_outlined), + Text(L10n.of(context)!.forward), + ], + ), ), ), - ), controller.selectedEvents.length == 1 ? controller.selectedEvents.first .getDisplayEvent(controller.timeline!) diff --git a/lib/pages/chat/chat_view.dart b/lib/pages/chat/chat_view.dart index 9e8ec9f0..798af551 100644 --- a/lib/pages/chat/chat_view.dart +++ b/lib/pages/chat/chat_view.dart @@ -91,20 +91,21 @@ class ChatView extends StatelessWidget { ], ), ), - PopupMenuItem( - value: _EventContextAction.report, - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - const Icon( - Icons.shield_outlined, - color: Colors.red, - ), - const SizedBox(width: 12), - Text(L10n.of(context)!.reportMessage), - ], + if (controller.selectedEvents.single.status.isSent) + PopupMenuItem( + value: _EventContextAction.report, + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + const Icon( + Icons.shield_outlined, + color: Colors.red, + ), + const SizedBox(width: 12), + Text(L10n.of(context)!.reportMessage), + ], + ), ), - ), ], ), ];