allow editing and redacting of other messages in the same bundle

This commit is contained in:
Sorunome 2021-09-19 13:13:58 +02:00
parent e8cc480c2f
commit c0faf04917
No known key found for this signature in database
GPG Key ID: B19471D07FC9BE9C
2 changed files with 45 additions and 11 deletions

View File

@ -458,19 +458,51 @@ class ChatController extends State<Chat> {
for (final event in selectedEvents) { for (final event in selectedEvents) {
await showFutureLoadingDialog( await showFutureLoadingDialog(
context: context, context: context,
future: () => future: () async {
event.status > 0 ? event.redactEvent() : event.remove()); if (event.status > 0) {
if (event.canRedact) {
await event.redactEvent();
} else {
final client = currentRoomBundle.firstWhere(
(cl) => selectedEvents.first.senderId == cl.userID,
orElse: () => null);
if (client == null) {
return;
}
final room = client.getRoomById(roomId);
await Event.fromJson(event.toJson(), room).redactEvent();
}
} else {
await event.remove();
}
});
} }
setState(() => selectedEvents.clear()); setState(() => selectedEvents.clear());
} }
List<Client> get currentRoomBundle {
final clients = matrix.currentBundle;
clients.removeWhere((c) => c.getRoomById(roomId) == null);
return clients;
}
bool get canRedactSelectedEvents { bool get canRedactSelectedEvents {
final clients = matrix.currentBundle;
for (final event in selectedEvents) { for (final event in selectedEvents) {
if (event.canRedact == false) return false; if (event.canRedact == false &&
!(clients.any((cl) => event.senderId == cl.userID))) return false;
} }
return true; return true;
} }
bool get canEditSelectedEvents {
if (selectedEvents.length != 1 || selectedEvents.first.status < 1) {
return false;
}
return currentRoomBundle
.any((cl) => selectedEvents.first.senderId == cl.userID);
}
void forwardEventsAction() async { void forwardEventsAction() async {
if (selectedEvents.length == 1) { if (selectedEvents.length == 1) {
Matrix.of(context).shareContent = selectedEvents.first.content; Matrix.of(context).shareContent = selectedEvents.first.content;
@ -595,6 +627,13 @@ class ChatController extends State<Chat> {
}); });
void editSelectedEventAction() { void editSelectedEventAction() {
final client = currentRoomBundle.firstWhere(
(cl) => selectedEvents.first.senderId == cl.userID,
orElse: () => null);
if (client == null) {
return;
}
setSendingClient(client);
setState(() { setState(() {
pendingText = sendController.text; pendingText = sendController.text;
editEvent = selectedEvents.first; editEvent = selectedEvents.first;
@ -700,8 +739,7 @@ class ChatController extends State<Chat> {
} }
void onInputBarChanged(String text) { void onInputBarChanged(String text) {
final clients = matrix.currentBundle; final clients = currentRoomBundle;
clients.removeWhere((c) => c.getRoomById(roomId) == null);
for (final client in clients) { for (final client in clients) {
final prefix = client.sendPrefix; final prefix = client.sendPrefix;
if ((prefix?.isNotEmpty ?? false) && if ((prefix?.isNotEmpty ?? false) &&

View File

@ -148,10 +148,7 @@ class ChatView extends StatelessWidget {
: Text(controller.selectedEvents.length.toString()), : Text(controller.selectedEvents.length.toString()),
actions: controller.selectMode actions: controller.selectMode
? <Widget>[ ? <Widget>[
if (controller.selectedEvents.length == 1 && if (controller.canEditSelectedEvents)
controller.selectedEvents.first.status > 0 &&
controller.selectedEvents.first.senderId ==
client.userID)
IconButton( IconButton(
icon: Icon(Icons.edit_outlined), icon: Icon(Icons.edit_outlined),
tooltip: L10n.of(context).edit, tooltip: L10n.of(context).edit,
@ -820,8 +817,7 @@ class _ChatAccountPicker extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
controller.matrix ??= Matrix.of(context); controller.matrix ??= Matrix.of(context);
final clients = controller.matrix.currentBundle; final clients = controller.currentRoomBundle;
clients.removeWhere((c) => c.getRoomById(controller.roomId) == null);
return Padding( return Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: FutureBuilder<Profile>( child: FutureBuilder<Profile>(