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/MessageReplyInfo.cpp
|
||||||
td/telegram/MessageSearchFilter.cpp
|
td/telegram/MessageSearchFilter.cpp
|
||||||
td/telegram/MessageSender.cpp
|
td/telegram/MessageSender.cpp
|
||||||
|
td/telegram/MessagesInfo.cpp
|
||||||
td/telegram/MessagesManager.cpp
|
td/telegram/MessagesManager.cpp
|
||||||
td/telegram/MessageThreadDb.cpp
|
td/telegram/MessageThreadDb.cpp
|
||||||
td/telegram/MessageTtl.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
|
#pragma once
|
||||||
|
|
||||||
|
#include "td/telegram/DialogId.h"
|
||||||
#include "td/telegram/telegram_api.h"
|
#include "td/telegram/telegram_api.h"
|
||||||
|
|
||||||
#include "td/utils/common.h"
|
#include "td/utils/common.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
|
class Td;
|
||||||
|
|
||||||
struct MessagesInfo {
|
struct MessagesInfo {
|
||||||
vector<telegram_api::object_ptr<telegram_api::Message>> messages;
|
vector<telegram_api::object_ptr<telegram_api::Message>> messages;
|
||||||
int32 total_count = 0;
|
int32 total_count = 0;
|
||||||
bool is_channel_messages = false;
|
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
|
} // namespace td
|
||||||
|
@ -469,7 +469,7 @@ class GetMessagesQuery final : public Td::ResultHandler {
|
|||||||
return on_error(result_ptr.move_as_error());
|
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";
|
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,
|
td_->messages_manager_->on_get_messages(std::move(info.messages), info.is_channel_messages, false,
|
||||||
std::move(promise_), "GetMessagesQuery");
|
std::move(promise_), "GetMessagesQuery");
|
||||||
@ -510,8 +510,7 @@ class GetChannelMessagesQuery final : public Td::ResultHandler {
|
|||||||
return on_error(result_ptr.move_as_error());
|
return on_error(result_ptr.move_as_error());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto info = td_->messages_manager_->get_messages_info(DialogId(channel_id_), result_ptr.move_as_ok(),
|
auto info = get_messages_info(td_, DialogId(channel_id_), result_ptr.move_as_ok(), "GetChannelMessagesQuery");
|
||||||
"GetChannelMessagesQuery");
|
|
||||||
LOG_IF(ERROR, !info.is_channel_messages) << "Receive ordinary messages in GetChannelMessagesQuery";
|
LOG_IF(ERROR, !info.is_channel_messages) << "Receive ordinary messages in GetChannelMessagesQuery";
|
||||||
// messages with invalid big identifiers can be received as messageEmpty
|
// messages with invalid big identifiers can be received as messageEmpty
|
||||||
// bots can receive messageEmpty because of their privacy mode
|
// 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());
|
return on_error(result_ptr.move_as_error());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto info =
|
auto info = get_messages_info(td_, dialog_id_, result_ptr.move_as_ok(), "GetScheduledMessagesQuery");
|
||||||
td_->messages_manager_->get_messages_info(dialog_id_, result_ptr.move_as_ok(), "GetScheduledMessagesQuery");
|
|
||||||
LOG_IF(ERROR, info.is_channel_messages != (dialog_id_.get_type() == DialogType::Channel))
|
LOG_IF(ERROR, info.is_channel_messages != (dialog_id_.get_type() == DialogType::Channel))
|
||||||
<< "Receive wrong messages constructor in GetScheduledMessagesQuery";
|
<< "Receive wrong messages constructor in GetScheduledMessagesQuery";
|
||||||
td_->messages_manager_->on_get_messages(std::move(info.messages), info.is_channel_messages, true,
|
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());
|
return on_error(result_ptr.move_as_error());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto info =
|
auto info = get_messages_info(td_, dialog_id_, result_ptr.move_as_ok(), "GetDialogMessageByDateQuery");
|
||||||
td_->messages_manager_->get_messages_info(dialog_id_, result_ptr.move_as_ok(), "GetDialogMessageByDateQuery");
|
|
||||||
td_->messages_manager_->get_channel_difference_if_needed(
|
td_->messages_manager_->get_channel_difference_if_needed(
|
||||||
dialog_id_, std::move(info),
|
dialog_id_, std::move(info),
|
||||||
PromiseCreator::lambda([actor_id = td_->messages_manager_actor_.get(), dialog_id = dialog_id_, date = date_,
|
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());
|
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(
|
td_->messages_manager_->get_channel_difference_if_needed(
|
||||||
dialog_id_, std::move(info),
|
dialog_id_, std::move(info),
|
||||||
PromiseCreator::lambda([actor_id = td_->messages_manager_actor_.get(), dialog_id = dialog_id_,
|
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());
|
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(
|
td_->messages_manager_->get_channel_difference_if_needed(
|
||||||
dialog_id_, std::move(info),
|
dialog_id_, std::move(info),
|
||||||
PromiseCreator::lambda([actor_id = td_->messages_manager_actor_.get(), dialog_id = dialog_id_,
|
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());
|
return on_error(result_ptr.move_as_error());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto info =
|
auto info = get_messages_info(td_, DialogId(), result_ptr.move_as_ok(), "SearchMessagesGlobalQuery");
|
||||||
td_->messages_manager_->get_messages_info(DialogId(), result_ptr.move_as_ok(), "SearchMessagesGlobalQuery");
|
|
||||||
td_->messages_manager_->get_channel_differences_if_needed(
|
td_->messages_manager_->get_channel_differences_if_needed(
|
||||||
std::move(info),
|
std::move(info),
|
||||||
PromiseCreator::lambda([actor_id = td_->messages_manager_actor_.get(), query = std::move(query_),
|
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) {
|
if (result_ptr.ok()->get_id() == telegram_api::messages_messagesNotModified::ID) {
|
||||||
td_->messages_manager_->on_get_scheduled_server_messages(dialog_id_, generation_, Auto(), true);
|
td_->messages_manager_->on_get_scheduled_server_messages(dialog_id_, generation_, Auto(), true);
|
||||||
} else {
|
} else {
|
||||||
auto info = td_->messages_manager_->get_messages_info(dialog_id_, result_ptr.move_as_ok(),
|
auto info = get_messages_info(td_, dialog_id_, result_ptr.move_as_ok(), "GetAllScheduledMessagesQuery");
|
||||||
"GetAllScheduledMessagesQuery");
|
|
||||||
td_->messages_manager_->on_get_scheduled_server_messages(dialog_id_, generation_, std::move(info.messages),
|
td_->messages_manager_->on_get_scheduled_server_messages(dialog_id_, generation_, std::move(info.messages),
|
||||||
false);
|
false);
|
||||||
}
|
}
|
||||||
@ -2836,7 +2831,7 @@ class SearchSentMediaQuery final : public Td::ResultHandler {
|
|||||||
return on_error(result_ptr.move_as_error());
|
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(
|
td_->messages_manager_->get_channel_differences_if_needed(
|
||||||
std::move(info), PromiseCreator::lambda([actor_id = td_->messages_manager_actor_.get(),
|
std::move(info), PromiseCreator::lambda([actor_id = td_->messages_manager_actor_.get(),
|
||||||
promise = std::move(promise_)](Result<MessagesInfo> &&result) mutable {
|
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());
|
return on_error(result_ptr.move_as_error());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto info =
|
auto info = get_messages_info(td_, dialog_id_, result_ptr.move_as_ok(), "GetRecentLocationsQuery");
|
||||||
td_->messages_manager_->get_messages_info(dialog_id_, result_ptr.move_as_ok(), "GetRecentLocationsQuery");
|
|
||||||
td_->messages_manager_->get_channel_difference_if_needed(
|
td_->messages_manager_->get_channel_difference_if_needed(
|
||||||
dialog_id_, std::move(info),
|
dialog_id_, std::move(info),
|
||||||
PromiseCreator::lambda([actor_id = td_->messages_manager_actor_.get(), dialog_id = dialog_id_, limit = limit_,
|
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());
|
return on_error(result_ptr.move_as_error());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto info =
|
auto info = get_messages_info(td_, DialogId(), result_ptr.move_as_ok(), "GetMessagePublicForwardsQuery");
|
||||||
td_->messages_manager_->get_messages_info(DialogId(), result_ptr.move_as_ok(), "GetMessagePublicForwardsQuery");
|
|
||||||
td_->messages_manager_->get_channel_differences_if_needed(
|
td_->messages_manager_->get_channel_differences_if_needed(
|
||||||
std::move(info), PromiseCreator::lambda([actor_id = td_->messages_manager_actor_.get(),
|
std::move(info), PromiseCreator::lambda([actor_id = td_->messages_manager_actor_.get(),
|
||||||
promise = std::move(promise_)](Result<MessagesInfo> &&result) mutable {
|
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,
|
void MessagesManager::get_channel_difference_if_needed(DialogId dialog_id, MessagesInfo &&messages_info,
|
||||||
Promise<MessagesInfo> &&promise) {
|
Promise<MessagesInfo> &&promise) {
|
||||||
if (!dialog_id.is_valid()) {
|
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);
|
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,
|
void get_channel_difference_if_needed(DialogId dialog_id, MessagesInfo &&messages_info,
|
||||||
Promise<MessagesInfo> &&promise);
|
Promise<MessagesInfo> &&promise);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user