🐛 Add ability check to text selection chat message action

This commit is contained in:
LittleSheep 2025-01-06 23:17:24 +08:00
parent 1f6bf33b0e
commit f2b3bdda2d

View File

@ -194,6 +194,10 @@ class _ChatMessageText extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final ua = context.read<UserProvider>();
final isOwner = ua.isAuthorized && data.sender.accountId == ua.user?.id;
if (data.body['text'] != null && data.body['text'].isNotEmpty) { if (data.body['text'] != null && data.body['text'].isNotEmpty) {
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@ -201,36 +205,44 @@ class _ChatMessageText extends StatelessWidget {
SelectionArea( SelectionArea(
contextMenuBuilder: (context, editableTextState) { contextMenuBuilder: (context, editableTextState) {
final List<ContextMenuButtonItem> items = editableTextState.contextMenuButtonItems; final List<ContextMenuButtonItem> items = editableTextState.contextMenuButtonItems;
items.insert(
0, if (onReply != null) {
ContextMenuButtonItem( items.insert(
label: 'reply'.tr(), 0,
onPressed: () { ContextMenuButtonItem(
ContextMenuController.removeAny(); label: 'reply'.tr(),
onReply?.call(data); onPressed: () {
}, ContextMenuController.removeAny();
), onReply?.call(data);
); },
items.insert( ),
1, );
ContextMenuButtonItem( }
label: 'edit'.tr(), if (isOwner && onEdit != null) {
onPressed: () { items.insert(
ContextMenuController.removeAny(); 1,
onEdit?.call(data); ContextMenuButtonItem(
}, label: 'edit'.tr(),
), onPressed: () {
); ContextMenuController.removeAny();
items.insert( onEdit?.call(data);
2, },
ContextMenuButtonItem( ),
label: 'delete'.tr(), );
onPressed: () { }
ContextMenuController.removeAny(); if (isOwner && onDelete != null) {
onDelete?.call(data); items.insert(
}, 2,
), ContextMenuButtonItem(
); label: 'delete'.tr(),
onPressed: () {
ContextMenuController.removeAny();
onDelete?.call(data);
},
),
);
}
return AdaptiveTextSelectionToolbar.buttonItems( return AdaptiveTextSelectionToolbar.buttonItems(
anchors: editableTextState.contextMenuAnchors, anchors: editableTextState.contextMenuAnchors,
buttonItems: items, buttonItems: items,