diff --git a/packages/stream_chat_flutter/lib/src/message_actions_modal.dart b/packages/stream_chat_flutter/lib/src/message_actions_modal.dart index 6f57e7df..296b1e59 100644 --- a/packages/stream_chat_flutter/lib/src/message_actions_modal.dart +++ b/packages/stream_chat_flutter/lib/src/message_actions_modal.dart @@ -15,6 +15,7 @@ class MessageActionsModal extends StatefulWidget { const MessageActionsModal({ Key? key, required this.message, + required this.messageWidget, required this.messageTheme, this.showReactions = true, this.showDeleteMessage = true, @@ -27,18 +28,15 @@ class MessageActionsModal extends StatefulWidget { this.showThreadReplyMessage = true, this.showFlagButton = true, this.showPinButton = true, - this.showPinHighlight = false, - this.showUserAvatar = DisplayWidget.show, this.editMessageInputBuilder, - this.messageShape, - this.attachmentShape, this.reverse = false, this.customActions = const [], - this.attachmentBorderRadiusGeometry, this.onCopyTap, - this.textBuilder, }) : super(key: key); + /// Widget that shows the message + final Widget messageWidget; + /// Builder for edit message final Widget Function(BuildContext, Message)? editMessageInputBuilder; @@ -84,30 +82,12 @@ class MessageActionsModal extends StatefulWidget { /// Flag for showing pin action final bool showPinButton; - /// Display Pin Highlight - final bool showPinHighlight; - /// Flag for reversing message final bool reverse; - /// [ShapeBorder] to apply to the widget - final ShapeBorder? messageShape; - - /// [ShapeBorder] to apply to attachment - final ShapeBorder? attachmentShape; - - /// Enum for displaying user avatar - final DisplayWidget showUserAvatar; - - /// [BorderRadius] for attachment border - final BorderRadius? attachmentBorderRadiusGeometry; - /// List of custom actions final List customActions; - /// Customize the MessageWidget textBuilder - final Widget Function(BuildContext context, Message message)? textBuilder; - @override _MessageActionsModalState createState() => _MessageActionsModalState(); } @@ -142,9 +122,6 @@ class _MessageActionsModalState extends State { ? 1 : (roughSentenceSize == 0 ? 1 : (roughSentenceSize / roughMaxSize)); - final hasFileAttachment = - widget.message.attachments.any((it) => it.type == 'file') == true; - final streamChatThemeData = StreamChatTheme.of(context); final numberOfReactions = streamChatThemeData.reactionIcons.length; @@ -178,41 +155,7 @@ class _MessageActionsModalState extends State { ), const SizedBox(height: 8), IgnorePointer( - child: MessageWidget( - key: const Key('MessageWidget'), - reverse: widget.reverse, - attachmentBorderRadiusGeometry: widget - .attachmentBorderRadiusGeometry - ?.mirrorBorderIfReversed(reverse: !widget.reverse), - message: widget.message.copyWith( - text: widget.message.text!.length > 200 - // ignore: lines_longer_than_80_chars - ? '${widget.message.text!.substring(0, 200)}...' - : widget.message.text, - ), - messageTheme: widget.messageTheme, - showReactions: false, - showUsername: false, - showReplyMessage: false, - showUserAvatar: widget.showUserAvatar, - attachmentPadding: EdgeInsets.all( - hasFileAttachment ? 4 : 2, - ), - showTimestamp: false, - translateUserAvatar: false, - padding: const EdgeInsets.all(0), - textPadding: EdgeInsets.symmetric( - vertical: 8, - horizontal: widget.message.text!.isOnlyEmoji ? 0 : 16.0, - ), - showReactionPickerIndicator: widget.showReactions && - (widget.message.status == MessageSendingStatus.sent), - showSendingIndicator: false, - shape: widget.messageShape, - attachmentShape: widget.attachmentShape, - showPinHighlight: false, - textBuilder: widget.textBuilder, - ), + child: widget.messageWidget, ), const SizedBox(height: 8), Padding( diff --git a/packages/stream_chat_flutter/lib/src/message_widget.dart b/packages/stream_chat_flutter/lib/src/message_widget.dart index aea2f8b9..49788f80 100644 --- a/packages/stream_chat_flutter/lib/src/message_widget.dart +++ b/packages/stream_chat_flutter/lib/src/message_widget.dart @@ -1023,19 +1023,30 @@ class _MessageWidgetState extends State builder: (context) => StreamChannel( channel: channel, child: MessageActionsModal( - textBuilder: widget.textBuilder, + messageWidget: widget.copyWith( + key: const Key('MessageWidget'), + message: widget.message.copyWith( + text: widget.message.text!.length > 200 + ? '${widget.message.text!.substring(0, 200)}...' + : widget.message.text, + ), + showReactions: false, + showUsername: false, + showTimestamp: false, + translateUserAvatar: false, + showSendingIndicator: false, + padding: const EdgeInsets.all(0), + showReactionPickerIndicator: widget.showReactions && + (widget.message.status == MessageSendingStatus.sent), + showPinHighlight: false, + showUserAvatar: + widget.message.user!.id == channel.client.state.user!.id + ? DisplayWidget.gone + : DisplayWidget.show, + ), onCopyTap: (message) => Clipboard.setData(ClipboardData(text: message.text)), - attachmentBorderRadiusGeometry: - widget.attachmentBorderRadiusGeometry as BorderRadius?, - showUserAvatar: - widget.message.user!.id == channel.client.state.user!.id - ? DisplayWidget.gone - : DisplayWidget.show, messageTheme: widget.messageTheme, - messageShape: widget.shape ?? _getDefaultShape(context), - attachmentShape: widget.attachmentShape ?? - _getDefaultAttachmentShape(context), reverse: widget.reverse, showDeleteMessage: widget.showDeleteMessage || isDeleteFailed, message: widget.message, @@ -1106,28 +1117,6 @@ class _MessageWidgetState extends State ); } - ShapeBorder _getDefaultAttachmentShape(BuildContext context) { - final hasFiles = - widget.message.attachments.any((it) => it.type == 'file') == true; - return RoundedRectangleBorder( - side: hasFiles - ? widget.attachmentBorderSide ?? - BorderSide( - color: _streamChatTheme.colorTheme.greyWhisper, - ) - : BorderSide.none, - borderRadius: widget.attachmentBorderRadiusGeometry ?? BorderRadius.zero, - ); - } - - ShapeBorder _getDefaultShape(BuildContext context) => RoundedRectangleBorder( - side: widget.borderSide ?? - BorderSide( - color: _streamChatTheme.colorTheme.greyWhisper, - ), - borderRadius: widget.borderRadiusGeometry ?? BorderRadius.zero, - ); - Widget _parseAttachments() { final attachmentGroups = >{};