api_self_destruct.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #include "api/api_self_destruct.h"
  8. #include "apiwrap.h"
  9. namespace Api {
  10. SelfDestruct::SelfDestruct(not_null<ApiWrap*> api)
  11. : _api(&api->instance()) {
  12. }
  13. void SelfDestruct::reload() {
  14. if (!_accountTTL.requestId) {
  15. _accountTTL.requestId = _api.request(MTPaccount_GetAccountTTL(
  16. )).done([=](const MTPAccountDaysTTL &result) {
  17. _accountTTL.requestId = 0;
  18. _accountTTL.days = result.data().vdays().v;
  19. }).fail([=] {
  20. _accountTTL.requestId = 0;
  21. }).send();
  22. }
  23. if (!_defaultHistoryTTL.requestId) {
  24. _defaultHistoryTTL.requestId = _api.request(
  25. MTPmessages_GetDefaultHistoryTTL()
  26. ).done([=](const MTPDefaultHistoryTTL &result) {
  27. _defaultHistoryTTL.requestId = 0;
  28. _defaultHistoryTTL.period = result.data().vperiod().v;
  29. }).fail([=] {
  30. _defaultHistoryTTL.requestId = 0;
  31. }).send();
  32. }
  33. }
  34. rpl::producer<int> SelfDestruct::daysAccountTTL() const {
  35. return _accountTTL.days.value() | rpl::filter(rpl::mappers::_1 != 0);
  36. }
  37. rpl::producer<TimeId> SelfDestruct::periodDefaultHistoryTTL() const {
  38. return _defaultHistoryTTL.period.value();
  39. }
  40. TimeId SelfDestruct::periodDefaultHistoryTTLCurrent() const {
  41. return _defaultHistoryTTL.period.current();
  42. }
  43. void SelfDestruct::updateAccountTTL(int days) {
  44. _api.request(_accountTTL.requestId).cancel();
  45. _accountTTL.requestId = _api.request(MTPaccount_SetAccountTTL(
  46. MTP_accountDaysTTL(MTP_int(days))
  47. )).done([=] {
  48. _accountTTL.requestId = 0;
  49. }).fail([=] {
  50. _accountTTL.requestId = 0;
  51. }).send();
  52. _accountTTL.days = days;
  53. }
  54. void SelfDestruct::updateDefaultHistoryTTL(TimeId period) {
  55. _api.request(_defaultHistoryTTL.requestId).cancel();
  56. _defaultHistoryTTL.requestId = _api.request(
  57. MTPmessages_SetDefaultHistoryTTL(MTP_int(period))
  58. ).done([=] {
  59. _defaultHistoryTTL.requestId = 0;
  60. }).fail([=] {
  61. _defaultHistoryTTL.requestId = 0;
  62. }).send();
  63. _defaultHistoryTTL.period = period;
  64. }
  65. } // namespace Api