2020-08-13 11:15:26 +03:00
|
|
|
/*
|
|
|
|
Copyright (C) 2020 Sebastian J. Wolf
|
|
|
|
|
|
|
|
This file is part of Fernschreiber.
|
|
|
|
|
2020-08-13 18:08:14 +03:00
|
|
|
Fernschreiber is free software: you can redistribute it and/or modify
|
2020-08-13 11:15:26 +03:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
2020-08-13 18:08:14 +03:00
|
|
|
Fernschreiber is distributed in the hope that it will be useful,
|
2020-08-13 11:15:26 +03:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-08-10 15:17:29 +03:00
|
|
|
#ifndef TDLIBWRAPPER_H
|
|
|
|
#define TDLIBWRAPPER_H
|
|
|
|
|
2020-08-10 21:17:13 +03:00
|
|
|
#include <QCoreApplication>
|
2020-08-10 15:17:29 +03:00
|
|
|
#include <td/telegram/td_json_client.h>
|
2020-08-10 21:17:13 +03:00
|
|
|
#include "tdlibreceiver.h"
|
2020-09-15 00:43:21 +03:00
|
|
|
#include "dbusadaptor.h"
|
|
|
|
#include "dbusinterface.h"
|
2020-08-10 15:17:29 +03:00
|
|
|
|
|
|
|
class TDLibWrapper : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit TDLibWrapper(QObject *parent = nullptr);
|
|
|
|
~TDLibWrapper();
|
|
|
|
|
2020-08-13 00:51:09 +03:00
|
|
|
enum AuthorizationState {
|
|
|
|
Closed,
|
|
|
|
Closing,
|
|
|
|
LoggingOut,
|
2020-08-13 11:15:26 +03:00
|
|
|
AuthorizationReady,
|
2020-08-13 00:51:09 +03:00
|
|
|
WaitCode,
|
|
|
|
WaitEncryptionKey,
|
|
|
|
WaitOtherDeviceConfirmation,
|
|
|
|
WaitPassword,
|
|
|
|
WaitPhoneNumber,
|
|
|
|
WaitRegistration,
|
|
|
|
WaitTdlibParameters
|
|
|
|
};
|
2020-08-13 11:15:26 +03:00
|
|
|
Q_ENUM(AuthorizationState)
|
2020-08-13 00:51:09 +03:00
|
|
|
|
2020-08-13 01:20:28 +03:00
|
|
|
enum ConnectionState {
|
|
|
|
Connecting,
|
|
|
|
ConnectingToProxy,
|
2020-08-13 11:15:26 +03:00
|
|
|
ConnectionReady,
|
2020-08-13 01:20:28 +03:00
|
|
|
Updating,
|
|
|
|
WaitingForNetwork
|
|
|
|
};
|
2020-08-13 11:15:26 +03:00
|
|
|
Q_ENUM(ConnectionState)
|
2020-08-13 01:20:28 +03:00
|
|
|
|
2020-10-04 04:27:49 +03:00
|
|
|
enum ChatType {
|
|
|
|
ChatTypeUnknown,
|
|
|
|
ChatTypePrivate,
|
|
|
|
ChatTypeBasicGroup,
|
|
|
|
ChatTypeSupergroup,
|
|
|
|
ChatTypeSecret
|
|
|
|
};
|
|
|
|
Q_ENUM(ChatType)
|
|
|
|
|
|
|
|
enum ChatMemberStatus {
|
|
|
|
ChatMemberStatusUnknown,
|
|
|
|
ChatMemberStatusCreator,
|
|
|
|
ChatMemberStatusAdministrator,
|
|
|
|
ChatMemberStatusMember,
|
|
|
|
ChatMemberStatusRestricted,
|
|
|
|
ChatMemberStatusLeft,
|
|
|
|
ChatMemberStatusBanned
|
|
|
|
};
|
|
|
|
Q_ENUM(ChatMemberStatus)
|
|
|
|
|
|
|
|
class Group {
|
|
|
|
public:
|
|
|
|
Group(qlonglong id) : groupId(id) { }
|
|
|
|
ChatMemberStatus chatMemberStatus() const;
|
|
|
|
public:
|
|
|
|
const qlonglong groupId;
|
|
|
|
QVariantMap groupInfo;
|
|
|
|
};
|
|
|
|
|
2020-08-12 11:50:01 +03:00
|
|
|
Q_INVOKABLE QString getVersion();
|
2020-08-13 00:51:09 +03:00
|
|
|
Q_INVOKABLE TDLibWrapper::AuthorizationState getAuthorizationState();
|
2020-10-01 01:55:26 +03:00
|
|
|
Q_INVOKABLE QVariantMap getAuthorizationStateData();
|
2020-08-13 01:20:28 +03:00
|
|
|
Q_INVOKABLE TDLibWrapper::ConnectionState getConnectionState();
|
2020-08-14 11:33:42 +03:00
|
|
|
Q_INVOKABLE QVariantMap getUserInformation();
|
2020-08-16 18:38:51 +03:00
|
|
|
Q_INVOKABLE QVariantMap getUserInformation(const QString &userId);
|
2020-08-17 00:31:20 +03:00
|
|
|
Q_INVOKABLE QVariantMap getUnreadMessageInformation();
|
|
|
|
Q_INVOKABLE QVariantMap getUnreadChatInformation();
|
2020-10-04 04:27:49 +03:00
|
|
|
Q_INVOKABLE QVariantMap getBasicGroup(qlonglong groupId) const;
|
|
|
|
Q_INVOKABLE QVariantMap getSuperGroup(qlonglong groupId) const;
|
2020-09-15 22:17:44 +03:00
|
|
|
Q_INVOKABLE QVariantMap getChat(const QString &chatId);
|
2020-08-28 12:43:51 +03:00
|
|
|
Q_INVOKABLE void copyFileToDownloads(const QString &filePath);
|
2020-08-28 17:18:33 +03:00
|
|
|
Q_INVOKABLE void openFileOnDevice(const QString &filePath);
|
2020-08-28 11:41:18 +03:00
|
|
|
Q_INVOKABLE void controlScreenSaver(const bool &enabled);
|
2020-08-14 11:33:42 +03:00
|
|
|
|
2020-09-15 00:43:21 +03:00
|
|
|
DBusAdaptor *getDBusAdaptor();
|
|
|
|
|
2020-08-14 11:33:42 +03:00
|
|
|
// Direct TDLib functions
|
|
|
|
Q_INVOKABLE void sendRequest(const QVariantMap &requestObject);
|
2020-08-13 11:15:26 +03:00
|
|
|
Q_INVOKABLE void setAuthenticationPhoneNumber(const QString &phoneNumber);
|
2020-08-13 16:35:43 +03:00
|
|
|
Q_INVOKABLE void setAuthenticationCode(const QString &authenticationCode);
|
2020-09-16 23:36:43 +03:00
|
|
|
Q_INVOKABLE void setAuthenticationPassword(const QString &authenticationPassword);
|
2020-10-01 01:55:26 +03:00
|
|
|
Q_INVOKABLE void registerUser(const QString &firstName, const QString &lastName);
|
2020-08-13 23:32:35 +03:00
|
|
|
Q_INVOKABLE void getChats();
|
2020-08-14 11:33:42 +03:00
|
|
|
Q_INVOKABLE void downloadFile(const QString &fileId);
|
2020-08-21 15:47:08 +03:00
|
|
|
Q_INVOKABLE void openChat(const QString &chatId);
|
|
|
|
Q_INVOKABLE void closeChat(const QString &chatId);
|
2020-08-22 18:30:02 +03:00
|
|
|
Q_INVOKABLE void getChatHistory(const QString &chatId, const qlonglong &fromMessageId = 0, const int &offset = 0, const int &limit = 50, const bool &onlyLocal = false);
|
2020-08-23 00:05:45 +03:00
|
|
|
Q_INVOKABLE void viewMessage(const QString &chatId, const QString &messageId);
|
2020-08-28 18:40:25 +03:00
|
|
|
Q_INVOKABLE void sendTextMessage(const QString &chatId, const QString &message, const QString &replyToMessageId = "0");
|
2020-09-27 14:49:06 +03:00
|
|
|
Q_INVOKABLE void sendPhotoMessage(const QString &chatId, const QString &filePath, const QString &message, const QString &replyToMessageId = "0");
|
2020-09-28 00:24:22 +03:00
|
|
|
Q_INVOKABLE void sendVideoMessage(const QString &chatId, const QString &filePath, const QString &message, const QString &replyToMessageId = "0");
|
|
|
|
Q_INVOKABLE void sendDocumentMessage(const QString &chatId, const QString &filePath, const QString &message, const QString &replyToMessageId = "0");
|
2020-10-15 00:25:56 +03:00
|
|
|
Q_INVOKABLE void sendStickerMessage(const QString &chatId, const QString &filePath, const QString &replyToMessageId = "0");
|
2020-08-25 17:42:46 +03:00
|
|
|
Q_INVOKABLE void getMessage(const QString &chatId, const QString &messageId);
|
2020-09-02 00:14:59 +03:00
|
|
|
Q_INVOKABLE void setOptionInteger(const QString &optionName, const int &optionValue);
|
2020-09-16 01:15:43 +03:00
|
|
|
Q_INVOKABLE void setChatNotificationSettings(const QString &chatId, const QVariantMap ¬ificationSettings);
|
2020-09-19 21:33:51 +03:00
|
|
|
Q_INVOKABLE void editMessageText(const QString &chatId, const QString &messageId, const QString &message);
|
2020-09-20 01:13:42 +03:00
|
|
|
Q_INVOKABLE void deleteMessages(const QString &chatId, const QVariantList messageIds);
|
2020-09-28 23:58:11 +03:00
|
|
|
Q_INVOKABLE void getMapThumbnailFile(const QString &chatId, const double &latitude, const double &longitude, const int &width, const int &height);
|
2020-10-06 00:08:47 +03:00
|
|
|
Q_INVOKABLE void getRecentStickers();
|
|
|
|
Q_INVOKABLE void getInstalledStickerSets();
|
2020-10-15 00:25:56 +03:00
|
|
|
Q_INVOKABLE void getStickerSet(const QString &setId);
|
2020-08-12 11:50:01 +03:00
|
|
|
|
2020-10-04 04:27:49 +03:00
|
|
|
public:
|
|
|
|
const Group* getGroup(qlonglong groupId) const;
|
|
|
|
static ChatMemberStatus chatMemberStatusFromString(const QString &status);
|
|
|
|
|
2020-08-10 15:17:29 +03:00
|
|
|
signals:
|
2020-08-12 11:50:01 +03:00
|
|
|
void versionDetected(const QString &version);
|
2020-08-20 01:24:24 +03:00
|
|
|
void ownUserIdFound(const QString &ownUserId);
|
2020-10-01 01:55:26 +03:00
|
|
|
void authorizationStateChanged(const TDLibWrapper::AuthorizationState &authorizationState, const QVariantMap &authorizationStateData);
|
2020-08-13 00:51:09 +03:00
|
|
|
void optionUpdated(const QString &optionName, const QVariant &optionValue);
|
2020-08-13 01:20:28 +03:00
|
|
|
void connectionStateChanged(const TDLibWrapper::ConnectionState &connectionState);
|
2020-08-17 00:31:20 +03:00
|
|
|
void fileUpdated(const int fileId, const QVariantMap &fileInformation);
|
2020-08-19 10:55:13 +03:00
|
|
|
void newChatDiscovered(const QString &chatId, const QVariantMap &chatInformation);
|
2020-08-17 00:31:20 +03:00
|
|
|
void unreadMessageCountUpdated(const QVariantMap &messageCountInformation);
|
|
|
|
void unreadChatCountUpdated(const QVariantMap &chatCountInformation);
|
2020-08-20 15:58:32 +03:00
|
|
|
void chatLastMessageUpdated(const QString &chatId, const QString &order, const QVariantMap &lastMessage);
|
2020-08-20 01:24:24 +03:00
|
|
|
void chatOrderUpdated(const QString &chatId, const QString &order);
|
2020-08-31 22:51:52 +03:00
|
|
|
void chatReadInboxUpdated(const QString &chatId, const QString &lastReadInboxMessageId, const int &unreadCount);
|
2020-08-30 20:04:16 +03:00
|
|
|
void chatReadOutboxUpdated(const QString &chatId, const QString &lastReadOutboxMessageId);
|
2020-08-21 19:03:51 +03:00
|
|
|
void userUpdated(const QString &userId, const QVariantMap &userInformation);
|
2020-10-04 04:27:49 +03:00
|
|
|
void basicGroupUpdated(qlonglong groupId);
|
|
|
|
void superGroupUpdated(qlonglong groupId);
|
2020-08-21 19:03:51 +03:00
|
|
|
void chatOnlineMemberCountUpdated(const QString &chatId, const int &onlineMemberCount);
|
2020-08-22 18:30:02 +03:00
|
|
|
void messagesReceived(const QVariantList &messages);
|
2020-08-23 00:49:02 +03:00
|
|
|
void newMessageReceived(const QString &chatId, const QVariantMap &message);
|
2020-08-25 00:02:08 +03:00
|
|
|
void copyToDownloadsSuccessful(const QString &fileName, const QString &filePath);
|
|
|
|
void copyToDownloadsError(const QString &fileName, const QString &filePath);
|
2020-08-25 17:42:46 +03:00
|
|
|
void receivedMessage(const QString &messageId, const QVariantMap &message);
|
2020-08-31 00:52:22 +03:00
|
|
|
void messageSendSucceeded(const QString &messageId, const QString &oldMessageId, const QVariantMap &message);
|
2020-09-02 23:49:15 +03:00
|
|
|
void activeNotificationsUpdated(const QVariantList notificationGroups);
|
|
|
|
void notificationGroupUpdated(const QVariantMap notificationGroupUpdate);
|
|
|
|
void notificationUpdated(const QVariantMap updatedNotification);
|
2020-09-16 21:43:36 +03:00
|
|
|
void chatNotificationSettingsUpdated(const QString &chatId, const QVariantMap chatNotificationSettings);
|
2020-09-19 21:33:51 +03:00
|
|
|
void messageContentUpdated(const QString &chatId, const QString &messageId, const QVariantMap &newContent);
|
2020-09-20 01:13:42 +03:00
|
|
|
void messagesDeleted(const QString &chatId, const QVariantList &messageIds);
|
2020-10-01 13:50:29 +03:00
|
|
|
void chatsReceived(const QVariantMap &chats);
|
2020-10-06 00:08:47 +03:00
|
|
|
void recentStickersUpdated(const QVariantList &stickerIds);
|
|
|
|
void stickersReceived(const QVariantList &stickers);
|
|
|
|
void installedStickerSetsUpdated(const QVariantList &stickerSetIds);
|
|
|
|
void stickerSetsReceived(const QVariantList &stickerSets);
|
2020-10-15 00:25:56 +03:00
|
|
|
void stickerSetReceived(const QVariantMap &stickerSet);
|
2020-08-10 15:17:29 +03:00
|
|
|
|
|
|
|
public slots:
|
2020-08-12 11:50:01 +03:00
|
|
|
void handleVersionDetected(const QString &version);
|
2020-10-01 01:55:26 +03:00
|
|
|
void handleAuthorizationStateChanged(const QString &authorizationState, const QVariantMap authorizationStateData);
|
2020-08-13 00:51:09 +03:00
|
|
|
void handleOptionUpdated(const QString &optionName, const QVariant &optionValue);
|
2020-08-13 01:20:28 +03:00
|
|
|
void handleConnectionStateChanged(const QString &connectionState);
|
2020-08-13 18:08:14 +03:00
|
|
|
void handleUserUpdated(const QVariantMap &userInformation);
|
2020-08-22 15:06:26 +03:00
|
|
|
void handleUserStatusUpdated(const QString &userId, const QVariantMap &userStatusInformation);
|
2020-08-16 18:38:51 +03:00
|
|
|
void handleFileUpdated(const QVariantMap &fileInformation);
|
|
|
|
void handleNewChatDiscovered(const QVariantMap &chatInformation);
|
2020-08-17 00:31:20 +03:00
|
|
|
void handleUnreadMessageCountUpdated(const QVariantMap &messageCountInformation);
|
|
|
|
void handleUnreadChatCountUpdated(const QVariantMap &chatCountInformation);
|
2020-08-20 15:58:32 +03:00
|
|
|
void handleChatLastMessageUpdated(const QString &chatId, const QString &order, const QVariantMap &lastMessage);
|
2020-08-20 01:24:24 +03:00
|
|
|
void handleChatOrderUpdated(const QString &chatId, const QString &order);
|
2020-08-31 22:51:52 +03:00
|
|
|
void handleChatReadInboxUpdated(const QString &chatId, const QString &lastReadInboxMessageId, const int &unreadCount);
|
2020-08-30 20:04:16 +03:00
|
|
|
void handleChatReadOutboxUpdated(const QString &chatId, const QString &lastReadOutboxMessageId);
|
2020-10-04 04:27:49 +03:00
|
|
|
void handleBasicGroupUpdated(qlonglong groupId, const QVariantMap &groupInformation);
|
|
|
|
void handleSuperGroupUpdated(qlonglong groupId, const QVariantMap &groupInformation);
|
2020-08-21 19:03:51 +03:00
|
|
|
void handleChatOnlineMemberCountUpdated(const QString &chatId, const int &onlineMemberCount);
|
2020-08-22 18:30:02 +03:00
|
|
|
void handleMessagesReceived(const QVariantList &messages);
|
2020-08-23 00:49:02 +03:00
|
|
|
void handleNewMessageReceived(const QString &chatId, const QVariantMap &message);
|
2020-08-25 17:42:46 +03:00
|
|
|
void handleMessageInformation(const QString &messageId, const QVariantMap &message);
|
2020-08-31 00:52:22 +03:00
|
|
|
void handleMessageSendSucceeded(const QString &messageId, const QString &oldMessageId, const QVariantMap &message);
|
2020-09-02 23:49:15 +03:00
|
|
|
void handleUpdateActiveNotifications(const QVariantList notificationGroups);
|
|
|
|
void handleUpdateNotificationGroup(const QVariantMap notificationGroupUpdate);
|
|
|
|
void handleUpdateNotification(const QVariantMap updatedNotification);
|
2020-09-16 21:43:36 +03:00
|
|
|
void handleChatNotificationSettingsUpdated(const QString &chatId, const QVariantMap &chatNotificationSettings);
|
2020-09-19 21:33:51 +03:00
|
|
|
void handleMessageContentUpdated(const QString &chatId, const QString &messageId, const QVariantMap &newContent);
|
2020-09-20 01:13:42 +03:00
|
|
|
void handleMessagesDeleted(const QString &chatId, const QVariantList &messageIds);
|
2020-10-01 13:50:29 +03:00
|
|
|
void handleChats(const QVariantMap &chats);
|
2020-10-06 00:08:47 +03:00
|
|
|
void handleRecentStickersUpdated(const QVariantList &stickerIds);
|
|
|
|
void handleStickers(const QVariantList &stickers);
|
|
|
|
void handleInstalledStickerSetsUpdated(const QVariantList &stickerSetIds);
|
|
|
|
void handleStickerSets(const QVariantList &stickerSets);
|
2020-10-15 00:25:56 +03:00
|
|
|
void handleStickerSet(const QVariantMap &stickerSet);
|
2020-08-21 19:03:51 +03:00
|
|
|
|
2020-10-04 04:27:49 +03:00
|
|
|
private:
|
|
|
|
void setInitialParameters();
|
|
|
|
void setEncryptionKey();
|
|
|
|
void setLogVerbosityLevel();
|
|
|
|
void initializeOpenWith();
|
|
|
|
const Group *updateGroup(qlonglong groupId, const QVariantMap &groupInfo, QHash<qlonglong,Group*> *groups);
|
|
|
|
|
2020-08-10 15:17:29 +03:00
|
|
|
private:
|
|
|
|
void *tdLibClient;
|
2020-08-10 21:17:13 +03:00
|
|
|
TDLibReceiver *tdLibReceiver;
|
2020-09-15 00:43:21 +03:00
|
|
|
DBusInterface *dbusInterface;
|
2020-08-12 11:50:01 +03:00
|
|
|
QString version;
|
2020-08-13 00:51:09 +03:00
|
|
|
TDLibWrapper::AuthorizationState authorizationState;
|
2020-10-01 01:55:26 +03:00
|
|
|
QVariantMap authorizationStateData;
|
2020-08-13 01:20:28 +03:00
|
|
|
TDLibWrapper::ConnectionState connectionState;
|
2020-08-13 00:51:09 +03:00
|
|
|
QVariantMap options;
|
2020-08-13 18:08:14 +03:00
|
|
|
QVariantMap userInformation;
|
2020-08-20 01:24:24 +03:00
|
|
|
QVariantMap allUsers;
|
2020-08-16 18:38:51 +03:00
|
|
|
QVariantMap chats;
|
2020-08-17 00:31:20 +03:00
|
|
|
QVariantMap unreadMessageInformation;
|
|
|
|
QVariantMap unreadChatInformation;
|
2020-10-04 04:27:49 +03:00
|
|
|
QHash<qlonglong,Group*> basicGroups;
|
|
|
|
QHash<qlonglong,Group*> superGroups;
|
2020-08-10 15:17:29 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // TDLIBWRAPPER_H
|