diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index bcb99c0..41f7901 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -341,12 +341,12 @@ Page { } Timer { id: viewMessageTimer - interval: 2000 + interval: 1000 property int lastQueuedIndex: -1 function queueViewMessage(index) { - if(index > lastQueuedIndex) { + if (index > lastQueuedIndex) { lastQueuedIndex = index; - start() + start(); } } diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp index bea9474..733ae0c 100644 --- a/src/tdlibwrapper.cpp +++ b/src/tdlibwrapper.cpp @@ -41,6 +41,8 @@ namespace { const QString STATUS("status"); + const QString ID("id"); + const QString TYPE("type"); const QString _TYPE("@type"); const QString _EXTRA("@extra"); } @@ -88,7 +90,7 @@ TDLibWrapper::TDLibWrapper(QObject *parent) : QObject(parent) connect(this->tdLibReceiver, SIGNAL(messageContentUpdated(QString, QString, QVariantMap)), this, SIGNAL(messageContentUpdated(QString, QString, QVariantMap))); connect(this->tdLibReceiver, SIGNAL(messagesDeleted(QString, QVariantList)), this, SIGNAL(messagesDeleted(QString, QVariantList))); connect(this->tdLibReceiver, SIGNAL(chats(QVariantMap)), this, SIGNAL(chatsReceived(QVariantMap))); - connect(this->tdLibReceiver, SIGNAL(chat(QVariantMap)), this, SIGNAL(chatReceived(QVariantMap))); + connect(this->tdLibReceiver, SIGNAL(chat(QVariantMap)), this, SLOT(handleChatReceived(QVariantMap))); connect(this->tdLibReceiver, SIGNAL(recentStickersUpdated(QVariantList)), this, SIGNAL(recentStickersUpdated(QVariantList))); connect(this->tdLibReceiver, SIGNAL(stickers(QVariantList)), this, SIGNAL(stickersReceived(QVariantList))); connect(this->tdLibReceiver, SIGNAL(installedStickerSetsUpdated(QVariantList)), this, SIGNAL(installedStickerSetsUpdated(QVariantList))); @@ -567,6 +569,26 @@ void TDLibWrapper::createPrivateChat(const QString &userId) this->sendRequest(requestObject); } +void TDLibWrapper::createSupergroupChat(const QString &supergroupId) +{ + LOG("Creating Supergroup Chat"); + QVariantMap requestObject; + requestObject.insert(_TYPE, "createSupergroupChat"); + requestObject.insert("supergroup_id", supergroupId); + requestObject.insert(_EXTRA, "openDirectly"); //gets matched in qml + this->sendRequest(requestObject); +} + +void TDLibWrapper::createBasicGroupChat(const QString &basicGroupId) +{ + LOG("Creating Basic Group Chat"); + QVariantMap requestObject; + requestObject.insert(_TYPE, "createBasicGroupChat"); + requestObject.insert("basic_group_id", basicGroupId); + requestObject.insert(_EXTRA, "openDirectly"); //gets matched in qml + this->sendRequest(requestObject); +} + void TDLibWrapper::getGroupsInCommon(const QString &userId, int limit, int offset) { LOG("Retrieving Groups in Common"); @@ -690,6 +712,7 @@ void TDLibWrapper::getPollVoters(const QString &chatId, const qlonglong &message void TDLibWrapper::searchPublicChat(const QString &userName) { LOG("Search public chat" << userName); + this->activeChatSearchName = userName; QVariantMap requestObject; requestObject.insert(_TYPE, "searchPublicChat"); requestObject.insert("username", userName); @@ -956,6 +979,25 @@ void TDLibWrapper::handleNewChatDiscovered(const QVariantMap &chatInformation) emit newChatDiscovered(chatId, chatInformation); } +void TDLibWrapper::handleChatReceived(const QVariantMap &chatInformation) +{ + emit chatReceived(chatInformation); + if (!this->activeChatSearchName.isEmpty()) { + QVariantMap chatType = chatInformation.value(TYPE).toMap(); + ChatType receivedChatType = chatTypeFromString(chatType.value(_TYPE).toString()); + if (receivedChatType == ChatTypeBasicGroup) { + LOG("Found basic group for active search" << this->activeChatSearchName); + this->activeChatSearchName.clear(); + this->createBasicGroupChat(chatType.value("basic_group_id").toString()); + } + if (receivedChatType == ChatTypeSupergroup) { + LOG("Found supergroup for active search" << this->activeChatSearchName); + this->activeChatSearchName.clear(); + this->createSupergroupChat(chatType.value("supergroup_id").toString()); + } + } +} + void TDLibWrapper::handleUnreadMessageCountUpdated(const QVariantMap &messageCountInformation) { if (messageCountInformation.value("chat_list_type").toString() == "chatListMain") { @@ -975,11 +1017,21 @@ void TDLibWrapper::handleUnreadChatCountUpdated(const QVariantMap &chatCountInfo void TDLibWrapper::handleBasicGroupUpdated(qlonglong groupId, const QVariantMap &groupInformation) { emit basicGroupUpdated(updateGroup(groupId, groupInformation, &basicGroups)->groupId); + if (!this->activeChatSearchName.isEmpty() && this->activeChatSearchName == groupInformation.value("username").toString()) { + LOG("Found basic group for active search" << this->activeChatSearchName); + this->activeChatSearchName.clear(); + this->createBasicGroupChat(groupInformation.value(ID).toString()); + } } void TDLibWrapper::handleSuperGroupUpdated(qlonglong groupId, const QVariantMap &groupInformation) { emit superGroupUpdated(updateGroup(groupId, groupInformation, &superGroups)->groupId); + if (!this->activeChatSearchName.isEmpty() && this->activeChatSearchName == groupInformation.value("username").toString()) { + LOG("Found supergroup for active search" << this->activeChatSearchName); + this->activeChatSearchName.clear(); + this->createSupergroupChat(groupInformation.value(ID).toString()); + } } void TDLibWrapper::handleStickerSets(const QVariantList &stickerSets) diff --git a/src/tdlibwrapper.h b/src/tdlibwrapper.h index 64e48c5..039d734 100644 --- a/src/tdlibwrapper.h +++ b/src/tdlibwrapper.h @@ -137,6 +137,8 @@ public: Q_INVOKABLE void getGroupFullInfo(const QString &groupId, bool isSuperGroup); Q_INVOKABLE void getUserFullInfo(const QString &userId); Q_INVOKABLE void createPrivateChat(const QString &userId); + Q_INVOKABLE void createSupergroupChat(const QString &supergroupId); + Q_INVOKABLE void createBasicGroupChat(const QString &basicGroupId); Q_INVOKABLE void getGroupsInCommon(const QString &userId, int limit, int offset); Q_INVOKABLE void getUserProfilePhotos(const QString &userId, int limit, int offset); Q_INVOKABLE void setChatPermissions(const QString &chatId, const QVariantMap &chatPermissions); @@ -218,6 +220,7 @@ public slots: void handleUserStatusUpdated(const QString &userId, const QVariantMap &userStatusInformation); void handleFileUpdated(const QVariantMap &fileInformation); void handleNewChatDiscovered(const QVariantMap &chatInformation); + void handleChatReceived(const QVariantMap &chatInformation); void handleUnreadMessageCountUpdated(const QVariantMap &messageCountInformation); void handleUnreadChatCountUpdated(const QVariantMap &chatCountInformation); void handleBasicGroupUpdated(qlonglong groupId, const QVariantMap &groupInformation); @@ -251,6 +254,8 @@ private: QHash superGroups; EmojiSearchWorker emojiSearchWorker; + QString activeChatSearchName; + }; #endif // TDLIBWRAPPER_H