| 196 | } |
| 197 | |
| 198 | void PeerPhoto::updateSelf( |
| 199 | not_null<PhotoData*> photo, |
| 200 | Data::FileOrigin origin, |
| 201 | Fn<void()> done) { |
| 202 | const auto send = [=](auto resend) -> void { |
| 203 | const auto usedFileReference = photo->fileReference(); |
| 204 | _api.request(MTPphotos_UpdateProfilePhoto( |
| 205 | MTP_flags(0), |
| 206 | MTPInputUser(), // bot |
| 207 | photo->mtpInput() |
| 208 | )).done([=](const MTPphotos_Photo &result) { |
| 209 | result.match([&](const MTPDphotos_photo &data) { |
| 210 | _session->data().processPhoto(data.vphoto()); |
| 211 | _session->data().processUsers(data.vusers()); |
| 212 | }); |
| 213 | if (done) { |
| 214 | done(); |
| 215 | } |
| 216 | }).fail([=](const MTP::Error &error) { |
| 217 | if (error.code() == 400 |
| 218 | && error.type().startsWith(u"FILE_REFERENCE_"_q)) { |
| 219 | photo->session().api().refreshFileReference(origin, [=]( |
| 220 | const auto &) { |
| 221 | if (photo->fileReference() != usedFileReference) { |
| 222 | resend(resend); |
| 223 | } |
| 224 | }); |
| 225 | } |
| 226 | }).send(); |
| 227 | }; |
| 228 | send(send); |
| 229 | } |
| 230 | |
| 231 | void PeerPhoto::upload( |
| 232 | not_null<PeerData*> peer, |
no test coverage detected