Merge branch 'krille/fix-remove-avatar' into 'main'

fix: Ability to remove avatar from room and account

Closes #223

See merge request famedly/company/frontend/famedlysdk!906
This commit is contained in:
td 2021-11-22 19:20:00 +00:00
commit 5da0180f1f
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. /// 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 {
final uploadResp = file == null
? null
: await uploadContent(
file.bytes, file.bytes,
filename: file.name, filename: file.name,
contentType: file.mimeType, 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 /// 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(),
},
); );
} }