#include "td-client.h" #include "config.h" #include class UpdateHandler { public: UpdateHandler(PurpleTdClient *owner) : m_owner(owner) {} void operator()(td::td_api::updateAuthorizationState &update_authorization_state) const { purple_debug_misc(config::pluginId, "Incoming update: authorization state\n"); td::td_api::downcast_call(*update_authorization_state.authorization_state_, *m_owner->m_authUpdateHandler); } void operator()(auto &update) const { purple_debug_misc(config::pluginId, "Incoming update: ignorig ID=%d\n", update.get_id()); } private: PurpleTdClient *m_owner; }; class AuthUpdateHandler { public: AuthUpdateHandler(PurpleTdClient *owner) : m_owner(owner) {} void operator()(td::td_api::authorizationStateWaitEncryptionKey &) const { purple_debug_misc(config::pluginId, "Authorization state update: encriytion key requested\n"); } void operator()(auto &update) const { purple_debug_misc(config::pluginId, "Authorization state update: ignorig ID=%d\n", update.get_id()); } private: PurpleTdClient *m_owner; }; PurpleTdClient::PurpleTdClient() { m_updateHandler = std::make_unique(this); m_authUpdateHandler = std::make_unique(this); } PurpleTdClient::~PurpleTdClient() { } void PurpleTdClient::setLogLevel(int level) { // Why not just call setLogVerbosityLevel? No idea! td::Client::execute({0, td::td_api::make_object(level)}); } void PurpleTdClient::startLogin() { m_client = std::make_unique(); processResponse(m_client->receive(1)); } void PurpleTdClient::processResponse(td::Client::Response response) { if (response.object) { if (response.id == 0) { purple_debug_misc(config::pluginId, "Incoming update\n"); td::td_api::downcast_call(*response.object, *m_updateHandler); } else { // Response to a request } } else purple_debug_misc(config::pluginId, "Response id %lu timed out or something\n", response.id); }