🐛 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,6 +205,8 @@ class _ChatMessageText extends StatelessWidget {
SelectionArea( SelectionArea(
contextMenuBuilder: (context, editableTextState) { contextMenuBuilder: (context, editableTextState) {
final List<ContextMenuButtonItem> items = editableTextState.contextMenuButtonItems; final List<ContextMenuButtonItem> items = editableTextState.contextMenuButtonItems;
if (onReply != null) {
items.insert( items.insert(
0, 0,
ContextMenuButtonItem( ContextMenuButtonItem(
@ -211,6 +217,8 @@ class _ChatMessageText extends StatelessWidget {
}, },
), ),
); );
}
if (isOwner && onEdit != null) {
items.insert( items.insert(
1, 1,
ContextMenuButtonItem( ContextMenuButtonItem(
@ -221,6 +229,8 @@ class _ChatMessageText extends StatelessWidget {
}, },
), ),
); );
}
if (isOwner && onDelete != null) {
items.insert( items.insert(
2, 2,
ContextMenuButtonItem( ContextMenuButtonItem(
@ -231,6 +241,8 @@ class _ChatMessageText extends StatelessWidget {
}, },
), ),
); );
}
return AdaptiveTextSelectionToolbar.buttonItems( return AdaptiveTextSelectionToolbar.buttonItems(
anchors: editableTextState.contextMenuAnchors, anchors: editableTextState.contextMenuAnchors,
buttonItems: items, buttonItems: items,