tdlibwrapper changes: refactored misleadingly names variables allUsers and to more proper names usersById and usersByName; fixed handleUserUpdated function as it mixed up userInformation parameter with userInformation member variable; made a dedicated method updateUserInformation to update both usersById and usersByName; eliminated unneeded status updates when user status didn't really change (those tend to happen a lot).
This commit is contained in:
parent
fd7563bc88
commit
e966eb4abd
2 changed files with 27 additions and 19 deletions
|
@ -1573,17 +1573,17 @@ QVariantMap TDLibWrapper::getUserInformation()
|
||||||
QVariantMap TDLibWrapper::getUserInformation(const QString &userId)
|
QVariantMap TDLibWrapper::getUserInformation(const QString &userId)
|
||||||
{
|
{
|
||||||
// LOG("Returning user information for ID" << userId);
|
// LOG("Returning user information for ID" << userId);
|
||||||
return this->allUsers.value(userId).toMap();
|
return this->usersById.value(userId).toMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TDLibWrapper::hasUserInformation(const QString &userId)
|
bool TDLibWrapper::hasUserInformation(const QString &userId)
|
||||||
{
|
{
|
||||||
return this->allUsers.contains(userId);
|
return this->usersById.contains(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap TDLibWrapper::getUserInformationByName(const QString &userName)
|
QVariantMap TDLibWrapper::getUserInformationByName(const QString &userName)
|
||||||
{
|
{
|
||||||
return this->allUserNames.value(userName).toMap();
|
return this->usersByName.value(userName).toMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
TDLibWrapper::UserPrivacySettingRule TDLibWrapper::getUserPrivacySettingRule(TDLibWrapper::UserPrivacySetting userPrivacySetting)
|
TDLibWrapper::UserPrivacySettingRule TDLibWrapper::getUserPrivacySettingRule(TDLibWrapper::UserPrivacySetting userPrivacySetting)
|
||||||
|
@ -1812,8 +1812,8 @@ void TDLibWrapper::handleAuthorizationStateChanged(const QString &authorizationS
|
||||||
LOG("Reloading TD Lib...");
|
LOG("Reloading TD Lib...");
|
||||||
this->basicGroups.clear();
|
this->basicGroups.clear();
|
||||||
this->superGroups.clear();
|
this->superGroups.clear();
|
||||||
this->allUsers.clear();
|
this->usersById.clear();
|
||||||
this->allUserNames.clear();
|
this->usersByName.clear();
|
||||||
this->tdLibReceiver->setActive(false);
|
this->tdLibReceiver->setActive(false);
|
||||||
while (this->tdLibReceiver->isRunning()) {
|
while (this->tdLibReceiver->isRunning()) {
|
||||||
QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
|
QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
|
||||||
|
@ -1864,18 +1864,17 @@ void TDLibWrapper::handleConnectionStateChanged(const QString &connectionState)
|
||||||
emit connectionStateChanged(this->connectionState);
|
emit connectionStateChanged(this->connectionState);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TDLibWrapper::handleUserUpdated(const QVariantMap &userInformation)
|
void TDLibWrapper::handleUserUpdated(const QVariantMap &updatedUserInformation)
|
||||||
{
|
{
|
||||||
QString updatedUserId = userInformation.value(ID).toString();
|
QString updatedUserId = updatedUserInformation.value(ID).toString();
|
||||||
if (updatedUserId == this->options.value("my_id").toString()) {
|
if (updatedUserId == this->options.value("my_id").toString()) {
|
||||||
LOG("Own user information updated :)");
|
LOG("Own user information updated :)");
|
||||||
this->userInformation = userInformation;
|
this->userInformation = updatedUserInformation;
|
||||||
emit ownUserUpdated(userInformation);
|
emit ownUserUpdated(updatedUserInformation);
|
||||||
}
|
}
|
||||||
LOG("User information updated:" << userInformation.value(USERNAMES).toMap().value(EDITABLE_USERNAME).toString() << userInformation.value(FIRST_NAME).toString() << userInformation.value(LAST_NAME).toString());
|
LOG("User information updated:" << updatedUserInformation.value(USERNAMES).toMap().value(EDITABLE_USERNAME).toString() << updatedUserInformation.value(FIRST_NAME).toString() << updatedUserInformation.value(LAST_NAME).toString());
|
||||||
this->allUsers.insert(updatedUserId, userInformation);
|
updateUserInformation(updatedUserId, updatedUserInformation);
|
||||||
this->allUserNames.insert(userInformation.value(USERNAMES).toMap().value(EDITABLE_USERNAME).toString(), userInformation);
|
emit userUpdated(updatedUserId, updatedUserInformation);
|
||||||
emit userUpdated(updatedUserId, userInformation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TDLibWrapper::handleUserStatusUpdated(const QString &userId, const QVariantMap &userStatusInformation)
|
void TDLibWrapper::handleUserStatusUpdated(const QString &userId, const QVariantMap &userStatusInformation)
|
||||||
|
@ -1884,14 +1883,22 @@ void TDLibWrapper::handleUserStatusUpdated(const QString &userId, const QVariant
|
||||||
LOG("Own user status information updated :)");
|
LOG("Own user status information updated :)");
|
||||||
this->userInformation.insert(STATUS, userStatusInformation);
|
this->userInformation.insert(STATUS, userStatusInformation);
|
||||||
}
|
}
|
||||||
|
QVariantMap updatedUserInformation = this->usersById.value(userId).toMap();
|
||||||
|
if(updatedUserInformation[STATUS] == userStatusInformation) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
LOG("User status information updated:" << userId << userStatusInformation.value(_TYPE).toString());
|
LOG("User status information updated:" << userId << userStatusInformation.value(_TYPE).toString());
|
||||||
QVariantMap updatedUserInformation = this->allUsers.value(userId).toMap();
|
|
||||||
updatedUserInformation.insert(STATUS, userStatusInformation);
|
updatedUserInformation.insert(STATUS, userStatusInformation);
|
||||||
this->allUsers.insert(userId, updatedUserInformation);
|
updateUserInformation(userId, updatedUserInformation);
|
||||||
this->allUserNames.insert(userInformation.value(USERNAMES).toMap().value(EDITABLE_USERNAME).toString(), userInformation);
|
|
||||||
emit userUpdated(userId, updatedUserInformation);
|
emit userUpdated(userId, updatedUserInformation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TDLibWrapper::updateUserInformation(const QString &userId, const QVariantMap &userInformation)
|
||||||
|
{
|
||||||
|
this->usersById.insert(userId, userInformation);
|
||||||
|
this->usersByName.insert(userInformation.value(USERNAMES).toMap().value(EDITABLE_USERNAME).toString(), userInformation);
|
||||||
|
}
|
||||||
|
|
||||||
void TDLibWrapper::handleFileUpdated(const QVariantMap &fileInformation)
|
void TDLibWrapper::handleFileUpdated(const QVariantMap &fileInformation)
|
||||||
{
|
{
|
||||||
emit fileUpdated(fileInformation.value(ID).toInt(), fileInformation);
|
emit fileUpdated(fileInformation.value(ID).toInt(), fileInformation);
|
||||||
|
|
|
@ -348,7 +348,7 @@ public slots:
|
||||||
void handleAuthorizationStateChanged(const QString &authorizationState, const QVariantMap authorizationStateData);
|
void handleAuthorizationStateChanged(const QString &authorizationState, const QVariantMap authorizationStateData);
|
||||||
void handleOptionUpdated(const QString &optionName, const QVariant &optionValue);
|
void handleOptionUpdated(const QString &optionName, const QVariant &optionValue);
|
||||||
void handleConnectionStateChanged(const QString &connectionState);
|
void handleConnectionStateChanged(const QString &connectionState);
|
||||||
void handleUserUpdated(const QVariantMap &userInformation);
|
void handleUserUpdated(const QVariantMap &updatedUserInformation);
|
||||||
void handleUserStatusUpdated(const QString &userId, const QVariantMap &userStatusInformation);
|
void handleUserStatusUpdated(const QString &userId, const QVariantMap &userStatusInformation);
|
||||||
void handleFileUpdated(const QVariantMap &fileInformation);
|
void handleFileUpdated(const QVariantMap &fileInformation);
|
||||||
void handleNewChatDiscovered(const QVariantMap &chatInformation);
|
void handleNewChatDiscovered(const QVariantMap &chatInformation);
|
||||||
|
@ -383,6 +383,7 @@ private:
|
||||||
const Group *updateGroup(qlonglong groupId, const QVariantMap &groupInfo, QHash<qlonglong,Group*> *groups);
|
const Group *updateGroup(qlonglong groupId, const QVariantMap &groupInfo, QHash<qlonglong,Group*> *groups);
|
||||||
QVariantMap newSendMessageRequest(qlonglong chatId, qlonglong replyToMessageId);
|
QVariantMap newSendMessageRequest(qlonglong chatId, qlonglong replyToMessageId);
|
||||||
void initializeTDLibReceiver();
|
void initializeTDLibReceiver();
|
||||||
|
void updateUserInformation(const QString &userId, const QVariantMap &userInformation);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void *tdLibClient;
|
void *tdLibClient;
|
||||||
|
@ -399,8 +400,8 @@ private:
|
||||||
QVariantMap options;
|
QVariantMap options;
|
||||||
QVariantMap userInformation;
|
QVariantMap userInformation;
|
||||||
QMap<UserPrivacySetting, UserPrivacySettingRule> userPrivacySettingRules;
|
QMap<UserPrivacySetting, UserPrivacySettingRule> userPrivacySettingRules;
|
||||||
QVariantMap allUsers;
|
QVariantMap usersById;
|
||||||
QVariantMap allUserNames;
|
QVariantMap usersByName;
|
||||||
QVariantMap chats;
|
QVariantMap chats;
|
||||||
QMap<qlonglong, QVariantMap> secretChats;
|
QMap<qlonglong, QVariantMap> secretChats;
|
||||||
QVariantMap unreadMessageInformation;
|
QVariantMap unreadMessageInformation;
|
||||||
|
|
Loading…
Reference in a new issue