Add class ChainId.

This commit is contained in:
levlam 2022-02-05 23:28:43 +03:00
parent 46e23a407f
commit b845766bd1
12 changed files with 134 additions and 103 deletions

View File

@ -474,6 +474,7 @@ set(TDLIB_SOURCE
td/telegram/CallId.h
td/telegram/CallManager.h
td/telegram/CallbackQueriesManager.h
td/telegram/ChainId.h
td/telegram/ChannelId.h
td/telegram/ChatId.h
td/telegram/ClientActor.h

37
td/telegram/ChainId.h Normal file
View File

@ -0,0 +1,37 @@
//
// 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/telegram/DialogId.h"
#include "td/telegram/FolderId.h"
#include "td/telegram/MessageContentType.h"
#include "td/telegram/PollId.h"
#include "td/utils/common.h"
namespace td {
class ChainId {
uint64 id = 0;
public:
ChainId(DialogId dialog_id, MessageContentType message_content_type = MessageContentType::None)
: id((static_cast<uint64>(dialog_id.get()) << 10) + get_message_content_chain_id(message_content_type)) {
}
ChainId(FolderId folder_id) : id((static_cast<uint64>(folder_id.get() + (1 << 30)) << 10)) {
}
ChainId(PollId poll_id) : id(static_cast<uint64>(poll_id.get())) {
}
uint64 get() const {
return id;
}
};
} // namespace td

View File

@ -8,6 +8,7 @@
#include "td/telegram/AccessRights.h"
#include "td/telegram/AuthManager.h"
#include "td/telegram/ChainId.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/DialogId.h"
#include "td/telegram/Global.h"
@ -35,7 +36,7 @@ class SetGameScoreQuery final : public Td::ResultHandler {
}
void send(DialogId dialog_id, MessageId message_id, bool edit_message,
tl_object_ptr<telegram_api::InputUser> input_user, int32 score, bool force, uint64 sequence_dispatcher_id) {
tl_object_ptr<telegram_api::InputUser> input_user, int32 score, bool force) {
int32 flags = 0;
if (edit_message) {
flags |= telegram_api::messages_setGameScore::EDIT_MESSAGE_MASK;
@ -55,7 +56,7 @@ class SetGameScoreQuery final : public Td::ResultHandler {
send_query(G()->net_query_creator().create(
telegram_api::messages_setGameScore(flags, false /*ignored*/, false /*ignored*/, std::move(input_peer),
message_id.get_server_message_id().get(), std::move(input_user), score),
{sequence_dispatcher_id}));
{{dialog_id}}));
}
void on_result(BufferSlice packet) final {
@ -227,8 +228,7 @@ void GameManager::set_game_score(FullMessageId full_message_id, bool edit_messag
send_closure(actor_id, &GameManager::on_set_game_score, full_message_id, std::move(promise));
});
td_->create_handler<SetGameScoreQuery>(std::move(query_promise))
->send(dialog_id, full_message_id.get_message_id(), edit_message, r_input_user.move_as_ok(), score, force,
MessagesManager::get_sequence_dispatcher_id(dialog_id, MessageContentType::None));
->send(dialog_id, full_message_id.get_message_id(), edit_message, r_input_user.move_as_ok(), score, force);
}
void GameManager::on_set_game_score(FullMessageId full_message_id,

View File

@ -341,4 +341,20 @@ bool can_have_message_content_caption(MessageContentType content_type) {
}
}
uint64 get_message_content_chain_id(MessageContentType content_type) {
switch (content_type) {
case MessageContentType::Animation:
case MessageContentType::Audio:
case MessageContentType::Document:
case MessageContentType::Photo:
case MessageContentType::Sticker:
case MessageContentType::Video:
case MessageContentType::VideoNote:
case MessageContentType::VoiceNote:
return 1;
default:
return 2;
}
}
} // namespace td

View File

@ -76,6 +76,8 @@ bool is_service_message_content(MessageContentType content_type);
bool can_have_message_content_caption(MessageContentType content_type);
uint64 get_message_content_chain_id(MessageContentType content_type);
struct MessageContentTypeHash {
std::size_t operator()(MessageContentType content_type) const {
return std::hash<int32>()(static_cast<int32>(content_type));

View File

@ -7,6 +7,7 @@
#include "td/telegram/MessagesManager.h"
#include "td/telegram/AuthManager.h"
#include "td/telegram/ChainId.h"
#include "td/telegram/ChatId.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/ContactsManager.h"
@ -334,10 +335,10 @@ class GetPinnedDialogsQuery final : public Td::ResultHandler {
explicit GetPinnedDialogsQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
NetQueryRef send(FolderId folder_id, uint64 sequence_id) {
NetQueryRef send(FolderId folder_id) {
folder_id_ = folder_id;
auto query =
G()->net_query_creator().create(telegram_api::messages_getPinnedDialogs(folder_id.get()), {sequence_id});
G()->net_query_creator().create(telegram_api::messages_getPinnedDialogs(folder_id.get()), {{folder_id}});
auto result = query.get_weak();
send_query(std::move(query));
return result;
@ -783,7 +784,7 @@ class GetDialogListQuery final : public Td::ResultHandler {
}
void send(FolderId folder_id, int32 offset_date, ServerMessageId offset_message_id, DialogId offset_dialog_id,
int32 limit, uint64 sequence_id) {
int32 limit) {
folder_id_ = folder_id;
auto input_peer = MessagesManager::get_input_peer_force(offset_dialog_id);
CHECK(input_peer != nullptr);
@ -793,7 +794,7 @@ class GetDialogListQuery final : public Td::ResultHandler {
send_query(G()->net_query_creator().create(
telegram_api::messages_getDialogs(flags, false /*ignored*/, folder_id.get(), offset_date,
offset_message_id.get(), std::move(input_peer), limit, 0),
{sequence_id}));
{{folder_id}}));
}
void on_result(BufferSlice packet) final {
@ -1841,7 +1842,7 @@ class ToggleDialogIsBlockedQuery final : public Td::ResultHandler {
explicit ToggleDialogIsBlockedQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(DialogId dialog_id, bool is_blocked, uint64 sequence_dispatcher_id) {
void send(DialogId dialog_id, bool is_blocked) {
dialog_id_ = dialog_id;
is_blocked_ = is_blocked;
@ -1849,7 +1850,7 @@ class ToggleDialogIsBlockedQuery final : public Td::ResultHandler {
CHECK(input_peer != nullptr && input_peer->get_id() != telegram_api::inputPeerEmpty::ID);
auto query = is_blocked ? G()->net_query_creator().create(telegram_api::contacts_block(std::move(input_peer)))
: G()->net_query_creator().create(telegram_api::contacts_unblock(std::move(input_peer)));
query->set_chain_ids({sequence_dispatcher_id});
query->set_chain_ids({{dialog_id, MessageContentType::Photo}, {dialog_id, MessageContentType::Text}});
send_query(std::move(query));
}
@ -3082,7 +3083,7 @@ class SaveDefaultSendAsQuery final : public Td::ResultHandler {
explicit SaveDefaultSendAsQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(DialogId dialog_id, DialogId send_as_dialog_id, uint64 sequence_dispatcher_id) {
void send(DialogId dialog_id, DialogId send_as_dialog_id) {
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
CHECK(input_peer != nullptr);
@ -3091,7 +3092,7 @@ class SaveDefaultSendAsQuery final : public Td::ResultHandler {
send_query(G()->net_query_creator().create(
telegram_api::messages_saveDefaultSendAs(std::move(input_peer), std::move(send_as_input_peer)),
{sequence_dispatcher_id}));
{{dialog_id, MessageContentType::Photo}, {dialog_id}}));
}
void on_result(BufferSlice packet) final {
@ -3120,7 +3121,7 @@ class SendMessageQuery final : public Td::ResultHandler {
void send(int32 flags, DialogId dialog_id, tl_object_ptr<telegram_api::InputPeer> as_input_peer,
MessageId reply_to_message_id, int32 schedule_date, tl_object_ptr<telegram_api::ReplyMarkup> &&reply_markup,
vector<tl_object_ptr<telegram_api::MessageEntity>> &&entities, const string &text, int64 random_id,
NetQueryRef *send_query_ref, uint64 sequence_dispatcher_id) {
NetQueryRef *send_query_ref) {
random_id_ = random_id;
dialog_id_ = dialog_id;
@ -3141,7 +3142,7 @@ class SendMessageQuery final : public Td::ResultHandler {
flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/,
std::move(input_peer), reply_to_message_id.get_server_message_id().get(), text, random_id,
std::move(reply_markup), std::move(entities), schedule_date, std::move(as_input_peer)),
{sequence_dispatcher_id});
{{dialog_id, MessageContentType::Text}});
if (G()->shared_config().get_option_boolean("use_quick_ack")) {
query->quick_ack_promise_ = PromiseCreator::lambda(
[random_id](Unit) {
@ -3307,7 +3308,7 @@ class SendMultiMediaQuery final : public Td::ResultHandler {
public:
void send(int32 flags, DialogId dialog_id, tl_object_ptr<telegram_api::InputPeer> as_input_peer,
MessageId reply_to_message_id, int32 schedule_date, vector<FileId> &&file_ids,
vector<tl_object_ptr<telegram_api::inputSingleMedia>> &&input_single_media, uint64 sequence_dispatcher_id) {
vector<tl_object_ptr<telegram_api::inputSingleMedia>> &&input_single_media, bool is_copy) {
for (auto &single_media : input_single_media) {
random_ids_.push_back(single_media->random_id_);
CHECK(FileManager::extract_was_uploaded(single_media->media_) == false);
@ -3332,7 +3333,8 @@ class SendMultiMediaQuery final : public Td::ResultHandler {
false /*ignored*/, std::move(input_peer),
reply_to_message_id.get_server_message_id().get(),
std::move(input_single_media), schedule_date, std::move(as_input_peer)),
{sequence_dispatcher_id}));
{{dialog_id, is_copy ? MessageContentType::None : MessageContentType::Photo},
{dialog_id, MessageContentType::Photo}}));
}
void on_result(BufferSlice packet) final {
@ -3420,8 +3422,8 @@ class SendMediaQuery final : public Td::ResultHandler {
tl_object_ptr<telegram_api::InputPeer> as_input_peer, MessageId reply_to_message_id, int32 schedule_date,
tl_object_ptr<telegram_api::ReplyMarkup> &&reply_markup,
vector<tl_object_ptr<telegram_api::MessageEntity>> &&entities, const string &text,
tl_object_ptr<telegram_api::InputMedia> &&input_media, int64 random_id, NetQueryRef *send_query_ref,
uint64 sequence_dispatcher_id) {
tl_object_ptr<telegram_api::InputMedia> &&input_media, MessageContentType content_type, int64 random_id,
NetQueryRef *send_query_ref) {
random_id_ = random_id;
file_id_ = file_id;
thumbnail_file_id_ = thumbnail_file_id;
@ -3447,7 +3449,7 @@ class SendMediaQuery final : public Td::ResultHandler {
flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, std::move(input_peer),
reply_to_message_id.get_server_message_id().get(), std::move(input_media), text, random_id,
std::move(reply_markup), std::move(entities), schedule_date, std::move(as_input_peer)),
{sequence_dispatcher_id});
{{dialog_id, content_type}});
if (G()->shared_config().get_option_boolean("use_quick_ack") && was_uploaded_) {
query->quick_ack_promise_ = PromiseCreator::lambda(
[random_id](Unit) {
@ -3605,7 +3607,7 @@ class SendScheduledMessageQuery final : public Td::ResultHandler {
explicit SendScheduledMessageQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(DialogId dialog_id, MessageId message_id, uint64 sequence_dispatcher_id) {
void send(DialogId dialog_id, MessageId message_id) {
dialog_id_ = dialog_id;
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Edit);
@ -3616,7 +3618,7 @@ class SendScheduledMessageQuery final : public Td::ResultHandler {
int32 server_message_id = message_id.get_scheduled_server_message_id().get();
send_query(G()->net_query_creator().create(
telegram_api::messages_sendScheduledMessages(std::move(input_peer), {server_message_id}),
{sequence_dispatcher_id}));
{{dialog_id, MessageContentType::Text}, {dialog_id, MessageContentType::Photo}}));
}
void on_result(BufferSlice packet) final {
@ -3657,8 +3659,7 @@ class EditMessageQuery final : public Td::ResultHandler {
void send(int32 flags, DialogId dialog_id, MessageId message_id, const string &text,
vector<tl_object_ptr<telegram_api::MessageEntity>> &&entities,
tl_object_ptr<telegram_api::InputMedia> &&input_media,
tl_object_ptr<telegram_api::ReplyMarkup> &&reply_markup, int32 schedule_date,
uint64 sequence_dispatcher_id) {
tl_object_ptr<telegram_api::ReplyMarkup> &&reply_markup, int32 schedule_date) {
dialog_id_ = dialog_id;
if (input_media != nullptr && false) {
@ -3692,7 +3693,7 @@ class EditMessageQuery final : public Td::ResultHandler {
telegram_api::messages_editMessage(flags, false /*ignored*/, std::move(input_peer), server_message_id, text,
std::move(input_media), std::move(reply_markup), std::move(entities),
schedule_date),
{sequence_dispatcher_id}));
{{dialog_id}}));
}
void on_result(BufferSlice packet) final {
@ -3786,7 +3787,7 @@ class ForwardMessagesQuery final : public Td::ResultHandler {
void send(int32 flags, DialogId to_dialog_id, DialogId from_dialog_id,
tl_object_ptr<telegram_api::InputPeer> as_input_peer, const vector<MessageId> &message_ids,
vector<int64> &&random_ids, int32 schedule_date, uint64 sequence_dispatcher_id) {
vector<int64> &&random_ids, int32 schedule_date) {
random_ids_ = random_ids;
from_dialog_id_ = from_dialog_id;
to_dialog_id_ = to_dialog_id;
@ -3810,7 +3811,7 @@ class ForwardMessagesQuery final : public Td::ResultHandler {
flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/,
false /*ignored*/, std::move(from_input_peer), MessagesManager::get_server_message_ids(message_ids),
std::move(random_ids), std::move(to_input_peer), schedule_date, std::move(as_input_peer)),
{sequence_dispatcher_id});
{{to_dialog_id, MessageContentType::Text}, {to_dialog_id, MessageContentType::Photo}});
if (G()->shared_config().get_option_boolean("use_quick_ack")) {
query->quick_ack_promise_ = PromiseCreator::lambda(
[random_ids = random_ids_](Unit) {
@ -12229,8 +12230,7 @@ void MessagesManager::repair_server_dialog_total_count(DialogListId dialog_list_
LOG(INFO) << "Repair total chat count in " << dialog_list_id;
td_->create_handler<GetDialogListQuery>(Promise<Unit>())
->send(dialog_list_id.get_folder_id(), 2147483647, ServerMessageId(), DialogId(), 1,
get_sequence_dispatcher_id(DialogId(), MessageContentType::None));
->send(dialog_list_id.get_folder_id(), 2147483647, ServerMessageId(), DialogId(), 1);
}
void MessagesManager::repair_secret_chat_total_count(DialogListId dialog_list_id) {
@ -16595,8 +16595,7 @@ void MessagesManager::load_folder_dialog_list(FolderId folder_id, int32 limit, b
td_->create_handler<GetDialogListQuery>(multipromise.get_promise())
->send(folder_id, folder.last_server_dialog_date_.get_date(),
folder.last_server_dialog_date_.get_message_id().get_next_server_message_id().get_server_message_id(),
folder.last_server_dialog_date_.get_dialog_id(), int32{MAX_GET_DIALOGS},
get_sequence_dispatcher_id(DialogId(), MessageContentType::None));
folder.last_server_dialog_date_.get_dialog_id(), int32{MAX_GET_DIALOGS});
is_query_sent = true;
}
if (folder_id == FolderId::main() && folder.last_server_dialog_date_ == MIN_DIALOG_DATE) {
@ -16862,8 +16861,7 @@ void MessagesManager::reload_pinned_dialogs(DialogListId dialog_list_id, Promise
CHECK(!td_->auth_manager_->is_bot());
if (dialog_list_id.is_folder()) {
td_->create_handler<GetPinnedDialogsQuery>(std::move(promise))
->send(dialog_list_id.get_folder_id(), get_sequence_dispatcher_id(DialogId(), MessageContentType::None));
td_->create_handler<GetPinnedDialogsQuery>(std::move(promise))->send(dialog_list_id.get_folder_id());
} else if (dialog_list_id.is_filter()) {
schedule_dialog_filters_reload(0.0);
dialog_filter_reload_queries_.push_back(std::move(promise));
@ -20018,7 +20016,7 @@ void MessagesManager::toggle_dialog_is_blocked_on_server(DialogId dialog_id, boo
}
td_->create_handler<ToggleDialogIsBlockedQuery>(get_erase_log_event_promise(log_event_id))
->send(dialog_id, is_blocked, get_sequence_dispatcher_id(dialog_id, MessageContentType::Text));
->send(dialog_id, is_blocked);
}
Status MessagesManager::toggle_dialog_silent_send_message(DialogId dialog_id, bool silent_send_message) {
@ -24773,7 +24771,7 @@ void MessagesManager::cancel_send_message_query(DialogId dialog_id, Message *m)
if (!m->message_id.is_scheduled() && G()->parameters().use_file_db &&
!m->is_copy) { // ResourceManager::Mode::Baseline
auto queue_id = get_sequence_dispatcher_id(dialog_id, m->content->get_type());
auto queue_id = ChainId(dialog_id, m->content->get_type()).get();
if (queue_id & 1) {
auto queue_it = yet_unsent_media_queues_.find(queue_id);
if (queue_it != yet_unsent_media_queues_.end()) {
@ -24975,9 +24973,7 @@ void MessagesManager::set_dialog_default_send_message_as_dialog_id(DialogId dial
}
}
// TODO save order with all types of messages
td_->create_handler<SaveDefaultSendAsQuery>(std::move(promise))
->send(dialog_id, message_sender_dialog_id, get_sequence_dispatcher_id(dialog_id, MessageContentType::Text));
td_->create_handler<SaveDefaultSendAsQuery>(std::move(promise))->send(dialog_id, message_sender_dialog_id);
on_update_dialog_default_send_message_as_dialog_id(dialog_id, message_sender_dialog_id, true);
}
@ -25441,8 +25437,7 @@ void MessagesManager::on_message_media_uploaded(DialogId dialog_id, const Messag
td_->create_handler<EditMessageQuery>(std::move(promise))
->send(1 << 11, dialog_id, message_id, caption == nullptr ? "" : caption->text,
get_input_message_entities(td_->contacts_manager_.get(), caption, "edit_message_media"),
std::move(input_media), std::move(input_reply_markup), schedule_date,
get_sequence_dispatcher_id(dialog_id, MessageContentType::None));
std::move(input_media), std::move(input_reply_markup), schedule_date);
return;
}
@ -25467,8 +25462,8 @@ void MessagesManager::on_message_media_uploaded(DialogId dialog_id, const Messag
file_id, thumbnail_file_id, get_message_flags(m), dialog_id, get_send_message_as_input_peer(m),
m->reply_to_message_id, get_message_schedule_date(m), get_input_reply_markup(m->reply_markup),
get_input_message_entities(td_->contacts_manager_.get(), caption, "on_message_media_uploaded"),
caption == nullptr ? "" : caption->text, std::move(input_media), random_id, &m->send_query_ref,
get_sequence_dispatcher_id(dialog_id, m->is_copy ? MessageContentType::None : m->content->get_type()));
caption == nullptr ? "" : caption->text, std::move(input_media),
m->is_copy ? MessageContentType::None : m->content->get_type(), random_id, &m->send_query_ref);
}));
} else {
switch (input_media->get_id()) {
@ -25832,10 +25827,9 @@ void MessagesManager::do_send_message_group(int64 media_album_id) {
if (input_single_media.empty()) {
LOG(INFO) << "Media group " << media_album_id << " from " << dialog_id << " is empty";
}
td_->create_handler<SendMultiMediaQuery>()->send(
flags, dialog_id, std::move(as_input_peer), reply_to_message_id, schedule_date, std::move(file_ids),
std::move(input_single_media),
get_sequence_dispatcher_id(dialog_id, is_copy ? MessageContentType::None : MessageContentType::Photo));
td_->create_handler<SendMultiMediaQuery>()->send(flags, dialog_id, std::move(as_input_peer), reply_to_message_id,
schedule_date, std::move(file_ids), std::move(input_single_media),
is_copy);
}
void MessagesManager::on_text_message_ready_to_send(DialogId dialog_id, MessageId message_id) {
@ -25858,8 +25852,6 @@ void MessagesManager::on_text_message_ready_to_send(DialogId dialog_id, MessageI
CHECK(!message_id.is_scheduled());
send_secret_message(dialog_id, m, get_secret_input_media(content, td_, nullptr, BufferSlice()));
} else {
auto content_type = content->get_type();
const FormattedText *message_text = get_message_content_text(content);
CHECK(message_text != nullptr);
@ -25868,7 +25860,7 @@ void MessagesManager::on_text_message_ready_to_send(DialogId dialog_id, MessageI
get_message_flags(m), dialog_id, get_send_message_as_input_peer(m), m->reply_to_message_id,
get_message_schedule_date(m), get_input_reply_markup(m->reply_markup),
get_input_message_entities(td_->contacts_manager_.get(), message_text->entities, "do_send_message"),
message_text->text, random_id, &m->send_query_ref, get_sequence_dispatcher_id(dialog_id, content_type));
message_text->text, random_id, &m->send_query_ref);
}
}
@ -25884,7 +25876,7 @@ void MessagesManager::on_media_message_ready_to_send(DialogId dialog_id, Message
return;
}
auto queue_id = get_sequence_dispatcher_id(dialog_id, MessageContentType::Photo);
auto queue_id = ChainId(dialog_id, MessageContentType::Photo).get();
CHECK(queue_id & 1);
auto &queue = yet_unsent_media_queues_[queue_id];
auto it = queue.find(message_id);
@ -25910,7 +25902,7 @@ void MessagesManager::on_media_message_ready_to_send(DialogId dialog_id, Message
}
void MessagesManager::on_yet_unsent_media_queue_updated(DialogId dialog_id) {
auto queue_id = get_sequence_dispatcher_id(dialog_id, MessageContentType::Photo);
auto queue_id = ChainId(dialog_id, MessageContentType::Photo).get();
CHECK(queue_id & 1);
while (true) {
auto it = yet_unsent_media_queues_.find(queue_id);
@ -26587,8 +26579,7 @@ void MessagesManager::edit_message_text(FullMessageId full_message_id,
->send(flags, dialog_id, m->message_id, input_message_text.text.text,
get_input_message_entities(td_->contacts_manager_.get(), input_message_text.text.entities,
"edit_message_text"),
nullptr, std::move(input_reply_markup), get_message_schedule_date(m),
get_sequence_dispatcher_id(dialog_id, MessageContentType::None));
nullptr, std::move(input_reply_markup), get_message_schedule_date(m));
}
void MessagesManager::edit_message_live_location(FullMessageId full_message_id,
@ -26648,8 +26639,7 @@ void MessagesManager::edit_message_live_location(FullMessageId full_message_id,
flags, false /*ignored*/, location.get_input_geo_point(), heading, 0, proximity_alert_radius);
td_->create_handler<EditMessageQuery>(std::move(promise))
->send(0, dialog_id, m->message_id, string(), vector<tl_object_ptr<telegram_api::MessageEntity>>(),
std::move(input_media), std::move(input_reply_markup), get_message_schedule_date(m),
get_sequence_dispatcher_id(dialog_id, MessageContentType::None));
std::move(input_media), std::move(input_reply_markup), get_message_schedule_date(m));
}
void MessagesManager::cancel_edit_message_media(DialogId dialog_id, Message *m, Slice error_message) {
@ -26876,8 +26866,7 @@ void MessagesManager::edit_message_caption(FullMessageId full_message_id,
td_->create_handler<EditMessageQuery>(std::move(promise))
->send(1 << 11, dialog_id, m->message_id, caption.text,
get_input_message_entities(td_->contacts_manager_.get(), caption.entities, "edit_message_caption"),
nullptr, std::move(input_reply_markup), get_message_schedule_date(m),
get_sequence_dispatcher_id(dialog_id, MessageContentType::None));
nullptr, std::move(input_reply_markup), get_message_schedule_date(m));
}
void MessagesManager::edit_message_reply_markup(FullMessageId full_message_id,
@ -26915,8 +26904,7 @@ void MessagesManager::edit_message_reply_markup(FullMessageId full_message_id,
auto input_reply_markup = get_input_reply_markup(r_new_reply_markup.ok());
td_->create_handler<EditMessageQuery>(std::move(promise))
->send(0, dialog_id, m->message_id, string(), vector<tl_object_ptr<telegram_api::MessageEntity>>(), nullptr,
std::move(input_reply_markup), get_message_schedule_date(m),
get_sequence_dispatcher_id(dialog_id, MessageContentType::None));
std::move(input_reply_markup), get_message_schedule_date(m));
}
void MessagesManager::edit_inline_message_text(const string &inline_message_id,
@ -27147,10 +27135,9 @@ void MessagesManager::edit_message_scheduling_state(
if (schedule_date > 0) {
td_->create_handler<EditMessageQuery>(std::move(promise))
->send(0, dialog_id, m->message_id, string(), vector<tl_object_ptr<telegram_api::MessageEntity>>(), nullptr,
nullptr, schedule_date, get_sequence_dispatcher_id(dialog_id, MessageContentType::None));
nullptr, schedule_date);
} else {
td_->create_handler<SendScheduledMessageQuery>(std::move(promise))
->send(dialog_id, m->message_id, get_sequence_dispatcher_id(dialog_id, MessageContentType::None));
td_->create_handler<SendScheduledMessageQuery>(std::move(promise))->send(dialog_id, m->message_id);
}
}
@ -27682,7 +27669,7 @@ void MessagesManager::do_forward_messages(DialogId to_dialog_id, DialogId from_d
transform(messages, [this, to_dialog_id](const Message *m) { return begin_send_message(to_dialog_id, m); });
td_->create_handler<ForwardMessagesQuery>(get_erase_log_event_promise(log_event_id))
->send(flags, to_dialog_id, from_dialog_id, get_send_message_as_input_peer(messages[0]), message_ids,
std::move(random_ids), schedule_date, get_sequence_dispatcher_id(to_dialog_id, MessageContentType::None));
std::move(random_ids), schedule_date);
}
Result<td_api::object_ptr<td_api::message>> MessagesManager::forward_message(
@ -32619,7 +32606,7 @@ void MessagesManager::on_send_dialog_action_timeout(DialogId dialog_id) {
return;
}
auto queue_id = get_sequence_dispatcher_id(dialog_id, MessageContentType::Photo);
auto queue_id = ChainId(dialog_id, MessageContentType::Photo).get();
CHECK(queue_id & 1);
auto queue_it = yet_unsent_media_queues_.find(queue_id);
@ -34115,7 +34102,7 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
if (G()->parameters().use_file_db && message_id.is_yet_unsent() && !message->via_bot_user_id.is_valid() &&
!message->hide_via_bot && !message->is_copy) {
auto queue_id = get_sequence_dispatcher_id(dialog_id, message_content_type);
auto queue_id = ChainId(dialog_id, message_content_type).get();
if (queue_id & 1) {
LOG(INFO) << "Add " << message_id << " from " << source << " to queue " << queue_id;
yet_unsent_media_queues_[queue_id][message_id]; // reserve place for promise
@ -36847,22 +36834,6 @@ void MessagesManager::update_list_last_dialog_date(DialogList &list) {
}
}
uint64 MessagesManager::get_sequence_dispatcher_id(DialogId dialog_id, MessageContentType message_content_type) {
switch (message_content_type) {
case MessageContentType::Animation:
case MessageContentType::Audio:
case MessageContentType::Document:
case MessageContentType::Photo:
case MessageContentType::Sticker:
case MessageContentType::Video:
case MessageContentType::VideoNote:
case MessageContentType::VoiceNote:
return static_cast<uint64>(dialog_id.get() * 2 + 1);
default:
return static_cast<uint64>(dialog_id.get() * 2 + 2);
}
}
MessagesManager::Dialog *MessagesManager::get_dialog(DialogId dialog_id) {
auto it = dialogs_.find(dialog_id);
return it == dialogs_.end() ? nullptr : it->second.get();

View File

@ -973,8 +973,6 @@ class MessagesManager final : public Actor {
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
static uint64 get_sequence_dispatcher_id(DialogId dialog_id, MessageContentType message_content_type);
private:
class PendingPtsUpdate {
public:

View File

@ -8,6 +8,7 @@
#include "td/telegram/AccessRights.h"
#include "td/telegram/AuthManager.h"
#include "td/telegram/ChainId.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/Dependencies.h"
#include "td/telegram/DialogId.h"
@ -144,7 +145,8 @@ class SendVoteQuery final : public Td::ResultHandler {
explicit SendVoteQuery(Promise<tl_object_ptr<telegram_api::Updates>> &&promise) : promise_(std::move(promise)) {
}
void send(FullMessageId full_message_id, vector<BufferSlice> &&options, uint64 generation, NetQueryRef *query_ref) {
void send(FullMessageId full_message_id, vector<BufferSlice> &&options, PollId poll_id, uint64 generation,
NetQueryRef *query_ref) {
dialog_id_ = full_message_id.get_dialog_id();
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id_, AccessRights::Read);
if (input_peer == nullptr) {
@ -153,9 +155,8 @@ class SendVoteQuery final : public Td::ResultHandler {
}
auto message_id = full_message_id.get_message_id().get_server_message_id().get();
auto sequence_id = static_cast<uint64>(-1);
auto query = G()->net_query_creator().create(
telegram_api::messages_sendVote(std::move(input_peer), message_id, std::move(options)), {sequence_id});
telegram_api::messages_sendVote(std::move(input_peer), message_id, std::move(options)), {{poll_id}});
*query_ref = query.get_weak();
send_query(std::move(query));
}
@ -185,7 +186,7 @@ class StopPollQuery final : public Td::ResultHandler {
explicit StopPollQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(FullMessageId full_message_id, unique_ptr<ReplyMarkup> &&reply_markup) {
void send(FullMessageId full_message_id, unique_ptr<ReplyMarkup> &&reply_markup, PollId poll_id) {
dialog_id_ = full_message_id.get_dialog_id();
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id_, AccessRights::Edit);
if (input_peer == nullptr) {
@ -204,14 +205,11 @@ class StopPollQuery final : public Td::ResultHandler {
poll->flags_ |= telegram_api::poll::CLOSED_MASK;
auto input_media = telegram_api::make_object<telegram_api::inputMediaPoll>(0, std::move(poll),
vector<BufferSlice>(), string(), Auto());
auto query = G()->net_query_creator().create(telegram_api::messages_editMessage(
flags, false /*ignored*/, std::move(input_peer), message_id, string(), std::move(input_media),
std::move(input_reply_markup), vector<tl_object_ptr<telegram_api::MessageEntity>>(), 0));
if (!td_->auth_manager_->is_bot()) {
auto sequence_id = static_cast<uint64>(-1);
query->set_chain_ids({sequence_id});
}
send_query(std::move(query));
send_query(G()->net_query_creator().create(
telegram_api::messages_editMessage(flags, false /*ignored*/, std::move(input_peer), message_id, string(),
std::move(input_media), std::move(input_reply_markup),
vector<tl_object_ptr<telegram_api::MessageEntity>>(), 0),
{{poll_id}}));
}
void on_result(BufferSlice packet) final {
@ -818,7 +816,7 @@ void PollManager::do_set_poll_answer(PollId poll_id, FullMessageId full_message_
send_closure(actor_id, &PollManager::on_set_poll_answer, poll_id, generation, std::move(result));
});
td_->create_handler<SendVoteQuery>(std::move(query_promise))
->send(full_message_id, std::move(sent_options), generation, &pending_answer.query_ref_);
->send(full_message_id, std::move(sent_options), poll_id, generation, &pending_answer.query_ref_);
}
void PollManager::on_set_poll_answer(PollId poll_id, uint64 generation,
@ -1130,7 +1128,7 @@ void PollManager::do_stop_poll(PollId poll_id, FullMessageId full_message_id, un
CHECK(is_inserted);
auto new_promise = get_erase_log_event_promise(log_event_id, std::move(promise));
td_->create_handler<StopPollQuery>(std::move(new_promise))->send(full_message_id, std::move(reply_markup));
td_->create_handler<StopPollQuery>(std::move(new_promise))->send(full_message_id, std::move(reply_markup), poll_id);
}
void PollManager::stop_local_poll(PollId poll_id) {

View File

@ -6,9 +6,11 @@
//
#include "td/telegram/net/NetQuery.h"
#include "td/telegram/ChainId.h"
#include "td/telegram/Global.h"
#include "td/telegram/telegram_api.h"
#include "td/utils/algorithm.h"
#include "td/utils/as.h"
#include "td/utils/misc.h"
#include "td/utils/SliceBuilder.h"
@ -21,6 +23,11 @@ int64 NetQuery::get_my_id() {
return G()->get_my_id();
}
void NetQuery::set_chain_ids(vector<ChainId> &&chain_ids) {
chain_ids_ = transform(chain_ids, [](ChainId chain_id) { return chain_id.get(); });
td::unique(chain_ids_);
}
void NetQuery::on_net_write(size_t size) {
if (file_type_ == -1) {
return;

View File

@ -34,6 +34,8 @@ namespace td {
extern int VERBOSITY_NAME(net_query);
class ChainId;
class NetQuery;
using NetQueryPtr = ObjectPool<NetQuery>::OwnerPtr;
using NetQueryRef = ObjectPool<NetQuery>::WeakPtr;
@ -279,9 +281,7 @@ class NetQuery final : public TsListNode<NetQueryDebug> {
Span<uint64> get_chain_ids() const {
return chain_ids_;
}
void set_chain_ids(vector<uint64> &&chain_ids) {
chain_ids_ = std::move(chain_ids);
}
void set_chain_ids(vector<ChainId> &&chain_ids);
void set_in_sequence_dispatcher(bool in_sequence_dispacher) {
in_sequence_dispacher_ = in_sequence_dispacher;

View File

@ -25,12 +25,12 @@ NetQueryCreator::NetQueryCreator(std::shared_ptr<NetQueryStats> net_query_stats)
object_pool_.set_check_empty(true);
}
NetQueryPtr NetQueryCreator::create(const telegram_api::Function &function, vector<uint64> chain_ids, DcId dc_id,
NetQueryPtr NetQueryCreator::create(const telegram_api::Function &function, vector<ChainId> chain_ids, DcId dc_id,
NetQuery::Type type) {
return create(UniqueId::next(), function, std::move(chain_ids), dc_id, type, NetQuery::AuthFlag::On);
}
NetQueryPtr NetQueryCreator::create(uint64 id, const telegram_api::Function &function, vector<uint64> &&chain_ids,
NetQueryPtr NetQueryCreator::create(uint64 id, const telegram_api::Function &function, vector<ChainId> &&chain_ids,
DcId dc_id, NetQuery::Type type, NetQuery::AuthFlag auth_flag) {
LOG(INFO) << "Create query " << to_string(function);
auto storer = DefaultStorer<telegram_api::Function>(function);

View File

@ -6,6 +6,7 @@
//
#pragma once
#include "td/telegram/ChainId.h"
#include "td/telegram/net/DcId.h"
#include "td/telegram/net/NetQuery.h"
#include "td/telegram/net/NetQueryStats.h"
@ -29,14 +30,14 @@ class NetQueryCreator {
object_pool_.set_check_empty(false);
}
NetQueryPtr create(const telegram_api::Function &function, vector<uint64> chain_ids = {}, DcId dc_id = DcId::main(),
NetQueryPtr create(const telegram_api::Function &function, vector<ChainId> chain_ids = {}, DcId dc_id = DcId::main(),
NetQuery::Type type = NetQuery::Type::Common);
NetQueryPtr create_unauth(const telegram_api::Function &function, DcId dc_id = DcId::main()) {
return create(UniqueId::next(), function, {}, dc_id, NetQuery::Type::Common, NetQuery::AuthFlag::Off);
}
NetQueryPtr create(uint64 id, const telegram_api::Function &function, vector<uint64> &&chain_ids, DcId dc_id,
NetQueryPtr create(uint64 id, const telegram_api::Function &function, vector<ChainId> &&chain_ids, DcId dc_id,
NetQuery::Type type, NetQuery::AuthFlag auth_flag);
private: