Cache discovered chats
This commit is contained in:
parent
39587a7724
commit
ee31736f83
5 changed files with 45 additions and 27 deletions
|
@ -63,7 +63,7 @@ Page {
|
|||
}
|
||||
|
||||
function updateContent() {
|
||||
// tdLibWrapper.getChats();
|
||||
tdLibWrapper.getChats();
|
||||
}
|
||||
|
||||
Connections {
|
||||
|
@ -93,6 +93,7 @@ Page {
|
|||
overviewPage.connectionState = connectionState;
|
||||
setPageStatus();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
|
|
|
@ -54,25 +54,12 @@ void TDLibReceiver::processReceivedDocument(const QJsonDocument &receivedJsonDoc
|
|||
QVariantMap receivedInformation = receivedJsonDocument.object().toVariantMap();
|
||||
QString objectTypeName = receivedInformation.value("@type").toString();
|
||||
|
||||
if (objectTypeName == "updateOption") {
|
||||
this->processUpdateOption(receivedInformation);
|
||||
}
|
||||
|
||||
if (objectTypeName == "updateAuthorizationState") {
|
||||
this->processUpdateAuthorizationState(receivedInformation);
|
||||
}
|
||||
|
||||
if (objectTypeName == "updateConnectionState") {
|
||||
this->processUpdateConnectionState(receivedInformation);
|
||||
}
|
||||
|
||||
if (objectTypeName == "updateUser") {
|
||||
this->processUpdateUser(receivedInformation);
|
||||
}
|
||||
|
||||
if (objectTypeName == "updateFile") {
|
||||
this->processUpdateFile(receivedInformation);
|
||||
}
|
||||
if (objectTypeName == "updateOption") { this->processUpdateOption(receivedInformation); }
|
||||
if (objectTypeName == "updateAuthorizationState") { this->processUpdateAuthorizationState(receivedInformation); }
|
||||
if (objectTypeName == "updateConnectionState") { this->processUpdateConnectionState(receivedInformation); }
|
||||
if (objectTypeName == "updateUser") { this->processUpdateUser(receivedInformation); }
|
||||
if (objectTypeName == "updateFile") { this->processUpdateFile(receivedInformation); }
|
||||
if (objectTypeName == "updateNewChat") { this->processUpdateNewChat(receivedInformation); }
|
||||
}
|
||||
|
||||
void TDLibReceiver::processUpdateOption(const QVariantMap &receivedInformation)
|
||||
|
@ -106,7 +93,7 @@ void TDLibReceiver::processUpdateConnectionState(const QVariantMap &receivedInfo
|
|||
void TDLibReceiver::processUpdateUser(const QVariantMap &receivedInformation)
|
||||
{
|
||||
QVariantMap userInformation = receivedInformation.value("user").toMap();
|
||||
qDebug() << "[TDLibReceiver] User was updated: " << userInformation.value("username").toString() << userInformation.value("first_name").toString() << userInformation.value("last_name").toString();
|
||||
// qDebug() << "[TDLibReceiver] User was updated: " << userInformation.value("username").toString() << userInformation.value("first_name").toString() << userInformation.value("last_name").toString();
|
||||
emit userUpdated(userInformation);
|
||||
}
|
||||
|
||||
|
@ -116,3 +103,10 @@ void TDLibReceiver::processUpdateFile(const QVariantMap &receivedInformation)
|
|||
qDebug() << "[TDLibReceiver] File was updated: " << fileInformation.value("id").toString();
|
||||
emit fileUpdated(fileInformation);
|
||||
}
|
||||
|
||||
void TDLibReceiver::processUpdateNewChat(const QVariantMap &receivedInformation)
|
||||
{
|
||||
QVariantMap chatInformation = receivedInformation.value("chat").toMap();
|
||||
qDebug() << "[TDLibReceiver] New chat discovered: " << chatInformation.value("id").toString() << chatInformation.value("title").toString();
|
||||
emit newChatDiscovered(chatInformation);
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ signals:
|
|||
void connectionStateChanged(const QString &connectionState);
|
||||
void userUpdated(const QVariantMap &userInformation);
|
||||
void fileUpdated(const QVariantMap &fileInformation);
|
||||
void newChatDiscovered(const QVariantMap &chatInformation);
|
||||
|
||||
private:
|
||||
void *tdLibClient;
|
||||
|
@ -54,6 +55,7 @@ private:
|
|||
void processUpdateConnectionState(const QVariantMap &receivedInformation);
|
||||
void processUpdateUser(const QVariantMap &receivedInformation);
|
||||
void processUpdateFile(const QVariantMap &receivedInformation);
|
||||
void processUpdateNewChat(const QVariantMap &receivedInformation);
|
||||
};
|
||||
|
||||
#endif // TDLIBRECEIVER_H
|
||||
|
|
|
@ -42,6 +42,7 @@ TDLibWrapper::TDLibWrapper(QObject *parent) : QObject(parent)
|
|||
connect(this->tdLibReceiver, SIGNAL(connectionStateChanged(QString)), this, SLOT(handleConnectionStateChanged(QString)));
|
||||
connect(this->tdLibReceiver, SIGNAL(userUpdated(QVariantMap)), this, SLOT(handleUserUpdated(QVariantMap)));
|
||||
connect(this->tdLibReceiver, SIGNAL(fileUpdated(QVariantMap)), this, SLOT(handleFileUpdated(QVariantMap)));
|
||||
connect(this->tdLibReceiver, SIGNAL(newChatDiscovered(QVariantMap)), this, SLOT(handleNewChatDiscovered(QVariantMap)));
|
||||
|
||||
this->tdLibReceiver->start();
|
||||
|
||||
|
@ -107,7 +108,7 @@ void TDLibWrapper::getChats()
|
|||
qDebug() << "[TDLibWrapper] Getting chats";
|
||||
QVariantMap requestObject;
|
||||
requestObject.insert("@type", "getChats");
|
||||
requestObject.insert("limit", 20);
|
||||
requestObject.insert("limit", 5);
|
||||
this->sendRequest(requestObject);
|
||||
}
|
||||
|
||||
|
@ -129,6 +130,12 @@ QVariantMap TDLibWrapper::getUserInformation()
|
|||
return this->userInformation;
|
||||
}
|
||||
|
||||
QVariantMap TDLibWrapper::getUserInformation(const QString &userId)
|
||||
{
|
||||
qDebug() << "[TDLibWrapper] Returning user information for ID " << userId;
|
||||
return this->otherUsers.value(userId).toMap();
|
||||
}
|
||||
|
||||
void TDLibWrapper::handleVersionDetected(const QString &version)
|
||||
{
|
||||
this->version = version;
|
||||
|
@ -216,17 +223,26 @@ void TDLibWrapper::handleConnectionStateChanged(const QString &connectionState)
|
|||
|
||||
void TDLibWrapper::handleUserUpdated(const QVariantMap &userInformation)
|
||||
{
|
||||
if (userInformation.value("id") == this->options.value("my_id")) {
|
||||
QString updatedUserId = userInformation.value("id").toString();
|
||||
if (updatedUserId == this->options.value("my_id").toString()) {
|
||||
qDebug() << "[TDLibWrapper] Own user information updated :)";
|
||||
this->userInformation = userInformation;
|
||||
} else {
|
||||
qDebug() << "[TDLibWrapper] Other user information updated";
|
||||
qDebug() << "[TDLibWrapper] Other user information updated: " << userInformation.value("username").toString() << userInformation.value("first_name").toString() << userInformation.value("last_name").toString();
|
||||
this->otherUsers.insert(updatedUserId, userInformation);
|
||||
}
|
||||
}
|
||||
|
||||
void TDLibWrapper::handleFileUpdated(const QVariantMap &userInformation)
|
||||
void TDLibWrapper::handleFileUpdated(const QVariantMap &fileInformation)
|
||||
{
|
||||
emit fileUpdated(userInformation.value("id").toInt(), userInformation);
|
||||
emit fileUpdated(fileInformation.value("id").toInt(), fileInformation);
|
||||
}
|
||||
|
||||
void TDLibWrapper::handleNewChatDiscovered(const QVariantMap &chatInformation)
|
||||
{
|
||||
QString chatId = chatInformation.value("id").toString();
|
||||
this->chats.insert(chatId, chatInformation);
|
||||
emit newChatDiscovered(chatId, chatInformation);
|
||||
}
|
||||
|
||||
void TDLibWrapper::setInitialParameters()
|
||||
|
|
|
@ -62,6 +62,7 @@ public:
|
|||
Q_INVOKABLE TDLibWrapper::AuthorizationState getAuthorizationState();
|
||||
Q_INVOKABLE TDLibWrapper::ConnectionState getConnectionState();
|
||||
Q_INVOKABLE QVariantMap getUserInformation();
|
||||
Q_INVOKABLE QVariantMap getUserInformation(const QString &userId);
|
||||
|
||||
// Direct TDLib functions
|
||||
Q_INVOKABLE void sendRequest(const QVariantMap &requestObject);
|
||||
|
@ -76,6 +77,7 @@ signals:
|
|||
void optionUpdated(const QString &optionName, const QVariant &optionValue);
|
||||
void connectionStateChanged(const TDLibWrapper::ConnectionState &connectionState);
|
||||
void fileUpdated(const int fileId, const QVariantMap fileInformation);
|
||||
void newChatDiscovered(const QString chatId, const QVariantMap chatInformation);
|
||||
|
||||
public slots:
|
||||
void handleVersionDetected(const QString &version);
|
||||
|
@ -83,7 +85,8 @@ public slots:
|
|||
void handleOptionUpdated(const QString &optionName, const QVariant &optionValue);
|
||||
void handleConnectionStateChanged(const QString &connectionState);
|
||||
void handleUserUpdated(const QVariantMap &userInformation);
|
||||
void handleFileUpdated(const QVariantMap &userInformation);
|
||||
void handleFileUpdated(const QVariantMap &fileInformation);
|
||||
void handleNewChatDiscovered(const QVariantMap &chatInformation);
|
||||
|
||||
private:
|
||||
void *tdLibClient;
|
||||
|
@ -93,6 +96,8 @@ private:
|
|||
TDLibWrapper::ConnectionState connectionState;
|
||||
QVariantMap options;
|
||||
QVariantMap userInformation;
|
||||
QVariantMap otherUsers;
|
||||
QVariantMap chats;
|
||||
|
||||
void setInitialParameters();
|
||||
void setEncryptionKey();
|
||||
|
|
Loading…
Reference in a new issue