From b402add586ed080fc5e2e1f5339b79fc21594270 Mon Sep 17 00:00:00 2001 From: Deven Joshi Date: Tue, 12 Jan 2021 15:11:52 +0530 Subject: [PATCH] feat: Added delete dialog and added dismiss dialog in case of message flagged --- lib/src/message_actions_modal.dart | 35 +++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/lib/src/message_actions_modal.dart b/lib/src/message_actions_modal.dart index f288fa7a..95ecdea5 100644 --- a/lib/src/message_actions_modal.dart +++ b/lib/src/message_actions_modal.dart @@ -1,3 +1,4 @@ +import 'dart:convert'; import 'dart:ui'; import 'package:flutter/foundation.dart'; @@ -253,6 +254,34 @@ class _MessageActionsModalState extends State { try { await client.flagMessage(widget.message.id); _showDismissAlert(); + } catch (err) { + if (json.decode(err?.body ?? {})['code'] == 4) { + _showDismissAlert(); + } else { + _showErrorAlert(); + } + } + } + } + + void _showDeleteDialog() async { + var answer = await showConfirmationDialog(context, + title: 'Delete message', + icon: StreamSvgIcon.flag( + color: StreamChatTheme.of(context).colorTheme.accentRed, + size: 24.0, + ), + question: 'Are you sure you want to permanently delete this\nmessage?', + okText: 'DELETE', + cancelText: 'CANCEL'); + + if (answer) { + try { + Navigator.pop(context); + StreamChat.of(context).client.deleteMessage( + widget.message, + StreamChannel.of(context).channel.cid, + ); } catch (err) { _showErrorAlert(); } @@ -455,11 +484,7 @@ class _MessageActionsModalState extends State { ], ), onTap: () { - Navigator.pop(context); - StreamChat.of(context).client.deleteMessage( - widget.message, - StreamChannel.of(context).channel.cid, - ); + _showDeleteDialog(); }, ); }