2024-05-30 15:14:29 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|
|
|
import 'package:get/get.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
|
|
|
import 'package:solian/widgets/chat/chat_event_deletion.dart';
|
2024-10-14 13:13:57 +00:00
|
|
|
import 'package:solian/widgets/loading_indicator.dart';
|
2024-05-30 15:14:29 +00:00
|
|
|
|
2024-06-27 16:59:11 +00:00
|
|
|
class ChatEventAction 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
|
|
|
final Function? onEdit;
|
|
|
|
final Function? onReply;
|
|
|
|
|
2024-06-27 16:59:11 +00:00
|
|
|
const ChatEventAction({
|
2024-05-30 15:14:29 +00:00
|
|
|
super.key,
|
|
|
|
required this.channel,
|
|
|
|
required this.realm,
|
|
|
|
required this.item,
|
|
|
|
this.onEdit,
|
|
|
|
this.onReply,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
2024-06-27 16:59:11 +00:00
|
|
|
State<ChatEventAction> createState() => _ChatEventActionState();
|
2024-05-30 15:14:29 +00:00
|
|
|
}
|
|
|
|
|
2024-06-27 16:59:11 +00:00
|
|
|
class _ChatEventActionState extends State<ChatEventAction> {
|
2024-05-30 15:14:29 +00:00
|
|
|
bool _isBusy = false;
|
|
|
|
bool _canModifyContent = false;
|
|
|
|
|
|
|
|
void checkAbleToModifyContent() async {
|
2024-06-27 16:59:11 +00:00
|
|
|
if (!['messages.new'].contains(widget.item.type)) return;
|
|
|
|
|
2024-07-24 17:18:47 +00:00
|
|
|
final AuthProvider auth = Get.find();
|
|
|
|
if (auth.isAuthorized.isFalse) return;
|
2024-05-30 15:14:29 +00:00
|
|
|
|
|
|
|
setState(() => _isBusy = true);
|
|
|
|
|
|
|
|
setState(() {
|
2024-09-11 15:40:23 +00:00
|
|
|
_canModifyContent =
|
|
|
|
auth.userProfile.value!['id'] == widget.item.sender.account.id;
|
2024-05-30 15:14:29 +00:00
|
|
|
_isBusy = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
checkAbleToModifyContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return SafeArea(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
'messageActionList'.tr,
|
|
|
|
style: Theme.of(context).textTheme.headlineSmall,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
'#${widget.item.id.toString().padLeft(8, '0')}',
|
|
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
).paddingOnly(left: 24, right: 24, top: 32, bottom: 16),
|
2024-10-14 13:13:57 +00:00
|
|
|
LoadingIndicator(isActive: _isBusy),
|
2024-05-30 15:14:29 +00:00
|
|
|
Expanded(
|
|
|
|
child: ListView(
|
|
|
|
children: [
|
|
|
|
ListTile(
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
|
|
|
leading: const FaIcon(FontAwesomeIcons.reply, size: 20),
|
|
|
|
title: Text('reply'.tr),
|
|
|
|
onTap: () async {
|
|
|
|
if (widget.onReply != null) widget.onReply!();
|
|
|
|
Navigator.pop(context);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
if (_canModifyContent)
|
|
|
|
const Divider(thickness: 0.3, height: 0.3)
|
|
|
|
.paddingSymmetric(vertical: 16),
|
|
|
|
if (_canModifyContent)
|
|
|
|
ListTile(
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
|
|
|
leading: const Icon(Icons.edit),
|
|
|
|
title: Text('edit'.tr),
|
|
|
|
onTap: () async {
|
|
|
|
if (widget.onEdit != null) widget.onEdit!();
|
|
|
|
Navigator.pop(context);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
if (_canModifyContent)
|
|
|
|
ListTile(
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
|
|
|
leading: const Icon(Icons.delete),
|
|
|
|
title: Text('delete'.tr),
|
|
|
|
onTap: () async {
|
|
|
|
final value = await showDialog(
|
|
|
|
context: context,
|
2024-06-27 16:59:11 +00:00
|
|
|
builder: (context) => ChatEventDeletionDialog(
|
2024-05-30 15:14:29 +00:00
|
|
|
channel: widget.channel,
|
|
|
|
realm: widget.realm,
|
|
|
|
item: widget.item,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
if (value != null) {
|
|
|
|
Navigator.pop(context, true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|