Remove most MESSAGE_FLAG usages.

This commit is contained in:
levlam 2023-09-25 22:09:31 +03:00
parent 9a44005187
commit 09ced5689b
3 changed files with 20 additions and 48 deletions

View File

@ -13997,7 +13997,7 @@ void MessagesManager::on_get_secret_message(SecretChatId secret_chat_id, UserId
pending_secret_message->load_data_multipromise.add_promise(Auto()); pending_secret_message->load_data_multipromise.add_promise(Auto());
auto lock_promise = pending_secret_message->load_data_multipromise.get_promise(); auto lock_promise = pending_secret_message->load_data_multipromise.get_promise();
int32 flags = MESSAGE_FLAG_HAS_UNREAD_CONTENT | MESSAGE_FLAG_HAS_FROM_ID; int32 flags = MESSAGE_FLAG_HAS_UNREAD_CONTENT;
if ((message->flags_ & secret_api::decryptedMessage::REPLY_TO_RANDOM_ID_MASK) != 0) { if ((message->flags_ & secret_api::decryptedMessage::REPLY_TO_RANDOM_ID_MASK) != 0) {
message_info.reply_header.reply_to_message_id_ = message_info.reply_header.reply_to_message_id_ =
get_message_id_by_random_id(d, message->reply_to_random_id_, "on_get_secret_message"); get_message_id_by_random_id(d, message->reply_to_random_id_, "on_get_secret_message");
@ -14050,7 +14050,7 @@ void MessagesManager::on_resolve_secret_chat_message_via_bot_username(const stri
auto user_id = dialog_id.get_user_id(); auto user_id = dialog_id.get_user_id();
auto r_bot_data = td_->contacts_manager_->get_bot_data(user_id); auto r_bot_data = td_->contacts_manager_->get_bot_data(user_id);
if (r_bot_data.is_ok() && r_bot_data.ok().is_inline) { if (r_bot_data.is_ok() && r_bot_data.ok().is_inline) {
message_info_ptr->flags |= MESSAGE_FLAG_IS_SENT_VIA_BOT; message_info_ptr->flags |= telegram_api::message::VIA_BOT_ID_MASK;
message_info_ptr->via_bot_user_id = user_id; message_info_ptr->via_bot_user_id = user_id;
} }
} }
@ -14074,7 +14074,6 @@ void MessagesManager::on_secret_chat_screenshot_taken(SecretChatId secret_chat_i
message_info.sender_user_id = user_id; message_info.sender_user_id = user_id;
message_info.date = date; message_info.date = date;
message_info.random_id = random_id; message_info.random_id = random_id;
message_info.flags = MESSAGE_FLAG_HAS_FROM_ID;
message_info.content = create_screenshot_taken_message_content(); message_info.content = create_screenshot_taken_message_content();
Dialog *d = get_dialog_force(message_info.dialog_id, "on_secret_chat_screenshot_taken"); Dialog *d = get_dialog_force(message_info.dialog_id, "on_secret_chat_screenshot_taken");
@ -14112,7 +14111,6 @@ void MessagesManager::on_secret_chat_ttl_changed(SecretChatId secret_chat_id, Us
message_info.sender_user_id = user_id; message_info.sender_user_id = user_id;
message_info.date = date; message_info.date = date;
message_info.random_id = random_id; message_info.random_id = random_id;
message_info.flags = MESSAGE_FLAG_HAS_FROM_ID;
message_info.content = create_chat_set_ttl_message_content(ttl, UserId()); message_info.content = create_chat_set_ttl_message_content(ttl, UserId());
Dialog *d = get_dialog_force(message_info.dialog_id, "on_secret_chat_ttl_changed"); Dialog *d = get_dialog_force(message_info.dialog_id, "on_secret_chat_ttl_changed");
@ -14233,35 +14231,23 @@ MessagesManager::MessageInfo MessagesManager::parse_telegram_api_message(
message_info.dialog_id.get_type() == DialogType::Channel && !is_broadcast_channel(message_info.dialog_id); message_info.dialog_id.get_type() == DialogType::Channel && !is_broadcast_channel(message_info.dialog_id);
message_info.reply_header = MessageReplyHeader(std::move(message->reply_to_), message_info.dialog_id, message_info.reply_header = MessageReplyHeader(std::move(message->reply_to_), message_info.dialog_id,
message_info.message_id, message_info.date, can_have_thread); message_info.message_id, message_info.date, can_have_thread);
if (message->flags_ & MESSAGE_FLAG_IS_SENT_VIA_BOT) { if (message->flags_ & telegram_api::message::VIA_BOT_ID_MASK) {
message_info.via_bot_user_id = UserId(message->via_bot_id_); message_info.via_bot_user_id = UserId(message->via_bot_id_);
if (!message_info.via_bot_user_id.is_valid()) { if (!message_info.via_bot_user_id.is_valid()) {
LOG(ERROR) << "Receive invalid " << message_info.via_bot_user_id << " from " << source; LOG(ERROR) << "Receive invalid " << message_info.via_bot_user_id << " from " << source;
message_info.via_bot_user_id = UserId(); message_info.via_bot_user_id = UserId();
} }
} }
if (message->flags_ & MESSAGE_FLAG_HAS_INTERACTION_INFO) {
message_info.view_count = message->views_; message_info.view_count = message->views_;
message_info.forward_count = message->forwards_; message_info.forward_count = message->forwards_;
}
if (message->flags_ & MESSAGE_FLAG_HAS_REPLY_INFO) {
message_info.reply_info = std::move(message->replies_); message_info.reply_info = std::move(message->replies_);
}
if (message->flags_ & MESSAGE_FLAG_HAS_REACTIONS) {
message_info.reactions = std::move(message->reactions_); message_info.reactions = std::move(message->reactions_);
}
if (message->flags_ & MESSAGE_FLAG_HAS_EDIT_DATE) {
message_info.edit_date = message->edit_date_; message_info.edit_date = message->edit_date_;
}
if (message->flags_ & MESSAGE_FLAG_HAS_MEDIA_ALBUM_ID) {
message_info.media_album_id = message->grouped_id_; message_info.media_album_id = message->grouped_id_;
}
if (message->flags_ & MESSAGE_FLAG_HAS_TTL_PERIOD) {
message_info.ttl_period = message->ttl_period_; message_info.ttl_period = message->ttl_period_;
}
message_info.flags = message->flags_; message_info.flags = message->flags_;
bool is_content_read = (message->flags_ & MESSAGE_FLAG_HAS_UNREAD_CONTENT) == 0; bool is_content_read = !message->media_unread_;
if (is_message_auto_read(message_info.dialog_id, (message->flags_ & MESSAGE_FLAG_IS_OUT) != 0)) { if (is_message_auto_read(message_info.dialog_id, message->out_)) {
is_content_read = true; is_content_read = true;
} }
if (is_scheduled) { if (is_scheduled) {
@ -14292,9 +14278,7 @@ MessagesManager::MessageInfo MessagesManager::parse_telegram_api_message(
message_info.sender_dialog_id = message_info.dialog_id; message_info.sender_dialog_id = message_info.dialog_id;
} }
message_info.date = message->date_; message_info.date = message->date_;
if (message->flags_ & MESSAGE_FLAG_HAS_TTL_PERIOD) {
message_info.ttl_period = message->ttl_period_; message_info.ttl_period = message->ttl_period_;
}
message_info.flags = message->flags_; message_info.flags = message->flags_;
bool can_have_thread = bool can_have_thread =
message_info.dialog_id.get_type() == DialogType::Channel && !is_broadcast_channel(message_info.dialog_id); message_info.dialog_id.get_type() == DialogType::Channel && !is_broadcast_channel(message_info.dialog_id);

View File

@ -118,31 +118,15 @@ class Td;
class MessagesManager final : public Actor { class MessagesManager final : public Actor {
public: public:
// static constexpr int32 MESSAGE_FLAG_IS_UNREAD = 1 << 0;
static constexpr int32 MESSAGE_FLAG_IS_OUT = 1 << 1; static constexpr int32 MESSAGE_FLAG_IS_OUT = 1 << 1;
static constexpr int32 MESSAGE_FLAG_IS_FORWARDED = 1 << 2;
static constexpr int32 MESSAGE_FLAG_IS_REPLY = 1 << 3;
static constexpr int32 MESSAGE_FLAG_HAS_MENTION = 1 << 4; static constexpr int32 MESSAGE_FLAG_HAS_MENTION = 1 << 4;
static constexpr int32 MESSAGE_FLAG_HAS_UNREAD_CONTENT = 1 << 5; static constexpr int32 MESSAGE_FLAG_HAS_UNREAD_CONTENT = 1 << 5;
static constexpr int32 MESSAGE_FLAG_HAS_REPLY_MARKUP = 1 << 6;
static constexpr int32 MESSAGE_FLAG_HAS_ENTITIES = 1 << 7;
static constexpr int32 MESSAGE_FLAG_HAS_FROM_ID = 1 << 8;
static constexpr int32 MESSAGE_FLAG_HAS_MEDIA = 1 << 9;
static constexpr int32 MESSAGE_FLAG_HAS_INTERACTION_INFO = 1 << 10;
static constexpr int32 MESSAGE_FLAG_IS_SENT_VIA_BOT = 1 << 11;
static constexpr int32 MESSAGE_FLAG_IS_SILENT = 1 << 13; static constexpr int32 MESSAGE_FLAG_IS_SILENT = 1 << 13;
static constexpr int32 MESSAGE_FLAG_IS_POST = 1 << 14; static constexpr int32 MESSAGE_FLAG_IS_POST = 1 << 14;
static constexpr int32 MESSAGE_FLAG_HAS_EDIT_DATE = 1 << 15;
static constexpr int32 MESSAGE_FLAG_HAS_AUTHOR_SIGNATURE = 1 << 16;
static constexpr int32 MESSAGE_FLAG_HAS_MEDIA_ALBUM_ID = 1 << 17;
static constexpr int32 MESSAGE_FLAG_IS_FROM_SCHEDULED = 1 << 18; static constexpr int32 MESSAGE_FLAG_IS_FROM_SCHEDULED = 1 << 18;
static constexpr int32 MESSAGE_FLAG_IS_LEGACY = 1 << 19; static constexpr int32 MESSAGE_FLAG_IS_LEGACY = 1 << 19;
static constexpr int32 MESSAGE_FLAG_HAS_REACTIONS = 1 << 20;
static constexpr int32 MESSAGE_FLAG_HIDE_EDIT_DATE = 1 << 21; static constexpr int32 MESSAGE_FLAG_HIDE_EDIT_DATE = 1 << 21;
static constexpr int32 MESSAGE_FLAG_IS_RESTRICTED = 1 << 22;
static constexpr int32 MESSAGE_FLAG_HAS_REPLY_INFO = 1 << 23;
static constexpr int32 MESSAGE_FLAG_IS_PINNED = 1 << 24; static constexpr int32 MESSAGE_FLAG_IS_PINNED = 1 << 24;
static constexpr int32 MESSAGE_FLAG_HAS_TTL_PERIOD = 1 << 25;
static constexpr int32 MESSAGE_FLAG_NOFORWARDS = 1 << 26; static constexpr int32 MESSAGE_FLAG_NOFORWARDS = 1 << 26;
static constexpr int32 SEND_MESSAGE_FLAG_DISABLE_WEB_PAGE_PREVIEW = 1 << 1; static constexpr int32 SEND_MESSAGE_FLAG_DISABLE_WEB_PAGE_PREVIEW = 1 << 1;

View File

@ -831,7 +831,7 @@ bool UpdatesManager::is_acceptable_message(const telegram_api::Message *message_
return false; return false;
} }
if ((message->flags_ & MessagesManager::MESSAGE_FLAG_IS_SENT_VIA_BOT) && if ((message->flags_ & telegram_api::message::VIA_BOT_ID_MASK) &&
!is_acceptable_user(UserId(message->via_bot_id_))) { !is_acceptable_user(UserId(message->via_bot_id_))) {
return false; return false;
} }
@ -1082,8 +1082,12 @@ bool UpdatesManager::is_acceptable_update(const telegram_api::Update *update) co
} }
int32 UpdatesManager::fix_short_message_flags(int32 flags) { int32 UpdatesManager::fix_short_message_flags(int32 flags) {
auto disallowed_flags = MessagesManager::MESSAGE_FLAG_HAS_REPLY_MARKUP | MessagesManager::MESSAGE_FLAG_HAS_MEDIA | static constexpr int32 MESSAGE_FLAG_HAS_REPLY_MARKUP = 1 << 6;
MessagesManager::MESSAGE_FLAG_HAS_REACTIONS | MessagesManager::MESSAGE_FLAG_HAS_REPLY_INFO; static constexpr int32 MESSAGE_FLAG_HAS_MEDIA = 1 << 9;
static constexpr int32 MESSAGE_FLAG_HAS_REACTIONS = 1 << 20;
static constexpr int32 MESSAGE_FLAG_HAS_REPLY_INFO = 1 << 23;
auto disallowed_flags =
MESSAGE_FLAG_HAS_REPLY_MARKUP | MESSAGE_FLAG_HAS_MEDIA | MESSAGE_FLAG_HAS_REACTIONS | MESSAGE_FLAG_HAS_REPLY_INFO;
if ((flags & disallowed_flags) != 0) { if ((flags & disallowed_flags) != 0) {
LOG(ERROR) << "Receive short message with flags " << flags; LOG(ERROR) << "Receive short message with flags " << flags;
flags = flags & ~disallowed_flags; flags = flags & ~disallowed_flags;