diff --git a/CMakeLists.txt b/CMakeLists.txt index ed447e756..8275ea98c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -479,6 +479,7 @@ set(TDLIB_SOURCE td/telegram/StoryDb.cpp td/telegram/StoryInteractionInfo.cpp td/telegram/StoryManager.cpp + td/telegram/StoryStealthMode.cpp td/telegram/SuggestedAction.cpp td/telegram/Support.cpp td/telegram/Td.cpp @@ -783,6 +784,7 @@ set(TDLIB_SOURCE td/telegram/StoryInteractionInfo.h td/telegram/StoryListId.h td/telegram/StoryManager.h + td/telegram/StoryStealthMode.h td/telegram/SuggestedAction.h td/telegram/Support.h td/telegram/Td.h @@ -861,6 +863,7 @@ set(TDLIB_SOURCE td/telegram/StickerPhotoSize.hpp td/telegram/StickersManager.hpp td/telegram/StoryInteractionInfo.hpp + td/telegram/StoryStealthMode.hpp td/telegram/TranscriptionInfo.hpp td/telegram/VideoNotesManager.hpp td/telegram/VideosManager.hpp diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 92ad160aa..afff09721 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -5850,6 +5850,11 @@ updateChatActiveStories active_stories:chatActiveStories = Update; //@description Number of chats in a story list has changed @story_list The story list @chat_count Approximate total number of chats with active stories in the list updateStoryListChatCount story_list:StoryList chat_count:int32 = Update; +//@description Story stealth mode settings has changed +//@active_until_date Point in time (Unix timestamp) until stealth mode is active; 0 if it is disabled +//@cooldown_until_date Point in time (Unix timestamp) when stealth mode can be enabled again; 0 if there is no active cooldown +updateStoryStealthMode active_until_date:int32 cooldown_until_date:int32 = Update; + //@description An option changed its value @name The option name @value The new option value updateOption name:string value:OptionValue = Update; diff --git a/td/telegram/StoryManager.cpp b/td/telegram/StoryManager.cpp index 370fad363..061bb54ac 100644 --- a/td/telegram/StoryManager.cpp +++ b/td/telegram/StoryManager.cpp @@ -26,6 +26,7 @@ #include "td/telegram/StoryContent.h" #include "td/telegram/StoryContentType.h" #include "td/telegram/StoryInteractionInfo.hpp" +#include "td/telegram/StoryStealthMode.hpp" #include "td/telegram/Td.h" #include "td/telegram/TdDb.h" #include "td/telegram/telegram_api.h" diff --git a/td/telegram/StoryStealthMode.cpp b/td/telegram/StoryStealthMode.cpp new file mode 100644 index 000000000..fadb82066 --- /dev/null +++ b/td/telegram/StoryStealthMode.cpp @@ -0,0 +1,65 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// +// 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 &&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() { + update(); + + 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 StoryStealthMode::get_update_story_stealth_mode_object() const { + return td_api::make_object(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 diff --git a/td/telegram/StoryStealthMode.h b/td/telegram/StoryStealthMode.h new file mode 100644 index 000000000..c557903fd --- /dev/null +++ b/td/telegram/StoryStealthMode.h @@ -0,0 +1,55 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// +// 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) +// +#pragma once + +#include "td/telegram/td_api.h" +#include "td/telegram/telegram_api.h" + +#include "td/utils/common.h" +#include "td/utils/StringBuilder.h" + +namespace td { + +class StoryStealthMode { + int32 active_until_date_ = 0; + int32 cooldown_until_date_ = 0; + + friend bool operator==(const StoryStealthMode &lhs, const StoryStealthMode &rhs); + + friend StringBuilder &operator<<(StringBuilder &string_builder, const StoryStealthMode &mode); + + public: + StoryStealthMode() = default; + + explicit StoryStealthMode(telegram_api::object_ptr &&stealth_mode); + + bool is_empty() const { + return active_until_date_ == 0 && cooldown_until_date_ == 0; + } + + int32 get_update_date(); + + bool update(); + + td_api::object_ptr get_update_story_stealth_mode_object() const; + + template + void store(StorerT &storer) const; + + template + void parse(ParserT &parser); +}; + +bool operator==(const StoryStealthMode &lhs, const StoryStealthMode &rhs); + +inline bool operator!=(const StoryStealthMode &lhs, const StoryStealthMode &rhs) { + return !(lhs == rhs); +} + +StringBuilder &operator<<(StringBuilder &string_builder, const StoryStealthMode &mode); + +} // namespace td diff --git a/td/telegram/StoryStealthMode.hpp b/td/telegram/StoryStealthMode.hpp new file mode 100644 index 000000000..ad0b31d8d --- /dev/null +++ b/td/telegram/StoryStealthMode.hpp @@ -0,0 +1,49 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// +// 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) +// +#pragma once + +#include "td/telegram/StoryStealthMode.h" + +#include "td/utils/common.h" +#include "td/utils/tl_helpers.h" + +namespace td { + +template +void StoryStealthMode::store(StorerT &storer) const { + bool has_active_until_date = active_until_date_ != 0; + bool has_cooldown_until_date = cooldown_until_date_ != 0; + BEGIN_STORE_FLAGS(); + STORE_FLAG(has_active_until_date); + STORE_FLAG(has_cooldown_until_date); + END_STORE_FLAGS(); + if (has_active_until_date) { + store(active_until_date_, storer); + } + if (has_cooldown_until_date) { + store(cooldown_until_date_, storer); + } +} + +template +void StoryStealthMode::parse(ParserT &parser) { + using td::parse; + bool has_active_until_date; + bool has_cooldown_until_date; + BEGIN_PARSE_FLAGS(); + PARSE_FLAG(has_active_until_date); + PARSE_FLAG(has_cooldown_until_date); + END_PARSE_FLAGS(); + if (has_active_until_date) { + parse(active_until_date_, parser); + } + if (has_cooldown_until_date) { + parse(cooldown_until_date_, parser); + } +} + +} // namespace td