From c1ea773fae45144f4a90c0a8790cce567e10d4be Mon Sep 17 00:00:00 2001 From: "Sebastian J. Wolf" Date: Mon, 5 Oct 2020 23:08:47 +0200 Subject: [PATCH] Prepare getting some stickers :D --- src/tdlibreceiver.cpp | 30 +++++++++++++++++++++++++++++- src/tdlibreceiver.h | 8 ++++++++ src/tdlibwrapper.cpp | 42 +++++++++++++++++++++++++++++++++++++++++- src/tdlibwrapper.h | 10 ++++++++++ 4 files changed, 88 insertions(+), 2 deletions(-) diff --git a/src/tdlibreceiver.cpp b/src/tdlibreceiver.cpp index 3156786..1a76bea 100644 --- a/src/tdlibreceiver.cpp +++ b/src/tdlibreceiver.cpp @@ -20,7 +20,7 @@ #define LOG(x) qDebug() << "[TDLibReceiver]" << x -#ifdef DEBUG +#if defined (QT_DEBUG) || defined (DEBUG) # define VERBOSE(x) LOG(x) #else # define VERBOSE(x) @@ -99,6 +99,10 @@ TDLibReceiver::TDLibReceiver(void *tdLibClient, QObject *parent) : QThread(paren handlers.insert("updateMessageContent", &TDLibReceiver::processUpdateMessageContent); handlers.insert("updateDeleteMessages", &TDLibReceiver::processUpdateDeleteMessages); handlers.insert("chats", &TDLibReceiver::processChats); + handlers.insert("updateRecentStickers", &TDLibReceiver::processUpdateRecentStickers); + handlers.insert("stickers", &TDLibReceiver::processStickers); + handlers.insert("updateInstalledStickerSets", &TDLibReceiver::processUpdateInstalledStickerSets); + handlers.insert("stickerSets", &TDLibReceiver::processStickerSets); } void TDLibReceiver::setActive(const bool &active) @@ -369,3 +373,27 @@ void TDLibReceiver::processChats(const QVariantMap &receivedInformation) { emit chats(receivedInformation); } + +void TDLibReceiver::processUpdateRecentStickers(const QVariantMap &receivedInformation) +{ + LOG("Recent stickers updated"); + emit recentStickersUpdated(receivedInformation.value("sticker_ids").toList()); +} + +void TDLibReceiver::processStickers(const QVariantMap &receivedInformation) +{ + LOG("Received some stickers..."); + emit stickers(receivedInformation.value("stickers").toList()); +} + +void TDLibReceiver::processUpdateInstalledStickerSets(const QVariantMap &receivedInformation) +{ + LOG("Recent sticker sets updated"); + emit installedStickerSetsUpdated(receivedInformation.value("sticker_set_ids").toList()); +} + +void TDLibReceiver::processStickerSets(const QVariantMap &receivedInformation) +{ + LOG("Received some sticker sets..."); + emit stickers(receivedInformation.value("sets").toList()); +} diff --git a/src/tdlibreceiver.h b/src/tdlibreceiver.h index a520f6d..7ed6ef7 100644 --- a/src/tdlibreceiver.h +++ b/src/tdlibreceiver.h @@ -64,6 +64,10 @@ signals: void messageContentUpdated(const QString &chatId, const QString &messageId, const QVariantMap &newContent); void messagesDeleted(const QString &chatId, const QVariantList &messageIds); void chats(const QVariantMap &chats); + void recentStickersUpdated(const QVariantList &stickerIds); + void stickers(const QVariantList &stickers); + void installedStickerSetsUpdated(const QVariantList &stickerSetIds); + void stickerSets(const QVariantList &stickerSets); private: typedef void (TDLibReceiver::*Handler)(const QVariantMap &); @@ -103,6 +107,10 @@ private: void processUpdateMessageContent(const QVariantMap &receivedInformation); void processUpdateDeleteMessages(const QVariantMap &receivedInformation); void processChats(const QVariantMap &receivedInformation); + void processUpdateRecentStickers(const QVariantMap &receivedInformation); + void processStickers(const QVariantMap &receivedInformation); + void processUpdateInstalledStickerSets(const QVariantMap &receivedInformation); + void processStickerSets(const QVariantMap &receivedInformation); }; #endif // TDLIBRECEIVER_H diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp index fce5754..89dc8c5 100644 --- a/src/tdlibwrapper.cpp +++ b/src/tdlibwrapper.cpp @@ -32,7 +32,7 @@ #define LOG(x) qDebug() << "[TDLibWrapper]" << x -#ifdef DEBUG +#if defined (QT_DEBUG) || defined (DEBUG) # define VERBOSE(x) LOG(x) #else # define VERBOSE(x) @@ -86,6 +86,10 @@ TDLibWrapper::TDLibWrapper(QObject *parent) : QObject(parent), settings("harbour connect(this->tdLibReceiver, SIGNAL(messageContentUpdated(QString, QString, QVariantMap)), this, SLOT(handleMessageContentUpdated(QString, QString, QVariantMap))); connect(this->tdLibReceiver, SIGNAL(messagesDeleted(QString, QVariantList)), this, SLOT(handleMessagesDeleted(QString, QVariantList))); connect(this->tdLibReceiver, SIGNAL(chats(QVariantMap)), this, SLOT(handleChats(QVariantMap))); + connect(this->tdLibReceiver, SIGNAL(recentStickersUpdated(QVariantList)), this, SLOT(handleRecentStickersUpdated(QVariantList))); + connect(this->tdLibReceiver, SIGNAL(stickers(QVariantList)), this, SLOT(handleStickers(QVariantList))); + connect(this->tdLibReceiver, SIGNAL(installedStickerSetsUpdated(QVariantList)), this, SLOT(handleInstalledStickerSetsUpdated(QVariantList))); + connect(this->tdLibReceiver, SIGNAL(stickerSets(QVariantList)), this, SLOT(handleStickerSets(QVariantList))); this->tdLibReceiver->start(); @@ -414,6 +418,22 @@ void TDLibWrapper::getMapThumbnailFile(const QString &chatId, const double &lati this->sendRequest(requestObject); } +void TDLibWrapper::getRecentStickers() +{ + LOG("Retrieving recent stickers"); + QVariantMap requestObject; + requestObject.insert(_TYPE, "getRecentStickers"); + this->sendRequest(requestObject); +} + +void TDLibWrapper::getInstalledStickerSets() +{ + LOG("Retrieving installed sticker sets"); + QVariantMap requestObject; + requestObject.insert(_TYPE, "getInstalledStickerSets"); + this->sendRequest(requestObject); +} + QVariantMap TDLibWrapper::getUserInformation() { return this->userInformation; @@ -755,6 +775,26 @@ void TDLibWrapper::handleChats(const QVariantMap &chats) emit this->chatsReceived(chats); } +void TDLibWrapper::handleRecentStickersUpdated(const QVariantList &stickerIds) +{ + emit this->recentStickersUpdated(stickerIds); +} + +void TDLibWrapper::handleStickers(const QVariantList &stickers) +{ + emit this->stickersReceived(stickers); +} + +void TDLibWrapper::handleInstalledStickerSetsUpdated(const QVariantList &stickerSetIds) +{ + emit this->installedStickerSetsUpdated(stickerSetIds); +} + +void TDLibWrapper::handleStickerSets(const QVariantList &stickerSets) +{ + emit this->stickerSetsReceived(stickerSets); +} + void TDLibWrapper::setInitialParameters() { LOG("Sending initial parameters to TD Lib"); diff --git a/src/tdlibwrapper.h b/src/tdlibwrapper.h index 0ddc23f..a6665b7 100644 --- a/src/tdlibwrapper.h +++ b/src/tdlibwrapper.h @@ -131,6 +131,8 @@ public: Q_INVOKABLE void editMessageText(const QString &chatId, const QString &messageId, const QString &message); Q_INVOKABLE void deleteMessages(const QString &chatId, const QVariantList messageIds); Q_INVOKABLE void getMapThumbnailFile(const QString &chatId, const double &latitude, const double &longitude, const int &width, const int &height); + Q_INVOKABLE void getRecentStickers(); + Q_INVOKABLE void getInstalledStickerSets(); public: const Group* getGroup(qlonglong groupId) const; @@ -167,6 +169,10 @@ signals: void messageContentUpdated(const QString &chatId, const QString &messageId, const QVariantMap &newContent); void messagesDeleted(const QString &chatId, const QVariantList &messageIds); void chatsReceived(const QVariantMap &chats); + void recentStickersUpdated(const QVariantList &stickerIds); + void stickersReceived(const QVariantList &stickers); + void installedStickerSetsUpdated(const QVariantList &stickerSetIds); + void stickerSetsReceived(const QVariantList &stickerSets); public slots: void handleVersionDetected(const QString &version); @@ -197,6 +203,10 @@ public slots: void handleMessageContentUpdated(const QString &chatId, const QString &messageId, const QVariantMap &newContent); void handleMessagesDeleted(const QString &chatId, const QVariantList &messageIds); void handleChats(const QVariantMap &chats); + void handleRecentStickersUpdated(const QVariantList &stickerIds); + void handleStickers(const QVariantList &stickers); + void handleInstalledStickerSetsUpdated(const QVariantList &stickerSetIds); + void handleStickerSets(const QVariantList &stickerSets); private: void setInitialParameters();