Fix crashes in MainWidget and ApiWrap.

This commit is contained in:
John Preston 2020-06-30 18:26:44 +04:00
parent 09aff23ac9
commit c15019dee6
7 changed files with 16 additions and 18 deletions

View File

@ -368,7 +368,6 @@ public:
not_null<PeerData*> peer, not_null<PeerData*> peer,
const std::vector<not_null<UserData*>> &users); const std::vector<not_null<UserData*>> &users);
rpl::producer<SendAction> sendActions() const { rpl::producer<SendAction> sendActions() const {
return _sendActions.events(); return _sendActions.events();
} }

View File

@ -781,12 +781,12 @@ bool BackgroundPreviewBox::Start(
Ui::show(Box<InformBox>(tr::lng_background_bad_link(tr::now))); Ui::show(Box<InformBox>(tr::lng_background_bad_link(tr::now)));
return false; return false;
} }
controller->session().api().requestWallPaper(slug, [=]( controller->session().api().requestWallPaper(slug, crl::guard(controller, [=](
const Data::WallPaper &result) { const Data::WallPaper &result) {
Ui::show(Box<BackgroundPreviewBox>( Ui::show(Box<BackgroundPreviewBox>(
controller, controller,
result.withUrlParams(params))); result.withUrlParams(params)));
}, [](const RPCError &error) { }), [](const RPCError &error) {
Ui::show(Box<InformBox>(tr::lng_background_bad_link(tr::now))); Ui::show(Box<InformBox>(tr::lng_background_bad_link(tr::now)));
}); });
return true; return true;

View File

@ -321,12 +321,12 @@ bool ResolvePrivatePost(
if (!channelId || !IsServerMsgId(msgId)) { if (!channelId || !IsServerMsgId(msgId)) {
return false; return false;
} }
const auto done = [=](not_null<PeerData*> peer) { const auto done = crl::guard(controller, [=](not_null<PeerData*> peer) {
App::wnd()->sessionController()->showPeerHistory( controller->showPeerHistory(
peer->id, peer->id,
Window::SectionShow::Way::Forward, Window::SectionShow::Way::Forward,
msgId); msgId);
}; });
const auto fail = [=] { const auto fail = [=] {
Ui::show(Box<InformBox>(tr::lng_error_post_link_invalid(tr::now))); Ui::show(Box<InformBox>(tr::lng_error_post_link_invalid(tr::now)));
}; };
@ -388,7 +388,7 @@ bool HandleUnknown(
return false; return false;
} }
const auto request = match->captured(1); const auto request = match->captured(1);
const auto callback = [=](const MTPDhelp_deepLinkInfo &result) { const auto callback = crl::guard(controller, [=](const MTPDhelp_deepLinkInfo &result) {
const auto text = TextWithEntities{ const auto text = TextWithEntities{
qs(result.vmessage()), qs(result.vmessage()),
Api::EntitiesFromMTP( Api::EntitiesFromMTP(
@ -408,7 +408,7 @@ bool HandleUnknown(
} else { } else {
Ui::show(Box<InformBox>(text)); Ui::show(Box<InformBox>(text));
} }
}; });
controller->session().api().requestDeepLinkInfo(request, callback); controller->session().api().requestDeepLinkInfo(request, callback);
return true; return true;
} }

View File

@ -230,6 +230,7 @@ MainWidget::MainWidget(
not_null<Window::SessionController*> controller) not_null<Window::SessionController*> controller)
: RpWidget(parent) : RpWidget(parent)
, _controller(controller) , _controller(controller)
, _api(&controller->session().mtp())
, _dialogsWidth(st::columnMinimalWidthLeft) , _dialogsWidth(st::columnMinimalWidthLeft)
, _thirdColumnWidth(st::columnMinimalWidthThird) , _thirdColumnWidth(st::columnMinimalWidthThird)
, _sideShadow(this) , _sideShadow(this)
@ -1264,7 +1265,6 @@ void MainWidget::scheduleViewIncrement(HistoryItem *item) {
} }
void MainWidget::viewsIncrement() { void MainWidget::viewsIncrement() {
const auto api = &session().api();
for (auto i = _viewsToIncrement.begin(); i != _viewsToIncrement.cend();) { for (auto i = _viewsToIncrement.begin(); i != _viewsToIncrement.cend();) {
if (_viewsIncrementRequests.contains(i->first)) { if (_viewsIncrementRequests.contains(i->first)) {
++i; ++i;
@ -1276,7 +1276,7 @@ void MainWidget::viewsIncrement() {
for (const auto msgId : i->second) { for (const auto msgId : i->second) {
ids.push_back(MTP_int(msgId)); ids.push_back(MTP_int(msgId));
} }
const auto requestId = api->request(MTPmessages_GetMessagesViews( const auto requestId = _api.request(MTPmessages_GetMessagesViews(
i->first->input, i->first->input,
MTP_vector<MTPint>(ids), MTP_vector<MTPint>(ids),
MTP_bool(true) MTP_bool(true)
@ -2624,7 +2624,7 @@ void MainWidget::openPeerByName(
}); });
} }
} else { } else {
session().api().request(MTPcontacts_ResolveUsername( _api.request(MTPcontacts_ResolveUsername(
MTP_string(username) MTP_string(username)
)).done([=](const MTPcontacts_ResolvedPeer &result) { )).done([=](const MTPcontacts_ResolvedPeer &result) {
usernameResolveDone(result, msgId, startToken); usernameResolveDone(result, msgId, startToken);

View File

@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/rp_widget.h" #include "ui/rp_widget.h"
#include "ui/effects/animations.h" #include "ui/effects/animations.h"
#include "media/player/media_player_float.h" #include "media/player/media_player_float.h"
#include "mtproto/sender.h"
#include "data/data_pts_waiter.h" #include "data/data_pts_waiter.h"
class RPCError; class RPCError;
@ -350,6 +351,7 @@ private:
void handleHistoryBack(); void handleHistoryBack();
const not_null<Window::SessionController*> _controller; const not_null<Window::SessionController*> _controller;
MTP::Sender _api;
Ui::Animations::Simple _a_show; Ui::Animations::Simple _a_show;
bool _showBack = false; bool _showBack = false;

View File

@ -1023,7 +1023,7 @@ void PeerMenuAddChannelMembers(
return; return;
} }
const auto api = &channel->session().api(); const auto api = &channel->session().api();
api->requestChannelMembersForAdd(channel, [=]( api->requestChannelMembersForAdd(channel, crl::guard(navigation, [=](
const MTPchannels_ChannelParticipants &result) { const MTPchannels_ChannelParticipants &result) {
api->parseChannelParticipants(channel, result, [&]( api->parseChannelParticipants(channel, result, [&](
int availableCount, int availableCount,
@ -1045,7 +1045,7 @@ void PeerMenuAddChannelMembers(
channel, channel,
{ already.begin(), already.end() }); { already.begin(), already.end() });
}); });
}); }));
} }
void PeerMenuAddMuteAction( void PeerMenuAddMuteAction(

View File

@ -116,7 +116,7 @@ struct SectionShow {
class SessionController; class SessionController;
class SessionNavigation { class SessionNavigation : public base::has_weak_ptr {
public: public:
explicit SessionNavigation(not_null<Main::Session*> session); explicit SessionNavigation(not_null<Main::Session*> session);
@ -156,10 +156,7 @@ private:
}; };
class SessionController class SessionController : public SessionNavigation, private base::Subscriber {
: public SessionNavigation
, public base::has_weak_ptr
, private base::Subscriber {
public: public:
SessionController( SessionController(
not_null<Main::Session*> session, not_null<Main::Session*> session,