summaryrefslogtreecommitdiff
path: root/protocols/Telegram/tdlib/td/td/telegram/StoryStealthMode.cpp
blob: d44ed53baef7181ea00cc7eed6fd5d497578273a (plain)
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
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include "td/telegram/StoryStealthMode.h"

#include "td/telegram/Global.h"

namespace td {

StoryStealthMode::StoryStealthMode(telegram_api::object_ptr<telegram_api::storiesStealthMode> &&stealth_mode)
    : active_until_date_(stealth_mode->active_until_date_), cooldown_until_date_(stealth_mode->cooldown_until_date_) {
  update();
}

bool StoryStealthMode::update() {
  auto current_time = G()->unix_time();
  bool result = false;
  if (active_until_date_ != 0 && active_until_date_ <= current_time) {
    active_until_date_ = 0;
    result = true;
  }
  if (cooldown_until_date_ != 0 && cooldown_until_date_ <= current_time) {
    cooldown_until_date_ = 0;
    result = true;
  }
  return result;
}

int32 StoryStealthMode::get_update_date() const {
  if (active_until_date_ > 0) {
    if (cooldown_until_date_ > 0) {
      return min(active_until_date_, cooldown_until_date_);
    }
    return active_until_date_;
  }
  if (cooldown_until_date_ > 0) {
    return cooldown_until_date_;
  }
  return 0;
}

td_api::object_ptr<td_api::updateStoryStealthMode> StoryStealthMode::get_update_story_stealth_mode_object() const {
  return td_api::make_object<td_api::updateStoryStealthMode>(active_until_date_, cooldown_until_date_);
}

bool operator==(const StoryStealthMode &lhs, const StoryStealthMode &rhs) {
  return lhs.active_until_date_ == rhs.active_until_date_ && lhs.cooldown_until_date_ == rhs.cooldown_until_date_;
}

StringBuilder &operator<<(StringBuilder &string_builder, const StoryStealthMode &mode) {
  if (mode.active_until_date_) {
    return string_builder << "Stealth mode is active until " << mode.active_until_date_;
  }
  if (mode.cooldown_until_date_) {
    return string_builder << "Stealth mode can't be activated until " << mode.cooldown_until_date_;
  }
  return string_builder << "Stealth mode can be activated";
}

}  // namespace td