| 320 | } |
| 321 | |
| 322 | void RequestButton( |
| 323 | std::shared_ptr<Ui::Show> show, |
| 324 | const MTPDurlAuthResultRequest &request, |
| 325 | not_null<const HistoryItem*> message, |
| 326 | int row, |
| 327 | int column) { |
| 328 | const auto itemId = message->fullId(); |
| 329 | const auto button = HistoryMessageMarkupButton::Get( |
| 330 | &message->history()->owner(), |
| 331 | itemId, |
| 332 | row, |
| 333 | column); |
| 334 | if (!button || button->requestId || !message->isRegular()) { |
| 335 | return; |
| 336 | } |
| 337 | const auto session = &message->history()->session(); |
| 338 | const auto inputPeer = message->history()->peer->input(); |
| 339 | const auto buttonId = button->buttonId; |
| 340 | const auto url = QString::fromUtf8(button->data); |
| 341 | |
| 342 | const auto bot = request.is_request_write_access() |
| 343 | ? session->data().processUser(request.vbot()).get() |
| 344 | : nullptr; |
| 345 | const auto box = std::make_shared<base::weak_qptr<Ui::BoxContent>>(); |
| 346 | const auto finishWithUrl = [=](const QString &url, bool accepted) { |
| 347 | if (*box) { |
| 348 | (*box)->closeBox(); |
| 349 | } |
| 350 | if (url.isEmpty() && accepted) { |
| 351 | show->showToast(tr::lng_passport_success(tr::now)); |
| 352 | } else { |
| 353 | UrlClickHandler::Open(url); |
| 354 | } |
| 355 | }; |
| 356 | const auto callback = [=](Result result) { |
| 357 | if (!result.auth) { |
| 358 | session->api().request(MTPmessages_DeclineUrlAuth( |
| 359 | MTP_string(url) |
| 360 | )).send(); |
| 361 | finishWithUrl(url, false); |
| 362 | } else if (session->data().message(itemId)) { |
| 363 | using Flag = MTPmessages_AcceptUrlAuth::Flag; |
| 364 | const auto flags = Flag(0) |
| 365 | | (result.allowWrite ? Flag::f_write_allowed : Flag(0)) |
| 366 | | (result.sharePhone ? Flag::f_share_phone_number : Flag(0)) |
| 367 | | (result.matchCode.isEmpty() ? Flag(0) : Flag::f_match_code) |
| 368 | | (Flag::f_peer | Flag::f_msg_id | Flag::f_button_id); |
| 369 | session->api().request(MTPmessages_AcceptUrlAuth( |
| 370 | MTP_flags(flags), |
| 371 | inputPeer, |
| 372 | MTP_int(itemId.msg), |
| 373 | MTP_int(buttonId), |
| 374 | MTPstring(), |
| 375 | result.matchCode.isEmpty() |
| 376 | ? MTPstring() |
| 377 | : MTP_string(result.matchCode) |
| 378 | )).done([=](const MTPUrlAuthResult &result) { |
| 379 | const auto accepted = result.match( |
no test coverage detected