/
s5z6
/
telegraf
Обзор
Документация
Войти
/
s5z6
/
telegraf
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/tdlib/tdlibresponsehandler.cpp
624 строки
32 KB
mbarashkov
Также убираем flood_wait код
06 июл 2025, 14:07
06 июл 2025, 14:07
4ae8cce
Код
Авторство
О чём код?
#include "tdlibresponsehandler.h" #include "../tdlibsecrets.h" #include <QLocale> #include <QSysInfo> #include <QDir> #include <QRegularExpression> #include <td/telegram/td_json_client.h> #include <td/telegram/Client.h> #include <td/telegram/td_api.h> #include "../data/groupsmodel.h" #include "../debuglog.h" TDLibResponseHandler* TDLibResponseHandler::instance; namespace { const char STATUS[] = "status"; const char ID[] = "id"; const char MESSAGE_ID[] = "message_id"; const char TYPE[] = "type"; const char USERNAME[] = "username"; const char CHAT_LIST_TYPE[] = "chat_list_type"; const char _TYPE[] = "@type"; const char _EXTRA[] = "@extra"; const char MESSAGE[] = "message"; const char CHAT_LIST_MAIN[] = "chatListMain"; const char CHAT_LIST_FOLDER[] = "chatListFolder"; const char CHAT_LIST_ARCHIVE[] = "chatListArchive"; const char CHAT_AVAILABLE_REACTIONS[] = "available_reactions"; } TDLibResponseHandler::TDLibResponseHandler( QString dbPath, QObject *parent ) : QObject(parent), dbPath(dbPath) { initializeTDLibReceiver(); TDLibResponseHandler::instance = this; } TDLibResponseHandler::~TDLibResponseHandler() { _tdLibReceiver->setActive(false); while (_tdLibReceiver->isRunning()) QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); } void TDLibResponseHandler::initializeTDLibReceiver() { _tdLibReceiver = new TDLibReceiver(TDLibState::getInstance()->getClientId(), this); connect(_tdLibReceiver, SIGNAL(versionDetected(QString)), this, SLOT(handleVersionDetected(QString))); connect(_tdLibReceiver, SIGNAL(authorizationStateChanged(QString,QVariantMap)), this, SLOT(handleAuthorizationStateChanged(QString,QVariantMap))); connect(_tdLibReceiver, SIGNAL(optionUpdated(QString,QVariant)), this, SLOT(handleOptionUpdated(QString,QVariant))); connect(_tdLibReceiver, SIGNAL(connectionStateChanged(QString)), this, SLOT(handleConnectionStateChanged(QString))); connect(_tdLibReceiver, SIGNAL(userUpdated(QVariantMap)), this, SLOT(handleUserUpdated(QVariantMap))); connect(_tdLibReceiver, SIGNAL(userStatusUpdated(qlonglong,QVariantMap)), this, SLOT(handleUserStatusUpdated(qlonglong,QVariantMap))); connect(_tdLibReceiver, SIGNAL(fileUpdated(QVariantMap)), this, SLOT(handleFileUpdated(QVariantMap))); connect(_tdLibReceiver, SIGNAL(newChatDiscovered(QVariantMap)), this, SLOT(handleNewChatDiscovered(QVariantMap))); connect(_tdLibReceiver, SIGNAL(updateChatFolders(QVariantList,qlonglong)), this, SLOT(handleChatFolders(QVariantList,qlonglong))); connect(_tdLibReceiver, SIGNAL(updateChatInArchive(qlonglong)), this, SIGNAL(chatInArchive(qlonglong))); connect(_tdLibReceiver, SIGNAL(unreadMessageCountUpdated(QVariantMap)), this, SLOT(handleUnreadMessageCountUpdated(QVariantMap))); connect(_tdLibReceiver, SIGNAL(unreadChatCountUpdated(QVariantMap)), this, SLOT(handleUnreadChatCountUpdated(QVariantMap))); connect(_tdLibReceiver, SIGNAL(chatLastMessageUpdated(QString,QString,QVariantMap)), this, SIGNAL(chatLastMessageUpdated(QString,QString,QVariantMap))); connect(_tdLibReceiver, SIGNAL(chatOrderUpdated(QString,QString,QString)), this, SIGNAL(chatOrderUpdated(QString,QString,QString))); connect(_tdLibReceiver, SIGNAL(chatReadInboxUpdated(QString,QString,int)), this, SIGNAL(chatReadInboxUpdated(QString,QString,int))); connect(_tdLibReceiver, SIGNAL(chatReadOutboxUpdated(QString,QString)), this, SIGNAL(chatReadOutboxUpdated(QString,QString))); connect(_tdLibReceiver, SIGNAL(chatAvailableReactionsUpdated(qlonglong,QVariantMap)), this, SLOT(handleAvailableReactionsUpdated(qlonglong,QVariantMap))); connect(_tdLibReceiver, SIGNAL(basicGroupUpdated(qlonglong,QVariantMap)), this, SLOT(handleBasicGroupUpdated(qlonglong,QVariantMap))); connect(_tdLibReceiver, SIGNAL(superGroupUpdated(qlonglong,QVariantMap)), this, SLOT(handleSuperGroupUpdated(qlonglong,QVariantMap))); connect(_tdLibReceiver, SIGNAL(chatOnlineMemberCountUpdated(QString,int)), this, SIGNAL(chatOnlineMemberCountUpdated(QString,int))); connect(_tdLibReceiver, SIGNAL(messagesReceived(QVariantList,int)), this, SIGNAL(messagesReceived(QVariantList,int))); connect(_tdLibReceiver, SIGNAL(messagePropertiesReceived(qlonglong,bool,bool,bool)), this, SIGNAL(messagePropertiesReceived(qlonglong,bool,bool,bool))); connect(_tdLibReceiver, SIGNAL(sponsoredMessageReceived(qlonglong,QVariantMap)), this, SLOT(handleSponsoredMessage(qlonglong,QVariantMap))); connect(_tdLibReceiver, SIGNAL(messageLinkInfoReceived(QString,QVariantMap,QString)), this, SIGNAL(messageLinkInfoReceived(QString,QVariantMap,QString))); connect(_tdLibReceiver, SIGNAL(newMessageReceived(qlonglong,QVariantMap)), this, SIGNAL(newMessageReceived(qlonglong,QVariantMap))); connect(_tdLibReceiver, SIGNAL(messageInformation(qlonglong,qlonglong,QVariantMap)), this, SLOT(handleMessageInformation(qlonglong,qlonglong,QVariantMap))); connect(_tdLibReceiver, SIGNAL(messageSendSucceeded(qlonglong,qlonglong,QVariantMap)), this, SIGNAL(messageSendSucceeded(qlonglong,qlonglong,QVariantMap))); connect(_tdLibReceiver, SIGNAL(activeNotificationsUpdated(QVariantList)), this, SIGNAL(activeNotificationsUpdated(QVariantList))); connect(_tdLibReceiver, SIGNAL(notificationGroupUpdated(QVariantMap)), this, SIGNAL(notificationGroupUpdated(QVariantMap))); connect(_tdLibReceiver, SIGNAL(notificationUpdated(QVariantMap)), this, SIGNAL(notificationUpdated(QVariantMap))); connect(_tdLibReceiver, SIGNAL(chatNotificationSettingsUpdated(QString,QVariantMap)), this, SIGNAL(chatNotificationSettingsUpdated(QString,QVariantMap))); connect(_tdLibReceiver, SIGNAL(messageContentUpdated(qlonglong,qlonglong,QVariantMap)), this, SIGNAL(messageContentUpdated(qlonglong,qlonglong,QVariantMap))); connect(_tdLibReceiver, SIGNAL(messagesDeleted(qlonglong,QList<qlonglong>)), this, SIGNAL(messagesDeleted(qlonglong,QList<qlonglong>))); connect(_tdLibReceiver, SIGNAL(chats(QVariantMap)), this, SIGNAL(chatsReceived(QVariantMap))); connect(_tdLibReceiver, SIGNAL(chat(QVariantMap)), this, SLOT(handleChatReceived(QVariantMap))); connect(_tdLibReceiver, SIGNAL(secretChat(qlonglong,QVariantMap)), this, SLOT(handleSecretChatReceived(qlonglong,QVariantMap))); connect(_tdLibReceiver, SIGNAL(secretChatUpdated(qlonglong,QVariantMap)), this, SLOT(handleSecretChatUpdated(qlonglong,QVariantMap))); connect(_tdLibReceiver, SIGNAL(recentStickersUpdated(QVariantList)), this, SIGNAL(recentStickersUpdated(QVariantList))); connect(_tdLibReceiver, SIGNAL(stickers(QVariantList)), this, SIGNAL(stickersReceived(QVariantList))); connect(_tdLibReceiver, SIGNAL(installedStickerSetsUpdated(QVariantList)), this, SIGNAL(installedStickerSetsUpdated(QVariantList))); connect(_tdLibReceiver, SIGNAL(stickerSets(QVariantList)), this, SLOT(handleStickerSets(QVariantList))); connect(_tdLibReceiver, SIGNAL(stickerSet(QVariantMap)), this, SIGNAL(stickerSetReceived(QVariantMap))); connect(_tdLibReceiver, SIGNAL(chatMembers(QString,QVariantList,int)), this, SIGNAL(chatMembersReceived(QString,QVariantList,int))); connect(_tdLibReceiver, SIGNAL(userFullInfo(QVariantMap)), this, SIGNAL(userFullInfoReceived(QVariantMap))); connect(_tdLibReceiver, SIGNAL(userFullInfoUpdated(QString,QVariantMap)), this, SIGNAL(userFullInfoUpdated(QString,QVariantMap))); connect(_tdLibReceiver, SIGNAL(basicGroupFullInfo(QString,QVariantMap)), this, SIGNAL(basicGroupFullInfoReceived(QString,QVariantMap))); connect(_tdLibReceiver, SIGNAL(basicGroupFullInfoUpdated(QString,QVariantMap)), this, SIGNAL(basicGroupFullInfoUpdated(QString,QVariantMap))); connect(_tdLibReceiver, SIGNAL(supergroupFullInfo(QString,QVariantMap)), this, SIGNAL(supergroupFullInfoReceived(QString,QVariantMap))); connect(_tdLibReceiver, SIGNAL(supergroupFullInfoUpdated(QString,QVariantMap)), this, SIGNAL(supergroupFullInfoUpdated(QString,QVariantMap))); connect(_tdLibReceiver, SIGNAL(userProfilePhotos(QString,QVariantList,int)), this, SIGNAL(userProfilePhotosReceived(QString,QVariantList,int))); connect(_tdLibReceiver, SIGNAL(chatPermissionsUpdated(QString,QVariantMap)), this, SIGNAL(chatPermissionsUpdated(QString,QVariantMap))); connect(_tdLibReceiver, SIGNAL(chatPhotoUpdated(qlonglong,QVariantMap)), this, SIGNAL(chatPhotoUpdated(qlonglong,QVariantMap))); connect(_tdLibReceiver, SIGNAL(chatTitleUpdated(QString,QString)), this, SIGNAL(chatTitleUpdated(QString,QString))); connect(_tdLibReceiver, SIGNAL(chatPinnedUpdated(qlonglong,bool,QString)), this, SIGNAL(chatPinnedUpdated(qlonglong,bool,QString))); connect(_tdLibReceiver, SIGNAL(chatPinnedMessageUpdated(qlonglong,qlonglong)), this, SIGNAL(chatPinnedMessageUpdated(qlonglong,qlonglong))); connect(_tdLibReceiver, SIGNAL(messageIsPinnedUpdated(qlonglong,qlonglong,bool)), this, SLOT(handleMessageIsPinnedUpdated(qlonglong,qlonglong,bool))); connect(_tdLibReceiver, SIGNAL(usersReceived(QString,QVariantList,int)), this, SIGNAL(usersReceived(QString,QVariantList,int))); connect(_tdLibReceiver, SIGNAL(messageSendersReceived(QString,QVariantList,int)), this, SIGNAL(messageSendersReceived(QString,QVariantList,int))); connect(_tdLibReceiver, SIGNAL(errorReceived(int,QString,QString)), this, SLOT(handleErrorReceived(int,QString,QString))); connect(_tdLibReceiver, SIGNAL(contactsImported(QVariantList,QVariantList)), this, SIGNAL(contactsImported(QVariantList,QVariantList))); connect(_tdLibReceiver, SIGNAL(messageEditedUpdated(qlonglong,qlonglong,QVariantMap)), this, SIGNAL(messageEditedUpdated(qlonglong,qlonglong,QVariantMap))); connect(_tdLibReceiver, SIGNAL(chatIsMarkedAsUnreadUpdated(qlonglong,bool)), this, SIGNAL(chatIsMarkedAsUnreadUpdated(qlonglong,bool))); connect(_tdLibReceiver, SIGNAL(chatDraftMessageUpdated(qlonglong,QVariantMap,QString)), this, SIGNAL(chatDraftMessageUpdated(qlonglong,QVariantMap,QString))); connect(_tdLibReceiver, SIGNAL(inlineQueryResults(QString,QString,QVariantList,QString,QString,QString)), this, SIGNAL(inlineQueryResults(QString,QString,QVariantList,QString,QString,QString))); connect(_tdLibReceiver, SIGNAL(callbackQueryAnswer(QString,bool,QString)), this, SIGNAL(callbackQueryAnswer(QString,bool,QString))); connect(_tdLibReceiver, SIGNAL(userPrivacySettingRules(QVariantMap)), this, SLOT(handleUserPrivacySettingRules(QVariantMap))); connect(_tdLibReceiver, SIGNAL(userPrivacySettingRulesUpdated(QVariantMap)), this, SLOT(handleUpdatedUserPrivacySettingRules(QVariantMap))); connect(_tdLibReceiver, SIGNAL(messageInteractionInfoUpdated(qlonglong,qlonglong,QVariantMap)), this, SIGNAL(messageInteractionInfoUpdated(qlonglong,qlonglong,QVariantMap))); connect(_tdLibReceiver, SIGNAL(okReceived(QString)), this, SIGNAL(okReceived(QString))); connect(_tdLibReceiver, SIGNAL(sessionsReceived(int,QVariantList)), this, SIGNAL(sessionsReceived(int,QVariantList))); connect(_tdLibReceiver, SIGNAL(availableReactionsReceived(qlonglong,QStringList)), this, SIGNAL(availableReactionsReceived(qlonglong,QStringList))); connect(_tdLibReceiver, SIGNAL(chatUnreadMentionCountUpdated(qlonglong,int)), this, SIGNAL(chatUnreadMentionCountUpdated(qlonglong,int))); connect(_tdLibReceiver, SIGNAL(chatUnreadReactionCountUpdated(qlonglong,int)), this, SIGNAL(chatUnreadReactionCountUpdated(qlonglong,int))); connect(_tdLibReceiver, SIGNAL(activeEmojiReactionsUpdated(QStringList)), this, SLOT(handleActiveEmojiReactionsUpdated(QStringList))); connect(_tdLibReceiver, SIGNAL(gotChatFolder(QVariantMap)), this, SLOT(handleChatFolder(QVariantMap))); connect(_tdLibReceiver, SIGNAL(responseOkOrErrorReceived(QJsonObject)), this, SLOT(handleOkOrErrorReceived(QJsonObject))); connect(_tdLibReceiver, SIGNAL(forumTopicsReceived(QVariantMap)), this, SLOT(handleForumTopics(QVariantMap))); connect(_tdLibReceiver, SIGNAL(forumTopicReceived(QVariantMap)), this, SLOT(handleForumTopic(QVariantMap))); connect(_tdLibReceiver, SIGNAL(updateForumTopicInfoReceived(QVariantMap)), this, SLOT(handleUpdateForumTopicInfo(QVariantMap))); connect(_tdLibReceiver, SIGNAL(userVerificationStatusUpdated(qlonglong,QVariantMap)), this, SIGNAL(userVerificationStatusUpdated(qlonglong,QVariantMap))); connect(_tdLibReceiver, SIGNAL(storageStatisticsFastReceived(QVariantMap)), this, SLOT(handleStorageStatisticsFastReceived(QVariantMap))); connect(_tdLibReceiver, SIGNAL(storageStatisticsReceived()), this, SIGNAL(receivedStorageStatistics())); _tdLibReceiver->start(); } void TDLibResponseHandler::handleOkOrErrorReceived(const QJsonObject &jsonResponse) { const QString extra = jsonResponse.value(_EXTRA).toString(); const QString message = jsonResponse.value(MESSAGE).toString(); const QString type = jsonResponse.value(_TYPE).toString(); int code = jsonResponse.value("code").toInt(); if (type == "ok") { if (extra.contains("chatListMain") && !_allMainChatsLoaded) { if (!TDLibRequestService::getInstance()->isRequestTimerActive()) TDLibRequestSender::getInstance()->callGetChatListMain(100); return; } if (extra.contains("chatListFolder") || extra.contains("chatListArchive")) { if (!TDLibRequestService::getInstance()->isRequestTimerActive()) TDLibRequestService::getInstance()->callProcessNextRequest(); return; } } if (type == "error") { /*if (code == 420) { // FLOOD_WAIT - tdlib его не присылает. Код писался вслепую и никогда не работал. LOG_DEBUG(LOG_TDLIB_FLOODWAIT, "Получили floodwait " << message); QRegularExpression re("FLOOD_WAIT_(\\d+)"); auto match = re.match(message); if (match.hasMatch()) { TDLibState::getInstance()->floodWait = true; int waitSeconds = match.captured(1).toInt(); int waitMs = (waitSeconds + 1) * 1000; LOG_DEBUG(LOG_TDLIB_FLOODWAIT, "Ожидаем floodwait секунд: " << waitSeconds); QTimer::singleShot(waitMs, this, []() { TDLibState::getInstance()->floodWait = false; if (!TDLibRequestService::getInstance()->isRequestTimerActive()) TDLibRequestService::getInstance()->callProcessNextRequest(); }); } } else */ if (code == 404) { if(extra.contains("chatListMain")) { _allMainChatsLoaded = true; } } else { // Для других ошибок продолжаем обработку if (!TDLibRequestService::getInstance()->isRequestTimerActive()) TDLibRequestService::getInstance()->callProcessNextRequest(); } } } void TDLibResponseHandler::handleForumTopics(const QVariantMap &forumTopicsInformation) { auto topics = forumTopicsInformation.value("topics").toList(); QVariantMap simpleTopicList; for (auto &topic: topics) { QVariantMap simpleTopic; auto info = topic.toMap().value("info").toMap(); auto name = info.value("name").toString(); auto message_thread_id = info.value("message_thread_id").toLongLong(); auto color = info.value("icon").toMap().value("color"); auto custom_emoji_id = info.value("icon").toMap().value("custom_emoji_id"); auto is_general = info.value("is_general").toBool(); simpleTopic.insert("name", name); simpleTopic.insert("message_thread_id", message_thread_id); simpleTopic.insert("color", color); simpleTopic.insert("custom_emoji_id",custom_emoji_id); simpleTopic.insert("is_general", is_general); simpleTopicList.insert(QString::number(message_thread_id), simpleTopic); } emit receivedForumTopics(simpleTopicList); } void TDLibResponseHandler::handleForumTopic(const QVariantMap &forumTopic) { emit receivedForumTopic(forumTopic); } void TDLibResponseHandler::handleUpdateForumTopicInfo(const QVariantMap &forumTopicInfo) { emit receivedUpdateForumTopicInfo(forumTopicInfo); } void TDLibResponseHandler::handleStorageStatisticsFastReceived(const QVariantMap &storageStatisticsFast) { auto databaseSize = storageStatisticsFast.value("database_size").toLongLong(); auto fileCount = storageStatisticsFast.value("file_count").toLongLong(); auto filesSize = storageStatisticsFast.value("files_size").toLongLong(); emit receivedStorageStatisticsFast(databaseSize, fileCount, filesSize); } void TDLibResponseHandler::handleVersionDetected(const QString &version) { TDLibState::getInstance()->setTdLibVersion(version); emit versionDetected(version); } void TDLibResponseHandler::handleAuthorizationStateChanged(const QString &authorizationState, const QVariantMap authorizationStateData) { TDLibConstants::AuthorizationState newAuthorizationState; if (authorizationState == "authorizationStateClosed") { newAuthorizationState = TDLibConstants::AuthorizationState::Closed; GroupsModel::getInstance()->reset(); TDLibDataRepository::getInstance()->clear(); _tdLibReceiver->setActive(false); while (_tdLibReceiver->isRunning()) QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); _tdLibReceiver->terminate(); QDir appPath(dbPath); appPath.removeRecursively(); initializeTDLibReceiver(); TDLibState::getInstance()->loggingOut = false; } else if (authorizationState == "authorizationStateClosing") { newAuthorizationState = TDLibConstants::AuthorizationState::Closing; } else if (authorizationState == "authorizationStateLoggingOut") { newAuthorizationState = TDLibConstants::AuthorizationState::LoggingOut; } else if (authorizationState == "authorizationStateReady") { newAuthorizationState = TDLibConstants::AuthorizationState::AuthorizationReady; } else if (authorizationState == "authorizationStateWaitCode") { newAuthorizationState = TDLibConstants::AuthorizationState::WaitCode; } else if (authorizationState == "authorizationStateWaitEncryptionKey") { TDLibRequestService::getInstance()->sendRequest(TDLibRequestFactory::getInstance()->setEncryptionKeyRequest()); newAuthorizationState = TDLibConstants::AuthorizationState::WaitEncryptionKey; } else if (authorizationState == "authorizationStateWaitOtherDeviceConfirmation") { newAuthorizationState = TDLibConstants::AuthorizationState::WaitOtherDeviceConfirmation; } else if (authorizationState == "authorizationStateWaitPassword") { newAuthorizationState = TDLibConstants::AuthorizationState::WaitPassword; } else if (authorizationState == "authorizationStateWaitPhoneNumber") { newAuthorizationState = TDLibConstants::AuthorizationState::WaitPhoneNumber; } else if (authorizationState == "authorizationStateWaitRegistration") { newAuthorizationState = TDLibConstants::AuthorizationState::WaitRegistration; } else if (authorizationState == "authorizationStateWaitTdlibParameters") { TDLibRequestService::getInstance()->sendRequest(TDLibRequestFactory::getInstance()->setTdLibParametersRequest(dbPath)); newAuthorizationState = TDLibConstants::AuthorizationState::WaitTdlibParameters; } else if (authorizationState == "authorizationStateLoggingOut") { newAuthorizationState = TDLibConstants::AuthorizationState::AuthorizationStateLoggingOut; } else { return; } TDLibState::getInstance()->setAuthorizationStateAndData(newAuthorizationState, authorizationStateData); } void TDLibResponseHandler::handleOptionUpdated(const QString &optionName, const QVariant &optionValue) { TDLibState::getInstance()->updateOption(optionName, optionValue); } void TDLibResponseHandler::handleConnectionStateChanged(const QString &connectionState) { TDLibState::getInstance()->setConnectionState(TDLibConstants::getInstance()->connectionStateFromString(connectionState)); } void TDLibResponseHandler::handleUserUpdated(const QVariantMap &updatedUserInformation) { const qlonglong userId = updatedUserInformation.value(ID).toLongLong(); if (userId == TDLibState::getInstance()->getMyUserId()) { TDLibState::getInstance()->updateMyUser(updatedUserInformation); } updateUserInformation(userId, updatedUserInformation); emit userUpdated(userId, updatedUserInformation); } void TDLibResponseHandler::handleUserStatusUpdated(const qlonglong userId, const QVariantMap &userStatusInformation) { if (userId == TDLibState::getInstance()->getMyUserId()) { TDLibState::getInstance()->setMyUserInformationStatus(userStatusInformation); } QVariantMap updatedUserInformation = TDLibDataRepository::getInstance()->getUserById(userId); if (updatedUserInformation[STATUS] == userStatusInformation) { return; } updatedUserInformation.insert(STATUS, userStatusInformation); updateUserInformation(userId, updatedUserInformation); emit userUpdated(userId, updatedUserInformation); } void TDLibResponseHandler::updateUserInformation(const qlonglong userId, const QVariantMap &userInformation) { TDLibDataRepository::getInstance()->putUser(userId, userInformation); } void TDLibResponseHandler::handleFileUpdated(const QVariantMap &fileInformation) { emit fileUpdated(fileInformation.value(ID).toInt(), fileInformation); } void TDLibResponseHandler::handleNewChatDiscovered(const QVariantMap &chatInformation) { TDLibDataRepository::getInstance()->putChat(chatInformation); QString chatId = chatInformation.value(ID).toString(); emit newChatDiscovered(chatId, chatInformation); } void TDLibResponseHandler::handleChatFolders(const QVariantList &foldersInformation, qlonglong mainChatlistPosition) { emit chatFolders(foldersInformation, mainChatlistPosition); for (const auto &folder : foldersInformation) { TDLibRequestSender::getInstance()->callGetChatFolder(folder.toMap().value("id").toLongLong()); } } void TDLibResponseHandler::handleChatFolder(const QVariantMap &chatFolderInformation) { emit chatFolder(chatFolderInformation); } void TDLibResponseHandler::handleChatReceived(const QVariantMap &chatInformation) { emit chatReceived(chatInformation); if (!TDLibState::getInstance()->activeChatSearchName.isEmpty()) { QVariantMap chatType = chatInformation.value(TYPE).toMap(); TDLibConstants::ChatType receivedChatType = TDLibConstants::getInstance()->chatTypeFromString(chatType.value(_TYPE).toString()); if (receivedChatType == TDLibConstants::ChatTypeBasicGroup) { TDLibState::getInstance()->activeChatSearchName.clear(); TDLibRequestSender::getInstance()->callCreateBasicGroupChat(chatType.value("basic_group_id").toString(), "openDirectly"); } if (receivedChatType == TDLibConstants::ChatTypeSuperGroup) { const bool isViewAsTopics = chatInformation.value("view_as_topics").toBool(); if (isViewAsTopics) { QString query = ""; TDLibRequestSender::getInstance()->callGetForumTopicsRequest(chatInformation.value(ID).toLongLong(), query); } TDLibState::getInstance()->activeChatSearchName.clear(); TDLibRequestSender::getInstance()->callCreateSupergroupChat(chatType.value("supergroup_id").toString(), "openDirectly"); } } } void TDLibResponseHandler::handleUnreadMessageCountUpdated(const QVariantMap &messageCountInformation) { if (messageCountInformation.value(CHAT_LIST_TYPE).toString() == CHAT_LIST_MAIN) { TDLibState::getInstance()->setUnreadMessageInformation(messageCountInformation); emit unreadMessageCountUpdated(messageCountInformation); } if (messageCountInformation.value(CHAT_LIST_TYPE).toString() == CHAT_LIST_FOLDER) { emit unreadFolderMessageCountUpdated(messageCountInformation); } if (messageCountInformation.value(CHAT_LIST_TYPE).toString() == CHAT_LIST_ARCHIVE) { emit unreadArchiveMessageCountUpdated(messageCountInformation); } } void TDLibResponseHandler::handleUnreadChatCountUpdated(const QVariantMap &chatCountInformation) { if (chatCountInformation.value(CHAT_LIST_TYPE).toString() == CHAT_LIST_MAIN) { TDLibState::getInstance()->setUnreadChatInformation(chatCountInformation); } emit unreadChatCountUpdated(chatCountInformation); } void TDLibResponseHandler::handleAvailableReactionsUpdated(qlonglong chatId, const QVariantMap &availableReactions) { QVariantMap chatInformation = TDLibDataRepository::getInstance()->getChat(chatId); chatInformation.insert(CHAT_AVAILABLE_REACTIONS, availableReactions); TDLibDataRepository::getInstance()->putChat(chatInformation); emit chatAvailableReactionsUpdated(chatId, availableReactions); } void TDLibResponseHandler::handleBasicGroupUpdated(qlonglong groupId, const QVariantMap &groupInformation) { GroupsModel::getInstance()->updateGroup(groupId, groupInformation, GroupsModel::GroupType::Basic); if (!(TDLibState::getInstance()->activeChatSearchName.isEmpty()) && TDLibState::getInstance()->activeChatSearchName == groupInformation.value(USERNAME).toString()) { TDLibState::getInstance()->activeChatSearchName.clear(); TDLibRequestSender::getInstance()->callCreateBasicGroupChat(groupInformation.value(ID).toString(), "openDirectly"); } } void TDLibResponseHandler::handleSuperGroupUpdated(qlonglong groupId, const QVariantMap &groupInformation) { GroupsModel::getInstance()->updateGroup(groupId, groupInformation, GroupsModel::GroupType::Supergroup); if (!TDLibState::getInstance()->activeChatSearchName.isEmpty() && TDLibState::getInstance()->activeChatSearchName == groupInformation.value(USERNAME).toString()) { TDLibState::getInstance()->activeChatSearchName.clear(); TDLibRequestSender::getInstance()->callCreateSupergroupChat(groupInformation.value(ID).toString(), "openDirectly"); } } void TDLibResponseHandler::handleStickerSets(const QVariantList &stickerSets) { QListIterator<QVariant> stickerSetIterator(stickerSets); while (stickerSetIterator.hasNext()) { QVariantMap stickerSet = stickerSetIterator.next().toMap(); TDLibRequestSender::getInstance()->callGetStickerSet(stickerSet.value(ID).toString()); } emit stickerSetsReceived(stickerSets); } void TDLibResponseHandler::handleSecretChatReceived(qlonglong secretChatId, const QVariantMap &secretChat) { TDLibDataRepository::getInstance()->putSecretChat(secretChatId, secretChat); emit secretChatReceived(secretChatId, secretChat); } void TDLibResponseHandler::handleSecretChatUpdated(qlonglong secretChatId, const QVariantMap &secretChat) { TDLibDataRepository::getInstance()->putSecretChat(secretChatId, secretChat); emit secretChatUpdated(secretChatId, secretChat); } void TDLibResponseHandler::handleErrorReceived(int code, const QString &message, const QString &extra) { if (!extra.isEmpty()) { QStringList parts(extra.split(':')); if (parts.size() == 3 && parts.at(0) == QStringLiteral("getMessage")) emit messageNotFound(parts.at(1).toLongLong(), parts.at(2).toLongLong()); } emit errorReceived(code, message, extra); } void TDLibResponseHandler::handleMessageInformation(qlonglong chatId, qlonglong messageId, const QVariantMap &receivedInformation) { QString extraInformation = receivedInformation.value(_EXTRA).toString(); if (extraInformation.startsWith("getChatPinnedMessage:")) emit chatPinnedMessageUpdated(chatId, messageId); emit receivedMessage(chatId, messageId, receivedInformation); } void TDLibResponseHandler::handleMessageIsPinnedUpdated(qlonglong chatId, qlonglong messageId, bool isPinned) { if (isPinned) { emit chatPinnedMessageUpdated(chatId, messageId); } else { emit chatPinnedMessageUpdated(chatId, 0); TDLibRequestSender::getInstance()->callGetChatPinnedMessage(chatId); } } void TDLibResponseHandler::handleUserPrivacySettingRules(const QVariantMap &rules) { QVariantList newGivenRules = rules.value("rules").toList(); // If nothing (or something unsupported is sent out) it is considered to be restricted completely auto newAppliedRule = TDLibConstants::UserPrivacySettingRule::RuleRestrictAll; QListIterator<QVariant> givenRulesIterator(newGivenRules); while (givenRulesIterator.hasNext()) { QString givenRule = givenRulesIterator.next().toMap().value(_TYPE).toString(); if (givenRule == "userPrivacySettingRuleAllowContacts") newAppliedRule = TDLibConstants::UserPrivacySettingRule::RuleAllowContacts; else if (givenRule == "userPrivacySettingRuleAllowAll") newAppliedRule = TDLibConstants::UserPrivacySettingRule::RuleAllowAll; } auto usedSetting = static_cast<TDLibConstants::UserPrivacySetting>(rules.value(_EXTRA).toInt()); TDLibState::getInstance()->setUserPrivacySettingRule(usedSetting, newAppliedRule); emit userPrivacySettingUpdated(usedSetting, newAppliedRule); } void TDLibResponseHandler::handleUpdatedUserPrivacySettingRules(const QVariantMap &updatedRules) { QString rawSetting = updatedRules.value("setting").toMap().value(_TYPE).toString(); auto usedSetting = TDLibConstants::UserPrivacySetting::SettingUnknown; if (rawSetting == "userPrivacySettingAllowChatInvites") usedSetting = TDLibConstants::UserPrivacySetting::SettingAllowChatInvites; else if (rawSetting == "userPrivacySettingAllowFindingByPhoneNumber") usedSetting = TDLibConstants::UserPrivacySetting::SettingAllowFindingByPhoneNumber; else if (rawSetting == "userPrivacySettingShowLinkInForwardedMessages") usedSetting = TDLibConstants::UserPrivacySetting::SettingShowLinkInForwardedMessages; else if (rawSetting == "userPrivacySettingShowPhoneNumber") usedSetting = TDLibConstants::UserPrivacySetting::SettingShowPhoneNumber; else if (rawSetting == "userPrivacySettingShowProfilePhoto") usedSetting = TDLibConstants::UserPrivacySetting::SettingShowProfilePhoto; else if (rawSetting == "userPrivacySettingShowStatus") usedSetting = TDLibConstants::UserPrivacySetting::SettingShowStatus; if (usedSetting != TDLibConstants::UserPrivacySetting::SettingUnknown) { QVariantMap rawRules = updatedRules.value("rules").toMap(); rawRules.insert(_EXTRA, usedSetting); handleUserPrivacySettingRules(rawRules); } } void TDLibResponseHandler::handleSponsoredMessage(qlonglong chatId, const QVariantMap &message) { switch (AppSettings::getInstance()->getSponsoredMess()) { case AppSettings::SponsoredMessHandle: emit sponsoredMessageReceived(chatId, message); break; case AppSettings::SponsoredMessAutoView: TDLibRequestSender::getInstance()->callViewMessage(chatId, message.value(MESSAGE_ID).toULongLong(), false); break; case AppSettings::SponsoredMessIgnore: break; } } void TDLibResponseHandler::handleActiveEmojiReactionsUpdated(const QStringList &emojis) { TDLibDataRepository::getInstance()->updateActiveEmojiReactions(emojis); }