1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-25 22:39:22 +00:00

Can remove conversation logo

This commit is contained in:
Pierre HUBERT 2021-03-13 11:42:58 +01:00
parent 642f5e11fc
commit 99ae726c0a
2 changed files with 43 additions and 6 deletions

View File

@ -109,6 +109,14 @@ class ConversationsHelper {
.addBytesFile("file", file)
.execWithFilesAndThrow();
/// Remove conversation logo
///
/// Throws in case of failure
static Future<void> removeLogo(int convID) async =>
await APIRequest.withLogin("conversations/delete_image")
.addInt("convID", convID)
.execWithThrow();
/// Delete a conversation specified by its [id]
Future<void> deleteConversation(int id) async =>
await APIRequest.withLogin("conversations/delete")

View File

@ -175,9 +175,6 @@ class _UpdateConversationScreen extends State<UpdateConversationScreen> {
],
),
// Conversation image
isUpdating ? _buildConversationImageWidget() : Container(),
// Add a member to the conversation
PickUserWidget(
resetOnChoose: true,
@ -190,6 +187,9 @@ class _UpdateConversationScreen extends State<UpdateConversationScreen> {
Column(
children: _members.map((f) => _buildMemberTile(f)).toList(),
),
// Conversation image
isUpdating ? _buildConversationImageWidget() : Container(),
],
),
),
@ -335,9 +335,22 @@ class _UpdateConversationScreen extends State<UpdateConversationScreen> {
: CachedNetworkImage(imageUrl: _image),
SizedBox(height: 5),
isAdmin
? OutlineButton(
? 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<UpdateConversationScreen> {
snack(context, tr("Failed to change conversation logo !"));
}
}
/// Delete conversation logo
Future<void> _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!"));
}
}
}