Add td_api::businessRecipients.

This commit is contained in:
levlam 2024-02-26 16:35:20 +03:00
parent 7476ff34de
commit 4513cf75b8
6 changed files with 220 additions and 0 deletions

View File

@ -301,6 +301,7 @@ set(TDLIB_SOURCE
td/telegram/BotCommandScope.cpp
td/telegram/BotInfoManager.cpp
td/telegram/BotMenuButton.cpp
td/telegram/BusinessRecipients.cpp
td/telegram/BusinessWorkHours.cpp
td/telegram/CallActor.cpp
td/telegram/CallbackQueriesManager.cpp
@ -580,6 +581,7 @@ set(TDLIB_SOURCE
td/telegram/BotCommandScope.h
td/telegram/BotInfoManager.h
td/telegram/BotMenuButton.h
td/telegram/BusinessRecipients.h
td/telegram/BusinessWorkHours.h
td/telegram/CallActor.h
td/telegram/CallDiscardReason.h
@ -879,6 +881,7 @@ set(TDLIB_SOURCE
td/telegram/AuthManager.hpp
td/telegram/BackgroundInfo.hpp
td/telegram/BackgroundType.hpp
td/telegram/BusinessRecipients.hpp
td/telegram/BusinessWorkHours.hpp
td/telegram/ChatReactions.hpp
td/telegram/DialogNotificationSettings.hpp

View File

@ -309,6 +309,8 @@ function split_file($file, $chunks, $undo) {
'BotMenuButton|[a-z_]*_menu_button' => 'BotMenuButton',
'boost_manager[_(-](?![.]get[(][)])|BoostManager' => 'BoostManager',
'bot_info_manager[_(-](?![.]get[(][)])|BotInfoManager' => 'BotInfoManager',
'BusinessRecipients' => 'BusinessRecipients',
'BusinessWorkHours' => 'BusinessWorkHours',
'callback_queries_manager[_(-](?![.]get[(][)])|CallbackQueriesManager' => 'CallbackQueriesManager',
'CallId' => 'CallId',
'call_manager[_(-](?![.]get[(][)])|CallManager' => 'CallManager',

View File

@ -579,6 +579,14 @@ chatLocation location:location address:string = ChatLocation;
//@description Represents a location of a business @location The location; may be null if not specified @address Location address; 1-96 characters
businessLocation location:location address:string = BusinessLocation;
//@description Describes private chats chosen for automatic interaction with a business
//@chat_ids Identifiers of selected private chats
//@select_existing_chats True, if all existing private chats are selected
//@select_new_chats True, if all new private chats are selected
//@select_contacts True, if all private chats with contacts are selected
//@select_non_contacts True, if all private chats with non-contacts are selected
//@exclude_selected If true, then all private chats except the selected are chosen. Otherwise, only the selected chats are chosen
businessRecipients chat_ids:vector<int53> select_existing_chats:Bool select_new_chats:Bool select_contacts:Bool select_non_contacts:Bool exclude_selected:Bool = BusinessRecipients;
//@description Describes an interval of time when the business is open
//@start_minute The first minute of the interval since start of the week; 0-7*24*60

View File

@ -0,0 +1,104 @@
//
// 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/BusinessRecipients.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"
namespace td {
BusinessRecipients::BusinessRecipients(telegram_api::object_ptr<telegram_api::businessRecipients> recipients)
: user_ids_(UserId::get_user_ids(recipients->users_))
, existing_chats_(recipients->existing_chats_)
, new_chats_(recipients->new_chats_)
, contacts_(recipients->contacts_)
, non_contacts_(recipients->non_contacts_)
, exclude_selected_(recipients->exclude_selected_) {
td::remove_if(user_ids_, [](UserId user_id) { return !user_id.is_valid(); });
}
BusinessRecipients::BusinessRecipients(td_api::object_ptr<td_api::businessRecipients> recipients) {
if (recipients == nullptr) {
return;
}
for (auto chat_id : recipients->chat_ids_) {
DialogId dialog_id(chat_id);
if (dialog_id.get_type() == DialogType::User) {
user_ids_.push_back(dialog_id.get_user_id());
}
}
existing_chats_ = recipients->select_existing_chats_;
new_chats_ = recipients->select_new_chats_;
contacts_ = recipients->select_contacts_;
non_contacts_ = recipients->select_non_contacts_;
exclude_selected_ = recipients->exclude_selected_;
}
td_api::object_ptr<td_api::businessRecipients> BusinessRecipients::get_business_recipients_object(Td *td) const {
vector<int64> chat_ids;
for (auto user_id : user_ids_) {
DialogId dialog_id(user_id);
td->dialog_manager_->force_create_dialog(dialog_id, "get_business_recipients_object", true);
CHECK(td->dialog_manager_->have_dialog_force(dialog_id, "get_business_recipients_object"));
chat_ids.push_back(td->dialog_manager_->get_chat_id_object(dialog_id, "businessRecipients"));
}
return td_api::make_object<td_api::businessRecipients>(std::move(chat_ids), existing_chats_, new_chats_, contacts_,
non_contacts_, exclude_selected_);
}
telegram_api::object_ptr<telegram_api::inputBusinessRecipients> BusinessRecipients::get_input_business_recipients(
Td *td) const {
int32 flags = 0;
if (existing_chats_) {
flags |= telegram_api::inputBusinessRecipients::EXISTING_CHATS_MASK;
}
if (new_chats_) {
flags |= telegram_api::inputBusinessRecipients::NEW_CHATS_MASK;
}
if (contacts_) {
flags |= telegram_api::inputBusinessRecipients::CONTACTS_MASK;
}
if (non_contacts_) {
flags |= telegram_api::inputBusinessRecipients::NON_CONTACTS_MASK;
}
if (exclude_selected_) {
flags |= telegram_api::inputBusinessRecipients::EXCLUDE_SELECTED_MASK;
}
vector<telegram_api::object_ptr<telegram_api::InputUser>> input_users;
for (auto user_id : user_ids_) {
auto r_input_user = td->contacts_manager_->get_input_user(user_id);
if (r_input_user.is_ok()) {
input_users.push_back(r_input_user.move_as_ok());
}
}
if (!input_users.empty()) {
flags |= telegram_api::inputBusinessRecipients::USERS_MASK;
}
return telegram_api::make_object<telegram_api::inputBusinessRecipients>(flags, false /*ignored*/, false /*ignored*/,
false /*ignored*/, false /*ignored*/,
false /*ignored*/, std::move(input_users));
}
bool operator==(const BusinessRecipients &lhs, const BusinessRecipients &rhs) {
return lhs.user_ids_ == rhs.user_ids_ && lhs.existing_chats_ == rhs.existing_chats_ &&
lhs.new_chats_ == rhs.new_chats_ && lhs.contacts_ == rhs.contacts_ && lhs.non_contacts_ == rhs.non_contacts_ &&
lhs.exclude_selected_ == rhs.exclude_selected_;
}
StringBuilder &operator<<(StringBuilder &string_builder, const BusinessRecipients &recipients) {
return string_builder << "received by " << (recipients.exclude_selected_ ? "all private chats except " : "")
<< recipients.user_ids_ << (recipients.contacts_ ? ", contacts " : "")
<< (recipients.non_contacts_ ? ", non-contacts " : "")
<< (recipients.existing_chats_ ? ", existing chats " : "")
<< (recipients.new_chats_ ? ", new chats " : "");
}
} // namespace td

View File

@ -0,0 +1,57 @@
//
// 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/td_api.h"
#include "td/telegram/telegram_api.h"
#include "td/telegram/UserId.h"
#include "td/utils/common.h"
#include "td/utils/StringBuilder.h"
namespace td {
class Td;
class BusinessRecipients {
public:
explicit BusinessRecipients(telegram_api::object_ptr<telegram_api::businessRecipients> recipients);
explicit BusinessRecipients(td_api::object_ptr<td_api::businessRecipients> recipients);
td_api::object_ptr<td_api::businessRecipients> get_business_recipients_object(Td *td) const;
telegram_api::object_ptr<telegram_api::inputBusinessRecipients> get_input_business_recipients(Td *td) const;
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
private:
vector<UserId> user_ids_;
bool existing_chats_ = false;
bool new_chats_ = false;
bool contacts_ = false;
bool non_contacts_ = false;
bool exclude_selected_ = false;
friend bool operator==(const BusinessRecipients &lhs, const BusinessRecipients &rhs);
friend StringBuilder &operator<<(StringBuilder &string_builder, const BusinessRecipients &recipients);
};
bool operator==(const BusinessRecipients &lhs, const BusinessRecipients &rhs);
inline bool operator!=(const BusinessRecipients &lhs, const BusinessRecipients &rhs) {
return !(lhs == rhs);
}
StringBuilder &operator<<(StringBuilder &string_builder, const BusinessRecipients &recipients);
} // namespace td

View File

@ -0,0 +1,46 @@
//
// 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/BusinessRecipients.h"
#include "td/utils/common.h"
#include "td/utils/tl_helpers.h"
namespace td {
template <class StorerT>
void BusinessRecipients::store(StorerT &storer) const {
bool has_user_ids = !user_ids_.empty();
BEGIN_STORE_FLAGS();
STORE_FLAG(existing_chats_);
STORE_FLAG(new_chats_);
STORE_FLAG(contacts_);
STORE_FLAG(non_contacts_);
STORE_FLAG(exclude_selected_);
END_STORE_FLAGS();
if (has_user_ids) {
td::store(user_ids_, storer);
}
}
template <class ParserT>
void BusinessRecipients::parse(ParserT &parser) {
bool has_user_ids = !user_ids_.empty();
BEGIN_PARSE_FLAGS();
PARSE_FLAG(existing_chats_);
PARSE_FLAG(new_chats_);
PARSE_FLAG(contacts_);
PARSE_FLAG(non_contacts_);
PARSE_FLAG(exclude_selected_);
END_PARSE_FLAGS();
if (has_user_ids) {
td::parse(user_ids_, parser);
}
}
} // namespace td