Implement RequestedDialogType.

This commit is contained in:
levlam 2023-01-11 19:52:35 +03:00
parent 1afcc3bcfd
commit 9a2dd58b6f
4 changed files with 206 additions and 5 deletions

View File

@ -1387,7 +1387,7 @@ keyboardButtonTypeRequestUser id:int32 restrict_user_is_bot:Bool user_is_bot:Boo
//@chat_is_created True, if the chat must be created by the current user
//@user_administrator_rights Expected user administrator rights in the chat; may be null if they aren't restricted
//@bot_administrator_rights Expected bot administrator rights in the chat; may be null if they aren't restricted
//@bot_is_member True, if the bot must be a member of the chat
//@bot_is_member True, if the bot must be a member of the chat; for basic group and supergroup chats only
keyboardButtonTypeRequestChat id:int32 chat_is_channel:Bool restrict_chat_is_forum:Bool chat_is_forum:Bool restrict_chat_has_username:Bool chat_has_username:Bool chat_is_created:Bool user_administrator_rights:chatAdministratorRights bot_administrator_rights:chatAdministratorRights bot_is_member:Bool = KeyboardButtonType;
//@description A button that opens a Web App by calling getWebAppUrl @url An HTTP URL to pass to getWebAppUrl

View File

@ -6,28 +6,169 @@
//
#include "td/telegram/RequestedDialogType.h"
#include "td/telegram/ChannelType.h"
namespace td {
RequestedDialogType::RequestedDialogType(td_api::object_ptr<td_api::keyboardButtonTypeRequestUser> &&request_user) {
CHECK(request_user != nullptr);
type_ = Type::User;
button_id_ = request_user->id_;
restrict_is_bot_ = request_user->restrict_user_is_bot_;
is_bot_ = request_user->user_is_bot_;
restrict_is_premium_ = request_user->restrict_user_is_premium_;
is_premium_ = request_user->user_is_premium_;
}
RequestedDialogType::RequestedDialogType(td_api::object_ptr<td_api::keyboardButtonTypeRequestChat> &&request_dialog) {
CHECK(request_dialog != nullptr);
type_ = request_dialog->chat_is_channel_ ? Type::Channel : Type::Group;
button_id_ = request_dialog->id_;
restrict_is_forum_ = request_dialog->restrict_chat_is_forum_;
is_forum_ = request_dialog->chat_is_forum_;
bot_is_participant_ = request_dialog->bot_is_member_;
restrict_has_username_ = request_dialog->restrict_chat_has_username_;
has_username_ = request_dialog->chat_has_username_;
is_created_ = request_dialog->chat_is_created_;
restrict_user_administrator_rights_ = request_dialog->user_administrator_rights_ != nullptr;
restrict_bot_administrator_rights_ = request_dialog->bot_administrator_rights_ != nullptr;
auto channel_type = request_dialog->chat_is_channel_ ? ChannelType::Broadcast : ChannelType::Megagroup;
user_administrator_rights_ = AdministratorRights(request_dialog->user_administrator_rights_, channel_type);
bot_administrator_rights_ = AdministratorRights(request_dialog->bot_administrator_rights_, channel_type);
}
RequestedDialogType::RequestedDialogType(telegram_api::object_ptr<telegram_api::RequestPeerType> &&chat_type, int32 button_id) {
RequestedDialogType::RequestedDialogType(telegram_api::object_ptr<telegram_api::RequestPeerType> &&peer_type,
int32 button_id) {
CHECK(peer_type != nullptr);
button_id_ = button_id;
switch (peer_type->get_id()) {
case telegram_api::requestPeerTypeUser::ID: {
auto type = telegram_api::move_object_as<telegram_api::requestPeerTypeUser>(peer_type);
type_ = Type::User;
restrict_is_bot_ = (type->flags_ & telegram_api::requestPeerTypeUser::BOT_MASK) != 0;
is_bot_ = type->bot_;
restrict_is_premium_ = (type->flags_ & telegram_api::requestPeerTypeUser::PREMIUM_MASK) != 0;
is_premium_ = type->premium_;
break;
}
case telegram_api::requestPeerTypeChat::ID: {
auto type = telegram_api::move_object_as<telegram_api::requestPeerTypeChat>(peer_type);
type_ = Type::Group;
restrict_is_forum_ = (type->flags_ & telegram_api::requestPeerTypeChat::FORUM_MASK) != 0;
is_forum_ = type->forum_;
bot_is_participant_ = type->bot_participant_;
restrict_has_username_ = (type->flags_ & telegram_api::requestPeerTypeChat::HAS_USERNAME_MASK) != 0;
has_username_ = type->has_username_;
is_created_ = type->creator_;
restrict_user_administrator_rights_ = type->user_admin_rights_ != nullptr;
restrict_bot_administrator_rights_ = type->bot_admin_rights_ != nullptr;
user_administrator_rights_ = AdministratorRights(type->user_admin_rights_, ChannelType::Megagroup);
bot_administrator_rights_ = AdministratorRights(type->bot_admin_rights_, ChannelType::Megagroup);
break;
}
case telegram_api::requestPeerTypeBroadcast::ID: {
auto type = telegram_api::move_object_as<telegram_api::requestPeerTypeBroadcast>(peer_type);
type_ = Type::Group;
restrict_has_username_ = (type->flags_ & telegram_api::requestPeerTypeChat::HAS_USERNAME_MASK) != 0;
has_username_ = type->has_username_;
is_created_ = type->creator_;
restrict_user_administrator_rights_ = type->user_admin_rights_ != nullptr;
restrict_bot_administrator_rights_ = type->bot_admin_rights_ != nullptr;
user_administrator_rights_ = AdministratorRights(type->user_admin_rights_, ChannelType::Megagroup);
bot_administrator_rights_ = AdministratorRights(type->bot_admin_rights_, ChannelType::Megagroup);
break;
}
default:
UNREACHABLE();
}
}
td_api::object_ptr<td_api::KeyboardButtonType> RequestedDialogType::get_keyboard_button_type_object() const {
return td_api::make_object<td_api::keyboardButtonTypeRequestUser>(0, false, false, false, false);
if (type_ == Type::User) {
return td_api::make_object<td_api::keyboardButtonTypeRequestUser>(button_id_, restrict_is_bot_, is_bot_,
restrict_is_premium_, is_premium_);
} else {
auto user_administrator_rights = restrict_user_administrator_rights_
? user_administrator_rights_.get_chat_administrator_rights_object()
: nullptr;
auto bot_administrator_rights =
restrict_bot_administrator_rights_ ? bot_administrator_rights_.get_chat_administrator_rights_object() : nullptr;
return td_api::make_object<td_api::keyboardButtonTypeRequestChat>(
button_id_, type_ == Type::Channel, restrict_is_forum_, is_forum_, restrict_has_username_, has_username_,
is_created_, std::move(user_administrator_rights), std::move(bot_administrator_rights), bot_is_participant_);
}
}
telegram_api::object_ptr<telegram_api::RequestPeerType> RequestedDialogType::get_input_request_peer_type_object()
const {
return telegram_api::make_object<telegram_api::requestPeerTypeUser>(0, false, false);
switch (type_) {
case Type::User: {
int32 flags = 0;
if (restrict_is_bot_) {
flags |= telegram_api::requestPeerTypeUser::BOT_MASK;
}
if (restrict_is_premium_) {
flags |= telegram_api::requestPeerTypeUser::PREMIUM_MASK;
}
return telegram_api::make_object<telegram_api::requestPeerTypeUser>(flags, is_bot_, is_premium_);
}
case Type::Group: {
int32 flags = 0;
if (restrict_is_forum_) {
flags |= telegram_api::requestPeerTypeChat::FORUM_MASK;
}
if (bot_is_participant_) {
flags |= telegram_api::requestPeerTypeChat::BOT_PARTICIPANT_MASK;
}
if (restrict_has_username_) {
flags |= telegram_api::requestPeerTypeChat::HAS_USERNAME_MASK;
}
if (is_created_) {
flags |= telegram_api::requestPeerTypeChat::CREATOR_MASK;
}
if (restrict_user_administrator_rights_) {
flags |= telegram_api::requestPeerTypeChat::USER_ADMIN_RIGHTS_MASK;
}
if (restrict_bot_administrator_rights_) {
flags |= telegram_api::requestPeerTypeChat::BOT_ADMIN_RIGHTS_MASK;
}
auto user_admin_rights =
restrict_user_administrator_rights_ ? user_administrator_rights_.get_chat_admin_rights() : nullptr;
auto bot_admin_rights =
restrict_bot_administrator_rights_ ? bot_administrator_rights_.get_chat_admin_rights() : nullptr;
return telegram_api::make_object<telegram_api::requestPeerTypeChat>(
flags, false /*ignored*/, false /*ignored*/, has_username_, is_forum_, std::move(user_admin_rights),
std::move(bot_admin_rights));
}
case Type::Channel: {
int32 flags = 0;
if (restrict_has_username_) {
flags |= telegram_api::requestPeerTypeBroadcast::HAS_USERNAME_MASK;
}
if (is_created_) {
flags |= telegram_api::requestPeerTypeBroadcast::CREATOR_MASK;
}
if (restrict_user_administrator_rights_) {
flags |= telegram_api::requestPeerTypeBroadcast::USER_ADMIN_RIGHTS_MASK;
}
if (restrict_bot_administrator_rights_) {
flags |= telegram_api::requestPeerTypeBroadcast::BOT_ADMIN_RIGHTS_MASK;
}
auto user_admin_rights =
restrict_user_administrator_rights_ ? user_administrator_rights_.get_chat_admin_rights() : nullptr;
auto bot_admin_rights =
restrict_bot_administrator_rights_ ? bot_administrator_rights_.get_chat_admin_rights() : nullptr;
return telegram_api::make_object<telegram_api::requestPeerTypeBroadcast>(
flags, false /*ignored*/, has_username_, std::move(user_admin_rights), std::move(bot_admin_rights));
}
default:
UNREACHABLE();
return nullptr;
}
}
int32 RequestedDialogType::get_button_id() const {
return 0;
return button_id_;
}
} // namespace td

View File

@ -6,6 +6,7 @@
//
#pragma once
#include "td/telegram/DialogParticipant.h"
#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
@ -14,6 +15,25 @@
namespace td {
class RequestedDialogType {
enum class Type : int32 { User, Group, Channel };
Type type_ = Type::User;
int32 button_id_ = 0;
bool restrict_is_bot_ = false; // User only
bool is_bot_ = false; // User only
bool restrict_is_premium_ = false; // User only
bool is_premium_ = false; // User only
bool restrict_is_forum_ = false; // Group only
bool is_forum_ = false; // Group only
bool bot_is_participant_ = false; // Group only
bool restrict_has_username_ = false; // Group and Channel only
bool has_username_ = false; // Group and Channel only
bool is_created_ = false; // Group and Channel only
bool restrict_user_administrator_rights_ = false; // Group and Channel only
bool restrict_bot_administrator_rights_ = false; // Group and Channel only
AdministratorRights user_administrator_rights_; // Group and Channel only
AdministratorRights bot_administrator_rights_; // Group and Channel only
public:
RequestedDialogType() = default;

View File

@ -15,13 +15,53 @@ namespace td {
template <class StorerT>
void RequestedDialogType::store(StorerT &storer) const {
BEGIN_STORE_FLAGS();
STORE_FLAG(restrict_is_bot_);
STORE_FLAG(is_bot_);
STORE_FLAG(restrict_is_premium_);
STORE_FLAG(is_premium_);
STORE_FLAG(restrict_is_forum_);
STORE_FLAG(is_forum_);
STORE_FLAG(bot_is_participant_);
STORE_FLAG(restrict_has_username_);
STORE_FLAG(has_username_);
STORE_FLAG(is_created_);
STORE_FLAG(restrict_user_administrator_rights_);
STORE_FLAG(restrict_bot_administrator_rights_);
END_STORE_FLAGS();
td::store(type_, storer);
td::store(button_id_, storer);
if (restrict_user_administrator_rights_) {
td::store(user_administrator_rights_, storer);
}
if (restrict_bot_administrator_rights_) {
td::store(bot_administrator_rights_, storer);
}
}
template <class ParserT>
void RequestedDialogType::parse(ParserT &parser) {
BEGIN_PARSE_FLAGS();
PARSE_FLAG(restrict_is_bot_);
PARSE_FLAG(is_bot_);
PARSE_FLAG(restrict_is_premium_);
PARSE_FLAG(is_premium_);
PARSE_FLAG(restrict_is_forum_);
PARSE_FLAG(is_forum_);
PARSE_FLAG(bot_is_participant_);
PARSE_FLAG(restrict_has_username_);
PARSE_FLAG(has_username_);
PARSE_FLAG(is_created_);
PARSE_FLAG(restrict_user_administrator_rights_);
PARSE_FLAG(restrict_bot_administrator_rights_);
END_PARSE_FLAGS();
td::parse(type_, parser);
td::parse(button_id_, parser);
if (restrict_user_administrator_rights_) {
td::parse(user_administrator_rights_, parser);
}
if (restrict_bot_administrator_rights_) {
td::parse(bot_administrator_rights_, parser);
}
}
} // namespace td