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,
const std::vector<not_null<UserData*>> &users);
rpl::producer<SendAction> sendActions() const {
return _sendActions.events();
}

View File

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

View File

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

View File

@ -230,6 +230,7 @@ MainWidget::MainWidget(
not_null<Window::SessionController*> controller)
: RpWidget(parent)
, _controller(controller)
, _api(&controller->session().mtp())
, _dialogsWidth(st::columnMinimalWidthLeft)
, _thirdColumnWidth(st::columnMinimalWidthThird)
, _sideShadow(this)
@ -1264,7 +1265,6 @@ void MainWidget::scheduleViewIncrement(HistoryItem *item) {
}
void MainWidget::viewsIncrement() {
const auto api = &session().api();
for (auto i = _viewsToIncrement.begin(); i != _viewsToIncrement.cend();) {
if (_viewsIncrementRequests.contains(i->first)) {
++i;
@ -1276,7 +1276,7 @@ void MainWidget::viewsIncrement() {
for (const auto msgId : i->second) {
ids.push_back(MTP_int(msgId));
}
const auto requestId = api->request(MTPmessages_GetMessagesViews(
const auto requestId = _api.request(MTPmessages_GetMessagesViews(
i->first->input,
MTP_vector<MTPint>(ids),
MTP_bool(true)
@ -2624,7 +2624,7 @@ void MainWidget::openPeerByName(
});
}
} else {
session().api().request(MTPcontacts_ResolveUsername(
_api.request(MTPcontacts_ResolveUsername(
MTP_string(username)
)).done([=](const MTPcontacts_ResolvedPeer &result) {
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/effects/animations.h"
#include "media/player/media_player_float.h"
#include "mtproto/sender.h"
#include "data/data_pts_waiter.h"
class RPCError;
@ -350,6 +351,7 @@ private:
void handleHistoryBack();
const not_null<Window::SessionController*> _controller;
MTP::Sender _api;
Ui::Animations::Simple _a_show;
bool _showBack = false;

View File

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

View File

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