2020-02-16 17:46:52 +01:00
|
|
|
#ifndef _TD_CLIENT_H
|
|
|
|
#define _TD_CLIENT_H
|
|
|
|
|
2020-02-23 14:02:47 +01:00
|
|
|
#include "account-data.h"
|
2020-05-02 12:44:07 +02:00
|
|
|
#include "transceiver.h"
|
2020-05-13 19:15:15 +02:00
|
|
|
#include "purple-utils.h"
|
2020-02-22 11:42:04 +01:00
|
|
|
#include <purple.h>
|
2020-02-16 17:46:52 +01:00
|
|
|
|
|
|
|
class PurpleTdClient {
|
|
|
|
public:
|
2020-05-06 18:17:05 +02:00
|
|
|
PurpleTdClient(PurpleAccount *acct, ITransceiverBackend *testBackend);
|
2020-02-16 17:46:52 +01:00
|
|
|
~PurpleTdClient();
|
|
|
|
|
2020-02-17 23:30:24 +01:00
|
|
|
static void setLogLevel(int level);
|
2020-05-10 12:05:55 +02:00
|
|
|
int sendMessage(const char *buddyName, const char *message);
|
2020-05-13 12:31:03 +02:00
|
|
|
void addContact(const std::string &phoneNumber, const std::string &alias, const std::string &groupName);
|
2020-05-10 12:05:55 +02:00
|
|
|
bool joinChat(const char *chatName);
|
2020-05-10 14:24:15 +02:00
|
|
|
int sendGroupMessage(int purpleChatId, const char *message);
|
2020-05-12 19:37:59 +02:00
|
|
|
bool joinChatByLink(const char *inviteLink);
|
2020-02-16 17:46:52 +01:00
|
|
|
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);
|
|
|
|
using TdAuthCodePtr = td::td_api::object_ptr<td::td_api::authenticationCodeInfo>;
|
2020-02-16 17:46:52 +01:00
|
|
|
|
2020-05-10 16:32:13 +02:00
|
|
|
void processUpdate(td::td_api::Object &object);
|
|
|
|
void processAuthorizationState(td::td_api::AuthorizationState &authState);
|
2020-05-02 12:44:07 +02:00
|
|
|
|
|
|
|
// Login sequence start
|
2020-05-02 13:40:48 +02:00
|
|
|
void sendTdlibParameters();
|
|
|
|
void sendPhoneNumber();
|
|
|
|
void requestAuthCode();
|
2020-02-22 14:58:32 +01:00
|
|
|
static void requestCodeEntered(PurpleTdClient *self, const gchar *code);
|
|
|
|
static void requestCodeCancelled(PurpleTdClient *self);
|
2020-02-22 15:53:07 +01:00
|
|
|
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);
|
2020-02-22 15:53:07 +01:00
|
|
|
void connectionReady();
|
2020-05-02 13:40:48 +02:00
|
|
|
void setPurpleConnectionInProgress();
|
|
|
|
void setPurpleConnectionUpdating();
|
2020-03-25 16:49:26 +01:00
|
|
|
void getContactsResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
|
2020-02-22 19:03:14 +01:00
|
|
|
void getChatsResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
|
2020-05-02 12:35:31 +02:00
|
|
|
void requestMissingPrivateChats();
|
|
|
|
void loginCreatePrivateChatResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
|
2020-02-29 15:30:24 +01:00
|
|
|
// List of chats is requested after connection is ready, and when response is received,
|
|
|
|
// then we report to libpurple that we are connected
|
2020-05-02 13:40:48 +02:00
|
|
|
void updatePurpleChatListAndReportConnected();
|
2020-05-02 12:35:31 +02:00
|
|
|
// Login sequence end
|
|
|
|
|
2020-05-12 11:45:49 +02:00
|
|
|
void showMessage(const td::td_api::chat &chat, td::td_api::message &message);
|
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, const TgMessageInfo &message, const td::td_api::messagePhoto &photo);
|
|
|
|
void showDocument(const td::td_api::chat &chat, const TgMessageInfo &message, const td::td_api::messageDocument &document);
|
|
|
|
void showVideo(const td::td_api::chat &chat, const TgMessageInfo &message, const td::td_api::messageVideo &video);
|
|
|
|
void showSticker(const td::td_api::chat &chat, const TgMessageInfo &message, td::td_api::messageSticker &sticker);
|
2020-02-27 21:16:12 +01:00
|
|
|
void onIncomingMessage(td::td_api::object_ptr<td::td_api::message> message);
|
2020-05-08 17:01:12 +02:00
|
|
|
|
2020-02-27 22:27:56 +01:00
|
|
|
void updateUserStatus(uint32_t userId, td::td_api::object_ptr<td::td_api::UserStatus> status);
|
2020-03-08 23:27:58 +01:00
|
|
|
void updateUser(td::td_api::object_ptr<td::td_api::user> user);
|
2020-05-09 14:07:21 +02:00
|
|
|
void updateGroup(td::td_api::object_ptr<td::td_api::basicGroup> group);
|
|
|
|
void updateSupergroup(td::td_api::object_ptr<td::td_api::supergroup> group);
|
|
|
|
void updatePrivateChat(const td::td_api::chat &chat, const td::td_api::user &user);
|
|
|
|
void updateBasicGroupChat(int32_t groupId);
|
|
|
|
void updateSupergroupChat(int32_t groupId);
|
2020-05-11 19:35:27 +02:00
|
|
|
void requestBasicGroupMembers(int32_t groupId);
|
|
|
|
void groupInfoResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
|
2020-05-09 14:07:21 +02:00
|
|
|
|
2020-05-08 19:50:55 +02:00
|
|
|
void addChat(td::td_api::object_ptr<td::td_api::chat> chat);
|
2020-03-15 21:47:47 +01:00
|
|
|
void handleUserChatAction(const td::td_api::updateUserChatAction &updateChatAction);
|
2020-05-02 13:40:48 +02:00
|
|
|
void showUserChatAction(int32_t userId, bool isTyping);
|
2020-03-23 22:56:16 +01:00
|
|
|
void importContactResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
|
2020-03-21 14:32:33 +01:00
|
|
|
void addContactResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
|
2020-05-02 12:35:31 +02:00
|
|
|
void addContactCreatePrivateChatResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
|
2020-05-04 17:07:53 +02:00
|
|
|
void notifyFailedContact(const std::string &phoneNumber, 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);
|
2020-02-22 13:23:01 +01:00
|
|
|
|
2020-05-13 19:15:15 +02:00
|
|
|
void requestDownload(int32_t fileId, int64_t chatId, const TgMessageInfo &message,
|
2020-05-12 13:01:18 +02:00
|
|
|
td::td_api::object_ptr<td::td_api::file> thumbnail,
|
|
|
|
TdTransceiver::ResponseCb responseCb);
|
2020-05-13 19:15:15 +02:00
|
|
|
void showImage(const td::td_api::chat &chat, const TgMessageInfo &message, const td::td_api::file &file);
|
2020-05-12 10:57:32 +02:00
|
|
|
void imageDownloadResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
|
2020-05-13 19:15:15 +02:00
|
|
|
void showDownloadedImage(int64_t chatId, const TgMessageInfo &message, const std::string &filePath);
|
|
|
|
void showInlineFile(const td::td_api::chat &chat, const TgMessageInfo &message,
|
2020-05-12 13:01:18 +02:00
|
|
|
const td::td_api::file &file);
|
2020-05-12 10:57:32 +02:00
|
|
|
void fileDownloadResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
|
2020-05-13 19:15:15 +02:00
|
|
|
void showDownloadedInlineFile(int64_t chatId, const TgMessageInfo &message,
|
|
|
|
const std::string &filePath, const char *label);
|
2020-05-12 13:01:18 +02:00
|
|
|
void stickerDownloadResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
|
2020-05-13 19:15:15 +02:00
|
|
|
void showDownloadedSticker(int64_t chatId, const TgMessageInfo &message,
|
|
|
|
const std::string &filePath,
|
2020-05-12 13:01:18 +02:00
|
|
|
td::td_api::object_ptr<td::td_api::file> thumbnail);
|
2020-05-08 17:01:12 +02:00
|
|
|
|
2020-05-13 22:22:55 +02:00
|
|
|
bool sendMessage(int64_t chatId, const char *message);
|
|
|
|
|
2020-05-11 22:56:31 +02:00
|
|
|
PurpleAccount *m_account;
|
|
|
|
TdTransceiver m_transceiver;
|
|
|
|
TdAccountData m_data;
|
|
|
|
int32_t m_lastAuthState = 0;
|
|
|
|
TdAuthCodePtr m_authCodeInfo;
|
|
|
|
std::vector<int32_t> m_usersForNewPrivateChats;
|
2020-02-16 17:46:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|