2017-03-22 15:38:40 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-03-22 15:38:40 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-03-22 15:38:40 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "base/variant.h"
|
2021-03-12 12:48:00 +00:00
|
|
|
#include "mtproto/mtproto_response.h"
|
2019-11-13 08:31:12 +00:00
|
|
|
#include "mtproto/mtp_instance.h"
|
|
|
|
#include "mtproto/facade.h"
|
2017-03-22 15:38:40 +00:00
|
|
|
|
|
|
|
namespace MTP {
|
|
|
|
|
|
|
|
class Sender {
|
|
|
|
class RequestBuilder {
|
|
|
|
public:
|
|
|
|
RequestBuilder(const RequestBuilder &other) = delete;
|
|
|
|
RequestBuilder &operator=(const RequestBuilder &other) = delete;
|
|
|
|
RequestBuilder &operator=(RequestBuilder &&other) = delete;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
enum class FailSkipPolicy {
|
|
|
|
Simple,
|
|
|
|
HandleFlood,
|
|
|
|
HandleAll,
|
|
|
|
};
|
2021-03-12 10:45:13 +00:00
|
|
|
using FailPlainHandler = Fn<void()>;
|
2021-03-12 12:48:00 +00:00
|
|
|
using FailErrorHandler = Fn<void(const Error&)>;
|
|
|
|
using FailRequestIdHandler = Fn<void(const Error&, mtpRequestId)>;
|
|
|
|
using FailFullHandler = Fn<void(const Error&, const Response&)>;
|
2021-03-12 10:45:13 +00:00
|
|
|
|
|
|
|
template <typename ...Args>
|
|
|
|
static constexpr bool IsCallable
|
|
|
|
= rpl::details::is_callable_plain_v<Args...>;
|
|
|
|
|
|
|
|
template <typename Result, typename Handler>
|
|
|
|
[[nodiscard]] DoneHandler MakeDoneHandler(
|
|
|
|
not_null<Sender*> sender,
|
|
|
|
Handler &&handler) {
|
|
|
|
return [sender, handler = std::forward<Handler>(handler)](
|
|
|
|
const Response &response) mutable {
|
|
|
|
auto onstack = std::move(handler);
|
|
|
|
sender->senderRequestHandled(response.requestId);
|
|
|
|
|
|
|
|
auto result = Result();
|
|
|
|
auto from = response.reply.constData();
|
|
|
|
if (!result.read(from, from + response.reply.size())) {
|
2019-07-18 14:06:38 +00:00
|
|
|
return false;
|
2021-03-12 10:45:13 +00:00
|
|
|
} else if (!onstack) {
|
|
|
|
return true;
|
|
|
|
} else if constexpr (IsCallable<
|
|
|
|
Handler,
|
|
|
|
const Result&,
|
|
|
|
const Response&>) {
|
|
|
|
onstack(result, response);
|
|
|
|
} else if constexpr (IsCallable<
|
|
|
|
Handler,
|
|
|
|
const Result&,
|
|
|
|
mtpRequestId>) {
|
|
|
|
onstack(result, response.requestId);
|
|
|
|
} else if constexpr (IsCallable<
|
|
|
|
Handler,
|
|
|
|
const Result&>) {
|
|
|
|
onstack(result);
|
|
|
|
} else if constexpr (IsCallable<Handler>) {
|
|
|
|
onstack();
|
|
|
|
} else {
|
|
|
|
static_assert(false_t(Handler{}), "Bad done handler.");
|
2017-03-22 15:38:40 +00:00
|
|
|
}
|
2019-07-18 14:06:38 +00:00
|
|
|
return true;
|
2021-03-12 10:45:13 +00:00
|
|
|
};
|
|
|
|
}
|
2017-03-22 15:38:40 +00:00
|
|
|
|
2021-03-12 10:45:13 +00:00
|
|
|
template <typename Handler>
|
|
|
|
[[nodiscard]] FailHandler MakeFailHandler(
|
|
|
|
not_null<Sender*> sender,
|
|
|
|
Handler &&handler,
|
|
|
|
FailSkipPolicy skipPolicy) {
|
|
|
|
return [
|
|
|
|
sender,
|
|
|
|
handler = std::forward<Handler>(handler),
|
|
|
|
skipPolicy
|
2021-03-12 12:48:00 +00:00
|
|
|
](const Error &error, const Response &response) {
|
2021-03-12 10:45:13 +00:00
|
|
|
if (skipPolicy == FailSkipPolicy::Simple) {
|
2021-03-12 12:48:00 +00:00
|
|
|
if (IsDefaultHandledError(error)) {
|
2017-03-22 15:38:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-03-12 10:45:13 +00:00
|
|
|
} else if (skipPolicy == FailSkipPolicy::HandleFlood) {
|
2021-03-12 12:48:00 +00:00
|
|
|
if (IsDefaultHandledError(error) && !IsFloodError(error)) {
|
2017-03-22 15:38:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-12 10:45:13 +00:00
|
|
|
auto onstack = handler;
|
|
|
|
sender->senderRequestHandled(response.requestId);
|
|
|
|
|
|
|
|
if (!onstack) {
|
|
|
|
return true;
|
|
|
|
} else if constexpr (IsCallable<
|
|
|
|
Handler,
|
2021-03-12 12:48:00 +00:00
|
|
|
const Error&,
|
2021-03-12 10:45:13 +00:00
|
|
|
const Response&>) {
|
|
|
|
onstack(error, response);
|
|
|
|
} else if constexpr (IsCallable<
|
|
|
|
Handler,
|
2021-03-12 12:48:00 +00:00
|
|
|
const Error&,
|
2021-03-12 10:45:13 +00:00
|
|
|
mtpRequestId>) {
|
|
|
|
onstack(error, response.requestId);
|
|
|
|
} else if constexpr (IsCallable<
|
|
|
|
Handler,
|
2021-03-12 12:48:00 +00:00
|
|
|
const Error&>) {
|
2021-03-12 10:45:13 +00:00
|
|
|
onstack(error);
|
|
|
|
} else if constexpr (IsCallable<Handler>) {
|
|
|
|
onstack();
|
|
|
|
} else {
|
|
|
|
static_assert(false_t(Handler{}), "Bad fail handler.");
|
2017-03-22 15:38:40 +00:00
|
|
|
}
|
|
|
|
return true;
|
2021-03-12 10:45:13 +00:00
|
|
|
};
|
|
|
|
}
|
2017-03-22 15:38:40 +00:00
|
|
|
|
2021-03-12 10:45:13 +00:00
|
|
|
explicit RequestBuilder(not_null<Sender*> sender) noexcept
|
|
|
|
: _sender(sender) {
|
2017-03-22 15:38:40 +00:00
|
|
|
}
|
|
|
|
RequestBuilder(RequestBuilder &&other) = default;
|
|
|
|
|
|
|
|
void setToDC(ShiftedDcId dcId) noexcept {
|
|
|
|
_dcId = dcId;
|
|
|
|
}
|
2019-02-19 06:57:53 +00:00
|
|
|
void setCanWait(crl::time ms) noexcept {
|
2017-03-22 15:38:40 +00:00
|
|
|
_canWait = ms;
|
|
|
|
}
|
2021-03-12 10:45:13 +00:00
|
|
|
void setDoneHandler(DoneHandler &&handler) noexcept {
|
2017-03-22 15:38:40 +00:00
|
|
|
_done = std::move(handler);
|
|
|
|
}
|
2021-03-12 10:45:13 +00:00
|
|
|
template <typename Handler>
|
|
|
|
void setFailHandler(Handler &&handler) noexcept {
|
|
|
|
_fail = std::forward<Handler>(handler);
|
2017-03-22 15:38:40 +00:00
|
|
|
}
|
|
|
|
void setFailSkipPolicy(FailSkipPolicy policy) noexcept {
|
|
|
|
_failSkipPolicy = policy;
|
|
|
|
}
|
|
|
|
void setAfter(mtpRequestId requestId) noexcept {
|
|
|
|
_afterRequestId = requestId;
|
|
|
|
}
|
|
|
|
|
|
|
|
ShiftedDcId takeDcId() const noexcept {
|
|
|
|
return _dcId;
|
|
|
|
}
|
2019-02-19 06:57:53 +00:00
|
|
|
crl::time takeCanWait() const noexcept {
|
2017-03-22 15:38:40 +00:00
|
|
|
return _canWait;
|
|
|
|
}
|
2021-03-12 10:45:13 +00:00
|
|
|
DoneHandler takeOnDone() noexcept {
|
2017-03-22 15:38:40 +00:00
|
|
|
return std::move(_done);
|
|
|
|
}
|
2021-03-12 10:45:13 +00:00
|
|
|
FailHandler takeOnFail() {
|
|
|
|
return v::match(_fail, [&](auto &value) {
|
|
|
|
return MakeFailHandler(
|
2020-08-31 08:14:53 +00:00
|
|
|
_sender,
|
|
|
|
std::move(value),
|
|
|
|
_failSkipPolicy);
|
|
|
|
});
|
2017-03-22 15:38:40 +00:00
|
|
|
}
|
|
|
|
mtpRequestId takeAfter() const noexcept {
|
|
|
|
return _afterRequestId;
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<Sender*> sender() const noexcept {
|
2017-03-22 15:38:40 +00:00
|
|
|
return _sender;
|
|
|
|
}
|
|
|
|
void registerRequest(mtpRequestId requestId) {
|
2017-08-14 12:48:11 +00:00
|
|
|
_sender->senderRequestRegister(requestId);
|
2017-03-22 15:38:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<Sender*> _sender;
|
2017-03-22 15:38:40 +00:00
|
|
|
ShiftedDcId _dcId = 0;
|
2019-02-19 06:57:53 +00:00
|
|
|
crl::time _canWait = 0;
|
2021-03-12 10:45:13 +00:00
|
|
|
DoneHandler _done;
|
|
|
|
std::variant<
|
|
|
|
FailPlainHandler,
|
|
|
|
FailErrorHandler,
|
|
|
|
FailRequestIdHandler,
|
|
|
|
FailFullHandler> _fail;
|
2017-03-22 15:38:40 +00:00
|
|
|
FailSkipPolicy _failSkipPolicy = FailSkipPolicy::Simple;
|
|
|
|
mtpRequestId _afterRequestId = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
2019-11-27 08:02:56 +00:00
|
|
|
explicit Sender(not_null<Instance*> instance) noexcept
|
|
|
|
: _instance(instance) {
|
|
|
|
}
|
|
|
|
|
2020-06-17 09:36:25 +00:00
|
|
|
[[nodiscard]] Instance &instance() const {
|
|
|
|
return *_instance;
|
2017-03-22 15:38:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Request>
|
|
|
|
class SpecificRequestBuilder : public RequestBuilder {
|
|
|
|
private:
|
|
|
|
friend class Sender;
|
2021-03-12 10:45:13 +00:00
|
|
|
SpecificRequestBuilder(not_null<Sender*> sender, Request &&request) noexcept
|
|
|
|
: RequestBuilder(sender)
|
|
|
|
, _request(std::move(request)) {
|
2017-03-22 15:38:40 +00:00
|
|
|
}
|
|
|
|
SpecificRequestBuilder(SpecificRequestBuilder &&other) = default;
|
|
|
|
|
|
|
|
public:
|
2017-10-13 19:07:04 +00:00
|
|
|
[[nodiscard]] SpecificRequestBuilder &toDC(ShiftedDcId dcId) noexcept {
|
2017-03-22 15:38:40 +00:00
|
|
|
setToDC(dcId);
|
|
|
|
return *this;
|
|
|
|
}
|
2019-02-19 06:57:53 +00:00
|
|
|
[[nodiscard]] SpecificRequestBuilder &afterDelay(crl::time ms) noexcept {
|
2017-03-22 15:38:40 +00:00
|
|
|
setCanWait(ms);
|
|
|
|
return *this;
|
|
|
|
}
|
2021-03-12 10:45:13 +00:00
|
|
|
|
|
|
|
using Result = typename Request::ResponseType;
|
|
|
|
[[nodiscard]] SpecificRequestBuilder &done(
|
|
|
|
FnMut<void(
|
|
|
|
const Result &result,
|
|
|
|
mtpRequestId requestId)> callback) {
|
|
|
|
setDoneHandler(
|
|
|
|
MakeDoneHandler<Result>(sender(), std::move(callback)));
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
[[nodiscard]] SpecificRequestBuilder &done(
|
|
|
|
FnMut<void(
|
|
|
|
const Result &result,
|
|
|
|
const Response &response)> callback) {
|
|
|
|
setDoneHandler(
|
|
|
|
MakeDoneHandler<Result>(sender(), std::move(callback)));
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
[[nodiscard]] SpecificRequestBuilder &done(
|
|
|
|
FnMut<void()> callback) {
|
|
|
|
setDoneHandler(
|
|
|
|
MakeDoneHandler<Result>(sender(), std::move(callback)));
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
[[nodiscard]] SpecificRequestBuilder &done(
|
|
|
|
FnMut<void(
|
|
|
|
const typename Request::ResponseType &result)> callback) {
|
|
|
|
setDoneHandler(
|
|
|
|
MakeDoneHandler<Result>(sender(), std::move(callback)));
|
2017-03-22 15:38:40 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2021-03-12 10:45:13 +00:00
|
|
|
|
|
|
|
[[nodiscard]] SpecificRequestBuilder &fail(
|
|
|
|
Fn<void(
|
2021-03-12 12:48:00 +00:00
|
|
|
const Error &error,
|
2021-03-12 10:45:13 +00:00
|
|
|
mtpRequestId requestId)> callback) noexcept {
|
|
|
|
setFailHandler(std::move(callback));
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
[[nodiscard]] SpecificRequestBuilder &fail(
|
|
|
|
Fn<void(
|
2021-03-12 12:48:00 +00:00
|
|
|
const Error &error,
|
2021-03-12 10:45:13 +00:00
|
|
|
const Response &response)> callback) noexcept {
|
|
|
|
setFailHandler(std::move(callback));
|
2017-03-22 15:38:40 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2021-03-12 10:45:13 +00:00
|
|
|
[[nodiscard]] SpecificRequestBuilder &fail(
|
|
|
|
Fn<void()> callback) noexcept {
|
2017-03-22 15:38:40 +00:00
|
|
|
setFailHandler(std::move(callback));
|
|
|
|
return *this;
|
|
|
|
}
|
2021-03-12 10:45:13 +00:00
|
|
|
[[nodiscard]] SpecificRequestBuilder &fail(
|
2021-03-12 12:48:00 +00:00
|
|
|
Fn<void(const Error &error)> callback) noexcept {
|
2017-03-22 15:38:40 +00:00
|
|
|
setFailHandler(std::move(callback));
|
|
|
|
return *this;
|
|
|
|
}
|
2021-03-12 10:45:13 +00:00
|
|
|
|
2017-10-13 19:07:04 +00:00
|
|
|
[[nodiscard]] SpecificRequestBuilder &handleFloodErrors() noexcept {
|
2017-03-22 15:38:40 +00:00
|
|
|
setFailSkipPolicy(FailSkipPolicy::HandleFlood);
|
|
|
|
return *this;
|
|
|
|
}
|
2017-10-13 19:07:04 +00:00
|
|
|
[[nodiscard]] SpecificRequestBuilder &handleAllErrors() noexcept {
|
2017-03-22 15:38:40 +00:00
|
|
|
setFailSkipPolicy(FailSkipPolicy::HandleAll);
|
|
|
|
return *this;
|
|
|
|
}
|
2017-12-07 13:02:24 +00:00
|
|
|
[[nodiscard]] SpecificRequestBuilder &afterRequest(mtpRequestId requestId) noexcept {
|
2017-03-22 15:38:40 +00:00
|
|
|
setAfter(requestId);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
mtpRequestId send() {
|
2020-06-17 09:36:25 +00:00
|
|
|
const auto id = sender()->_instance->send(
|
2017-12-18 12:40:15 +00:00
|
|
|
_request,
|
|
|
|
takeOnDone(),
|
|
|
|
takeOnFail(),
|
|
|
|
takeDcId(),
|
|
|
|
takeCanWait(),
|
|
|
|
takeAfter());
|
2017-03-22 15:38:40 +00:00
|
|
|
registerRequest(id);
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Request _request;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class SentRequestWrap {
|
|
|
|
private:
|
|
|
|
friend class Sender;
|
2017-08-17 08:31:24 +00:00
|
|
|
SentRequestWrap(not_null<Sender*> sender, mtpRequestId requestId) : _sender(sender), _requestId(requestId) {
|
2017-03-22 15:38:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
void cancel() {
|
2020-06-11 09:41:03 +00:00
|
|
|
if (_requestId) {
|
|
|
|
_sender->senderRequestCancel(_requestId);
|
|
|
|
}
|
2017-03-22 15:38:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<Sender*> _sender;
|
2017-03-22 15:38:40 +00:00
|
|
|
mtpRequestId _requestId = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-10-29 15:32:01 +00:00
|
|
|
template <
|
|
|
|
typename Request,
|
|
|
|
typename = std::enable_if_t<!std::is_reference_v<Request>>,
|
|
|
|
typename = typename Request::Unboxed>
|
2017-10-13 19:07:04 +00:00
|
|
|
[[nodiscard]] SpecificRequestBuilder<Request> request(Request &&request) noexcept;
|
2017-03-22 15:38:40 +00:00
|
|
|
|
2017-10-13 19:07:04 +00:00
|
|
|
[[nodiscard]] SentRequestWrap request(mtpRequestId requestId) noexcept;
|
2017-03-22 15:38:40 +00:00
|
|
|
|
2017-10-29 15:32:01 +00:00
|
|
|
[[nodiscard]] auto requestCanceller() noexcept {
|
2017-08-14 12:48:11 +00:00
|
|
|
return [this](mtpRequestId requestId) {
|
|
|
|
request(requestId).cancel();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-04-06 19:02:40 +00:00
|
|
|
void requestSendDelayed() {
|
2019-11-27 08:02:56 +00:00
|
|
|
_instance->sendAnything();
|
2017-04-06 19:02:40 +00:00
|
|
|
}
|
2017-03-23 16:11:35 +00:00
|
|
|
void requestCancellingDiscard() {
|
2020-06-11 16:09:46 +00:00
|
|
|
for (auto &request : base::take(_requests)) {
|
2017-03-23 16:11:35 +00:00
|
|
|
request.handled();
|
|
|
|
}
|
|
|
|
}
|
2017-04-06 19:02:40 +00:00
|
|
|
|
2017-03-22 15:38:40 +00:00
|
|
|
private:
|
|
|
|
class RequestWrap {
|
|
|
|
public:
|
2017-10-29 15:32:01 +00:00
|
|
|
RequestWrap(
|
2020-06-11 16:09:46 +00:00
|
|
|
not_null<Instance*> instance,
|
2017-10-29 15:32:01 +00:00
|
|
|
mtpRequestId requestId) noexcept
|
2020-06-11 16:09:46 +00:00
|
|
|
: _instance(instance)
|
|
|
|
, _id(requestId) {
|
2017-10-29 15:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RequestWrap(const RequestWrap &other) = delete;
|
|
|
|
RequestWrap &operator=(const RequestWrap &other) = delete;
|
2020-06-11 16:09:46 +00:00
|
|
|
RequestWrap(RequestWrap &&other)
|
|
|
|
: _instance(other._instance)
|
|
|
|
, _id(base::take(other._id)) {
|
2017-10-29 15:32:01 +00:00
|
|
|
}
|
|
|
|
RequestWrap &operator=(RequestWrap &&other) {
|
2020-06-11 16:09:46 +00:00
|
|
|
Expects(_instance == other._instance);
|
|
|
|
|
2017-10-30 19:24:20 +00:00
|
|
|
if (_id != other._id) {
|
|
|
|
cancelRequest();
|
|
|
|
_id = base::take(other._id);
|
|
|
|
}
|
2017-10-29 15:32:01 +00:00
|
|
|
return *this;
|
2017-03-22 15:38:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mtpRequestId id() const noexcept {
|
|
|
|
return _id;
|
|
|
|
}
|
|
|
|
void handled() const noexcept {
|
2020-06-11 16:09:46 +00:00
|
|
|
_id = 0;
|
2017-03-22 15:38:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~RequestWrap() {
|
2017-10-29 15:32:01 +00:00
|
|
|
cancelRequest();
|
2017-03-22 15:38:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-10-29 15:32:01 +00:00
|
|
|
void cancelRequest() {
|
|
|
|
if (_id) {
|
2020-06-11 16:09:46 +00:00
|
|
|
_instance->cancel(_id);
|
2017-10-29 15:32:01 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-11 16:09:46 +00:00
|
|
|
const not_null<Instance*> _instance;
|
|
|
|
mutable mtpRequestId _id = 0;
|
2017-03-22 15:38:40 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RequestWrapComparator {
|
|
|
|
using is_transparent = std::true_type;
|
|
|
|
|
|
|
|
struct helper {
|
|
|
|
mtpRequestId requestId = 0;
|
|
|
|
|
|
|
|
helper() = default;
|
|
|
|
helper(const helper &other) = default;
|
|
|
|
helper(mtpRequestId requestId) noexcept : requestId(requestId) {
|
|
|
|
}
|
|
|
|
helper(const RequestWrap &request) noexcept : requestId(request.id()) {
|
|
|
|
}
|
|
|
|
bool operator<(helper other) const {
|
|
|
|
return requestId < other.requestId;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
bool operator()(const helper &&lhs, const helper &&rhs) const {
|
|
|
|
return lhs < rhs;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Request>
|
2020-06-17 09:36:25 +00:00
|
|
|
friend class SpecificRequestBuilder;
|
2017-03-22 15:38:40 +00:00
|
|
|
friend class RequestBuilder;
|
|
|
|
friend class RequestWrap;
|
|
|
|
friend class SentRequestWrap;
|
|
|
|
|
2017-08-14 12:48:11 +00:00
|
|
|
void senderRequestRegister(mtpRequestId requestId) {
|
2020-06-11 16:09:46 +00:00
|
|
|
_requests.emplace(_instance, requestId);
|
2017-03-22 15:38:40 +00:00
|
|
|
}
|
2017-08-14 12:48:11 +00:00
|
|
|
void senderRequestHandled(mtpRequestId requestId) {
|
2017-03-22 15:38:40 +00:00
|
|
|
auto it = _requests.find(requestId);
|
|
|
|
if (it != _requests.cend()) {
|
|
|
|
it->handled();
|
|
|
|
_requests.erase(it);
|
|
|
|
}
|
|
|
|
}
|
2017-08-14 12:48:11 +00:00
|
|
|
void senderRequestCancel(mtpRequestId requestId) {
|
2017-03-22 15:38:40 +00:00
|
|
|
auto it = _requests.find(requestId);
|
|
|
|
if (it != _requests.cend()) {
|
|
|
|
_requests.erase(it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-27 08:02:56 +00:00
|
|
|
const not_null<Instance*> _instance;
|
2017-10-29 15:32:01 +00:00
|
|
|
base::flat_set<RequestWrap, RequestWrapComparator> _requests;
|
2017-03-22 15:38:40 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Request, typename, typename>
|
|
|
|
Sender::SpecificRequestBuilder<Request> Sender::request(Request &&request) noexcept {
|
2017-03-31 15:50:02 +00:00
|
|
|
return SpecificRequestBuilder<Request>(this, std::move(request));
|
2017-03-22 15:38:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline Sender::SentRequestWrap Sender::request(mtpRequestId requestId) noexcept {
|
2017-03-31 15:50:02 +00:00
|
|
|
return SentRequestWrap(this, requestId);
|
2017-03-22 15:38:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace MTP
|