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-15 19:46:07 +02:00
|
|
|
#include "client-utils.h"
|
2020-06-02 16:55:48 +02:00
|
|
|
#include <td/telegram/Log.h>
|
2020-02-22 11:42:04 +01:00
|
|
|
#include <purple.h>
|
2020-02-16 17:46:52 +01:00
|
|
|
|
2020-05-22 21:21:50 +02:00
|
|
|
enum class BasicGroupMembership: uint8_t {
|
|
|
|
Invalid,
|
|
|
|
Creator,
|
|
|
|
NonCreator,
|
|
|
|
};
|
|
|
|
|
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-06-02 16:55:48 +02:00
|
|
|
static void setTdlibFatalErrorCallback(td::Log::FatalErrorCallbackPtr callback);
|
|
|
|
static std::string getBaseDatabasePath();
|
2020-05-10 12:05:55 +02:00
|
|
|
int sendMessage(const char *buddyName, const char *message);
|
2020-05-22 18:20:29 +02:00
|
|
|
void sendTyping(const char *buddyName, bool isTyping);
|
2021-01-01 14:14:16 +01:00
|
|
|
void sendReadReceipts(PurpleConversation *conversation);
|
2020-05-22 18:20:29 +02:00
|
|
|
|
2020-05-20 21:31:08 +02:00
|
|
|
void addContact(const std::string &purpleName, const std::string &alias, const std::string &groupName);
|
2020-05-20 13:33:47 +02:00
|
|
|
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);
|
|
|
|
|
2020-05-10 12:05:55 +02:00
|
|
|
bool joinChat(const char *chatName);
|
2020-08-13 13:34:23 +02:00
|
|
|
void joinChatByInviteLink(const char *inviteLink);
|
|
|
|
void joinChatByGroupName(const char *joinString, const char *groupName);
|
2020-05-22 14:48:17 +02:00
|
|
|
void createGroup(const char *name, int type, const std::vector<std::string> &basicGroupMembers);
|
2020-05-22 21:21:50 +02:00
|
|
|
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);
|
2020-06-01 11:13:23 +02:00
|
|
|
void setGroupDescription(int purpleChatId, const char *description);
|
2020-06-07 13:09:35 +02:00
|
|
|
void kickUserFromChat(PurpleConversation *conv, const char *name);
|
2020-06-07 14:07:58 +02:00
|
|
|
void addUserToChat(int purpleChatId, const char *name);
|
2020-06-07 15:18:22 +02:00
|
|
|
void showInviteLink(const std::string &purpleChatName);
|
2020-06-11 00:04:29 +02:00
|
|
|
void getGroupChatList(PurpleRoomlist *roomlist);
|
2020-05-25 23:21:04 +02:00
|
|
|
|
2020-05-31 14:19:09 +02:00
|
|
|
void setTwoFactorAuth(const char *oldPassword, const char *newPassword, const char *hint,
|
2020-05-25 23:21:04 +02:00
|
|
|
const char *email);
|
2020-05-28 21:29:58 +02:00
|
|
|
|
2020-06-12 17:29:58 +02:00
|
|
|
void sendFileToChat(PurpleXfer *xfer, const char *purpleName, PurpleConversationType type,
|
|
|
|
int purpleChatId);
|
2020-05-28 21:29:58 +02:00
|
|
|
void cancelUpload(PurpleXfer *xfer);
|
2020-07-27 17:31:27 +02:00
|
|
|
|
2020-07-26 23:44:51 +02:00
|
|
|
bool startVoiceCall(const char *buddyName);
|
2020-07-27 17:31:27 +02:00
|
|
|
bool terminateCall(PurpleConversation *conv);
|
2020-10-04 16:52:57 +02:00
|
|
|
|
|
|
|
void createSecretChat(const char *buddyName);
|
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);
|
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-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();
|
2020-05-02 13:40:48 +02:00
|
|
|
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);
|
2020-05-22 22:06:02 +02:00
|
|
|
static void displayNameEntered(PurpleTdClient *self, const gchar *name);
|
|
|
|
static void displayNameCancelled(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-05-02 13:40:48 +02:00
|
|
|
void setPurpleConnectionInProgress();
|
2020-05-13 13:14:38 +02:00
|
|
|
void onLoggedIn();
|
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-08-27 17:23:59 +02:00
|
|
|
void onChatListReady();
|
2020-05-02 12:35:31 +02:00
|
|
|
// Login sequence end
|
|
|
|
|
2020-02-27 21:16:12 +01:00
|
|
|
void onIncomingMessage(td::td_api::object_ptr<td::td_api::message> message);
|
2021-01-03 14:20:23 +01:00
|
|
|
void updateChatLastMessage(const td::td_api::updateChatLastMessage &lastMessage);
|
2020-05-08 17:01:12 +02:00
|
|
|
|
2020-10-04 15:17:04 +02:00
|
|
|
void updateUserStatus(UserId 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-06-04 22:57:01 +02:00
|
|
|
void downloadProfilePhoto(const td::td_api::user &user);
|
|
|
|
void avatarDownloadResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
|
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);
|
2020-05-20 21:31:08 +02:00
|
|
|
void updateChat(const td::td_api::chat *chat);
|
2020-06-06 21:36:42 +02:00
|
|
|
void updateUserInfo(const td::td_api::user &user, const td::td_api::chat *privateChat);
|
2020-06-04 22:57:01 +02:00
|
|
|
void downloadChatPhoto(const td::td_api::chat &chat);
|
2020-10-04 15:17:04 +02:00
|
|
|
void requestBasicGroupFullInfo(BasicGroupId groupId);
|
|
|
|
void requestSupergroupFullInfo(SupergroupId groupId);
|
2020-05-11 19:35:27 +02:00
|
|
|
void groupInfoResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
|
2020-06-01 11:12:26 +02:00
|
|
|
void supergroupInfoResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
|
2020-07-05 15:01:24 +02:00
|
|
|
void supergroupMembersResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
|
|
|
|
void supergroupAdministratorsResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
|
2020-10-04 15:17:04 +02:00
|
|
|
void updateGroupFull(BasicGroupId groupId, td::td_api::object_ptr<td::td_api::basicGroupFullInfo> groupInfo);
|
|
|
|
void updateSupergroupFull(SupergroupId groupId, td::td_api::object_ptr<td::td_api::supergroupFullInfo> groupInfo);
|
2020-05-09 14:07:21 +02:00
|
|
|
|
2020-10-04 15:17:04 +02:00
|
|
|
void addContactById(UserId userId, const std::string &phoneNumber, const std::string &alias,
|
2020-05-20 21:31:08 +02:00
|
|
|
const std::string &groupName);
|
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-10-04 15:17:04 +02:00
|
|
|
void showUserChatAction(UserId userId, bool isTyping);
|
2020-08-27 10:26:42 +02:00
|
|
|
void addBuddySearchChatResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
|
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-20 21:31:08 +02:00
|
|
|
void notifyFailedContact(const std::string &errorMessage);
|
2020-08-13 13:34:23 +02:00
|
|
|
void joinChatResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
|
|
|
|
void joinGroupSearchChatResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
|
2020-05-22 21:21:50 +02:00
|
|
|
void deleteSupergroupResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
|
2020-06-01 11:13:23 +02:00
|
|
|
void setGroupDescriptionResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
|
2020-06-07 14:07:58 +02:00
|
|
|
void chatActionResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
|
2020-02-22 13:23:01 +01:00
|
|
|
|
2020-10-18 18:33:41 +02:00
|
|
|
void onAnimatedStickerConverted(AccountThread *arg);
|
2020-06-06 20:12:12 +02:00
|
|
|
void sendMessageCreatePrivateChatResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
|
2020-05-28 21:29:58 +02:00
|
|
|
void uploadResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
|
2020-05-08 17:01:12 +02:00
|
|
|
|
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);
|
2020-05-13 22:22:55 +02:00
|
|
|
|
2020-05-31 14:19:09 +02:00
|
|
|
void setTwoFactorAuthResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
|
2020-05-25 23:21:04 +02:00
|
|
|
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;
|
2020-10-04 15:17:04 +02:00
|
|
|
std::vector<UserId> m_usersForNewPrivateChats;
|
2020-08-27 17:23:59 +02:00
|
|
|
bool m_chatListReady = false;
|
2020-05-20 18:31:37 +02:00
|
|
|
bool m_isProxyAdded = false;
|
2020-06-05 23:20:44 +02:00
|
|
|
int64_t m_lastChatOrderOffset = 0;
|
2020-06-11 00:04:29 +02:00
|
|
|
std::vector<PurpleRoomlist *> m_pendingRoomLists;
|
2020-05-20 18:31:37 +02:00
|
|
|
td::td_api::object_ptr<td::td_api::proxy> m_addedProxy;
|
|
|
|
td::td_api::object_ptr<td::td_api::proxies> m_proxies;
|
2021-01-03 14:20:23 +01:00
|
|
|
|
|
|
|
struct ChatGap {
|
|
|
|
ChatId chatId;
|
|
|
|
MessageId lastMessage;
|
|
|
|
};
|
|
|
|
std::vector<ChatGap> m_chatGaps;
|
2020-02-16 17:46:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|