| 246 | } |
| 247 | |
| 248 | void Controller::checkLockByTerms() { |
| 249 | const auto data = account().sessionExists() |
| 250 | ? account().session().termsLocked() |
| 251 | : std::nullopt; |
| 252 | if (!data) { |
| 253 | if (_termsBox) { |
| 254 | _termsBox->closeBox(); |
| 255 | } |
| 256 | return; |
| 257 | } |
| 258 | hideSettingsAndLayer(anim::type::instant); |
| 259 | const auto box = show(Box<TermsBox>( |
| 260 | *data, |
| 261 | tr::lng_terms_agree(), |
| 262 | tr::lng_terms_decline())); |
| 263 | |
| 264 | box->setCloseByEscape(false); |
| 265 | box->setCloseByOutsideClick(false); |
| 266 | |
| 267 | const auto id = data->id; |
| 268 | box->agreeClicks( |
| 269 | ) | rpl::on_next([=] { |
| 270 | const auto mention = box ? box->lastClickedMention() : QString(); |
| 271 | box->closeBox(); |
| 272 | if (const auto session = account().maybeSession()) { |
| 273 | session->api().acceptTerms(id); |
| 274 | session->unlockTerms(); |
| 275 | if (!mention.isEmpty()) { |
| 276 | MentionClickHandler(mention).onClick({}); |
| 277 | } |
| 278 | } |
| 279 | }, box->lifetime()); |
| 280 | |
| 281 | box->cancelClicks( |
| 282 | ) | rpl::on_next([=] { |
| 283 | showTermsDecline(); |
| 284 | }, box->lifetime()); |
| 285 | |
| 286 | QObject::connect(box.get(), &QObject::destroyed, [=] { |
| 287 | crl::on_main(widget(), [=] { checkLockByTerms(); }); |
| 288 | }); |
| 289 | |
| 290 | _termsBox = box; |
| 291 | } |
| 292 | |
| 293 | void Controller::showTermsDecline() { |
| 294 | const auto box = show(Box<Window::TermsBox>( |
nothing calls this directly
no test coverage detected