From 77bae4d6fd371fe1283c6ab47fd6fa01fdec65a6 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Thu, 9 Oct 2025 00:00:25 +0800 Subject: [PATCH] :lipstick: Optimize message action area --- lib/widgets/chat/message_item.dart | 97 ++++++++++++++++++------------ 1 file changed, 59 insertions(+), 38 deletions(-) diff --git a/lib/widgets/chat/message_item.dart b/lib/widgets/chat/message_item.dart index c891ce92..9e1c183d 100644 --- a/lib/widgets/chat/message_item.dart +++ b/lib/widgets/chat/message_item.dart @@ -383,6 +383,54 @@ class MessageHoverActionMenu extends StatelessWidget { @override Widget build(BuildContext context) { + // General actions (available for all users) + final generalActions = [ + if (!isCurrentUser) // Hide reply for message author + IconButton( + icon: Icon(Symbols.reply, size: 16), + onPressed: () => onAction?.call(MessageItemAction.reply), + tooltip: 'reply'.tr(), + padding: const EdgeInsets.all(8), + constraints: const BoxConstraints(minWidth: 32, minHeight: 32), + ), + IconButton( + icon: Icon(Symbols.forward, size: 16), + onPressed: () => onAction?.call(MessageItemAction.forward), + tooltip: 'forward'.tr(), + padding: const EdgeInsets.all(8), + constraints: const BoxConstraints(minWidth: 32, minHeight: 32), + ), + if (translatableLanguage) + IconButton( + icon: Icon(Symbols.translate, size: 16), + onPressed: translate, + tooltip: + translatedText == null ? 'translate'.tr() : 'translated'.tr(), + padding: const EdgeInsets.all(8), + constraints: const BoxConstraints(minWidth: 32, minHeight: 32), + ), + ]; + + // Author-only actions (edit/delete) + final authorActions = [ + if (isCurrentUser) + IconButton( + icon: Icon(Symbols.edit, size: 16), + onPressed: () => onAction?.call(MessageItemAction.edit), + tooltip: 'edit'.tr(), + padding: const EdgeInsets.all(8), + constraints: const BoxConstraints(minWidth: 32, minHeight: 32), + ), + if (isCurrentUser) + IconButton( + icon: Icon(Symbols.delete, size: 16, color: Colors.red), + onPressed: () => _handleDelete(context), + tooltip: 'delete'.tr(), + padding: const EdgeInsets.all(8), + constraints: const BoxConstraints(minWidth: 32, minHeight: 32), + ), + ]; + return Container( decoration: BoxDecoration( color: Theme.of(context).colorScheme.surfaceContainerHighest, @@ -398,45 +446,18 @@ class MessageHoverActionMenu extends StatelessWidget { child: Row( mainAxisSize: MainAxisSize.min, children: [ - if (isCurrentUser) - IconButton( - icon: Icon(Symbols.edit, size: 16), - onPressed: () => onAction?.call(MessageItemAction.edit), - tooltip: 'edit'.tr(), - padding: const EdgeInsets.all(8), - constraints: const BoxConstraints(minWidth: 32, minHeight: 32), - ), - if (isCurrentUser) - IconButton( - icon: Icon(Symbols.delete, size: 16), - onPressed: () => _handleDelete(context), - tooltip: 'delete'.tr(), - padding: const EdgeInsets.all(8), - constraints: const BoxConstraints(minWidth: 32, minHeight: 32), - ), - IconButton( - icon: Icon(Symbols.reply, size: 16), - onPressed: () => onAction?.call(MessageItemAction.reply), - tooltip: 'reply'.tr(), - padding: const EdgeInsets.all(8), - constraints: const BoxConstraints(minWidth: 32, minHeight: 32), - ), - IconButton( - icon: Icon(Symbols.forward, size: 16), - onPressed: () => onAction?.call(MessageItemAction.forward), - tooltip: 'forward'.tr(), - padding: const EdgeInsets.all(8), - constraints: const BoxConstraints(minWidth: 32, minHeight: 32), - ), - if (translatableLanguage) - IconButton( - icon: Icon(Symbols.translate, size: 16), - onPressed: translate, - tooltip: - translatedText == null ? 'translate'.tr() : 'translated'.tr(), - padding: const EdgeInsets.all(8), - constraints: const BoxConstraints(minWidth: 32, minHeight: 32), + // General actions (left side) + ...generalActions, + // Separator (only if both general and author actions exist) + if (generalActions.isNotEmpty && authorActions.isNotEmpty) + Container( + width: 1, + height: 24, + color: Theme.of(context).colorScheme.outlineVariant, + margin: const EdgeInsets.symmetric(horizontal: 4), ), + // Author actions (right side) + ...authorActions, ], ), );