mirror of
https://github.com/vale981/tdesktop
synced 2025-03-06 02:01:40 -05:00
Remove mtproto/session.h from precompiled header.
This commit is contained in:
parent
fa3a76b3d8
commit
ddf4a36bdc
11 changed files with 241 additions and 145 deletions
|
@ -750,23 +750,24 @@ void AddBotToGroupBoxController::shareBotGame(not_null<PeerData*> chat) {
|
|||
if (!weak) {
|
||||
return;
|
||||
}
|
||||
auto history = App::historyLoaded(chat);
|
||||
auto afterRequestId = history ? history->sendRequestId : 0;
|
||||
auto randomId = rand_value<uint64>();
|
||||
auto gameShortName = bot->botInfo->shareGameShortName;
|
||||
auto inputGame = MTP_inputGameShortName(
|
||||
bot->inputUser,
|
||||
MTP_string(gameShortName));
|
||||
auto request = MTPmessages_SendMedia(
|
||||
MTP_flags(0),
|
||||
chat->input,
|
||||
MTP_int(0),
|
||||
MTP_inputMediaGame(inputGame),
|
||||
MTP_long(randomId),
|
||||
MTPnullMarkup);
|
||||
auto done = App::main()->rpcDone(&MainWidget::sentUpdatesReceived);
|
||||
auto fail = App::main()->rpcFail(&MainWidget::sendMessageFail);
|
||||
auto requestId = MTP::send(request, done, fail, 0, 0, afterRequestId);
|
||||
const auto history = App::historyLoaded(chat);
|
||||
const auto randomId = rand_value<uint64>();
|
||||
const auto requestId = MTP::send(
|
||||
MTPmessages_SendMedia(
|
||||
MTP_flags(0),
|
||||
chat->input,
|
||||
MTP_int(0),
|
||||
MTP_inputMediaGame(
|
||||
MTP_inputGameShortName(
|
||||
bot->inputUser,
|
||||
MTP_string(bot->botInfo->shareGameShortName))),
|
||||
MTP_long(randomId),
|
||||
MTPnullMarkup),
|
||||
App::main()->rpcDone(&MainWidget::sentUpdatesReceived),
|
||||
App::main()->rpcFail(&MainWidget::sendMessageFail),
|
||||
0,
|
||||
0,
|
||||
history ? history->sendRequestId : 0);
|
||||
if (history) {
|
||||
history->sendRequestId = requestId;
|
||||
}
|
||||
|
@ -778,9 +779,9 @@ void AddBotToGroupBoxController::shareBotGame(not_null<PeerData*> chat) {
|
|||
return lng_bot_sure_share_game(lt_user, App::peerName(chat));
|
||||
}
|
||||
return lng_bot_sure_share_game_group(lt_group, chat->name);
|
||||
};
|
||||
}();
|
||||
Ui::show(
|
||||
Box<ConfirmBox>(confirmText(), send),
|
||||
Box<ConfirmBox>(confirmText, std::move(send)),
|
||||
LayerOption::KeepOther);
|
||||
}
|
||||
|
||||
|
@ -799,17 +800,16 @@ void AddBotToGroupBoxController::addBotToGroup(not_null<PeerData*> chat) {
|
|||
}
|
||||
if (auto &info = bot->botInfo) {
|
||||
if (!info->startGroupToken.isEmpty()) {
|
||||
auto request = MTPmessages_StartBot(
|
||||
bot->inputUser,
|
||||
chat->input,
|
||||
MTP_long(rand_value<uint64>()),
|
||||
MTP_string(info->startGroupToken));
|
||||
auto done = App::main()->rpcDone(
|
||||
&MainWidget::sentUpdatesReceived);
|
||||
auto fail = App::main()->rpcFail(
|
||||
&MainWidget::addParticipantFail,
|
||||
{ bot, chat });
|
||||
MTP::send(request, done, fail);
|
||||
MTP::send(
|
||||
MTPmessages_StartBot(
|
||||
bot->inputUser,
|
||||
chat->input,
|
||||
MTP_long(rand_value<uint64>()),
|
||||
MTP_string(info->startGroupToken)),
|
||||
App::main()->rpcDone(&MainWidget::sentUpdatesReceived),
|
||||
App::main()->rpcFail(
|
||||
&MainWidget::addParticipantFail,
|
||||
{ bot, chat }));
|
||||
} else {
|
||||
App::main()->addParticipants(
|
||||
chat,
|
||||
|
|
|
@ -57,7 +57,11 @@ void ConfigLoader::load() {
|
|||
}
|
||||
|
||||
mtpRequestId ConfigLoader::sendRequest(ShiftedDcId shiftedDcId) {
|
||||
return _instance->send(MTPhelp_GetConfig(), _doneHandler, _failHandler, shiftedDcId);
|
||||
return _instance->send(
|
||||
MTPhelp_GetConfig(),
|
||||
base::duplicate(_doneHandler),
|
||||
base::duplicate(_failHandler),
|
||||
shiftedDcId);
|
||||
}
|
||||
|
||||
DcId ConfigLoader::specialToRealDcId(DcId specialDcId) {
|
||||
|
@ -146,16 +150,24 @@ void ConfigLoader::sendSpecialRequest() {
|
|||
return;
|
||||
}
|
||||
|
||||
auto weak = base::make_weak(this);
|
||||
auto index = rand_value<uint32>() % uint32(_specialEndpoints.size());
|
||||
auto endpoint = _specialEndpoints.begin() + index;
|
||||
const auto weak = base::make_weak(this);
|
||||
const auto index = rand_value<uint32>() % _specialEndpoints.size();
|
||||
const auto endpoint = _specialEndpoints.begin() + index;
|
||||
_specialEnumCurrent = specialToRealDcId(endpoint->dcId);
|
||||
_instance->dcOptions()->constructAddOne(_specialEnumCurrent, MTPDdcOption::Flag::f_tcpo_only, endpoint->ip, endpoint->port);
|
||||
_specialEnumRequest = _instance->send(MTPhelp_GetConfig(), rpcDone([weak](const MTPConfig &result) {
|
||||
if (const auto strong = weak.get()) {
|
||||
strong->specialConfigLoaded(result);
|
||||
}
|
||||
}), _failHandler, _specialEnumCurrent);
|
||||
_instance->dcOptions()->constructAddOne(
|
||||
_specialEnumCurrent,
|
||||
MTPDdcOption::Flag::f_tcpo_only,
|
||||
endpoint->ip,
|
||||
endpoint->port);
|
||||
_specialEnumRequest = _instance->send(
|
||||
MTPhelp_GetConfig(),
|
||||
rpcDone([weak](const MTPConfig &result) {
|
||||
if (const auto strong = weak.get()) {
|
||||
strong->specialConfigLoaded(result);
|
||||
}
|
||||
}),
|
||||
base::duplicate(_failHandler),
|
||||
_specialEnumCurrent);
|
||||
_triedSpecialEndpoints.push_back(*endpoint);
|
||||
_specialEndpoints.erase(endpoint);
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
*/
|
||||
#include "mtproto/connection.h"
|
||||
|
||||
#include "mtproto/session.h"
|
||||
#include "mtproto/rsa_public_key.h"
|
||||
#include "mtproto/rpc_sender.h"
|
||||
#include "mtproto/dc_options.h"
|
||||
|
@ -1637,7 +1638,9 @@ ConnectionPrivate::HandleResult ConnectionPrivate::handleOneReceived(const mtpPr
|
|||
mtpRequestId requestId = wasSent(resendId);
|
||||
if (requestId) {
|
||||
LOG(("Message Error: bad message notification received, msgId %1, error_code %2, fatal: clearing callbacks").arg(data.vbad_msg_id.v).arg(errorCode));
|
||||
_instance->clearCallbacksDelayed(RPCCallbackClears(1, RPCCallbackClear(requestId, -errorCode)));
|
||||
_instance->clearCallbacksDelayed(RPCCallbackClears(
|
||||
1,
|
||||
RPCCallbackClear(requestId, -errorCode)));
|
||||
} else {
|
||||
DEBUG_LOG(("Message Error: such message was not sent recently %1").arg(resendId));
|
||||
}
|
||||
|
@ -2177,7 +2180,9 @@ void ConnectionPrivate::requestsAcked(const QVector<MTPlong> &ids, bool byRespon
|
|||
clearedAcked.reserve(ackedCount - MTPIdsBufferSize);
|
||||
while (ackedCount-- > MTPIdsBufferSize) {
|
||||
mtpRequestIdsMap::iterator i(wereAcked.begin());
|
||||
clearedAcked.push_back(RPCCallbackClear(i.key(), RPCError::TimeoutError));
|
||||
clearedAcked.push_back(RPCCallbackClear(
|
||||
i.key(),
|
||||
RPCError::TimeoutError));
|
||||
wereAcked.erase(i);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,6 +71,14 @@ public:
|
|||
static mtpRequest prepare(uint32 requestSize, uint32 maxSize = 0);
|
||||
static void padding(mtpRequest &request);
|
||||
|
||||
template <typename TRequest>
|
||||
static mtpRequest serialize(const TRequest &request) {
|
||||
const auto requestSize = request.innerLength() >> 2;
|
||||
auto serialized = prepare(requestSize);
|
||||
request.write(*serialized);
|
||||
return serialized;
|
||||
}
|
||||
|
||||
static uint32 messageSize(const mtpRequest &request) {
|
||||
if (request->size() < 9) return 0;
|
||||
return 4 + (request.innerLength() >> 2); // 2: msg_id, 1: seq_no, q: message_length
|
||||
|
|
|
@ -20,9 +20,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
#include "mtproto/type_utils.h"
|
||||
#include "mtproto/session.h"
|
||||
#include "core/single_timer.h"
|
||||
#include "mtproto/type_utils.h"
|
||||
#include "mtproto/mtp_instance.h"
|
||||
|
||||
namespace MTP {
|
||||
|
@ -193,12 +192,23 @@ inline QString dctransport(ShiftedDcId shiftedDcId = 0) {
|
|||
}
|
||||
|
||||
template <typename TRequest>
|
||||
inline mtpRequestId send(const TRequest &request, RPCResponseHandler callbacks = RPCResponseHandler(), ShiftedDcId dcId = 0, TimeMs msCanWait = 0, mtpRequestId after = 0) {
|
||||
inline mtpRequestId send(
|
||||
const TRequest &request,
|
||||
RPCResponseHandler &&callbacks = {},
|
||||
ShiftedDcId dcId = 0,
|
||||
TimeMs msCanWait = 0,
|
||||
mtpRequestId after = 0) {
|
||||
return MainInstance()->send(request, std::move(callbacks), dcId, msCanWait, after);
|
||||
}
|
||||
|
||||
template <typename TRequest>
|
||||
inline mtpRequestId send(const TRequest &request, RPCDoneHandlerPtr onDone, RPCFailHandlerPtr onFail = RPCFailHandlerPtr(), ShiftedDcId dcId = 0, TimeMs msCanWait = 0, mtpRequestId after = 0) {
|
||||
inline mtpRequestId send(
|
||||
const TRequest &request,
|
||||
RPCDoneHandlerPtr &&onDone,
|
||||
RPCFailHandlerPtr &&onFail = nullptr,
|
||||
ShiftedDcId dcId = 0,
|
||||
TimeMs msCanWait = 0,
|
||||
mtpRequestId after = 0) {
|
||||
return MainInstance()->send(request, std::move(onDone), std::move(onFail), dcId, msCanWait, after);
|
||||
}
|
||||
|
||||
|
@ -226,31 +236,4 @@ inline int32 state(mtpRequestId requestId) { // < 0 means waiting for such count
|
|||
return MainInstance()->state(requestId);
|
||||
}
|
||||
|
||||
namespace internal {
|
||||
|
||||
template <typename TRequest>
|
||||
mtpRequestId Session::send(const TRequest &request, RPCResponseHandler callbacks, TimeMs msCanWait, bool needsLayer, bool toMainDC, mtpRequestId after) {
|
||||
mtpRequestId requestId = 0;
|
||||
try {
|
||||
uint32 requestSize = request.innerLength() >> 2;
|
||||
mtpRequest reqSerialized(mtpRequestData::prepare(requestSize));
|
||||
request.write(*reqSerialized);
|
||||
|
||||
DEBUG_LOG(("MTP Info: adding request to toSendMap, msCanWait %1").arg(msCanWait));
|
||||
|
||||
reqSerialized->msDate = getms(true); // > 0 - can send without container
|
||||
reqSerialized->needsLayer = needsLayer;
|
||||
if (after) reqSerialized->after = getRequest(after);
|
||||
requestId = storeRequest(reqSerialized, callbacks);
|
||||
|
||||
sendPrepared(reqSerialized, msCanWait);
|
||||
} catch (Exception &e) {
|
||||
requestId = 0;
|
||||
requestPrepareFailed(callbacks.onFail, e);
|
||||
}
|
||||
if (requestId) registerRequest(requestId, toMainDC ? -getDcWithShift() : getDcWithShift());
|
||||
return requestId;
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace MTP
|
||||
|
|
|
@ -20,6 +20,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
*/
|
||||
#include "mtproto/mtp_instance.h"
|
||||
|
||||
#include "mtproto/session.h"
|
||||
#include "mtproto/dc_options.h"
|
||||
#include "mtproto/dcenter.h"
|
||||
#include "mtproto/config_loader.h"
|
||||
|
@ -71,12 +72,15 @@ public:
|
|||
std::shared_ptr<internal::Dcenter> getDcById(ShiftedDcId shiftedDcId);
|
||||
void unpaused();
|
||||
|
||||
void queueQuittingConnection(std::unique_ptr<internal::Connection> connection);
|
||||
void queueQuittingConnection(
|
||||
std::unique_ptr<internal::Connection> &&connection);
|
||||
void connectionFinished(internal::Connection *connection);
|
||||
|
||||
void registerRequest(mtpRequestId requestId, int32 dcWithShift);
|
||||
void unregisterRequest(mtpRequestId requestId);
|
||||
mtpRequestId storeRequest(mtpRequest &request, const RPCResponseHandler &parser);
|
||||
mtpRequestId storeRequest(
|
||||
mtpRequest &request,
|
||||
RPCResponseHandler &&callbacks);
|
||||
mtpRequest getRequest(mtpRequestId requestId);
|
||||
void clearCallbacks(mtpRequestId requestId, int32 errorCode = RPCError::NoError); // 0 - do not toggle onError callback
|
||||
void clearCallbacksDelayed(const RPCCallbackClears &requestIds);
|
||||
|
@ -127,6 +131,7 @@ private:
|
|||
bool exportFail(const RPCError &error, mtpRequestId requestId);
|
||||
bool onErrorDefault(mtpRequestId requestId, const RPCError &error);
|
||||
|
||||
void logoutGuestDcs();
|
||||
bool logoutGuestDone(mtpRequestId requestId);
|
||||
|
||||
void configLoadDone(const MTPConfig &result);
|
||||
|
@ -452,9 +457,14 @@ void Instance::Private::reInitConnection(DcId dcId) {
|
|||
getSession(dcId)->notifyLayerInited(false);
|
||||
}
|
||||
|
||||
void Instance::Private::logout(RPCDoneHandlerPtr onDone, RPCFailHandlerPtr onFail) {
|
||||
_instance->send(MTPauth_LogOut(), onDone, onFail);
|
||||
void Instance::Private::logout(
|
||||
RPCDoneHandlerPtr onDone,
|
||||
RPCFailHandlerPtr onFail) {
|
||||
_instance->send(MTPauth_LogOut(), std::move(onDone), std::move(onFail));
|
||||
logoutGuestDcs();
|
||||
}
|
||||
|
||||
void Instance::Private::logoutGuestDcs() {
|
||||
auto dcIds = std::vector<DcId>();
|
||||
{
|
||||
QReadLocker lock(&_keysForWriteLock);
|
||||
|
@ -566,7 +576,8 @@ void Instance::Private::unpaused() {
|
|||
}
|
||||
}
|
||||
|
||||
void Instance::Private::queueQuittingConnection(std::unique_ptr<internal::Connection> connection) {
|
||||
void Instance::Private::queueQuittingConnection(
|
||||
std::unique_ptr<internal::Connection> &&connection) {
|
||||
_quittingConnections.insert(std::move(connection));
|
||||
}
|
||||
|
||||
|
@ -690,18 +701,20 @@ void Instance::Private::unregisterRequest(mtpRequestId requestId) {
|
|||
_requestsByDc.erase(requestId);
|
||||
}
|
||||
|
||||
mtpRequestId Instance::Private::storeRequest(mtpRequest &request, const RPCResponseHandler &parser) {
|
||||
mtpRequestId res = reqid();
|
||||
request->requestId = res;
|
||||
if (parser.onDone || parser.onFail) {
|
||||
mtpRequestId Instance::Private::storeRequest(
|
||||
mtpRequest &request,
|
||||
RPCResponseHandler &&callbacks) {
|
||||
const auto requestId = reqid();
|
||||
request->requestId = requestId;
|
||||
if (callbacks.onDone || callbacks.onFail) {
|
||||
QMutexLocker locker(&_parserMapLock);
|
||||
_parserMap.emplace(res, parser);
|
||||
_parserMap.emplace(requestId, std::move(callbacks));
|
||||
}
|
||||
{
|
||||
QWriteLocker locker(&_requestMapLock);
|
||||
_requestMap.emplace(res, request);
|
||||
_requestMap.emplace(requestId, request);
|
||||
}
|
||||
return res;
|
||||
return requestId;
|
||||
}
|
||||
|
||||
mtpRequest Instance::Private::getRequest(mtpRequestId requestId) {
|
||||
|
@ -1378,7 +1391,8 @@ void Instance::unpaused() {
|
|||
_private->unpaused();
|
||||
}
|
||||
|
||||
void Instance::queueQuittingConnection(std::unique_ptr<internal::Connection> connection) {
|
||||
void Instance::queueQuittingConnection(
|
||||
std::unique_ptr<internal::Connection> &&connection) {
|
||||
_private->queueQuittingConnection(std::move(connection));
|
||||
}
|
||||
|
||||
|
@ -1414,8 +1428,10 @@ void Instance::registerRequest(mtpRequestId requestId, ShiftedDcId dcWithShift)
|
|||
_private->registerRequest(requestId, dcWithShift);
|
||||
}
|
||||
|
||||
mtpRequestId Instance::storeRequest(mtpRequest &request, const RPCResponseHandler &parser) {
|
||||
return _private->storeRequest(request, parser);
|
||||
mtpRequestId Instance::storeRequest(
|
||||
mtpRequest &request,
|
||||
RPCResponseHandler &&callbacks) {
|
||||
return _private->storeRequest(request, std::move(callbacks));
|
||||
}
|
||||
|
||||
mtpRequest Instance::getRequest(mtpRequestId requestId) {
|
||||
|
@ -1442,10 +1458,6 @@ bool Instance::rpcErrorOccured(mtpRequestId requestId, const RPCFailHandlerPtr &
|
|||
return _private->rpcErrorOccured(requestId, onFail, err);
|
||||
}
|
||||
|
||||
internal::Session *Instance::getSession(ShiftedDcId shiftedDcId) {
|
||||
return _private->getSession(shiftedDcId);
|
||||
}
|
||||
|
||||
bool Instance::isKeysDestroyer() const {
|
||||
return _private->isKeysDestroyer();
|
||||
}
|
||||
|
@ -1458,6 +1470,30 @@ void Instance::onKeyDestroyed(qint32 shiftedDcId) {
|
|||
_private->completedKeyDestroy(shiftedDcId);
|
||||
}
|
||||
|
||||
mtpRequestId Instance::send(
|
||||
mtpRequest &&request,
|
||||
RPCResponseHandler &&callbacks,
|
||||
ShiftedDcId dcId,
|
||||
TimeMs msCanWait,
|
||||
mtpRequestId after) {
|
||||
if (const auto session = _private->getSession(dcId)) {
|
||||
return session->send(
|
||||
mtpRequestData::serialize(request),
|
||||
std::move(callbacks),
|
||||
msCanWait,
|
||||
true,
|
||||
!dcId,
|
||||
after);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Instance::sendAnything(ShiftedDcId dcId, TimeMs msCanWait) {
|
||||
if (const auto session = _private->getSession(dcId)) {
|
||||
session->sendAnything(msCanWait);
|
||||
}
|
||||
}
|
||||
|
||||
Instance::~Instance() {
|
||||
_private->prepareToDestroy();
|
||||
}
|
||||
|
|
|
@ -22,14 +22,16 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include "mtproto/rpc_sender.h"
|
||||
|
||||
namespace MTP {
|
||||
namespace internal {
|
||||
class Dcenter;
|
||||
class Session;
|
||||
class Connection;
|
||||
} // namespace internal
|
||||
|
||||
class DcOptions;
|
||||
class Session;
|
||||
class AuthKey;
|
||||
using AuthKeyPtr = std::shared_ptr<AuthKey>;
|
||||
using AuthKeysList = std::vector<AuthKeyPtr>;
|
||||
|
@ -70,23 +72,37 @@ public:
|
|||
not_null<DcOptions*> dcOptions();
|
||||
|
||||
template <typename TRequest>
|
||||
mtpRequestId send(const TRequest &request, RPCResponseHandler callbacks = RPCResponseHandler(), ShiftedDcId dcId = 0, TimeMs msCanWait = 0, mtpRequestId after = 0) {
|
||||
if (auto session = getSession(dcId)) {
|
||||
return session->send(request, callbacks, msCanWait, true, !dcId, after);
|
||||
}
|
||||
return 0;
|
||||
mtpRequestId send(
|
||||
const TRequest &request,
|
||||
RPCResponseHandler &&callbacks = {},
|
||||
ShiftedDcId dcId = 0,
|
||||
TimeMs msCanWait = 0,
|
||||
mtpRequestId after = 0) {
|
||||
return send(
|
||||
mtpRequestData::serialize(request),
|
||||
std::move(callbacks),
|
||||
dcId,
|
||||
msCanWait,
|
||||
after);
|
||||
}
|
||||
|
||||
template <typename TRequest>
|
||||
mtpRequestId send(const TRequest &request, RPCDoneHandlerPtr onDone, RPCFailHandlerPtr onFail = RPCFailHandlerPtr(), int32 dc = 0, TimeMs msCanWait = 0, mtpRequestId after = 0) {
|
||||
return send(request, RPCResponseHandler(onDone, onFail), dc, msCanWait, after);
|
||||
mtpRequestId send(
|
||||
const TRequest &request,
|
||||
RPCDoneHandlerPtr &&onDone,
|
||||
RPCFailHandlerPtr &&onFail = nullptr,
|
||||
ShiftedDcId dc = 0,
|
||||
TimeMs msCanWait = 0,
|
||||
mtpRequestId after = 0) {
|
||||
return send(
|
||||
request,
|
||||
RPCResponseHandler(std::move(onDone), std::move(onFail)),
|
||||
dc,
|
||||
msCanWait,
|
||||
after);
|
||||
}
|
||||
|
||||
void sendAnything(ShiftedDcId dcId = 0, TimeMs msCanWait = 0) {
|
||||
if (auto session = getSession(dcId)) {
|
||||
session->sendAnything(msCanWait);
|
||||
}
|
||||
}
|
||||
void sendAnything(ShiftedDcId dcId = 0, TimeMs msCanWait = 0);
|
||||
|
||||
void restart();
|
||||
void restart(ShiftedDcId shiftedDcId);
|
||||
|
@ -103,7 +119,7 @@ public:
|
|||
std::shared_ptr<internal::Dcenter> getDcById(ShiftedDcId shiftedDcId);
|
||||
void unpaused();
|
||||
|
||||
void queueQuittingConnection(std::unique_ptr<internal::Connection> connection);
|
||||
void queueQuittingConnection(std::unique_ptr<internal::Connection> &&connection);
|
||||
|
||||
void setUpdatesHandler(RPCDoneHandlerPtr onDone);
|
||||
void setGlobalFailHandler(RPCFailHandlerPtr onFail);
|
||||
|
@ -115,7 +131,9 @@ public:
|
|||
void onSessionReset(ShiftedDcId dcWithShift);
|
||||
|
||||
void registerRequest(mtpRequestId requestId, ShiftedDcId dcWithShift);
|
||||
mtpRequestId storeRequest(mtpRequest &request, const RPCResponseHandler &parser);
|
||||
mtpRequestId storeRequest(
|
||||
mtpRequest &request,
|
||||
RPCResponseHandler &&callbacks);
|
||||
mtpRequest getRequest(mtpRequestId requestId);
|
||||
void clearCallbacksDelayed(const RPCCallbackClears &requestIds);
|
||||
|
||||
|
@ -147,7 +165,12 @@ private slots:
|
|||
void onKeyDestroyed(qint32 shiftedDcId);
|
||||
|
||||
private:
|
||||
internal::Session *getSession(ShiftedDcId shiftedDcId);
|
||||
mtpRequestId send(
|
||||
mtpRequest &&request,
|
||||
RPCResponseHandler &&callbacks,
|
||||
ShiftedDcId dcId,
|
||||
TimeMs msCanWait,
|
||||
mtpRequestId after);
|
||||
|
||||
class Private;
|
||||
const std::unique_ptr<Private> _private;
|
||||
|
|
|
@ -98,9 +98,10 @@ public:
|
|||
using RPCFailHandlerPtr = std::shared_ptr<RPCAbstractFailHandler>;
|
||||
|
||||
struct RPCResponseHandler {
|
||||
RPCResponseHandler() {
|
||||
}
|
||||
RPCResponseHandler(const RPCDoneHandlerPtr &ondone, const RPCFailHandlerPtr &onfail) : onDone(ondone), onFail(onfail) {
|
||||
RPCResponseHandler() = default;
|
||||
RPCResponseHandler(RPCDoneHandlerPtr &&done, RPCFailHandlerPtr &&fail)
|
||||
: onDone(std::move(done))
|
||||
, onFail(std::move(fail)) {
|
||||
}
|
||||
|
||||
RPCDoneHandlerPtr onDone;
|
||||
|
@ -108,10 +109,6 @@ struct RPCResponseHandler {
|
|||
|
||||
};
|
||||
|
||||
inline RPCResponseHandler rpcCb(const RPCDoneHandlerPtr &onDone = RPCDoneHandlerPtr(), const RPCFailHandlerPtr &onFail = RPCFailHandlerPtr()) {
|
||||
return RPCResponseHandler(onDone, onFail);
|
||||
}
|
||||
|
||||
template <typename TReturn>
|
||||
class RPCDoneHandlerBare : public RPCAbstractDoneHandler { // done(from, end)
|
||||
using CallbackType = TReturn (*)(const mtpPrime *, const mtpPrime *);
|
||||
|
|
|
@ -252,7 +252,13 @@ public:
|
|||
}
|
||||
|
||||
mtpRequestId send() {
|
||||
auto id = MainInstance()->send(_request, takeOnDone(), takeOnFail(), takeDcId(), takeCanWait(), takeAfter());
|
||||
const auto id = MainInstance()->send(
|
||||
_request,
|
||||
takeOnDone(),
|
||||
takeOnFail(),
|
||||
takeDcId(),
|
||||
takeCanWait(),
|
||||
takeAfter());
|
||||
registerRequest(id);
|
||||
return id;
|
||||
}
|
||||
|
|
|
@ -141,8 +141,10 @@ void Session::registerRequest(mtpRequestId requestId, ShiftedDcId dcWithShift) {
|
|||
return _instance->registerRequest(requestId, dcWithShift);
|
||||
}
|
||||
|
||||
mtpRequestId Session::storeRequest(mtpRequest &request, const RPCResponseHandler &parser) {
|
||||
return _instance->storeRequest(request, parser);
|
||||
mtpRequestId Session::storeRequest(
|
||||
mtpRequest &request,
|
||||
RPCResponseHandler &&callbacks) {
|
||||
return _instance->storeRequest(request, std::move(callbacks));
|
||||
}
|
||||
|
||||
mtpRequest Session::getRequest(mtpRequestId requestId) {
|
||||
|
@ -153,23 +155,6 @@ bool Session::rpcErrorOccured(mtpRequestId requestId, const RPCFailHandlerPtr &o
|
|||
return _instance->rpcErrorOccured(requestId, onFail, err);
|
||||
}
|
||||
|
||||
void Session::requestPrepareFailed(
|
||||
const RPCFailHandlerPtr &onFail,
|
||||
Exception &e) {
|
||||
CrashReports::SetAnnotation("RequestException", QString::fromLatin1(e.what()));
|
||||
Unexpected("Exception in Session::send()");
|
||||
|
||||
const auto requestId = 0;
|
||||
const auto error = rpcClientError(
|
||||
"NO_REQUEST_ID",
|
||||
QString(
|
||||
"send() failed to queue request, exception: %1"
|
||||
).arg(
|
||||
e.what()
|
||||
));
|
||||
rpcErrorOccured(requestId, onFail, error);
|
||||
}
|
||||
|
||||
void Session::restart() {
|
||||
if (_killed) {
|
||||
DEBUG_LOG(("Session Error: can't restart a killed session"));
|
||||
|
@ -255,7 +240,9 @@ void Session::needToResumeAndSend() {
|
|||
}
|
||||
|
||||
void Session::sendPong(quint64 msgId, quint64 pingId) {
|
||||
send(MTP_pong(MTP_long(msgId), MTP_long(pingId)));
|
||||
send(mtpRequestData::serialize(MTPPong(MTP_pong(
|
||||
MTP_long(msgId),
|
||||
MTP_long(pingId)))));
|
||||
}
|
||||
|
||||
void Session::sendMsgsStateInfo(quint64 msgId, QByteArray data) {
|
||||
|
@ -267,7 +254,8 @@ void Session::sendMsgsStateInfo(quint64 msgId, QByteArray data) {
|
|||
auto dst = gsl::as_writeable_bytes(gsl::make_span(&info[0], info.size()));
|
||||
base::copy_bytes(dst, src);
|
||||
}
|
||||
send(MTPMsgsStateInfo(MTP_msgs_state_info(MTP_long(msgId), MTP_string(std::move(info)))));
|
||||
send(mtpRequestData::serialize(MTPMsgsStateInfo(
|
||||
MTP_msgs_state_info(MTP_long(msgId), MTP_string(std::move(info))))));
|
||||
}
|
||||
|
||||
void Session::checkRequestsByTimer() {
|
||||
|
@ -425,13 +413,17 @@ mtpRequestId Session::resend(quint64 msgId, qint64 msCanWait, bool forceContaine
|
|||
QWriteLocker locker(data.haveSentMutex());
|
||||
mtpRequestMap &haveSent(data.haveSentMap());
|
||||
|
||||
mtpRequestMap::iterator i = haveSent.find(msgId);
|
||||
auto i = haveSent.find(msgId);
|
||||
if (i == haveSent.end()) {
|
||||
if (sendMsgStateInfo) {
|
||||
char cantResend[2] = {1, 0};
|
||||
DEBUG_LOG(("Message Info: cant resend %1, request not found").arg(msgId));
|
||||
|
||||
return send(MTP_msgs_state_info(MTP_long(msgId), MTP_string(std::string(cantResend, cantResend + 1))));
|
||||
auto info = std::string(cantResend, cantResend + 1);
|
||||
return send(mtpRequestData::serialize(MTPMsgsStateInfo(
|
||||
MTP_msgs_state_info(
|
||||
MTP_long(msgId),
|
||||
MTP_string(std::move(info))))));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -480,6 +472,30 @@ void Session::resendAll() {
|
|||
}
|
||||
}
|
||||
|
||||
mtpRequestId Session::send(
|
||||
mtpRequest &&request,
|
||||
RPCResponseHandler &&callbacks,
|
||||
TimeMs msCanWait,
|
||||
bool needsLayer,
|
||||
bool toMainDC,
|
||||
mtpRequestId after) {
|
||||
DEBUG_LOG(("MTP Info: adding request to toSendMap, msCanWait %1").arg(msCanWait));
|
||||
|
||||
request->msDate = getms(true); // > 0 - can send without container
|
||||
request->needsLayer = needsLayer;
|
||||
if (after) {
|
||||
request->after = getRequest(after);
|
||||
}
|
||||
const auto requestId = storeRequest(request, std::move(callbacks));
|
||||
Assert(requestId != 0);
|
||||
|
||||
const auto signedDcId = toMainDC ? -getDcWithShift() : getDcWithShift();
|
||||
sendPrepared(request, msCanWait);
|
||||
registerRequest(requestId, signedDcId);
|
||||
|
||||
return requestId;
|
||||
}
|
||||
|
||||
void Session::sendPrepared(const mtpRequest &request, TimeMs msCanWait, bool newRequest) { // returns true, if emit of needToSend() is needed
|
||||
{
|
||||
QWriteLocker locker(data.toSendMutex());
|
||||
|
|
|
@ -311,16 +311,25 @@ public:
|
|||
void destroyKey();
|
||||
void notifyLayerInited(bool wasInited);
|
||||
|
||||
template <typename TRequest>
|
||||
mtpRequestId send(const TRequest &request, RPCResponseHandler callbacks = RPCResponseHandler(), TimeMs msCanWait = 0, bool needsLayer = false, bool toMainDC = false, mtpRequestId after = 0); // send mtp request
|
||||
|
||||
void ping();
|
||||
void cancel(mtpRequestId requestId, mtpMsgId msgId);
|
||||
int32 requestState(mtpRequestId requestId) const;
|
||||
int32 getState() const;
|
||||
QString transport() const;
|
||||
|
||||
void sendPrepared(const mtpRequest &request, TimeMs msCanWait = 0, bool newRequest = true); // nulls msgId and seqNo in request, if newRequest = true
|
||||
mtpRequestId send(
|
||||
mtpRequest &&request,
|
||||
RPCResponseHandler &&callbacks = {},
|
||||
TimeMs msCanWait = 0,
|
||||
bool needsLayer = false,
|
||||
bool toMainDC = false,
|
||||
mtpRequestId after = 0);
|
||||
|
||||
// Nulls msgId and seqNo in request, if newRequest = true.
|
||||
void sendPrepared(
|
||||
const mtpRequest &request,
|
||||
TimeMs msCanWait = 0,
|
||||
bool newRequest = true);
|
||||
|
||||
~Session();
|
||||
|
||||
|
@ -353,10 +362,11 @@ private:
|
|||
void createDcData();
|
||||
|
||||
void registerRequest(mtpRequestId requestId, ShiftedDcId dcWithShift);
|
||||
mtpRequestId storeRequest(mtpRequest &request, const RPCResponseHandler &parser);
|
||||
mtpRequestId storeRequest(
|
||||
mtpRequest &request,
|
||||
RPCResponseHandler &&callbacks);
|
||||
mtpRequest getRequest(mtpRequestId requestId);
|
||||
bool rpcErrorOccured(mtpRequestId requestId, const RPCFailHandlerPtr &onFail, const RPCError &err);
|
||||
void requestPrepareFailed(const RPCFailHandlerPtr &onFail, Exception &e);
|
||||
|
||||
not_null<Instance*> _instance;
|
||||
std::unique_ptr<Connection> _connection;
|
||||
|
|
Loading…
Add table
Reference in a new issue