Add ChannelType.h.

This commit is contained in:
levlam 2022-04-04 15:35:09 +03:00
parent 7f587c24d9
commit a8a343704a
11 changed files with 49 additions and 34 deletions

View File

@ -483,6 +483,7 @@ set(TDLIB_SOURCE
td/telegram/ChainId.h
td/telegram/ChannelId.h
td/telegram/ChannelParticipantFilter.h
td/telegram/ChannelType.h
td/telegram/ChatId.h
td/telegram/ClientActor.h
td/telegram/ConfigManager.h

View File

@ -8,6 +8,7 @@
#include "td/telegram/AccessRights.h"
#include "td/telegram/AuthManager.h"
#include "td/telegram/ChannelType.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/MessagesManager.h"
#include "td/telegram/Td.h"
@ -78,8 +79,7 @@ Result<BotCommandScope> BotCommandScope::get_bot_command_scope(Td *td,
// ok
break;
case DialogType::Channel:
if (td->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) !=
ContactsManager::ChannelType::Megagroup) {
if (td->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) != ChannelType::Megagroup) {
return Status::Error(400, "Can't change commands in channel chats");
}
break;

15
td/telegram/ChannelType.h Normal file
View File

@ -0,0 +1,15 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
//
// 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/utils/common.h"
namespace td {
enum class ChannelType : uint8 { Broadcast, Megagroup, Unknown };
} // namespace td

View File

@ -14626,7 +14626,7 @@ bool ContactsManager::is_channel_public(const Channel *c) {
return c != nullptr && (!c->username.empty() || c->has_location);
}
ContactsManager::ChannelType ContactsManager::get_channel_type(ChannelId channel_id) const {
ChannelType ContactsManager::get_channel_type(ChannelId channel_id) const {
auto c = get_channel(channel_id);
if (c == nullptr) {
auto min_channel = get_min_channel(channel_id);
@ -14638,7 +14638,7 @@ ContactsManager::ChannelType ContactsManager::get_channel_type(ChannelId channel
return get_channel_type(c);
}
ContactsManager::ChannelType ContactsManager::get_channel_type(const Channel *c) {
ChannelType ContactsManager::get_channel_type(const Channel *c) {
if (c->is_megagroup) {
return ChannelType::Megagroup;
}

View File

@ -9,6 +9,7 @@
#include "td/telegram/AccessRights.h"
#include "td/telegram/BotCommand.h"
#include "td/telegram/ChannelId.h"
#include "td/telegram/ChannelType.h"
#include "td/telegram/ChatId.h"
#include "td/telegram/Contact.h"
#include "td/telegram/DialogAdministrator.h"
@ -518,8 +519,6 @@ class ContactsManager final : public Actor {
bool get_secret_chat(SecretChatId secret_chat_id, bool force, Promise<Unit> &&promise);
bool get_secret_chat_full(SecretChatId secret_chat_id, Promise<Unit> &&promise);
enum class ChannelType : uint8 { Broadcast, Megagroup, Unknown };
ChannelType get_channel_type(ChannelId channel_id) const;
int32 get_channel_date(ChannelId channel_id) const;
DialogParticipantStatus get_channel_status(ChannelId channel_id) const;

View File

@ -6,6 +6,7 @@
//
#include "td/telegram/DialogActionBar.h"
#include "td/telegram/ChannelType.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/Td.h"
@ -97,8 +98,8 @@ void DialogActionBar::fix(Td *td, DialogId dialog_id, bool is_dialog_blocked, Fo
}
if (can_invite_members_) {
if (dialog_type != DialogType::Chat &&
(dialog_type != DialogType::Channel || td->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) ==
ContactsManager::ChannelType::Broadcast)) {
(dialog_type != DialogType::Channel ||
td->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) == ChannelType::Broadcast)) {
LOG(ERROR) << "Receive can_invite_members in " << dialog_id;
can_invite_members_ = false;
} else if (can_report_spam_ || can_add_contact_ || can_block_user_ || can_share_phone_number_ || can_unarchive_) {

View File

@ -10,6 +10,7 @@
#include "td/telegram/AnimationsManager.h"
#include "td/telegram/AudiosManager.h"
#include "td/telegram/AuthManager.h"
#include "td/telegram/ChannelType.h"
#include "td/telegram/Contact.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/Document.h"
@ -1462,8 +1463,7 @@ void InlineQueriesManager::on_get_inline_query_results(DialogId dialog_id, UserI
break;
}
if (dialog_type == DialogType::Channel &&
td_->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) ==
ContactsManager::ChannelType::Broadcast) {
td_->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) == ChannelType::Broadcast) {
continue;
}
if (dialog_type == DialogType::SecretChat) {

View File

@ -13,6 +13,7 @@
#include "td/telegram/AuthManager.h"
#include "td/telegram/CallDiscardReason.h"
#include "td/telegram/ChannelId.h"
#include "td/telegram/ChannelType.h"
#include "td/telegram/ChatId.h"
#include "td/telegram/Contact.h"
#include "td/telegram/ContactsManager.h"
@ -2593,8 +2594,8 @@ Status can_send_message_content(DialogId dialog_id, const MessageContent *conten
}
break;
case MessageContentType::Game:
if (dialog_type == DialogType::Channel && td->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) ==
ContactsManager::ChannelType::Broadcast) {
if (dialog_type == DialogType::Channel &&
td->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) == ChannelType::Broadcast) {
// return Status::Error(400, "Games can't be sent to channel chats");
}
if (dialog_type == DialogType::SecretChat) {
@ -2632,8 +2633,7 @@ Status can_send_message_content(DialogId dialog_id, const MessageContent *conten
return Status::Error(400, "Not enough rights to send polls to the chat");
}
if (dialog_type == DialogType::Channel &&
td->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) ==
ContactsManager::ChannelType::Broadcast &&
td->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) == ChannelType::Broadcast &&
!td->poll_manager_->get_poll_is_anonymous(static_cast<const MessagePoll *>(content)->poll_id)) {
return Status::Error(400, "Non-anonymous polls can't be sent to channel chats");
}

View File

@ -8,6 +8,7 @@
#include "td/telegram/AuthManager.h"
#include "td/telegram/ChainId.h"
#include "td/telegram/ChannelType.h"
#include "td/telegram/ChatId.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/ContactsManager.h"
@ -2365,8 +2366,7 @@ class SearchMessagesQuery final : public Td::ResultHandler {
} else if (top_thread_message_id.is_valid() && query.empty() && !sender_dialog_id.is_valid() &&
filter == MessageSearchFilter::Empty) {
handle_errors_ = dialog_id.get_type() != DialogType::Channel ||
td_->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) !=
ContactsManager::ChannelType::Broadcast;
td_->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) != ChannelType::Broadcast;
send_query(G()->net_query_creator().create(telegram_api::messages_getReplies(
std::move(input_peer), top_thread_message_id.get_server_message_id().get(),
from_message_id.get_server_message_id().get(), 0, offset, limit, std::numeric_limits<int32>::max(), 0, 0)));
@ -11660,7 +11660,7 @@ void MessagesManager::delete_dialog_messages_by_sender(DialogId dialog_id, Dialo
case DialogType::Channel: {
channel_id = dialog_id.get_channel_id();
auto channel_type = td_->contacts_manager_->get_channel_type(channel_id);
if (channel_type != ContactsManager::ChannelType::Megagroup) {
if (channel_type != ChannelType::Megagroup) {
return promise.set_error(Status::Error(400, "The method is available only for supergroup chats"));
}
channel_status = td_->contacts_manager_->get_channel_permissions(channel_id);
@ -21344,7 +21344,7 @@ td_api::object_ptr<td_api::ChatType> MessagesManager::get_chat_type_object(Dialo
auto channel_type = td_->contacts_manager_->get_channel_type(channel_id);
return td_api::make_object<td_api::chatTypeSupergroup>(
td_->contacts_manager_->get_supergroup_id_object(channel_id, "chatTypeSupergroup"),
channel_type != ContactsManager::ChannelType::Megagroup);
channel_type != ChannelType::Megagroup);
}
case DialogType::SecretChat: {
auto secret_chat_id = dialog_id.get_secret_chat_id();
@ -25202,13 +25202,13 @@ Status MessagesManager::can_send_message(DialogId dialog_id) const {
auto channel_status = td_->contacts_manager_->get_channel_permissions(channel_id);
switch (channel_type) {
case ContactsManager::ChannelType::Unknown:
case ContactsManager::ChannelType::Megagroup:
case ChannelType::Unknown:
case ChannelType::Megagroup:
if (!channel_status.can_send_messages()) {
return Status::Error(400, "Have no rights to send a message");
}
break;
case ContactsManager::ChannelType::Broadcast: {
case ChannelType::Broadcast: {
if (!channel_status.can_post_messages()) {
return Status::Error(400, "Need administrator rights in the channel chat");
}
@ -26573,14 +26573,14 @@ Result<MessageId> MessagesManager::send_bot_start_message(UserId bot_user_id, Di
return Status::Error(400, "Can't access the chat");
}
switch (td_->contacts_manager_->get_channel_type(channel_id)) {
case ContactsManager::ChannelType::Megagroup:
case ChannelType::Megagroup:
if (!bot_data.can_join_groups) {
return Status::Error(400, "The bot can't join groups");
}
break;
case ContactsManager::ChannelType::Broadcast:
case ChannelType::Broadcast:
return Status::Error(400, "Bots can't be invited to channel chats. Add them as administrators instead");
case ContactsManager::ChannelType::Unknown:
case ChannelType::Unknown:
default:
UNREACHABLE();
}
@ -27047,8 +27047,7 @@ bool MessagesManager::is_group_dialog(DialogId dialog_id) const {
case DialogType::Chat:
return true;
case DialogType::Channel:
return td_->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) ==
ContactsManager::ChannelType::Megagroup;
return td_->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) == ChannelType::Megagroup;
default:
return false;
}
@ -27059,8 +27058,7 @@ bool MessagesManager::is_broadcast_channel(DialogId dialog_id) const {
return false;
}
return td_->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) ==
ContactsManager::ChannelType::Broadcast;
return td_->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) == ChannelType::Broadcast;
}
bool MessagesManager::is_deleted_secret_chat(DialogId dialog_id) const {
@ -36384,7 +36382,7 @@ MessagesManager::Dialog *MessagesManager::add_new_dialog(unique_ptr<Dialog> &&d,
break;
case DialogType::Channel: {
auto channel_type = td_->contacts_manager_->get_channel_type(dialog_id.get_channel_id());
if (channel_type == ContactsManager::ChannelType::Broadcast) {
if (channel_type == ChannelType::Broadcast) {
d->last_read_outbox_message_id = MessageId::max();
d->is_last_read_outbox_message_id_inited = true;
}
@ -38885,13 +38883,13 @@ void MessagesManager::update_top_dialogs(DialogId dialog_id, const Message *m) {
break;
case DialogType::Channel:
switch (td_->contacts_manager_->get_channel_type(dialog_id.get_channel_id())) {
case ContactsManager::ChannelType::Broadcast:
case ChannelType::Broadcast:
category = TopDialogCategory::Channel;
break;
case ContactsManager::ChannelType::Megagroup:
case ChannelType::Megagroup:
category = TopDialogCategory::Group;
break;
case ContactsManager::ChannelType::Unknown:
case ChannelType::Unknown:
break;
default:
UNREACHABLE();

View File

@ -7,6 +7,7 @@
#include "td/telegram/PrivacyManager.h"
#include "td/telegram/ChannelId.h"
#include "td/telegram/ChannelType.h"
#include "td/telegram/ChatId.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/DialogId.h"
@ -159,7 +160,7 @@ void PrivacyManager::UserPrivacySettingRule::set_chat_ids(const vector<int64> &d
break;
case DialogType::Channel: {
auto channel_id = dialog_id.get_channel_id();
if (td->contacts_manager_->get_channel_type(channel_id) != ContactsManager::ChannelType::Megagroup) {
if (td->contacts_manager_->get_channel_type(channel_id) != ChannelType::Megagroup) {
LOG(ERROR) << "Ignore broadcast " << channel_id;
break;
}

View File

@ -206,7 +206,7 @@ void SponsoredMessageManager::get_dialog_sponsored_message(
return promise.set_error(Status::Error(400, "Chat not found"));
}
if (dialog_id.get_type() != DialogType::Channel ||
td_->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) != ContactsManager::ChannelType::Broadcast) {
td_->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) != ChannelType::Broadcast) {
return promise.set_value(nullptr);
}