fix: Remove failed to sent events

This commit is contained in:
krille-chan 2023-11-05 10:09:02 +01:00
parent e70ff68c48
commit 9f0bcd5523
No known key found for this signature in database
3 changed files with 61 additions and 23 deletions

View file

@ -772,6 +772,24 @@ class ChatController extends State<ChatPageWithRoom> {
);
}
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<ChatPageWithRoom> {
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;
}

View file

@ -30,18 +30,36 @@ class ChatInputRow extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: controller.selectMode
? <Widget>[
SizedBox(
height: 56,
child: TextButton(
onPressed: controller.forwardEventsAction,
child: Row(
children: <Widget>[
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: <Widget>[
const Icon(Icons.delete),
Text(L10n.of(context)!.delete),
],
),
),
)
else
SizedBox(
height: 56,
child: TextButton(
onPressed: controller.forwardEventsAction,
child: Row(
children: <Widget>[
const Icon(Icons.keyboard_arrow_left_outlined),
Text(L10n.of(context)!.forward),
],
),
),
),
),
controller.selectedEvents.length == 1
? controller.selectedEvents.first
.getDisplayEvent(controller.timeline!)

View file

@ -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),
],
),
),
),
],
),
];