Added api support for global TTL settings.
This commit is contained in:
parent
c481d48865
commit
97fa92de0b
|
@ -16,36 +16,61 @@ SelfDestruct::SelfDestruct(not_null<ApiWrap*> api)
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelfDestruct::reload() {
|
void SelfDestruct::reload() {
|
||||||
if (_requestId) {
|
if (!_accountTTL.requestId) {
|
||||||
return;
|
_accountTTL.requestId = _api.request(MTPaccount_GetAccountTTL(
|
||||||
|
)).done([=](const MTPAccountDaysTTL &result) {
|
||||||
|
_accountTTL.requestId = 0;
|
||||||
|
_accountTTL.days = result.data().vdays().v;
|
||||||
|
}).fail([=] {
|
||||||
|
_accountTTL.requestId = 0;
|
||||||
|
}).send();
|
||||||
|
}
|
||||||
|
if (!_defaultHistoryTTL.requestId) {
|
||||||
|
_defaultHistoryTTL.requestId = _api.request(
|
||||||
|
MTPmessages_GetDefaultHistoryTTL()
|
||||||
|
).done([=](const MTPDefaultHistoryTTL &result) {
|
||||||
|
_defaultHistoryTTL.requestId = 0;
|
||||||
|
_defaultHistoryTTL.period = result.data().vperiod().v;
|
||||||
|
}).fail([=] {
|
||||||
|
_defaultHistoryTTL.requestId = 0;
|
||||||
|
}).send();
|
||||||
}
|
}
|
||||||
_requestId = _api.request(MTPaccount_GetAccountTTL(
|
|
||||||
)).done([=](const MTPAccountDaysTTL &result) {
|
|
||||||
_requestId = 0;
|
|
||||||
result.match([&](const MTPDaccountDaysTTL &data) {
|
|
||||||
_days = data.vdays().v;
|
|
||||||
});
|
|
||||||
}).fail([=] {
|
|
||||||
_requestId = 0;
|
|
||||||
}).send();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rpl::producer<int> SelfDestruct::days() const {
|
rpl::producer<int> SelfDestruct::daysAccountTTL() const {
|
||||||
using namespace rpl::mappers;
|
return _accountTTL.days.value() | rpl::filter(rpl::mappers::_1 != 0);
|
||||||
|
|
||||||
return _days.value() | rpl::filter(_1 != 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelfDestruct::update(int days) {
|
rpl::producer<TimeId> SelfDestruct::periodDefaultHistoryTTL() const {
|
||||||
_api.request(_requestId).cancel();
|
return _defaultHistoryTTL.period.value();
|
||||||
_requestId = _api.request(MTPaccount_SetAccountTTL(
|
}
|
||||||
|
|
||||||
|
TimeId SelfDestruct::periodDefaultHistoryTTLCurrent() const {
|
||||||
|
return _defaultHistoryTTL.period.current();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SelfDestruct::updateAccountTTL(int days) {
|
||||||
|
_api.request(_accountTTL.requestId).cancel();
|
||||||
|
_accountTTL.requestId = _api.request(MTPaccount_SetAccountTTL(
|
||||||
MTP_accountDaysTTL(MTP_int(days))
|
MTP_accountDaysTTL(MTP_int(days))
|
||||||
)).done([=] {
|
)).done([=] {
|
||||||
_requestId = 0;
|
_accountTTL.requestId = 0;
|
||||||
}).fail([=] {
|
}).fail([=] {
|
||||||
_requestId = 0;
|
_accountTTL.requestId = 0;
|
||||||
}).send();
|
}).send();
|
||||||
_days = days;
|
_accountTTL.days = days;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SelfDestruct::updateDefaultHistoryTTL(TimeId period) {
|
||||||
|
_api.request(_defaultHistoryTTL.requestId).cancel();
|
||||||
|
_defaultHistoryTTL.requestId = _api.request(
|
||||||
|
MTPmessages_SetDefaultHistoryTTL(MTP_int(period))
|
||||||
|
).done([=] {
|
||||||
|
_defaultHistoryTTL.requestId = 0;
|
||||||
|
}).fail([=] {
|
||||||
|
_defaultHistoryTTL.requestId = 0;
|
||||||
|
}).send();
|
||||||
|
_defaultHistoryTTL.period = period;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Api
|
} // namespace Api
|
||||||
|
|
|
@ -18,14 +18,24 @@ public:
|
||||||
explicit SelfDestruct(not_null<ApiWrap*> api);
|
explicit SelfDestruct(not_null<ApiWrap*> api);
|
||||||
|
|
||||||
void reload();
|
void reload();
|
||||||
void update(int days);
|
void updateAccountTTL(int days);
|
||||||
|
void updateDefaultHistoryTTL(TimeId period);
|
||||||
|
|
||||||
rpl::producer<int> days() const;
|
[[nodiscard]] rpl::producer<int> daysAccountTTL() const;
|
||||||
|
[[nodiscard]] rpl::producer<TimeId> periodDefaultHistoryTTL() const;
|
||||||
|
[[nodiscard]] TimeId periodDefaultHistoryTTLCurrent() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MTP::Sender _api;
|
MTP::Sender _api;
|
||||||
mtpRequestId _requestId = 0;
|
struct {
|
||||||
rpl::variable<int> _days = 0;
|
mtpRequestId requestId = 0;
|
||||||
|
rpl::variable<int> days = 0;
|
||||||
|
} _accountTTL;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
mtpRequestId requestId = 0;
|
||||||
|
rpl::variable<TimeId> period = 0;
|
||||||
|
} _defaultHistoryTTL;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -95,12 +95,13 @@ void SelfDestructionBox::showContent() {
|
||||||
|
|
||||||
clearButtons();
|
clearButtons();
|
||||||
addButton(tr::lng_settings_save(), [=] {
|
addButton(tr::lng_settings_save(), [=] {
|
||||||
|
const auto value = _ttlGroup->value();
|
||||||
switch (_type) {
|
switch (_type) {
|
||||||
case Type::Account:
|
case Type::Account:
|
||||||
_session->api().selfDestruct().update(_ttlGroup->value());
|
_session->api().selfDestruct().updateAccountTTL(value);
|
||||||
break;
|
break;
|
||||||
case Type::Sessions:
|
case Type::Sessions:
|
||||||
_session->api().authorizations().updateTTL(_ttlGroup->value());
|
_session->api().authorizations().updateTTL(value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -520,10 +520,8 @@ void SetupSelfDestruction(
|
||||||
session->api().selfDestruct().reload();
|
session->api().selfDestruct().reload();
|
||||||
}, container->lifetime());
|
}, container->lifetime());
|
||||||
const auto label = [&] {
|
const auto label = [&] {
|
||||||
return session->api().selfDestruct().days(
|
return session->api().selfDestruct().daysAccountTTL(
|
||||||
) | rpl::map(
|
) | rpl::map(SelfDestructionBox::DaysLabel);
|
||||||
SelfDestructionBox::DaysLabel
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
AddButtonWithLabel(
|
AddButtonWithLabel(
|
||||||
|
@ -535,7 +533,7 @@ void SetupSelfDestruction(
|
||||||
controller->show(Box<SelfDestructionBox>(
|
controller->show(Box<SelfDestructionBox>(
|
||||||
session,
|
session,
|
||||||
SelfDestructionBox::Type::Account,
|
SelfDestructionBox::Type::Account,
|
||||||
session->api().selfDestruct().days()));
|
session->api().selfDestruct().daysAccountTTL()));
|
||||||
});
|
});
|
||||||
|
|
||||||
AddSkip(container);
|
AddSkip(container);
|
||||||
|
|
Loading…
Reference in New Issue