1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
/*
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
|