mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-18 15:17:07 +02:00
Added api support for global TTL settings.
This commit is contained in:
parent
c481d48865
commit
97fa92de0b
4 changed files with 66 additions and 32 deletions
Telegram/SourceFiles
|
@ -16,36 +16,61 @@ SelfDestruct::SelfDestruct(not_null<ApiWrap*> api)
|
|||
}
|
||||
|
||||
void SelfDestruct::reload() {
|
||||
if (_requestId) {
|
||||
return;
|
||||
if (!_accountTTL.requestId) {
|
||||
_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 {
|
||||
using namespace rpl::mappers;
|
||||
|
||||
return _days.value() | rpl::filter(_1 != 0);
|
||||
rpl::producer<int> SelfDestruct::daysAccountTTL() const {
|
||||
return _accountTTL.days.value() | rpl::filter(rpl::mappers::_1 != 0);
|
||||
}
|
||||
|
||||
void SelfDestruct::update(int days) {
|
||||
_api.request(_requestId).cancel();
|
||||
_requestId = _api.request(MTPaccount_SetAccountTTL(
|
||||
rpl::producer<TimeId> SelfDestruct::periodDefaultHistoryTTL() const {
|
||||
return _defaultHistoryTTL.period.value();
|
||||
}
|
||||
|
||||
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))
|
||||
)).done([=] {
|
||||
_requestId = 0;
|
||||
_accountTTL.requestId = 0;
|
||||
}).fail([=] {
|
||||
_requestId = 0;
|
||||
_accountTTL.requestId = 0;
|
||||
}).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
|
||||
|
|
|
@ -18,14 +18,24 @@ public:
|
|||
explicit SelfDestruct(not_null<ApiWrap*> api);
|
||||
|
||||
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:
|
||||
MTP::Sender _api;
|
||||
mtpRequestId _requestId = 0;
|
||||
rpl::variable<int> _days = 0;
|
||||
struct {
|
||||
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();
|
||||
addButton(tr::lng_settings_save(), [=] {
|
||||
const auto value = _ttlGroup->value();
|
||||
switch (_type) {
|
||||
case Type::Account:
|
||||
_session->api().selfDestruct().update(_ttlGroup->value());
|
||||
_session->api().selfDestruct().updateAccountTTL(value);
|
||||
break;
|
||||
case Type::Sessions:
|
||||
_session->api().authorizations().updateTTL(_ttlGroup->value());
|
||||
_session->api().authorizations().updateTTL(value);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -520,10 +520,8 @@ void SetupSelfDestruction(
|
|||
session->api().selfDestruct().reload();
|
||||
}, container->lifetime());
|
||||
const auto label = [&] {
|
||||
return session->api().selfDestruct().days(
|
||||
) | rpl::map(
|
||||
SelfDestructionBox::DaysLabel
|
||||
);
|
||||
return session->api().selfDestruct().daysAccountTTL(
|
||||
) | rpl::map(SelfDestructionBox::DaysLabel);
|
||||
};
|
||||
|
||||
AddButtonWithLabel(
|
||||
|
@ -535,7 +533,7 @@ void SetupSelfDestruction(
|
|||
controller->show(Box<SelfDestructionBox>(
|
||||
session,
|
||||
SelfDestructionBox::Type::Account,
|
||||
session->api().selfDestruct().days()));
|
||||
session->api().selfDestruct().daysAccountTTL()));
|
||||
});
|
||||
|
||||
AddSkip(container);
|
||||
|
|
Loading…
Add table
Reference in a new issue