Add StoryStealthMode class.
This commit is contained in:
parent
086df4db4e
commit
3448c6f4ab
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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"
|
||||
|
65
td/telegram/StoryStealthMode.cpp
Normal file
65
td/telegram/StoryStealthMode.cpp
Normal file
@ -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<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() {
|
||||
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<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
|
55
td/telegram/StoryStealthMode.h
Normal file
55
td/telegram/StoryStealthMode.h
Normal file
@ -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<telegram_api::storiesStealthMode> &&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<td_api::updateStoryStealthMode> get_update_story_stealth_mode_object() const;
|
||||
|
||||
template <class StorerT>
|
||||
void store(StorerT &storer) const;
|
||||
|
||||
template <class ParserT>
|
||||
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
|
49
td/telegram/StoryStealthMode.hpp
Normal file
49
td/telegram/StoryStealthMode.hpp
Normal file
@ -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 <class StorerT>
|
||||
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 <class ParserT>
|
||||
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
|
Loading…
Reference in New Issue
Block a user