Files
tdesktop/Telegram/SourceFiles/api/api_self_destruct.cpp
allhaileris afb81b8278
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Close stale issues and PRs / stale (push) Successful in 13s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
init
2026-02-16 15:50:16 +03:00

77 lines
2.1 KiB
C++

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "api/api_self_destruct.h"
#include "apiwrap.h"
namespace Api {
SelfDestruct::SelfDestruct(not_null<ApiWrap*> api)
: _api(&api->instance()) {
}
void SelfDestruct::reload() {
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();
}
}
rpl::producer<int> SelfDestruct::daysAccountTTL() const {
return _accountTTL.days.value() | rpl::filter(rpl::mappers::_1 != 0);
}
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([=] {
_accountTTL.requestId = 0;
}).fail([=] {
_accountTTL.requestId = 0;
}).send();
_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