mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 08:15:16 +00:00
Can delete a conversation from the list of conversations
This commit is contained in:
@ -2,6 +2,7 @@ import 'package:comunic/enums/load_error_level.dart';
|
||||
import 'package:comunic/helpers/conversations_helper.dart';
|
||||
import 'package:comunic/helpers/users_helper.dart';
|
||||
import 'package:comunic/lists/conversations_list.dart';
|
||||
import 'package:comunic/models/conversation.dart';
|
||||
import 'package:comunic/ui/routes/conversation_route.dart';
|
||||
import 'package:comunic/ui/routes/create_conversation_route.dart';
|
||||
import 'package:comunic/ui/tiles/conversation_tile.dart';
|
||||
@ -105,6 +106,43 @@ class _ConversationScreenState extends State<ConversationsListScreen> {
|
||||
.push(MaterialPageRoute(builder: (c) => CreateConversationRoute()));
|
||||
}
|
||||
|
||||
/// Handles conversation deletion request
|
||||
Future<void> _requestDeleteConversation(Conversation conversation) async {
|
||||
final result = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (c) {
|
||||
return AlertDialog(
|
||||
title: Text(tr("Delete conversation")),
|
||||
content: Text(tr(
|
||||
"Do you really want to remove this conversation from your list of conversations ? If you are the owner of this conversation, it will be completely deleted!")),
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
onPressed: () => Navigator.pop(context, false),
|
||||
child: Text(tr("cancel").toUpperCase()),
|
||||
),
|
||||
FlatButton(
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
child: Text(
|
||||
tr("delete").toUpperCase(),
|
||||
style: TextStyle(color: Colors.red),
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (result == null || !result) return;
|
||||
|
||||
// Request the conversation to be deleted now
|
||||
if (!await _conversationsHelper.deleteConversation(conversation.id))
|
||||
Scaffold.of(context).showSnackBar(
|
||||
SnackBar(content: Text(tr("Could not delete the conversation!"))));
|
||||
|
||||
// Reload the list of conversations
|
||||
_loadConversationsList(false);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_error == LoadErrorLevel.MAJOR) return _buildErrorCard();
|
||||
@ -128,6 +166,7 @@ class _ConversationScreenState extends State<ConversationsListScreen> {
|
||||
onOpen: (c) {
|
||||
_openConversation(context, c.id);
|
||||
},
|
||||
onRequestDelete: _requestDeleteConversation,
|
||||
);
|
||||
},
|
||||
itemCount: _list.length,
|
||||
|
Reference in New Issue
Block a user