From 9d20c407fcb2d313f9a252598d8a5f5bb1cd6a7d Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 1 May 2019 11:30:55 +0200 Subject: [PATCH] Fix issue on conversation update --- lib/helpers/conversations_helper.dart | 9 ++++++++- lib/helpers/database/model_database_helper.dart | 11 +++++++++++ lib/ui/screens/update_conversation_screen.dart | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/helpers/conversations_helper.dart b/lib/helpers/conversations_helper.dart index f68d587..ab771b6 100644 --- a/lib/helpers/conversations_helper.dart +++ b/lib/helpers/conversations_helper.dart @@ -58,7 +58,14 @@ class ConversationsHelper { final response = await request.exec(); - return response.code == 200; + if(response.code != 200) + return false; + + //Delete old conversation entry from the database + await _conversationsDatabaseHelper.delete(settings.id); + + // Success + return true; } /// Delete a conversation specified by its [id] diff --git a/lib/helpers/database/model_database_helper.dart b/lib/helpers/database/model_database_helper.dart index b20ad01..addddff 100644 --- a/lib/helpers/database/model_database_helper.dart +++ b/lib/helpers/database/model_database_helper.dart @@ -46,6 +46,17 @@ abstract class ModelDatabaseHelper { return null; } + /// Delete an entry from the database with a specified [id] + /// + /// Return true if at least one entry was deleted / false else + Future delete(int id) async { + return await (await DatabaseHelper.get()).delete( + tableName(), + where: '${BaseTableContract.C_ID} = ?', + whereArgs: [id], + ) > 0; + } + /// Get all the entries from the table Future> getAll() async { List maps = await (await DatabaseHelper.get()).query(tableName()); diff --git a/lib/ui/screens/update_conversation_screen.dart b/lib/ui/screens/update_conversation_screen.dart index fdaaafe..6972688 100644 --- a/lib/ui/screens/update_conversation_screen.dart +++ b/lib/ui/screens/update_conversation_screen.dart @@ -143,13 +143,13 @@ class _UpdateConversationScreen extends State { Future _submitForm() async { final settings = Conversation( id: isUpdating ? widget.initialSettings.id : 0, + ownerID: isUpdating ? widget.initialSettings.ownerID : 0, name: _nameController.text, following: _followConversation, members: _members.usersID, // Give random value to these fields as they are ignored here lastActive: 0, - ownerID: 0, sawLastMessage: true); // Create the conversation