Skip to content

Commit

Permalink
Replace InvokeQueued with on_main for has_weak_ptr.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Jun 11, 2018
1 parent c63c750 commit c2fa149
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 27 deletions.
21 changes: 0 additions & 21 deletions Telegram/SourceFiles/base/weak_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 12 additions & 5 deletions Telegram/SourceFiles/calls/calls_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down Expand Up @@ -763,24 +763,31 @@ 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);
}).send();
}

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);
});
}
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/core/update_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit c2fa149

Please sign in to comment.