Move get_messages_info to MessagesInfo.cpp.
This commit is contained in:
parent
75453b542f
commit
a32bb3e7ef
@ -387,6 +387,7 @@ set(TDLIB_SOURCE
|
||||
td/telegram/MessageReplyInfo.cpp
|
||||
td/telegram/MessageSearchFilter.cpp
|
||||
td/telegram/MessageSender.cpp
|
||||
td/telegram/MessagesInfo.cpp
|
||||
td/telegram/MessagesManager.cpp
|
||||
td/telegram/MessageThreadDb.cpp
|
||||
td/telegram/MessageTtl.cpp
|
||||
|
73
td/telegram/MessagesInfo.cpp
Normal file
73
td/telegram/MessagesInfo.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
#include "td/telegram/MessagesInfo.h"
|
||||
|
||||
#include "td/telegram/ContactsManager.h"
|
||||
#include "td/telegram/ForumTopicManager.h"
|
||||
#include "td/telegram/Td.h"
|
||||
|
||||
#include "td/utils/logging.h"
|
||||
#include "td/utils/misc.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
MessagesInfo get_messages_info(Td *td, DialogId dialog_id,
|
||||
telegram_api::object_ptr<telegram_api::messages_Messages> &&messages_ptr,
|
||||
const char *source) {
|
||||
CHECK(messages_ptr != nullptr);
|
||||
LOG(DEBUG) << "Receive result for " << source << ": " << to_string(messages_ptr);
|
||||
|
||||
vector<tl_object_ptr<telegram_api::User>> users;
|
||||
vector<tl_object_ptr<telegram_api::Chat>> chats;
|
||||
vector<tl_object_ptr<telegram_api::ForumTopic>> topics;
|
||||
MessagesInfo result;
|
||||
switch (messages_ptr->get_id()) {
|
||||
case telegram_api::messages_messages::ID: {
|
||||
auto messages = move_tl_object_as<telegram_api::messages_messages>(messages_ptr);
|
||||
|
||||
users = std::move(messages->users_);
|
||||
chats = std::move(messages->chats_);
|
||||
result.total_count = narrow_cast<int32>(messages->messages_.size());
|
||||
result.messages = std::move(messages->messages_);
|
||||
break;
|
||||
}
|
||||
case telegram_api::messages_messagesSlice::ID: {
|
||||
auto messages = move_tl_object_as<telegram_api::messages_messagesSlice>(messages_ptr);
|
||||
|
||||
users = std::move(messages->users_);
|
||||
chats = std::move(messages->chats_);
|
||||
result.total_count = messages->count_;
|
||||
result.messages = std::move(messages->messages_);
|
||||
break;
|
||||
}
|
||||
case telegram_api::messages_channelMessages::ID: {
|
||||
auto messages = move_tl_object_as<telegram_api::messages_channelMessages>(messages_ptr);
|
||||
|
||||
users = std::move(messages->users_);
|
||||
chats = std::move(messages->chats_);
|
||||
topics = std::move(messages->topics_);
|
||||
result.total_count = messages->count_;
|
||||
result.messages = std::move(messages->messages_);
|
||||
result.is_channel_messages = true;
|
||||
break;
|
||||
}
|
||||
case telegram_api::messages_messagesNotModified::ID:
|
||||
LOG(ERROR) << "Server returned messagesNotModified in response to " << source;
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
break;
|
||||
}
|
||||
|
||||
td->contacts_manager_->on_get_users(std::move(users), source);
|
||||
td->contacts_manager_->on_get_chats(std::move(chats), source);
|
||||
td->forum_topic_manager_->on_get_forum_topic_infos(dialog_id, std::move(topics), source);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace td
|
@ -6,16 +6,23 @@
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "td/telegram/DialogId.h"
|
||||
#include "td/telegram/telegram_api.h"
|
||||
|
||||
#include "td/utils/common.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
class Td;
|
||||
|
||||
struct MessagesInfo {
|
||||
vector<telegram_api::object_ptr<telegram_api::Message>> messages;
|
||||
int32 total_count = 0;
|
||||
bool is_channel_messages = false;
|
||||
};
|
||||
|
||||
MessagesInfo get_messages_info(Td *td, DialogId dialog_id,
|
||||
telegram_api::object_ptr<telegram_api::messages_Messages> &&messages_ptr,
|
||||
const char *source);
|
||||
|
||||
} // namespace td
|
||||
|
@ -469,7 +469,7 @@ class GetMessagesQuery final : public Td::ResultHandler {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto info = td_->messages_manager_->get_messages_info(DialogId(), result_ptr.move_as_ok(), "GetMessagesQuery");
|
||||
auto info = get_messages_info(td_, DialogId(), result_ptr.move_as_ok(), "GetMessagesQuery");
|
||||
LOG_IF(ERROR, info.is_channel_messages) << "Receive channel messages in GetMessagesQuery";
|
||||
td_->messages_manager_->on_get_messages(std::move(info.messages), info.is_channel_messages, false,
|
||||
std::move(promise_), "GetMessagesQuery");
|
||||
@ -510,8 +510,7 @@ class GetChannelMessagesQuery final : public Td::ResultHandler {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto info = td_->messages_manager_->get_messages_info(DialogId(channel_id_), result_ptr.move_as_ok(),
|
||||
"GetChannelMessagesQuery");
|
||||
auto info = get_messages_info(td_, DialogId(channel_id_), result_ptr.move_as_ok(), "GetChannelMessagesQuery");
|
||||
LOG_IF(ERROR, !info.is_channel_messages) << "Receive ordinary messages in GetChannelMessagesQuery";
|
||||
// messages with invalid big identifiers can be received as messageEmpty
|
||||
// bots can receive messageEmpty because of their privacy mode
|
||||
@ -573,8 +572,7 @@ class GetScheduledMessagesQuery final : public Td::ResultHandler {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto info =
|
||||
td_->messages_manager_->get_messages_info(dialog_id_, result_ptr.move_as_ok(), "GetScheduledMessagesQuery");
|
||||
auto info = get_messages_info(td_, dialog_id_, result_ptr.move_as_ok(), "GetScheduledMessagesQuery");
|
||||
LOG_IF(ERROR, info.is_channel_messages != (dialog_id_.get_type() == DialogType::Channel))
|
||||
<< "Receive wrong messages constructor in GetScheduledMessagesQuery";
|
||||
td_->messages_manager_->on_get_messages(std::move(info.messages), info.is_channel_messages, true,
|
||||
@ -2116,8 +2114,7 @@ class GetDialogMessageByDateQuery final : public Td::ResultHandler {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto info =
|
||||
td_->messages_manager_->get_messages_info(dialog_id_, result_ptr.move_as_ok(), "GetDialogMessageByDateQuery");
|
||||
auto info = get_messages_info(td_, dialog_id_, result_ptr.move_as_ok(), "GetDialogMessageByDateQuery");
|
||||
td_->messages_manager_->get_channel_difference_if_needed(
|
||||
dialog_id_, std::move(info),
|
||||
PromiseCreator::lambda([actor_id = td_->messages_manager_actor_.get(), dialog_id = dialog_id_, date = date_,
|
||||
@ -2194,7 +2191,7 @@ class GetHistoryQuery final : public Td::ResultHandler {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto info = td_->messages_manager_->get_messages_info(dialog_id_, result_ptr.move_as_ok(), "GetHistoryQuery");
|
||||
auto info = get_messages_info(td_, dialog_id_, result_ptr.move_as_ok(), "GetHistoryQuery");
|
||||
td_->messages_manager_->get_channel_difference_if_needed(
|
||||
dialog_id_, std::move(info),
|
||||
PromiseCreator::lambda([actor_id = td_->messages_manager_actor_.get(), dialog_id = dialog_id_,
|
||||
@ -2581,7 +2578,7 @@ class SearchMessagesQuery final : public Td::ResultHandler {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto info = td_->messages_manager_->get_messages_info(dialog_id_, result_ptr.move_as_ok(), "SearchMessagesQuery");
|
||||
auto info = get_messages_info(td_, dialog_id_, result_ptr.move_as_ok(), "SearchMessagesQuery");
|
||||
td_->messages_manager_->get_channel_difference_if_needed(
|
||||
dialog_id_, std::move(info),
|
||||
PromiseCreator::lambda([actor_id = td_->messages_manager_actor_.get(), dialog_id = dialog_id_,
|
||||
@ -2747,8 +2744,7 @@ class SearchMessagesGlobalQuery final : public Td::ResultHandler {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto info =
|
||||
td_->messages_manager_->get_messages_info(DialogId(), result_ptr.move_as_ok(), "SearchMessagesGlobalQuery");
|
||||
auto info = get_messages_info(td_, DialogId(), result_ptr.move_as_ok(), "SearchMessagesGlobalQuery");
|
||||
td_->messages_manager_->get_channel_differences_if_needed(
|
||||
std::move(info),
|
||||
PromiseCreator::lambda([actor_id = td_->messages_manager_actor_.get(), query = std::move(query_),
|
||||
@ -2802,8 +2798,7 @@ class GetAllScheduledMessagesQuery final : public Td::ResultHandler {
|
||||
if (result_ptr.ok()->get_id() == telegram_api::messages_messagesNotModified::ID) {
|
||||
td_->messages_manager_->on_get_scheduled_server_messages(dialog_id_, generation_, Auto(), true);
|
||||
} else {
|
||||
auto info = td_->messages_manager_->get_messages_info(dialog_id_, result_ptr.move_as_ok(),
|
||||
"GetAllScheduledMessagesQuery");
|
||||
auto info = get_messages_info(td_, dialog_id_, result_ptr.move_as_ok(), "GetAllScheduledMessagesQuery");
|
||||
td_->messages_manager_->on_get_scheduled_server_messages(dialog_id_, generation_, std::move(info.messages),
|
||||
false);
|
||||
}
|
||||
@ -2836,7 +2831,7 @@ class SearchSentMediaQuery final : public Td::ResultHandler {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto info = td_->messages_manager_->get_messages_info(DialogId(), result_ptr.move_as_ok(), "SearchSentMediaQuery");
|
||||
auto info = get_messages_info(td_, DialogId(), result_ptr.move_as_ok(), "SearchSentMediaQuery");
|
||||
td_->messages_manager_->get_channel_differences_if_needed(
|
||||
std::move(info), PromiseCreator::lambda([actor_id = td_->messages_manager_actor_.get(),
|
||||
promise = std::move(promise_)](Result<MessagesInfo> &&result) mutable {
|
||||
@ -2884,8 +2879,7 @@ class GetRecentLocationsQuery final : public Td::ResultHandler {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto info =
|
||||
td_->messages_manager_->get_messages_info(dialog_id_, result_ptr.move_as_ok(), "GetRecentLocationsQuery");
|
||||
auto info = get_messages_info(td_, dialog_id_, result_ptr.move_as_ok(), "GetRecentLocationsQuery");
|
||||
td_->messages_manager_->get_channel_difference_if_needed(
|
||||
dialog_id_, std::move(info),
|
||||
PromiseCreator::lambda([actor_id = td_->messages_manager_actor_.get(), dialog_id = dialog_id_, limit = limit_,
|
||||
@ -2938,8 +2932,7 @@ class GetMessagePublicForwardsQuery final : public Td::ResultHandler {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto info =
|
||||
td_->messages_manager_->get_messages_info(DialogId(), result_ptr.move_as_ok(), "GetMessagePublicForwardsQuery");
|
||||
auto info = get_messages_info(td_, DialogId(), result_ptr.move_as_ok(), "GetMessagePublicForwardsQuery");
|
||||
td_->messages_manager_->get_channel_differences_if_needed(
|
||||
std::move(info), PromiseCreator::lambda([actor_id = td_->messages_manager_actor_.get(),
|
||||
promise = std::move(promise_)](Result<MessagesInfo> &&result) mutable {
|
||||
@ -9798,61 +9791,6 @@ void MessagesManager::on_get_empty_messages(DialogId dialog_id, const vector<Mes
|
||||
}
|
||||
}
|
||||
|
||||
MessagesInfo MessagesManager::get_messages_info(DialogId dialog_id,
|
||||
tl_object_ptr<telegram_api::messages_Messages> &&messages_ptr,
|
||||
const char *source) {
|
||||
CHECK(messages_ptr != nullptr);
|
||||
LOG(DEBUG) << "Receive result for " << source << ": " << to_string(messages_ptr);
|
||||
|
||||
vector<tl_object_ptr<telegram_api::User>> users;
|
||||
vector<tl_object_ptr<telegram_api::Chat>> chats;
|
||||
vector<tl_object_ptr<telegram_api::ForumTopic>> topics;
|
||||
MessagesInfo result;
|
||||
switch (messages_ptr->get_id()) {
|
||||
case telegram_api::messages_messages::ID: {
|
||||
auto messages = move_tl_object_as<telegram_api::messages_messages>(messages_ptr);
|
||||
|
||||
users = std::move(messages->users_);
|
||||
chats = std::move(messages->chats_);
|
||||
result.total_count = narrow_cast<int32>(messages->messages_.size());
|
||||
result.messages = std::move(messages->messages_);
|
||||
break;
|
||||
}
|
||||
case telegram_api::messages_messagesSlice::ID: {
|
||||
auto messages = move_tl_object_as<telegram_api::messages_messagesSlice>(messages_ptr);
|
||||
|
||||
users = std::move(messages->users_);
|
||||
chats = std::move(messages->chats_);
|
||||
result.total_count = messages->count_;
|
||||
result.messages = std::move(messages->messages_);
|
||||
break;
|
||||
}
|
||||
case telegram_api::messages_channelMessages::ID: {
|
||||
auto messages = move_tl_object_as<telegram_api::messages_channelMessages>(messages_ptr);
|
||||
|
||||
users = std::move(messages->users_);
|
||||
chats = std::move(messages->chats_);
|
||||
topics = std::move(messages->topics_);
|
||||
result.total_count = messages->count_;
|
||||
result.messages = std::move(messages->messages_);
|
||||
result.is_channel_messages = true;
|
||||
break;
|
||||
}
|
||||
case telegram_api::messages_messagesNotModified::ID:
|
||||
LOG(ERROR) << "Server returned messagesNotModified in response to " << source;
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
break;
|
||||
}
|
||||
|
||||
td_->contacts_manager_->on_get_users(std::move(users), source);
|
||||
td_->contacts_manager_->on_get_chats(std::move(chats), source);
|
||||
td_->forum_topic_manager_->on_get_forum_topic_infos(dialog_id, std::move(topics), source);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void MessagesManager::get_channel_difference_if_needed(DialogId dialog_id, MessagesInfo &&messages_info,
|
||||
Promise<MessagesInfo> &&promise) {
|
||||
if (!dialog_id.is_valid()) {
|
||||
|
@ -196,9 +196,6 @@ class MessagesManager final : public Actor {
|
||||
|
||||
void on_get_empty_messages(DialogId dialog_id, const vector<MessageId> &empty_message_ids);
|
||||
|
||||
MessagesInfo get_messages_info(DialogId dialog_id, tl_object_ptr<telegram_api::messages_Messages> &&messages_ptr,
|
||||
const char *source);
|
||||
|
||||
void get_channel_difference_if_needed(DialogId dialog_id, MessagesInfo &&messages_info,
|
||||
Promise<MessagesInfo> &&promise);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user