mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-12-26 04:48:51 +00:00
Can delete a conversation from the list of conversations
This commit is contained in:
parent
fcc8c2faa4
commit
db02a41b75
@ -51,7 +51,7 @@ class ConversationsHelper {
|
||||
});
|
||||
|
||||
// Update all conversation settings, if possible
|
||||
if(settings.isOwner) {
|
||||
if (settings.isOwner) {
|
||||
request.addString("name", settings.hasName ? settings.name : "false");
|
||||
request.addString("members", settings.members.join(","));
|
||||
}
|
||||
@ -61,6 +61,19 @@ class ConversationsHelper {
|
||||
return response.code == 200;
|
||||
}
|
||||
|
||||
/// Delete a conversation specified by its [id]
|
||||
Future<bool> deleteConversation(int id) async {
|
||||
final response = await APIRequest(
|
||||
uri: "conversations/delete",
|
||||
needLogin: true,
|
||||
args: {
|
||||
"conversationID": id.toString(),
|
||||
},
|
||||
).exec();
|
||||
|
||||
return response.code == 200;
|
||||
}
|
||||
|
||||
/// Download the list of conversations from the server
|
||||
Future<ConversationsList> downloadList() async {
|
||||
final response =
|
||||
|
@ -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,
|
||||
|
@ -10,20 +10,26 @@ import 'package:flutter/material.dart';
|
||||
/// @author Pierre HUBERT
|
||||
|
||||
typedef OpenConversationCallback = void Function(Conversation);
|
||||
typedef RequestDeleteConversationCallback = void Function(Conversation);
|
||||
|
||||
enum _PopupMenuChoices { DELETE }
|
||||
|
||||
class ConversationTile extends StatelessWidget {
|
||||
final Conversation conversation;
|
||||
final UsersList usersList;
|
||||
final OpenConversationCallback onOpen;
|
||||
final RequestDeleteConversationCallback onRequestDelete;
|
||||
|
||||
const ConversationTile(
|
||||
{Key key,
|
||||
@required this.conversation,
|
||||
@required this.usersList,
|
||||
@required this.onOpen})
|
||||
@required this.onOpen,
|
||||
@required this.onRequestDelete})
|
||||
: assert(conversation != null),
|
||||
assert(usersList != null),
|
||||
assert(onOpen != null),
|
||||
assert(onRequestDelete != null),
|
||||
super(key: key);
|
||||
|
||||
_buildSubInformation(IconData icon, String content) {
|
||||
@ -80,6 +86,26 @@ class ConversationTile extends StatelessWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
// Trailing information
|
||||
trailing: PopupMenuButton<_PopupMenuChoices>(
|
||||
itemBuilder: (b) => <PopupMenuEntry<_PopupMenuChoices>>[
|
||||
PopupMenuItem(
|
||||
child: Text(tr("Delete")),
|
||||
value: _PopupMenuChoices.DELETE,
|
||||
)
|
||||
],
|
||||
onSelected: _conversationMenuCallback,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Method called each time an option of the menu is selected
|
||||
void _conversationMenuCallback(_PopupMenuChoices c) {
|
||||
switch (c) {
|
||||
case _PopupMenuChoices.DELETE:
|
||||
onRequestDelete(conversation);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user