31 _lanstUpdateTime = QDateTime::currentMSecsSinceEpoch();
44void TelegramRestBot::startUpdates() {
48 long long delta = QDateTime::currentMSecsSinceEpoch() - _lanstUpdateTime;
51 if (
delta >= _updateDelay) {
52 auto&& replay =
sendRequest(QSharedPointer<TelegramGetUpdate>::create(_lanstUpdateid + 1));
54 connect(replay.get(), &QNetworkReply::finished,
55 this, std::bind(&TelegramRestBot::handleReceiveUpdates,
this, replay.toWeakRef()),
56 Qt::DirectConnection);
58 connect(replay.get(), &QNetworkReply::errorOccurred,
59 this, &TelegramRestBot::handleReceiveUpdatesErr,
60 Qt::DirectConnection);
64 QTimer::singleShot( _updateDelay -
delta,
this, [
this](){startUpdates();});
85void TelegramRestBot::handleReceiveUpdates(
const QWeakPointer<QNetworkReply> &replay) {
91 _lanstUpdateTime = QDateTime::currentMSecsSinceEpoch();
98 _lanstUpdateid =
update->updateId();
107void TelegramRestBot::handleReceiveUpdatesErr(QNetworkReply::NetworkError err) {
109 qDebug() <<
"Network error occured. code: " <<
err;
static QSharedPointer< MessageType > makeMesasge(const QByteArray &data, Args &&...args)
makeMesasge This is factory method tha can create a messages types.
const QByteArray & token() const
token This is token value for authication on the remote server (bot)
void incomeNewUpdate(const QSharedPointer< iUpdate > &message)
incomeNewUpdate This method save incomed messages into store.
virtual void setProcessed(const QSet< unsigned long long > &newProcessed)
setProcessed This method sets new list of processed mesages.
virtual void logout()
login This method remove login token of bot.
QSharedPointer< QNetworkReply > sendRequest(const QSharedPointer< iRequest > &rquest)
sendRequest This method sent custom requests to the server.
bool login(const QByteArray &token) override
login This method get bae information of the bot from remote server.
void logout() override
login This method remove login token of bot.
void setUpdateDelay(int newUpdateDelay)
setUpdateDelay This method sets new value for the TelegramRestBot::updateDelay property.
void setProcessed(const QSet< unsigned long long > &newProcessed) override
setProcessed This method sets new list of processed mesages.
bool login(const QByteArray &token) override
login This method get bae information of the bot from remote server.
int updateDelay() const
updateDelay This is interval "how many msec bot will be wait for sent next request of updates" By def...