Skip to content

Commit

Permalink
TW-1567: Prevent action select/hover when message is sending/error
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev authored and hoangdat committed Mar 15, 2024
1 parent c197736 commit 3e5d04f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 18 deletions.
10 changes: 4 additions & 6 deletions lib/pages/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ class ChatController extends State<Chat>
}

void forwardEventsAction({Event? event}) async {
if (event != null && !event.status.isAvailableToForwardEvent) {
if (event != null && !event.status.isAvailable) {
return;
}
if (selectedEvents.isEmpty && event != null) {
Expand Down Expand Up @@ -813,7 +813,7 @@ class ChatController extends State<Chat>
void replyAction({
Event? replyTo,
}) {
if (replyTo?.status.isAvailableToForwardEvent == false) {
if (replyTo?.status.isAvailable == false) {
return;
}
_updateReplyEvent(
Expand Down Expand Up @@ -1342,8 +1342,7 @@ class ChatController extends State<Chat>
Event event,
) {
final listAction = [
if (event.status.isAvailableToForwardEvent)
ChatHorizontalActionMenu.reply,
if (event.status.isAvailable) ChatHorizontalActionMenu.reply,
ChatHorizontalActionMenu.more,
];
return listAction
Expand Down Expand Up @@ -1387,8 +1386,7 @@ class ChatController extends State<Chat>
ChatContextMenuActions.select,
if (event.isCopyable) ChatContextMenuActions.copyMessage,
ChatContextMenuActions.pinChat,
if (event.status.isAvailableToForwardEvent)
ChatContextMenuActions.forward,
if (event.status.isAvailable) ChatContextMenuActions.forward,
if (PlatformInfos.isWeb && event.hasAttachment)
ChatContextMenuActions.downloadFile,
];
Expand Down
32 changes: 23 additions & 9 deletions lib/pages/chat/events/message/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:fluffychat/pages/chat/events/state_message.dart';
import 'package:fluffychat/pages/chat/events/verification_request_content.dart';
import 'package:fluffychat/pages/chat/sticky_timestamp_widget.dart';
import 'package:fluffychat/utils/date_time_extension.dart';
import 'package:fluffychat/utils/extension/event_status_custom_extension.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/event_extension.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/filtered_timeline_extension.dart';
import 'package:fluffychat/utils/responsive/responsive_utils.dart';
Expand Down Expand Up @@ -241,6 +242,9 @@ class _MessageState extends State<Message> {
MultiPlatformsMessageContainer(
onTap: widget.hideKeyboardChatScreen,
onHover: (hover) {
if (!widget.event.status.isAvailable) {
return;
}
if (widget.onHover != null) {
widget.onHover!(hover, widget.event);
}
Expand All @@ -260,12 +264,14 @@ class _MessageState extends State<Message> {
: CrossAxisAlignment.start,
children: [
GestureDetector(
onLongPress: () => widget.selectMode
? widget.onSelect!(widget.event)
: null,
onTap: () => widget.selectMode
? widget.onSelect!(widget.event)
: widget.hideKeyboardChatScreen?.call(),
onLongPress: () =>
widget.selectMode && widget.event.status.isAvailable
? widget.onSelect!(widget.event)
: null,
onTap: () =>
widget.selectMode && widget.event.status.isAvailable
? widget.onSelect!(widget.event)
: widget.hideKeyboardChatScreen?.call(),
child: Center(
child: Container(
padding: EdgeInsets.only(
Expand All @@ -279,7 +285,11 @@ class _MessageState extends State<Message> {
top: widget.selected ? 0 : 1.0,
bottom: widget.selected ? 0 : 1.0,
),
child: _messageSelectedWidget(context, row),
child: _messageSelectedWidget(
context,
row,
widget.event,
),
),
),
),
Expand Down Expand Up @@ -318,7 +328,11 @@ class _MessageState extends State<Message> {
return const SizedBox(width: MessageStyle.avatarSize);
}

Widget _messageSelectedWidget(BuildContext context, Widget child) {
Widget _messageSelectedWidget(
BuildContext context,
Widget child,
Event event,
) {
return Container(
padding: EdgeInsets.only(
left: widget.selectMode ? 12.0 : 8.0,
Expand All @@ -331,7 +345,7 @@ class _MessageState extends State<Message> {
child: Row(
mainAxisSize: MainAxisSize.max,
children: [
if (widget.selectMode)
if (widget.selectMode && event.status.isAvailable)
Align(
alignment: AlignmentDirectional.centerStart,
child: Padding(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:fluffychat/pages/chat/events/message/multi_platform_message_cont
import 'package:fluffychat/pages/chat/events/message_reactions.dart';
import 'package:fluffychat/pages/chat/events/message_time.dart';
import 'package:fluffychat/utils/date_time_extension.dart';
import 'package:fluffychat/utils/extension/event_status_custom_extension.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/event_extension.dart';
import 'package:fluffychat/utils/responsive/responsive_utils.dart';
import 'package:fluffychat/widgets/context_menu/context_menu_action_item.dart';
Expand Down Expand Up @@ -90,7 +91,7 @@ class MessageContentWithTimestampBuilder extends StatelessWidget {
child: MultiPlatformSelectionMode(
event: event,
isClickable: responsiveUtils.isMobileOrTablet(context),
onLongPress: onLongPress,
onLongPress: event.status.isAvailable ? onLongPress : null,
child: Stack(
alignment: event.isOwnMessage
? AlignmentDirectional.bottomStart
Expand Down Expand Up @@ -191,7 +192,8 @@ class MessageContentWithTimestampBuilder extends StatelessWidget {
),
),
),
if (!event.isOwnMessage) _menuActionsRowBuilder(context),
if (!event.isOwnMessage && event.status.isAvailable)
_menuActionsRowBuilder(context),
],
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class MultiPlatformsMessageContainer extends StatelessWidget {
onHover: (event) {
onHover(true);
},
onExit: (event) {
onHover(false);
},
);
}
return InkWell(
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/extension/event_status_custom_extension.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:matrix/matrix.dart';

extension EventStatusCustomExtension on EventStatus {
bool get isAvailableToForwardEvent {
bool get isAvailable {
return !isError && !isSending;
}
}

0 comments on commit 3e5d04f

Please sign in to comment.