diff --git a/packages/stream_chat_flutter/CHANGELOG.md b/packages/stream_chat_flutter/CHANGELOG.md index b026f9b3..4b77dfa0 100644 --- a/packages/stream_chat_flutter/CHANGELOG.md +++ b/packages/stream_chat_flutter/CHANGELOG.md @@ -22,6 +22,19 @@ ) ``` +- Added support for `StreamMessageWidget.onConfirmDeleteTap` to override the default action on delete confirmation. + [#1604](https://github.com/GetStream/stream-chat-flutter/issues/1604) + + ```dart + StreamMessageWidget( + ..., + onConfirmDeleteTap: (message) async { + final channel = StreamChannel.of(context).channel; + await channel.deleteMessage(message, hard: false); + }, + ) + ``` + ## 6.3.0 🐞 Fixed diff --git a/packages/stream_chat_flutter/lib/src/message_actions_modal/message_actions_modal.dart b/packages/stream_chat_flutter/lib/src/message_actions_modal/message_actions_modal.dart index b6c43c76..7fcda8a9 100644 --- a/packages/stream_chat_flutter/lib/src/message_actions_modal/message_actions_modal.dart +++ b/packages/stream_chat_flutter/lib/src/message_actions_modal/message_actions_modal.dart @@ -19,6 +19,7 @@ class MessageActionsModal extends StatefulWidget { this.showDeleteMessage = true, this.showEditMessage = true, this.onReplyTap, + this.onConfirmDeleteTap, this.onThreadReplyTap, this.showCopyMessage = true, this.showReplyMessage = true, @@ -44,6 +45,9 @@ class MessageActionsModal extends StatefulWidget { /// The action to perform when "reply" is tapped final OnMessageTap? onReplyTap; + /// The action to perform when delete confirmation button is tapped. + final Future Function(Message)? onConfirmDeleteTap; + /// Message in focus for actions final Message message; @@ -363,7 +367,12 @@ class _MessageActionsModalState extends State { if (answer == true) { try { Navigator.of(context).pop(); - await StreamChannel.of(context).channel.deleteMessage(widget.message); + final onConfirmDeleteTap = widget.onConfirmDeleteTap; + if (onConfirmDeleteTap != null) { + await onConfirmDeleteTap(widget.message); + } else { + await StreamChannel.of(context).channel.deleteMessage(widget.message); + } } catch (err) { _showErrorAlertBottomSheet(); } diff --git a/packages/stream_chat_flutter/lib/src/message_widget/message_widget.dart b/packages/stream_chat_flutter/lib/src/message_widget/message_widget.dart index b002d2b5..fe7ccc19 100644 --- a/packages/stream_chat_flutter/lib/src/message_widget/message_widget.dart +++ b/packages/stream_chat_flutter/lib/src/message_widget/message_widget.dart @@ -61,6 +61,7 @@ class StreamMessageWidget extends StatefulWidget { this.showInChannelIndicator = false, this.onReplyTap, this.onThreadTap, + this.onConfirmDeleteTap, this.showUsername = true, this.showTimestamp = true, this.showReactions = true, @@ -307,6 +308,11 @@ class StreamMessageWidget extends StatefulWidget { /// {@endtemplate} final void Function(Message)? onReplyTap; + /// {@template onDeleteTap} + /// The function called when delete confirmation button is tapped. + /// {@endtemplate} + final Future Function(Message)? onConfirmDeleteTap; + /// {@template editMessageInputBuilder} /// Widget builder for edit message layout /// {@endtemplate} @@ -568,6 +574,7 @@ class StreamMessageWidget extends StatefulWidget { void Function(User)? onMentionTap, void Function(Message)? onThreadTap, void Function(Message)? onReplyTap, + Future Function(Message)? onConfirmDeleteTap, Widget Function(BuildContext, Message)? editMessageInputBuilder, Widget Function(BuildContext, Message)? textBuilder, @Deprecated(''' @@ -659,6 +666,7 @@ class StreamMessageWidget extends StatefulWidget { onMentionTap: onMentionTap ?? this.onMentionTap, onThreadTap: onThreadTap ?? this.onThreadTap, onReplyTap: onReplyTap ?? this.onReplyTap, + onConfirmDeleteTap: onConfirmDeleteTap ?? this.onConfirmDeleteTap, editMessageInputBuilder: editMessageInputBuilder ?? this.editMessageInputBuilder, textBuilder: textBuilder ?? this.textBuilder, @@ -1098,16 +1106,21 @@ class _StreamMessageWidgetState extends State ), onClick: () async { Navigator.of(context, rootNavigator: true).pop(); - final deleted = await showDialog( + final deleted = await showDialog( context: context, barrierDismissible: false, builder: (_) => const DeleteMessageDialog(), ); - if (deleted) { + if (deleted == true) { try { - await StreamChannel.of(context) - .channel - .deleteMessage(widget.message); + final onConfirmDeleteTap = widget.onConfirmDeleteTap; + if (onConfirmDeleteTap != null) { + await onConfirmDeleteTap(widget.message); + } else { + await StreamChannel.of(context) + .channel + .deleteMessage(widget.message); + } } catch (e) { showDialog( context: context, @@ -1197,21 +1210,4 @@ class _StreamMessageWidgetState extends State ), ); } - - void retryMessage(BuildContext context) { - final channel = StreamChannel.of(context).channel; - if (widget.message.status == MessageSendingStatus.failed) { - channel.sendMessage(widget.message); - return; - } - if (widget.message.status == MessageSendingStatus.failed_update) { - channel.updateMessage(widget.message); - return; - } - - if (widget.message.status == MessageSendingStatus.failed_delete) { - channel.deleteMessage(widget.message); - return; - } - } }