Handle user status updates

This commit is contained in:
Sebastian J. Wolf 2020-08-22 14:06:26 +02:00
parent 2f5d725f7b
commit 8dc8dd3651
4 changed files with 26 additions and 0 deletions

View file

@ -58,6 +58,7 @@ void TDLibReceiver::processReceivedDocument(const QJsonDocument &receivedJsonDoc
if (objectTypeName == "updateAuthorizationState") { this->processUpdateAuthorizationState(receivedInformation); }
if (objectTypeName == "updateConnectionState") { this->processUpdateConnectionState(receivedInformation); }
if (objectTypeName == "updateUser") { this->processUpdateUser(receivedInformation); }
if (objectTypeName == "updateUserStatus") { this->processUpdateUserStatus(receivedInformation); }
if (objectTypeName == "updateFile") { this->processUpdateFile(receivedInformation); }
if (objectTypeName == "updateNewChat") { this->processUpdateNewChat(receivedInformation); }
if (objectTypeName == "updateUnreadMessageCount") { this->processUpdateUnreadMessageCount(receivedInformation); }
@ -105,6 +106,14 @@ void TDLibReceiver::processUpdateUser(const QVariantMap &receivedInformation)
emit userUpdated(userInformation);
}
void TDLibReceiver::processUpdateUserStatus(const QVariantMap &receivedInformation)
{
QString userId = receivedInformation.value("user_id").toString();
QVariantMap userStatusInformation = receivedInformation.value("status").toMap();
// qDebug() << "[TDLibReceiver] User status was updated: " << receivedInformation.value("user_id").toString() << userStatusInformation.value("@type").toString();
emit userStatusUpdated(userId, userStatusInformation);
}
void TDLibReceiver::processUpdateFile(const QVariantMap &receivedInformation)
{
QVariantMap fileInformation = receivedInformation.value("file").toMap();

View file

@ -41,6 +41,7 @@ signals:
void optionUpdated(const QString &optionName, const QVariant &optionValue);
void connectionStateChanged(const QString &connectionState);
void userUpdated(const QVariantMap &userInformation);
void userStatusUpdated(const QString &userId, const QVariantMap &userStatusInformation);
void fileUpdated(const QVariantMap &fileInformation);
void newChatDiscovered(const QVariantMap &chatInformation);
void unreadMessageCountUpdated(const QVariantMap &messageCountInformation);
@ -62,6 +63,7 @@ private:
void processUpdateAuthorizationState(const QVariantMap &receivedInformation);
void processUpdateConnectionState(const QVariantMap &receivedInformation);
void processUpdateUser(const QVariantMap &receivedInformation);
void processUpdateUserStatus(const QVariantMap &receivedInformation);
void processUpdateFile(const QVariantMap &receivedInformation);
void processUpdateNewChat(const QVariantMap &receivedInformation);
void processUpdateUnreadMessageCount(const QVariantMap &receivedInformation);

View file

@ -41,6 +41,7 @@ TDLibWrapper::TDLibWrapper(QObject *parent) : QObject(parent)
connect(this->tdLibReceiver, SIGNAL(optionUpdated(QString, QVariant)), this, SLOT(handleOptionUpdated(QString, QVariant)));
connect(this->tdLibReceiver, SIGNAL(connectionStateChanged(QString)), this, SLOT(handleConnectionStateChanged(QString)));
connect(this->tdLibReceiver, SIGNAL(userUpdated(QVariantMap)), this, SLOT(handleUserUpdated(QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(userStatusUpdated(QString, QVariantMap)), this, SLOT(handleUserStatusUpdated(QString, QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(fileUpdated(QVariantMap)), this, SLOT(handleFileUpdated(QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(newChatDiscovered(QVariantMap)), this, SLOT(handleNewChatDiscovered(QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(unreadMessageCountUpdated(QVariantMap)), this, SLOT(handleUnreadMessageCountUpdated(QVariantMap)));
@ -284,6 +285,19 @@ void TDLibWrapper::handleUserUpdated(const QVariantMap &userInformation)
emit userUpdated(updatedUserId, userInformation);
}
void TDLibWrapper::handleUserStatusUpdated(const QString &userId, const QVariantMap &userStatusInformation)
{
if (userId == this->options.value("my_id").toString()) {
qDebug() << "[TDLibWrapper] Own user status information updated :)";
this->userInformation.insert("status", userStatusInformation);
}
qDebug() << "[TDLibWrapper] User status information updated: " << userId << userStatusInformation.value("@type").toString();
QVariantMap updatedUserInformation = this->allUsers.value(userId).toMap();
updatedUserInformation.insert("status", userStatusInformation);
this->allUsers.insert(userId, updatedUserInformation);
emit userUpdated(userId, updatedUserInformation);
}
void TDLibWrapper::handleFileUpdated(const QVariantMap &fileInformation)
{
emit fileUpdated(fileInformation.value("id").toInt(), fileInformation);

View file

@ -101,6 +101,7 @@ public slots:
void handleOptionUpdated(const QString &optionName, const QVariant &optionValue);
void handleConnectionStateChanged(const QString &connectionState);
void handleUserUpdated(const QVariantMap &userInformation);
void handleUserStatusUpdated(const QString &userId, const QVariantMap &userStatusInformation);
void handleFileUpdated(const QVariantMap &fileInformation);
void handleNewChatDiscovered(const QVariantMap &chatInformation);
void handleUnreadMessageCountUpdated(const QVariantMap &messageCountInformation);