fix: Ability to remove avatar from room and account

To remove an avatar the
client needs to send an
empty object. This is now
possible by making the
MatrixFile parameter nullable.
This commit is contained in:
Krille Fear 2021-11-22 19:36:38 +01:00
parent 7e4f27c657
commit 3338da4e09
2 changed files with 18 additions and 12 deletions

View File

@ -821,9 +821,12 @@ class Client extends MatrixApi {
}
}
/// Uploads a new user avatar for this user.
Future<void> setAvatar(MatrixFile file) async {
final uploadResp = await uploadContent(
/// Uploads a new user avatar for this user. Leave file null to remove the
/// current avatar.
Future<void> setAvatar(MatrixFile? file) async {
final uploadResp = file == null
? null
: await uploadContent(
file.bytes,
filename: file.name,
contentType: file.mimeType,

View File

@ -1356,15 +1356,18 @@ class Room {
}
/// Uploads a new user avatar for this room. Returns the event ID of the new
/// m.room.avatar event.
Future<String> setAvatar(MatrixFile file) async {
final uploadResp =
await client.uploadContent(file.bytes, filename: file.name);
/// m.room.avatar event. Leave empty to remove the current avatar.
Future<String> setAvatar(MatrixFile? file) async {
final uploadResp = file == null
? null
: await client.uploadContent(file.bytes, filename: file.name);
return await client.setRoomStateWithKey(
id,
EventTypes.RoomAvatar,
'',
{'url': uploadResp.toString()},
{
if (uploadResp != null) 'url': uploadResp.toString(),
},
);
}