Solian/lib/widgets/chat/chat_event_deletion.dart

71 lines
1.9 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:solian/exts.dart';
import 'package:solian/models/channel.dart';
import 'package:solian/models/event.dart';
import 'package:solian/models/realm.dart';
import 'package:solian/providers/auth.dart';
2024-06-27 16:59:11 +00:00
class ChatEventDeletionDialog extends StatefulWidget {
final Channel channel;
final Realm? realm;
final Event item;
2024-06-27 16:59:11 +00:00
const ChatEventDeletionDialog({
super.key,
required this.channel,
required this.realm,
required this.item,
});
@override
2024-06-27 16:59:11 +00:00
State<ChatEventDeletionDialog> createState() =>
_ChatEventDeletionDialogState();
}
2024-06-27 16:59:11 +00:00
class _ChatEventDeletionDialogState extends State<ChatEventDeletionDialog> {
bool _isBusy = false;
void performAction() async {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) return;
2024-06-22 14:39:32 +00:00
final client = auth.configureClient('messaging');
setState(() => _isBusy = true);
final scope = (widget.realm?.alias.isNotEmpty ?? false)
? widget.realm?.alias
: 'global';
final resp = await client.delete(
'/api/channels/$scope/${widget.channel.alias}/messages/${widget.item.id}',
);
if (resp.statusCode == 200) {
Navigator.pop(context, resp.body);
} else {
context.showErrorDialog(resp.bodyString);
setState(() => _isBusy = false);
}
}
@override
Widget build(BuildContext context) {
return AlertDialog(
title: Text('messageDeletionConfirm'.tr),
content: Text('messageDeletionConfirmCaption'.trParams({
'id': '#${widget.item.id}',
})),
actions: <Widget>[
TextButton(
onPressed: _isBusy ? null : () => Navigator.pop(context, false),
child: Text('cancel'.tr),
),
TextButton(
onPressed: _isBusy ? null : performAction,
child: Text('confirm'.tr),
),
],
);
}
}