1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 12:59:21 +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) .addBytesFile("file", file)
.execWithFilesAndThrow(); .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] /// Delete a conversation specified by its [id]
Future<void> deleteConversation(int id) async => Future<void> deleteConversation(int id) async =>
await APIRequest.withLogin("conversations/delete") 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 // Add a member to the conversation
PickUserWidget( PickUserWidget(
resetOnChoose: true, resetOnChoose: true,
@ -190,6 +187,9 @@ class _UpdateConversationScreen extends State<UpdateConversationScreen> {
Column( Column(
children: _members.map((f) => _buildMemberTile(f)).toList(), children: _members.map((f) => _buildMemberTile(f)).toList(),
), ),
// Conversation image
isUpdating ? _buildConversationImageWidget() : Container(),
], ],
), ),
), ),
@ -335,9 +335,22 @@ class _UpdateConversationScreen extends State<UpdateConversationScreen> {
: CachedNetworkImage(imageUrl: _image), : CachedNetworkImage(imageUrl: _image),
SizedBox(height: 5), SizedBox(height: 5),
isAdmin isAdmin
? OutlineButton( ? Row(
onPressed: _uploadNewLogo, mainAxisAlignment: MainAxisAlignment.center,
child: Text(tr("Change logo")), 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(), : Container(),
SizedBox(height: 10), SizedBox(height: 10),
@ -366,4 +379,20 @@ class _UpdateConversationScreen extends State<UpdateConversationScreen> {
snack(context, tr("Failed to change conversation logo !")); 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!"));
}
}
} }