Guarantee session order in GetActiveSessions.

GitOrigin-RevId: 9d625e4d9a1c8fb5e2ff5d9aff3591e84ac842f3
This commit is contained in:
levlam 2019-02-19 22:36:26 +03:00
parent 97c62b48f5
commit a73c383c66
2 changed files with 13 additions and 1 deletions

View File

@ -2032,7 +2032,8 @@ userPrivacySettingAllowPeerToPeerCalls = UserPrivacySetting;
accountTtl days:int32 = AccountTtl;
//@description Contains information about one session in a Telegram application used by the current user @id Session identifier @is_current True, if this session is the current session
//@description Contains information about one session in a Telegram application used by the current user. Sessions should be shown to the user in the returned order
//@id Session identifier @is_current True, if this session is the current session
//@is_password_pending True, if a password is needed to complete authorization of the session
//@api_id Telegram API identifier, as provided by the application @application_name Name of the application, as provided by the application
//@application_version The version of the application, as provided by the application @is_official_application True, if the application is an official application or uses the api_id of an official application

View File

@ -152,6 +152,17 @@ class GetAuthorizationsQuery : public Td::ResultHandler {
authorization->country_, authorization->region_));
}
std::sort(results->sessions_.begin(), results->sessions_.end(),
[](const td_api::object_ptr<td_api::session> &lhs, const td_api::object_ptr<td_api::session> &rhs) {
if (lhs->is_current_ != rhs->is_current_) {
return lhs->is_current_;
}
if (lhs->is_password_pending_ != rhs->is_password_pending_) {
return lhs->is_password_pending_;
}
return lhs->last_active_date_ > rhs->last_active_date_;
});
promise_.set_value(std::move(results));
}