updateChatAvatar method
- ChatId id, {
- NativeFile? file,
- CropAreaInput? crop,
- void onSendProgress()?,
override
Updates the Chat.avatar field with the provided image, or resets it to
null, by authority of the authenticated MyUser.
Implementation
@override
Future<void> updateChatAvatar(
ChatId id, {
NativeFile? file,
CropAreaInput? crop,
void Function(int count, int total)? onSendProgress,
}) async {
Log.debug(
'updateChatAvatar($id, $file, crop: $crop, onSendProgress)',
'$runtimeType',
);
late dio.MultipartFile upload;
if (file != null) {
await file.ensureCorrectMediaType();
upload = await file.toMultipartFile();
}
final RxChatImpl? chat = chats[id];
final ChatAvatar? avatar = chat?.chat.value.avatar;
if (file == null) {
chat?.chat.update((c) => c?.avatar = null);
}
if (id.isLocalWith(me)) {
id = (await ensureRemoteMonolog()).id;
}
try {
try {
await Backoff.run(
() async {
await _graphQlProvider.updateChatAvatar(
id,
file: file == null ? null : upload,
crop: crop,
onSendProgress: onSendProgress,
);
},
retryIf: (e) => e.isNetworkRelated,
retries: 10,
);
} on UpdateChatAvatarException catch (e) {
switch (e.code) {
case UpdateChatAvatarErrorCode.unknownChat:
await remove(id);
break;
case UpdateChatAvatarErrorCode.invalidCropCoordinates:
case UpdateChatAvatarErrorCode.invalidCropPoints:
case UpdateChatAvatarErrorCode.malformed:
case UpdateChatAvatarErrorCode.unsupportedFormat:
case UpdateChatAvatarErrorCode.invalidSize:
case UpdateChatAvatarErrorCode.invalidDimensions:
case UpdateChatAvatarErrorCode.artemisUnknown:
case UpdateChatAvatarErrorCode.dialog:
rethrow;
}
}
} catch (e) {
if (file == null) {
chat?.chat.update((c) => c?.avatar = avatar);
}
rethrow;
}
}