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:
parent
7e4f27c657
commit
3338da4e09
|
|
@ -821,13 +821,16 @@ class Client extends MatrixApi {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Uploads a new user avatar for this user.
|
/// Uploads a new user avatar for this user. Leave file null to remove the
|
||||||
Future<void> setAvatar(MatrixFile file) async {
|
/// current avatar.
|
||||||
final uploadResp = await uploadContent(
|
Future<void> setAvatar(MatrixFile? file) async {
|
||||||
file.bytes,
|
final uploadResp = file == null
|
||||||
filename: file.name,
|
? null
|
||||||
contentType: file.mimeType,
|
: await uploadContent(
|
||||||
);
|
file.bytes,
|
||||||
|
filename: file.name,
|
||||||
|
contentType: file.mimeType,
|
||||||
|
);
|
||||||
await setAvatarUrl(userID!, uploadResp);
|
await setAvatarUrl(userID!, uploadResp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1356,15 +1356,18 @@ class Room {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Uploads a new user avatar for this room. Returns the event ID of the new
|
/// Uploads a new user avatar for this room. Returns the event ID of the new
|
||||||
/// m.room.avatar event.
|
/// m.room.avatar event. Leave empty to remove the current avatar.
|
||||||
Future<String> setAvatar(MatrixFile file) async {
|
Future<String> setAvatar(MatrixFile? file) async {
|
||||||
final uploadResp =
|
final uploadResp = file == null
|
||||||
await client.uploadContent(file.bytes, filename: file.name);
|
? null
|
||||||
|
: await client.uploadContent(file.bytes, filename: file.name);
|
||||||
return await client.setRoomStateWithKey(
|
return await client.setRoomStateWithKey(
|
||||||
id,
|
id,
|
||||||
EventTypes.RoomAvatar,
|
EventTypes.RoomAvatar,
|
||||||
'',
|
'',
|
||||||
{'url': uploadResp.toString()},
|
{
|
||||||
|
if (uploadResp != null) 'url': uploadResp.toString(),
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue