Merge pull request #1610 from GetStream/feat/ui-hard-delete

This commit is contained in:
Sahil Kumar
2023-06-15 19:31:41 +05:30
committed by GitHub
3 changed files with 41 additions and 23 deletions
+13
View File
@@ -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 ## 6.3.0
🐞 Fixed 🐞 Fixed
@@ -19,6 +19,7 @@ class MessageActionsModal extends StatefulWidget {
this.showDeleteMessage = true, this.showDeleteMessage = true,
this.showEditMessage = true, this.showEditMessage = true,
this.onReplyTap, this.onReplyTap,
this.onConfirmDeleteTap,
this.onThreadReplyTap, this.onThreadReplyTap,
this.showCopyMessage = true, this.showCopyMessage = true,
this.showReplyMessage = true, this.showReplyMessage = true,
@@ -44,6 +45,9 @@ class MessageActionsModal extends StatefulWidget {
/// The action to perform when "reply" is tapped /// The action to perform when "reply" is tapped
final OnMessageTap? onReplyTap; final OnMessageTap? onReplyTap;
/// The action to perform when delete confirmation button is tapped.
final Future<void> Function(Message)? onConfirmDeleteTap;
/// Message in focus for actions /// Message in focus for actions
final Message message; final Message message;
@@ -363,7 +367,12 @@ class _MessageActionsModalState extends State<MessageActionsModal> {
if (answer == true) { if (answer == true) {
try { try {
Navigator.of(context).pop(); 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) { } catch (err) {
_showErrorAlertBottomSheet(); _showErrorAlertBottomSheet();
} }
@@ -61,6 +61,7 @@ class StreamMessageWidget extends StatefulWidget {
this.showInChannelIndicator = false, this.showInChannelIndicator = false,
this.onReplyTap, this.onReplyTap,
this.onThreadTap, this.onThreadTap,
this.onConfirmDeleteTap,
this.showUsername = true, this.showUsername = true,
this.showTimestamp = true, this.showTimestamp = true,
this.showReactions = true, this.showReactions = true,
@@ -307,6 +308,11 @@ class StreamMessageWidget extends StatefulWidget {
/// {@endtemplate} /// {@endtemplate}
final void Function(Message)? onReplyTap; final void Function(Message)? onReplyTap;
/// {@template onDeleteTap}
/// The function called when delete confirmation button is tapped.
/// {@endtemplate}
final Future<void> Function(Message)? onConfirmDeleteTap;
/// {@template editMessageInputBuilder} /// {@template editMessageInputBuilder}
/// Widget builder for edit message layout /// Widget builder for edit message layout
/// {@endtemplate} /// {@endtemplate}
@@ -568,6 +574,7 @@ class StreamMessageWidget extends StatefulWidget {
void Function(User)? onMentionTap, void Function(User)? onMentionTap,
void Function(Message)? onThreadTap, void Function(Message)? onThreadTap,
void Function(Message)? onReplyTap, void Function(Message)? onReplyTap,
Future<void> Function(Message)? onConfirmDeleteTap,
Widget Function(BuildContext, Message)? editMessageInputBuilder, Widget Function(BuildContext, Message)? editMessageInputBuilder,
Widget Function(BuildContext, Message)? textBuilder, Widget Function(BuildContext, Message)? textBuilder,
@Deprecated(''' @Deprecated('''
@@ -659,6 +666,7 @@ class StreamMessageWidget extends StatefulWidget {
onMentionTap: onMentionTap ?? this.onMentionTap, onMentionTap: onMentionTap ?? this.onMentionTap,
onThreadTap: onThreadTap ?? this.onThreadTap, onThreadTap: onThreadTap ?? this.onThreadTap,
onReplyTap: onReplyTap ?? this.onReplyTap, onReplyTap: onReplyTap ?? this.onReplyTap,
onConfirmDeleteTap: onConfirmDeleteTap ?? this.onConfirmDeleteTap,
editMessageInputBuilder: editMessageInputBuilder:
editMessageInputBuilder ?? this.editMessageInputBuilder, editMessageInputBuilder ?? this.editMessageInputBuilder,
textBuilder: textBuilder ?? this.textBuilder, textBuilder: textBuilder ?? this.textBuilder,
@@ -1098,16 +1106,21 @@ class _StreamMessageWidgetState extends State<StreamMessageWidget>
), ),
onClick: () async { onClick: () async {
Navigator.of(context, rootNavigator: true).pop(); Navigator.of(context, rootNavigator: true).pop();
final deleted = await showDialog( final deleted = await showDialog<bool?>(
context: context, context: context,
barrierDismissible: false, barrierDismissible: false,
builder: (_) => const DeleteMessageDialog(), builder: (_) => const DeleteMessageDialog(),
); );
if (deleted) { if (deleted == true) {
try { try {
await StreamChannel.of(context) final onConfirmDeleteTap = widget.onConfirmDeleteTap;
.channel if (onConfirmDeleteTap != null) {
.deleteMessage(widget.message); await onConfirmDeleteTap(widget.message);
} else {
await StreamChannel.of(context)
.channel
.deleteMessage(widget.message);
}
} catch (e) { } catch (e) {
showDialog( showDialog(
context: context, context: context,
@@ -1197,21 +1210,4 @@ class _StreamMessageWidgetState extends State<StreamMessageWidget>
), ),
); );
} }
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;
}
}
} }