2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Allow editing sessions auto-termination period.

This commit is contained in:
John Preston
2021-11-26 00:52:06 +04:00
parent fe4bb19358
commit f3e1aef264
9 changed files with 143 additions and 23 deletions

View File

@@ -119,6 +119,7 @@ void Authorizations::reload() {
_requestId = 0;
_lastReceived = crl::now();
result.match([&](const MTPDaccount_authorizations &auths) {
_ttlDays = auths.vauthorization_ttl_days().v;
_list = (
auths.vauthorizations().v
) | ranges::views::transform([](const MTPAuthorization &d) {
@@ -184,6 +185,22 @@ rpl::producer<int> Authorizations::totalChanges() const {
_listChanges.events() | rpl::map([=] { return total(); }));
}
void Authorizations::updateTTL(int days) {
_api.request(_ttlRequestId).cancel();
_ttlRequestId = _api.request(MTPaccount_SetAuthorizationTTL(
MTP_int(days)
)).done([=](const MTPBool &result) {
_ttlRequestId = 0;
}).fail([=](const MTP::Error &result) {
_ttlRequestId = 0;
}).send();
_ttlDays = days;
}
rpl::producer<int> Authorizations::ttlDays() const {
return _ttlDays.value() | rpl::filter(rpl::mappers::_1 != 0);
}
int Authorizations::total() const {
return ranges::count_if(
_list,

View File

@@ -40,6 +40,9 @@ public:
[[nodiscard]] int total() const;
[[nodiscard]] rpl::producer<int> totalChanges() const;
void updateTTL(int days);
[[nodiscard]] rpl::producer<int> ttlDays() const;
private:
MTP::Sender _api;
mtpRequestId _requestId = 0;
@@ -47,6 +50,9 @@ private:
List _list;
rpl::event_stream<> _listChanges;
mtpRequestId _ttlRequestId = 0;
rpl::variable<int> _ttlDays = 0;
crl::time _lastReceived = 0;
rpl::lifetime _lifetime;