Add ContactsManager::is_broadcast_channel/is_megagroup_channel helpers.

This commit is contained in:
levlam 2022-04-04 15:48:33 +03:00
parent a8a343704a
commit 1d6488ab09
9 changed files with 27 additions and 27 deletions

View File

@ -8,7 +8,6 @@
#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"
@ -79,7 +78,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()) != ChannelType::Megagroup) {
if (td->contacts_manager_->is_broadcast_channel(dialog_id.get_channel_id())) {
return Status::Error(400, "Can't change commands in channel chats");
}
break;

View File

@ -11822,7 +11822,7 @@ void ContactsManager::update_chat_online_member_count(const ChatFull *chat_full,
}
void ContactsManager::update_channel_online_member_count(ChannelId channel_id, bool is_from_server) {
if (get_channel_type(channel_id) != ChannelType::Megagroup) {
if (!is_megagroup_channel(channel_id)) {
return;
}
@ -12103,7 +12103,7 @@ void ContactsManager::on_get_channel_participants(
total_count = static_cast<int32>(result.size());
}
const auto max_participant_count = get_channel_type(channel_id) == ChannelType::Megagroup ? 975 : 195;
const auto max_participant_count = is_megagroup_channel(channel_id) ? 975 : 195;
auto participant_count =
filter.is_recent() && total_count != 0 && total_count < max_participant_count ? total_count : -1;
int32 administrator_count = filter.is_administrators() ? total_count : -1;
@ -12126,7 +12126,7 @@ void ContactsManager::on_get_channel_participants(
}
administrator_count = narrow_cast<int32>(administrators.size());
if (get_channel_type(channel_id) == ChannelType::Megagroup && !td_->auth_manager_->is_bot()) {
if (is_megagroup_channel(channel_id) && !td_->auth_manager_->is_bot()) {
cached_channel_participants_[channel_id] = result;
update_channel_online_member_count(channel_id, true);
}
@ -14645,6 +14645,14 @@ ChannelType ContactsManager::get_channel_type(const Channel *c) {
return ChannelType::Broadcast;
}
bool ContactsManager::is_broadcast_channel(ChannelId channel_id) const {
return get_channel_type(channel_id) == ChannelType::Broadcast;
}
bool ContactsManager::is_megagroup_channel(ChannelId channel_id) const {
return get_channel_type(channel_id) == ChannelType::Megagroup;
}
int32 ContactsManager::get_channel_date(ChannelId channel_id) const {
auto c = get_channel(channel_id);
if (c == nullptr) {

View File

@ -520,6 +520,8 @@ class ContactsManager final : public Actor {
bool get_secret_chat_full(SecretChatId secret_chat_id, Promise<Unit> &&promise);
ChannelType get_channel_type(ChannelId channel_id) const;
bool is_broadcast_channel(ChannelId channel_id) const;
bool is_megagroup_channel(ChannelId channel_id) const;
int32 get_channel_date(ChannelId channel_id) const;
DialogParticipantStatus get_channel_status(ChannelId channel_id) const;
DialogParticipantStatus get_channel_permissions(ChannelId channel_id) const;

View File

@ -6,7 +6,6 @@
//
#include "td/telegram/DialogActionBar.h"
#include "td/telegram/ChannelType.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/Td.h"
@ -97,9 +96,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()) == ChannelType::Broadcast)) {
if (dialog_type != DialogType::Chat && (dialog_type != DialogType::Channel ||
td->contacts_manager_->is_broadcast_channel(dialog_id.get_channel_id()))) {
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,7 +10,6 @@
#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"
@ -1463,7 +1462,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()) == ChannelType::Broadcast) {
td_->contacts_manager_->is_broadcast_channel(dialog_id.get_channel_id())) {
continue;
}
if (dialog_type == DialogType::SecretChat) {

View File

@ -13,7 +13,6 @@
#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"
@ -2595,7 +2594,7 @@ 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()) == ChannelType::Broadcast) {
td->contacts_manager_->is_broadcast_channel(dialog_id.get_channel_id())) {
// return Status::Error(400, "Games can't be sent to channel chats");
}
if (dialog_type == DialogType::SecretChat) {
@ -2633,7 +2632,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()) == ChannelType::Broadcast &&
td->contacts_manager_->is_broadcast_channel(dialog_id.get_channel_id()) &&
!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

@ -2366,7 +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()) != ChannelType::Broadcast;
!td_->contacts_manager_->is_broadcast_channel(dialog_id.get_channel_id());
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)));
@ -11659,8 +11659,7 @@ void MessagesManager::delete_dialog_messages_by_sender(DialogId dialog_id, Dialo
Status::Error(400, "All messages from a sender can be deleted only in supergroup chats"));
case DialogType::Channel: {
channel_id = dialog_id.get_channel_id();
auto channel_type = td_->contacts_manager_->get_channel_type(channel_id);
if (channel_type != ChannelType::Megagroup) {
if (!td_->contacts_manager_->is_megagroup_channel(channel_id)) {
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);
@ -21341,10 +21340,9 @@ td_api::object_ptr<td_api::ChatType> MessagesManager::get_chat_type_object(Dialo
td_->contacts_manager_->get_basic_group_id_object(dialog_id.get_chat_id(), "chatTypeBasicGroup"));
case DialogType::Channel: {
auto channel_id = dialog_id.get_channel_id();
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 != ChannelType::Megagroup);
!td_->contacts_manager_->is_megagroup_channel(channel_id));
}
case DialogType::SecretChat: {
auto secret_chat_id = dialog_id.get_secret_chat_id();
@ -27047,7 +27045,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()) == ChannelType::Megagroup;
return td_->contacts_manager_->is_megagroup_channel(dialog_id.get_channel_id());
default:
return false;
}
@ -27058,7 +27056,7 @@ bool MessagesManager::is_broadcast_channel(DialogId dialog_id) const {
return false;
}
return td_->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) == ChannelType::Broadcast;
return td_->contacts_manager_->is_broadcast_channel(dialog_id.get_channel_id());
}
bool MessagesManager::is_deleted_secret_chat(DialogId dialog_id) const {
@ -36381,8 +36379,7 @@ MessagesManager::Dialog *MessagesManager::add_new_dialog(unique_ptr<Dialog> &&d,
d->is_is_blocked_inited = true;
break;
case DialogType::Channel: {
auto channel_type = td_->contacts_manager_->get_channel_type(dialog_id.get_channel_id());
if (channel_type == ChannelType::Broadcast) {
if (td_->contacts_manager_->is_broadcast_channel(dialog_id.get_channel_id())) {
d->last_read_outbox_message_id = MessageId::max();
d->is_last_read_outbox_message_id_inited = true;
}

View File

@ -7,7 +7,6 @@
#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"
@ -160,7 +159,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) != ChannelType::Megagroup) {
if (!td->contacts_manager_->is_megagroup_channel(channel_id)) {
LOG(ERROR) << "Ignore broadcast " << channel_id;
break;
}

View File

@ -205,8 +205,7 @@ void SponsoredMessageManager::get_dialog_sponsored_message(
if (!td_->messages_manager_->have_dialog_force(dialog_id, "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()) != ChannelType::Broadcast) {
if (dialog_id.get_type() != DialogType::Channel) {
return promise.set_value(nullptr);
}