diff --git a/CMakeLists.txt b/CMakeLists.txt index ade9d2d6c..0b94b81a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -301,6 +301,7 @@ set(TDLIB_SOURCE td/telegram/BotCommandScope.cpp td/telegram/BotInfoManager.cpp td/telegram/BotMenuButton.cpp + td/telegram/BusinessAwayMessage.cpp td/telegram/BusinessAwayMessageSchedule.cpp td/telegram/BusinessGreetingMessage.cpp td/telegram/BusinessRecipients.cpp @@ -583,6 +584,7 @@ set(TDLIB_SOURCE td/telegram/BotCommandScope.h td/telegram/BotInfoManager.h td/telegram/BotMenuButton.h + td/telegram/BusinessAwayMessage.h td/telegram/BusinessAwayMessageSchedule.h td/telegram/BusinessGreetingMessage.h td/telegram/BusinessRecipients.h @@ -885,6 +887,7 @@ set(TDLIB_SOURCE td/telegram/AuthManager.hpp td/telegram/BackgroundInfo.hpp td/telegram/BackgroundType.hpp + td/telegram/BusinessAwayMessage.hpp td/telegram/BusinessAwayMessageSchedule.hpp td/telegram/BusinessGreetingMessage.hpp td/telegram/BusinessRecipients.hpp diff --git a/SplitSource.php b/SplitSource.php index 5d83e5d74..e5bc55360 100644 --- a/SplitSource.php +++ b/SplitSource.php @@ -309,6 +309,7 @@ function split_file($file, $chunks, $undo) { 'BotMenuButton|[a-z_]*_menu_button' => 'BotMenuButton', 'boost_manager[_(-](?![.]get[(][)])|BoostManager' => 'BoostManager', 'bot_info_manager[_(-](?![.]get[(][)])|BotInfoManager' => 'BotInfoManager', + 'BusinessAwayMessage' => 'BusinessAwayMessage', 'BusinessGreetingMessage' => 'BusinessGreetingMessage', 'BusinessRecipients' => 'BusinessRecipients', 'BusinessWorkHours' => 'BusinessWorkHours', diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 8944aa101..c2acc771c 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -602,6 +602,12 @@ businessLocation location:location address:string = BusinessLocation; //@exclude_selected If true, then all private chats except the selected are chosen. Otherwise, only the selected chats are chosen businessRecipients chat_ids:vector select_existing_chats:Bool select_new_chats:Bool select_contacts:Bool select_non_contacts:Bool exclude_selected:Bool = BusinessRecipients; +//@description Describes settings for messages that are automatically sent by a Telegram Business account when it is away +//@shortcut_id Unique quick reply shortcut identifier for the away messages +//@recipients Chosen recipients of the away messages +//@schedule Settings used to check whether the current user is away +businessAwayMessageSettings shortcut_id:int32 recipients:businessRecipients schedule:BusinessAwayMessageSchedule = BusinessAwayMessageSettings; + //@description Describes settings for greeting messages that are automatically sent by a Telegram Business account as response to incoming messages in an inactive private chat //@shortcut_id Unique quick reply shortcut identifier for the greeting messages //@recipients Chosen recipients of the greeting messages diff --git a/td/telegram/BusinessAwayMessage.cpp b/td/telegram/BusinessAwayMessage.cpp new file mode 100644 index 000000000..6e7ec20d1 --- /dev/null +++ b/td/telegram/BusinessAwayMessage.cpp @@ -0,0 +1,61 @@ +// +// 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/BusinessAwayMessage.h" + +#include "td/telegram/ContactsManager.h" +#include "td/telegram/DialogId.h" +#include "td/telegram/DialogManager.h" +#include "td/telegram/Td.h" + +#include "td/utils/algorithm.h" +#include "td/utils/misc.h" + +namespace td { + +BusinessAwayMessage::BusinessAwayMessage(telegram_api::object_ptr away_message) + : shortcut_id_(away_message->shortcut_id_) + , recipients_(std::move(away_message->recipients_)) + , schedule_(std::move(away_message->schedule_)) { +} + +BusinessAwayMessage::BusinessAwayMessage(td_api::object_ptr away_message) { + if (away_message == nullptr) { + return; + } + shortcut_id_ = QuickReplyShortcutId(away_message->shortcut_id_); + recipients_ = BusinessRecipients(std::move(away_message->recipients_)); + schedule_ = BusinessAwayMessageSchedule(std::move(away_message->schedule_)); +} + +td_api::object_ptr BusinessAwayMessage::get_business_away_message_settings_object( + Td *td) const { + if (!is_valid()) { + return nullptr; + } + return td_api::make_object( + shortcut_id_.get(), recipients_.get_business_recipients_object(td), + schedule_.get_business_away_message_schedule_object()); +} + +telegram_api::object_ptr BusinessAwayMessage::get_input_business_away_message( + Td *td) const { + int32 flags = 0; + return telegram_api::make_object( + flags, false /*ignored*/, shortcut_id_.get(), schedule_.get_input_business_away_message_schedule(), + recipients_.get_input_business_recipients(td)); +} + +bool operator==(const BusinessAwayMessage &lhs, const BusinessAwayMessage &rhs) { + return lhs.shortcut_id_ == rhs.shortcut_id_ && lhs.recipients_ == rhs.recipients_ && lhs.schedule_ == rhs.schedule_; +} + +StringBuilder &operator<<(StringBuilder &string_builder, const BusinessAwayMessage &away_message) { + return string_builder << "away message " << away_message.shortcut_id_ << ' ' << away_message.recipients_ << ' ' + << away_message.schedule_; +} + +} // namespace td diff --git a/td/telegram/BusinessAwayMessage.h b/td/telegram/BusinessAwayMessage.h new file mode 100644 index 000000000..b564e2f72 --- /dev/null +++ b/td/telegram/BusinessAwayMessage.h @@ -0,0 +1,62 @@ +// +// 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) +// +#pragma once + +#include "td/telegram/BusinessAwayMessageSchedule.h" +#include "td/telegram/BusinessRecipients.h" +#include "td/telegram/QuickReplyShortcutId.h" +#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 Td; + +class BusinessAwayMessage { + public: + BusinessAwayMessage() = default; + + explicit BusinessAwayMessage(telegram_api::object_ptr away_message); + + explicit BusinessAwayMessage(td_api::object_ptr away_message); + + td_api::object_ptr get_business_away_message_settings_object(Td *td) const; + + telegram_api::object_ptr get_input_business_away_message(Td *td) const; + + bool is_valid() const { + return shortcut_id_.is_server(); + } + + template + void store(StorerT &storer) const; + + template + void parse(ParserT &parser); + + private: + QuickReplyShortcutId shortcut_id_; + BusinessRecipients recipients_; + BusinessAwayMessageSchedule schedule_; + + friend bool operator==(const BusinessAwayMessage &lhs, const BusinessAwayMessage &rhs); + + friend StringBuilder &operator<<(StringBuilder &string_builder, const BusinessAwayMessage &away_message); +}; + +bool operator==(const BusinessAwayMessage &lhs, const BusinessAwayMessage &rhs); + +inline bool operator!=(const BusinessAwayMessage &lhs, const BusinessAwayMessage &rhs) { + return !(lhs == rhs); +} + +StringBuilder &operator<<(StringBuilder &string_builder, const BusinessAwayMessage &away_message); + +} // namespace td diff --git a/td/telegram/BusinessAwayMessage.hpp b/td/telegram/BusinessAwayMessage.hpp new file mode 100644 index 000000000..b1cc70fa2 --- /dev/null +++ b/td/telegram/BusinessAwayMessage.hpp @@ -0,0 +1,36 @@ +// +// 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) +// +#pragma once + +#include "td/telegram/BusinessAwayMessage.h" +#include "td/telegram/BusinessAwayMessageSchedule.hpp" +#include "td/telegram/BusinessRecipients.hpp" + +#include "td/utils/common.h" +#include "td/utils/tl_helpers.h" + +namespace td { + +template +void BusinessAwayMessage::store(StorerT &storer) const { + BEGIN_STORE_FLAGS(); + END_STORE_FLAGS(); + td::store(shortcut_id_, storer); + td::store(recipients_, storer); + td::store(schedule_, storer); +} + +template +void BusinessAwayMessage::parse(ParserT &parser) { + BEGIN_PARSE_FLAGS(); + END_PARSE_FLAGS(); + td::parse(shortcut_id_, parser); + td::parse(recipients_, parser); + td::parse(schedule_, parser); +} + +} // namespace td