Replace InvokeQueued with on_main for has_weak_ptr.

This commit is contained in:
John Preston 2018-06-07 21:04:51 +03:00
parent c63c75018d
commit c2fa149ffd
3 changed files with 13 additions and 27 deletions

View File

@ -315,24 +315,3 @@ struct guard_traits<
};
} // namespace crl
#ifdef QT_VERSION
template <typename Lambda>
inline void InvokeQueued(const base::has_weak_ptr *context, Lambda &&lambda) {
auto callback = [
guard = base::make_weak(context),
lambda = std::forward<Lambda>(lambda)
] {
if (guard) {
lambda();
}
};
QObject proxy;
QObject::connect(
&proxy,
&QObject::destroyed,
QCoreApplication::instance(),
std::move(callback),
Qt::QueuedConnection);
}
#endif // QT_VERSION

View File

@ -632,7 +632,7 @@ void Call::handleControllerBarCountChange(
// Expects(controller == _controller.get());
Expects(controller->implData == static_cast<void*>(this));
InvokeQueued(this, [=] {
crl::on_main(this, [=] {
setSignalBarCount(count);
});
}
@ -763,10 +763,17 @@ void Call::finish(FinishType type, const MTPPhoneCallDiscardReason &reason) {
auto duration = getDurationMs() / 1000;
auto connectionId = _controller ? _controller->GetPreferredRelayID() : 0;
_finishByTimeoutTimer.call(kHangupTimeoutMs, [this, finalState] { setState(finalState); });
request(MTPphone_DiscardCall(MTP_inputPhoneCall(MTP_long(_id), MTP_long(_accessHash)), MTP_int(duration), reason, MTP_long(connectionId))).done([this, finalState](const MTPUpdates &result) {
request(MTPphone_DiscardCall(
MTP_inputPhoneCall(
MTP_long(_id),
MTP_long(_accessHash)),
MTP_int(duration),
reason,
MTP_long(connectionId)
)).done([=](const MTPUpdates &result) {
// This could be destroyed by updates, so we set Ended after
// updates being handled, but in a guarded way.
InvokeQueued(this, [this, finalState] { setState(finalState); });
crl::on_main(this, [=] { setState(finalState); });
App::main()->sentUpdatesReceived(result);
}).fail([this, finalState](const RPCError &error) {
setState(finalState);
@ -774,13 +781,13 @@ void Call::finish(FinishType type, const MTPPhoneCallDiscardReason &reason) {
}
void Call::setStateQueued(State state) {
InvokeQueued(this, [=] {
crl::on_main(this, [=] {
setState(state);
});
}
void Call::setFailedQueued(int error) {
InvokeQueued(this, [=] {
crl::on_main(this, [=] {
handleControllerError(error);
});
}

View File

@ -1254,7 +1254,7 @@ MtpChecker::MtpChecker(QPointer<MTP::Instance> instance, bool testing)
void MtpChecker::start() {
if (!_mtp.valid()) {
LOG(("Update Info: MTP is unavailable."));
InvokeQueued(this, [=] { fail(); });
crl::on_main(this, [=] { fail(); });
return;
}
constexpr auto kFeedUsername = "tdhbcfeed";