2020-02-16 17:46:52 +01:00
|
|
|
#ifndef _TD_CLIENT_H
|
|
|
|
#define _TD_CLIENT_H
|
|
|
|
|
2020-02-22 11:42:04 +01:00
|
|
|
#include <purple.h>
|
2020-02-16 17:46:52 +01:00
|
|
|
#include <td/telegram/Client.h>
|
|
|
|
#include <td/telegram/td_api.h>
|
|
|
|
#include <td/telegram/td_api.hpp>
|
|
|
|
|
|
|
|
#include <memory>
|
2020-02-22 11:10:30 +01:00
|
|
|
#include <thread>
|
|
|
|
#include <atomic>
|
2020-02-22 11:42:04 +01:00
|
|
|
#include <map>
|
2020-02-16 17:46:52 +01:00
|
|
|
|
|
|
|
class UpdateHandler;
|
|
|
|
class AuthUpdateHandler;
|
|
|
|
|
|
|
|
class PurpleTdClient {
|
|
|
|
public:
|
2020-02-22 11:42:04 +01:00
|
|
|
PurpleTdClient(PurpleAccount *acct);
|
2020-02-16 17:46:52 +01:00
|
|
|
~PurpleTdClient();
|
|
|
|
|
2020-02-17 23:30:24 +01:00
|
|
|
static void setLogLevel(int level);
|
2020-02-16 17:46:52 +01:00
|
|
|
void startLogin();
|
|
|
|
private:
|
|
|
|
friend class UpdateHandler;
|
|
|
|
friend class AuthUpdateHandler;
|
2020-02-22 11:10:30 +01:00
|
|
|
using TdObjectPtr = td::td_api::object_ptr<td::td_api::Object>;
|
2020-02-22 11:42:04 +01:00
|
|
|
using ResponseCb = std::function<void(uint64_t requestId, TdObjectPtr object)>;
|
2020-02-16 17:46:52 +01:00
|
|
|
|
2020-02-22 11:10:30 +01:00
|
|
|
void pollThreadLoop();
|
2020-02-16 17:46:52 +01:00
|
|
|
void processResponse(td::Client::Response response);
|
2020-02-22 11:10:30 +01:00
|
|
|
void sendTdlibParameters();
|
2020-02-22 12:08:02 +01:00
|
|
|
void sendPhoneNumber();
|
2020-02-22 11:42:04 +01:00
|
|
|
void sendQuery(td::td_api::object_ptr<td::td_api::Function> f, ResponseCb handler);
|
|
|
|
|
|
|
|
PurpleAccount *m_account;
|
|
|
|
std::unique_ptr<UpdateHandler> m_updateHandler;
|
|
|
|
std::unique_ptr<AuthUpdateHandler> m_authUpdateHandler;
|
|
|
|
std::unique_ptr<td::Client> m_client;
|
|
|
|
std::thread m_pollThread;
|
|
|
|
std::atomic_bool m_stopThread;
|
|
|
|
uint64_t m_lastQueryId;
|
|
|
|
std::map<std::uint64_t, ResponseCb> m_responseHandlers;
|
2020-02-16 17:46:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|