From 99ae726c0ac9b60b569dc97def4ba26b5269922a Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 13 Mar 2021 11:42:58 +0100 Subject: [PATCH] Can remove conversation logo --- lib/helpers/conversations_helper.dart | 8 ++++ .../screens/update_conversation_screen.dart | 41 ++++++++++++++++--- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/lib/helpers/conversations_helper.dart b/lib/helpers/conversations_helper.dart index 04c6474..f739794 100644 --- a/lib/helpers/conversations_helper.dart +++ b/lib/helpers/conversations_helper.dart @@ -109,6 +109,14 @@ class ConversationsHelper { .addBytesFile("file", file) .execWithFilesAndThrow(); + /// Remove conversation logo + /// + /// Throws in case of failure + static Future removeLogo(int convID) async => + await APIRequest.withLogin("conversations/delete_image") + .addInt("convID", convID) + .execWithThrow(); + /// Delete a conversation specified by its [id] Future deleteConversation(int id) async => await APIRequest.withLogin("conversations/delete") diff --git a/lib/ui/screens/update_conversation_screen.dart b/lib/ui/screens/update_conversation_screen.dart index e7d3346..b5f85e9 100644 --- a/lib/ui/screens/update_conversation_screen.dart +++ b/lib/ui/screens/update_conversation_screen.dart @@ -175,9 +175,6 @@ class _UpdateConversationScreen extends State { ], ), - // Conversation image - isUpdating ? _buildConversationImageWidget() : Container(), - // Add a member to the conversation PickUserWidget( resetOnChoose: true, @@ -190,6 +187,9 @@ class _UpdateConversationScreen extends State { Column( children: _members.map((f) => _buildMemberTile(f)).toList(), ), + + // Conversation image + isUpdating ? _buildConversationImageWidget() : Container(), ], ), ), @@ -335,9 +335,22 @@ class _UpdateConversationScreen extends State { : CachedNetworkImage(imageUrl: _image), SizedBox(height: 5), isAdmin - ? OutlineButton( - onPressed: _uploadNewLogo, - child: Text(tr("Change logo")), + ? Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + OutlineButton( + onPressed: _uploadNewLogo, + child: Text(tr("Change logo")), + ), + SizedBox(width: 5), + _image == null + ? Container() + : OutlineButton( + onPressed: _deleteLogo, + child: Text(tr("Delete logo")), + highlightedBorderColor: Colors.red, + ), + ], ) : Container(), SizedBox(height: 10), @@ -366,4 +379,20 @@ class _UpdateConversationScreen extends State { snack(context, tr("Failed to change conversation logo !")); } } + + /// Delete conversation logo + Future _deleteLogo() async { + try { + if (!await showConfirmDialog( + context: context, + message: tr("Do you really want to delete this logo?"))) return; + + await ConversationsHelper.removeLogo(_conversation.id); + + setState(() => _image = null); + } catch (e, s) { + logError(e, s); + snack(context, tr("Failed to remove conversation logo!")); + } + } }