2024-05-30 15:14:29 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
import 'package:solian/exts.dart';
|
|
|
|
import 'package:solian/models/channel.dart';
|
2024-06-27 16:05:43 +00:00
|
|
|
import 'package:solian/models/event.dart';
|
2024-05-30 15:14:29 +00:00
|
|
|
import 'package:solian/models/realm.dart';
|
|
|
|
import 'package:solian/providers/auth.dart';
|
|
|
|
|
2024-06-27 16:59:11 +00:00
|
|
|
class ChatEventDeletionDialog extends StatefulWidget {
|
2024-05-30 15:14:29 +00:00
|
|
|
final Channel channel;
|
|
|
|
final Realm? realm;
|
2024-06-27 16:05:43 +00:00
|
|
|
final Event item;
|
2024-05-30 15:14:29 +00:00
|
|
|
|
2024-06-27 16:59:11 +00:00
|
|
|
const ChatEventDeletionDialog({
|
2024-05-30 15:14:29 +00:00
|
|
|
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-05-30 15:14:29 +00:00
|
|
|
}
|
|
|
|
|
2024-06-27 16:59:11 +00:00
|
|
|
class _ChatEventDeletionDialogState extends State<ChatEventDeletionDialog> {
|
2024-05-30 15:14:29 +00:00
|
|
|
bool _isBusy = false;
|
|
|
|
|
|
|
|
void performAction() async {
|
|
|
|
final AuthProvider auth = Get.find();
|
2024-07-24 17:18:47 +00:00
|
|
|
if (auth.isAuthorized.isFalse) return;
|
2024-05-30 15:14:29 +00:00
|
|
|
|
2024-09-16 03:57:16 +00:00
|
|
|
final client = await auth.configureClient('messaging');
|
2024-05-30 15:14:29 +00:00
|
|
|
|
|
|
|
setState(() => _isBusy = true);
|
|
|
|
|
|
|
|
final scope = (widget.realm?.alias.isNotEmpty ?? false)
|
|
|
|
? widget.realm?.alias
|
|
|
|
: 'global';
|
|
|
|
final resp = await client.delete(
|
2024-07-16 11:46:53 +00:00
|
|
|
'/channels/$scope/${widget.channel.alias}/messages/${widget.item.id}',
|
2024-05-30 15:14:29 +00:00
|
|
|
);
|
|
|
|
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),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|