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