| 79 | }; |
| 80 | |
| 81 | ResolvePhoneAction::ResolvePhoneAction( |
| 82 | not_null<Ui::Menu::Menu*> parent, |
| 83 | const style::PopupMenu &st, |
| 84 | const QString &phone, |
| 85 | not_null<Window::SessionController*> controller) |
| 86 | : ItemBase(parent, st.menu) |
| 87 | , _dummyAction(Ui::CreateChild<QAction>(parent)) |
| 88 | , _st(st.menu) |
| 89 | , _api(&controller->session().mtp()) |
| 90 | , _height(rect::m::sum::v(st::groupCallJoinAsPadding) |
| 91 | + st::groupCallJoinAsPhotoSize) { |
| 92 | setAcceptBoth(true); |
| 93 | fitToMenuWidth(); |
| 94 | setActionTriggered([=] { |
| 95 | if (const auto peer = _peer.current()) { |
| 96 | controller->showPeerInfo(peer); |
| 97 | } |
| 98 | }); |
| 99 | |
| 100 | const auto formattedPhone = Trim(phone); |
| 101 | |
| 102 | const auto owner = &controller->session().data(); |
| 103 | |
| 104 | if (const auto peer = owner->userByPhone(formattedPhone)) { |
| 105 | _peer = peer; |
| 106 | _loaded.force_assign(true); |
| 107 | } else { |
| 108 | _api.request(MTPcontacts_ResolvePhone( |
| 109 | MTP_string(phone) |
| 110 | )).done([=](const MTPcontacts_ResolvedPeer &result) { |
| 111 | result.match([&](const MTPDcontacts_resolvedPeer &data) { |
| 112 | owner->processUsers(data.vusers()); |
| 113 | owner->processChats(data.vchats()); |
| 114 | if (const auto peerId = peerFromMTP(data.vpeer())) { |
| 115 | _peer = owner->peer(peerId); |
| 116 | } |
| 117 | _loaded.force_assign(true); |
| 118 | }); |
| 119 | }).fail([=](const MTP::Error &error) { |
| 120 | if (error.code() == 400) { |
| 121 | _peer.force_assign(nullptr); |
| 122 | _loaded.force_assign(true); |
| 123 | } |
| 124 | }).send(); |
| 125 | } |
| 126 | |
| 127 | paintRequest( |
| 128 | ) | rpl::on_next([=] { |
| 129 | Painter p(this); |
| 130 | paint(p); |
| 131 | }, lifetime()); |
| 132 | |
| 133 | enableMouseSelecting(); |
| 134 | prepare(); |
| 135 | } |
| 136 | |
| 137 | QString ResolvePhoneAction::firstName() const { |
| 138 | const auto peer = _peer.current(); |
nothing calls this directly
no test coverage detected