2
0
mirror of https://github.com/ars3niy/tdlib-purple synced 2025-08-22 09:57:52 +00:00
tdlib-purple/td-client.h

164 lines
9.8 KiB
C
Raw Normal View History

#ifndef _TD_CLIENT_H
#define _TD_CLIENT_H
#include "account-data.h"
#include "transceiver.h"
2020-05-15 19:46:07 +02:00
#include "client-utils.h"
2020-02-22 11:42:04 +01:00
#include <purple.h>
enum class BasicGroupMembership: uint8_t {
Invalid,
Creator,
NonCreator,
};
class PurpleTdClient {
public:
2020-05-06 18:17:05 +02:00
PurpleTdClient(PurpleAccount *acct, ITransceiverBackend *testBackend);
~PurpleTdClient();
static void setLogLevel(int level);
int sendMessage(const char *buddyName, const char *message);
2020-05-22 18:20:29 +02:00
void sendTyping(const char *buddyName, bool isTyping);
2020-05-20 21:31:08 +02:00
void addContact(const std::string &purpleName, const std::string &alias, const std::string &groupName);
void renameContact(const char *buddyName, const char *newAlias);
2020-05-22 18:20:29 +02:00
void removeContactAndPrivateChat(const std::string &buddyName);
void getUsers(const char *username, std::vector<const td::td_api::user *> &users);
bool joinChat(const char *chatName);
void joinChatByLink(const char *inviteLink);
void createGroup(const char *name, int type, const std::vector<std::string> &basicGroupMembers);
BasicGroupMembership getBasicGroupMembership(const char *purpleChatName);
void leaveGroup(const std::string &purpleChatName, bool deleteSupergroup);
2020-05-22 18:20:29 +02:00
int sendGroupMessage(int purpleChatId, const char *message);
void setGroupDescription(int purpleChatId, const char *description);
void setTwoFactorAuth(const char *oldPassword, const char *newPassword, const char *hint,
const char *email);
void sendFileToChat(PurpleXfer *xfer, const char *purpleName, PurpleConversationType type);
void cancelUpload(PurpleXfer *xfer);
private:
2020-02-22 14:58:32 +01:00
using TdObjectPtr = td::td_api::object_ptr<td::td_api::Object>;
using ResponseCb = void (PurpleTdClient::*)(uint64_t requestId, TdObjectPtr object);
void processUpdate(td::td_api::Object &object);
void processAuthorizationState(td::td_api::AuthorizationState &authState);
// Login sequence start
2020-05-20 18:31:37 +02:00
bool addProxy();
void addProxyResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
void getProxiesResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
void removeOldProxies();
void sendTdlibParameters();
void sendPhoneNumber();
2020-05-14 14:42:05 +02:00
void requestAuthCode(const td::td_api::authenticationCodeInfo *authCodeInfo);
2020-05-25 23:53:21 +02:00
void requestPassword(const td::td_api::authorizationStateWaitPassword &pwInfo);
2020-05-14 14:42:05 +02:00
void registerUser();
2020-02-22 14:58:32 +01:00
static void requestCodeEntered(PurpleTdClient *self, const gchar *code);
static void requestCodeCancelled(PurpleTdClient *self);
2020-05-25 23:53:21 +02:00
static void passwordEntered(PurpleTdClient *self, const gchar *code);
static void passwordCancelled(PurpleTdClient *self);
static void displayNameEntered(PurpleTdClient *self, const gchar *name);
static void displayNameCancelled(PurpleTdClient *self);
void authResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
2020-05-12 16:00:07 +02:00
void notifyAuthError(const td::td_api::object_ptr<td::td_api::Object> &response);
void connectionReady();
void setPurpleConnectionInProgress();
void setPurpleConnectionUpdating();
void onLoggedIn();
void getContactsResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
void getChatsResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
void requestMissingPrivateChats();
void loginCreatePrivateChatResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
// List of chats is requested after connection is ready, and when response is received,
// then we report to libpurple that we are connected
void updatePurpleChatListAndReportConnected();
// Login sequence end
void showMessage(const td::td_api::chat &chat, td::td_api::message &message,
td::td_api::object_ptr<td::td_api::message> repliedMessage);
2020-05-13 19:15:15 +02:00
void showTextMessage(const td::td_api::chat &chat, const TgMessageInfo &message,const td::td_api::messageText &text);
void showPhotoMessage(const td::td_api::chat &chat, TgMessageInfo &message, const td::td_api::messagePhoto &photo);
void showFileMessage(const td::td_api::chat &chat, TgMessageInfo &message,
td::td_api::object_ptr<td::td_api::file> file,
td::td_api::object_ptr<td::td_api::formattedText> caption,
const std::string &fileDescription);
void showStickerMessage(const td::td_api::chat &chat, TgMessageInfo &message, td::td_api::messageSticker &sticker);
void onIncomingMessage(td::td_api::object_ptr<td::td_api::message> message);
void findMessageResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
2020-02-27 22:27:56 +01:00
void updateUserStatus(uint32_t userId, td::td_api::object_ptr<td::td_api::UserStatus> status);
void updateUser(td::td_api::object_ptr<td::td_api::user> user);
void updateGroup(td::td_api::object_ptr<td::td_api::basicGroup> group);
void updateSupergroup(td::td_api::object_ptr<td::td_api::supergroup> group);
2020-05-20 21:31:08 +02:00
void updateChat(const td::td_api::chat *chat);
2020-05-11 19:35:27 +02:00
void requestBasicGroupMembers(int32_t groupId);
void requestSupergroupFullInfo(int32_t groupId);
2020-05-11 19:35:27 +02:00
void groupInfoResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
void supergroupInfoResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
2020-05-20 21:31:08 +02:00
void addContactById(int32_t userId, const std::string &phoneNumber, const std::string &alias,
const std::string &groupName);
void addChat(td::td_api::object_ptr<td::td_api::chat> chat);
void handleUserChatAction(const td::td_api::updateUserChatAction &updateChatAction);
void showUserChatAction(int32_t userId, bool isTyping);
void importContactResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
void addContactResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
void addContactCreatePrivateChatResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
2020-05-20 21:31:08 +02:00
void notifyFailedContact(const std::string &errorMessage);
2020-05-12 19:37:59 +02:00
void joinChatByLinkResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
void deleteSupergroupResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
void setGroupDescriptionResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
2020-02-22 13:23:01 +01:00
void showFile(const td::td_api::chat &chat, TgMessageInfo &message,
const td::td_api::file &file, const char *caption, const std::string &fileDesc,
td::td_api::object_ptr<td::td_api::file> thumbnail,
FileDownloadCb downloadCallback);
void downloadFile(int32_t fileId, int64_t chatId, TgMessageInfo &message,
const std::string &fileDescription,
td::td_api::object_ptr<td::td_api::file> thumbnail,
FileDownloadCb callback);
void requestDownload(const char *sender, const td::td_api::file &file,
const std::string &fileDesc, const td::td_api::chat &chat,
TgMessageInfo &message, FileDownloadCb callback);
static void startDownload(void *user_data);
void downloadResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
void showDownloadedImage(int64_t chatId, TgMessageInfo &message,
const std::string &filePath, const char *caption,
const std::string &fileDesc,
td::td_api::object_ptr<td::td_api::file> thumbnail);
void showDownloadedFile(int64_t chatId, TgMessageInfo &message,
const std::string &filePath, const char *caption,
const std::string &fileDescription,
td::td_api::object_ptr<td::td_api::file> thumbnail);
void showDownloadedSticker(int64_t chatId, TgMessageInfo &message,
const std::string &filePath, const char *caption,
const std::string &fileDescription,
2020-05-12 13:01:18 +02:00
td::td_api::object_ptr<td::td_api::file> thumbnail);
void uploadResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
void updateFile(const td::td_api::file &file);
bool sendMessage(int64_t chatId, const char *message);
2020-05-16 00:16:06 +02:00
void sendMessageResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
void removeTempFile(int64_t messageId);
void setTwoFactorAuthResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
void requestRecoveryEmailConfirmation(const std::string &emailInfo);
static void verifyRecoveryEmail(PurpleTdClient *self, const char *code);
void verifyRecoveryEmailResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
2020-05-11 22:56:31 +02:00
PurpleAccount *m_account;
TdTransceiver m_transceiver;
TdAccountData m_data;
int32_t m_lastAuthState = 0;
bool m_connectionReady = false;
2020-05-11 22:56:31 +02:00
std::vector<int32_t> m_usersForNewPrivateChats;
2020-05-20 18:31:37 +02:00
bool m_isProxyAdded = false;
td::td_api::object_ptr<td::td_api::proxy> m_addedProxy;
td::td_api::object_ptr<td::td_api::proxies> m_proxies;
};
#endif