| 667 | } |
| 668 | |
| 669 | void CheckChatInvite( |
| 670 | not_null<Window::SessionController*> controller, |
| 671 | const QString &hash, |
| 672 | ChannelData *invitePeekChannel, |
| 673 | Fn<void()> loaded) { |
| 674 | const auto session = &controller->session(); |
| 675 | const auto weak = base::make_weak(controller); |
| 676 | session->api().checkChatInvite(hash, [=](const MTPChatInvite &result) { |
| 677 | const auto strong = weak.get(); |
| 678 | if (!strong) { |
| 679 | return; |
| 680 | } |
| 681 | if (loaded) { |
| 682 | loaded(); |
| 683 | } |
| 684 | Core::App().hideMediaView(); |
| 685 | const auto show = [&](not_null<PeerData*> chat) { |
| 686 | const auto way = Window::SectionShow::Way::Forward; |
| 687 | if (const auto forum = chat->forum()) { |
| 688 | strong->showForum(forum, way); |
| 689 | } else { |
| 690 | strong->showPeerHistory(chat, way); |
| 691 | } |
| 692 | }; |
| 693 | result.match([=](const MTPDchatInvite &data) { |
| 694 | const auto isGroup = !data.is_broadcast(); |
| 695 | const auto hasPricing = !!data.vsubscription_pricing(); |
| 696 | const auto canRefulfill = data.is_can_refulfill_subscription(); |
| 697 | if (hasPricing |
| 698 | && !canRefulfill |
| 699 | && !data.vsubscription_form_id()) { |
| 700 | strong->uiShow()->showToast( |
| 701 | tr::lng_confirm_phone_link_invalid(tr::now)); |
| 702 | return; |
| 703 | } |
| 704 | const auto box = (hasPricing && !canRefulfill) |
| 705 | ? strong->show(Box( |
| 706 | ConfirmSubscriptionBox, |
| 707 | session, |
| 708 | hash, |
| 709 | &data)) |
| 710 | : strong->show(Box( |
| 711 | ConfirmInviteBox, |
| 712 | session, |
| 713 | &data, |
| 714 | invitePeekChannel, |
| 715 | [=] { SubmitChatInvite(weak, session, hash, isGroup); })); |
| 716 | if (invitePeekChannel) { |
| 717 | box->boxClosing( |
| 718 | ) | rpl::filter([=] { |
| 719 | return !invitePeekChannel->amIn(); |
| 720 | }) | rpl::on_next([=] { |
| 721 | if (const auto strong = weak.get()) { |
| 722 | strong->clearSectionStack(Window::SectionShow( |
| 723 | Window::SectionShow::Way::ClearStack, |
| 724 | anim::type::normal, |
| 725 | anim::activation::background)); |
| 726 | } |
no test coverage detected