| 329 | } |
| 330 | |
| 331 | void PeerPhoto::clear(not_null<PhotoData*> photo) { |
| 332 | const auto self = _session->user(); |
| 333 | if (self->userpicPhotoId() == photo->id) { |
| 334 | const auto photoId = photo->id; |
| 335 | const auto peerId = self->id; |
| 336 | _api.request(MTPphotos_UpdateProfilePhoto( |
| 337 | MTP_flags(0), |
| 338 | MTPInputUser(), // bot |
| 339 | MTP_inputPhotoEmpty() |
| 340 | )).done([=](const MTPphotos_Photo &result) { |
| 341 | self->setPhoto(MTP_userProfilePhotoEmpty()); |
| 342 | _session->storage().remove( |
| 343 | Storage::UserPhotosRemoveOne(peerToUser(peerId), photoId)); |
| 344 | }).send(); |
| 345 | } else if (photo->peer && photo->peer->userpicPhotoId() == photo->id) { |
| 346 | const auto applier = [=](const MTPUpdates &result) { |
| 347 | _session->updates().applyUpdates(result); |
| 348 | }; |
| 349 | if (const auto chat = photo->peer->asChat()) { |
| 350 | _api.request(MTPmessages_EditChatPhoto( |
| 351 | chat->inputChat(), |
| 352 | MTP_inputChatPhotoEmpty() |
| 353 | )).done(applier).send(); |
| 354 | } else if (const auto channel = photo->peer->asChannel()) { |
| 355 | _api.request(MTPchannels_EditPhoto( |
| 356 | channel->inputChannel(), |
| 357 | MTP_inputChatPhotoEmpty() |
| 358 | )).done(applier).send(); |
| 359 | } |
| 360 | } else { |
| 361 | const auto fallbackPhotoId = SyncUserFallbackPhotoViewer(self); |
| 362 | if (fallbackPhotoId && (*fallbackPhotoId) == photo->id) { |
| 363 | _api.request(MTPphotos_UpdateProfilePhoto( |
| 364 | MTP_flags(MTPphotos_UpdateProfilePhoto::Flag::f_fallback), |
| 365 | MTPInputUser(), // bot |
| 366 | MTP_inputPhotoEmpty() |
| 367 | )).send(); |
| 368 | _session->storage().add(Storage::UserPhotosSetBack( |
| 369 | peerToUser(self->id), |
| 370 | PhotoId())); |
| 371 | } else { |
| 372 | _api.request(MTPphotos_DeletePhotos( |
| 373 | MTP_vector<MTPInputPhoto>(1, photo->mtpInput()) |
| 374 | )).send(); |
| 375 | _session->storage().remove(Storage::UserPhotosRemoveOne( |
| 376 | peerToUser(self->id), |
| 377 | photo->id)); |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | void PeerPhoto::clearPersonal(not_null<UserData*> user) { |
| 383 | _api.request(MTPphotos_UploadContactProfilePhoto( |
no test coverage detected