Move get_message_sender_object to MessageSender.cpp.

This commit is contained in:
levlam 2021-11-15 01:18:47 +03:00
parent e52508bdc1
commit a56c34c4dd
12 changed files with 116 additions and 83 deletions

View File

@ -357,6 +357,7 @@ set(TDLIB_SOURCE
td/telegram/MessageReplyInfo.cpp
td/telegram/MessagesDb.cpp
td/telegram/MessageSearchFilter.cpp
td/telegram/MessageSender.cpp
td/telegram/MessagesManager.cpp
td/telegram/MessageTtlSetting.cpp
td/telegram/misc.cpp
@ -558,6 +559,7 @@ set(TDLIB_SOURCE
td/telegram/MessageThreadInfo.h
td/telegram/MessagesDb.h
td/telegram/MessageSearchFilter.h
td/telegram/MessageSender.h
td/telegram/MessagesManager.h
td/telegram/MessageTtlSetting.h
td/telegram/misc.h

View File

@ -24,6 +24,7 @@
#include "td/telegram/LinkManager.h"
#include "td/telegram/logevent/LogEvent.h"
#include "td/telegram/logevent/LogEventHelper.h"
#include "td/telegram/MessageSender.h"
#include "td/telegram/MessagesManager.h"
#include "td/telegram/MessageTtlSetting.h"
#include "td/telegram/misc.h"
@ -11833,7 +11834,7 @@ tl_object_ptr<td_api::chatMember> ContactsManager::get_chat_member_object(
td_->messages_manager_->force_create_dialog(dialog_id, "get_chat_member_object", true);
}
return td_api::make_object<td_api::chatMember>(
td_->messages_manager_->get_message_sender_object_const(dialog_id, "get_chat_member_object"),
get_message_sender_object_const(td_, dialog_id, "get_chat_member_object"),
get_user_id_object(dialog_participant.inviter_user_id_, "chatMember.inviter_user_id"),
dialog_participant.joined_date_, dialog_participant.status_.get_chat_member_status_object());
}

View File

@ -15,6 +15,7 @@
#include "td/telegram/GroupCallManager.h"
#include "td/telegram/GroupCallParticipant.h"
#include "td/telegram/InputGroupCallId.h"
#include "td/telegram/MessageSender.h"
#include "td/telegram/MessagesManager.h"
#include "td/telegram/MessageTtlSetting.h"
#include "td/telegram/StickersManager.h"
@ -86,8 +87,7 @@ static td_api::object_ptr<td_api::ChatEventAction> get_chat_event_action_object(
return nullptr;
}
return td_api::make_object<td_api::chatEventMemberRestricted>(
td->messages_manager_->get_message_sender_object(old_dialog_participant.dialog_id_,
"chatEventMemberRestricted"),
get_message_sender_object(td, old_dialog_participant.dialog_id_, "chatEventMemberRestricted"),
old_dialog_participant.status_.get_chat_member_status_object(),
new_dialog_participant.status_.get_chat_member_status_object());
}
@ -294,9 +294,7 @@ static td_api::object_ptr<td_api::ChatEventAction> get_chat_event_action_object(
return nullptr;
}
return td_api::make_object<td_api::chatEventVideoChatParticipantIsMutedToggled>(
td->messages_manager_->get_message_sender_object(participant.dialog_id,
"chatEventVideoChatParticipantIsMutedToggled"),
true);
get_message_sender_object(td, participant.dialog_id, "chatEventVideoChatParticipantIsMutedToggled"), true);
}
case telegram_api::channelAdminLogEventActionParticipantUnmute::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionParticipantUnmute>(action_ptr);
@ -305,9 +303,7 @@ static td_api::object_ptr<td_api::ChatEventAction> get_chat_event_action_object(
return nullptr;
}
return td_api::make_object<td_api::chatEventVideoChatParticipantIsMutedToggled>(
td->messages_manager_->get_message_sender_object(participant.dialog_id,
"chatEventVideoChatParticipantIsMutedToggled"),
false);
get_message_sender_object(td, participant.dialog_id, "chatEventVideoChatParticipantIsMutedToggled"), false);
}
case telegram_api::channelAdminLogEventActionParticipantVolume::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionParticipantVolume>(action_ptr);
@ -316,8 +312,7 @@ static td_api::object_ptr<td_api::ChatEventAction> get_chat_event_action_object(
return nullptr;
}
return td_api::make_object<td_api::chatEventVideoChatParticipantVolumeLevelChanged>(
td->messages_manager_->get_message_sender_object(participant.dialog_id,
"chatEventVideoChatParticipantVolumeLevelChanged"),
get_message_sender_object(td, participant.dialog_id, "chatEventVideoChatParticipantVolumeLevelChanged"),
participant.volume_level);
}
case telegram_api::channelAdminLogEventActionToggleGroupCallSetting::ID: {

View File

@ -12,6 +12,7 @@
#include "td/telegram/DialogAction.h"
#include "td/telegram/Global.h"
#include "td/telegram/MessageId.h"
#include "td/telegram/MessageSender.h"
#include "td/telegram/MessagesManager.h"
#include "td/telegram/misc.h"
#include "td/telegram/net/DcId.h"
@ -113,8 +114,7 @@ class GetGroupCallJoinAsQuery final : public Td::ResultHandler {
td_->messages_manager_->force_create_dialog(dialog_id, "GetGroupCallJoinAsQuery");
}
participant_aliaces.push_back(
td_->messages_manager_->get_message_sender_object(dialog_id, "GetGroupCallJoinAsQuery"));
participant_aliaces.push_back(get_message_sender_object(td_, dialog_id, "GetGroupCallJoinAsQuery"));
}
promise_.set_value(td_api::make_object<td_api::messageSenders>(static_cast<int32>(participant_aliaces.size()),
@ -4647,11 +4647,10 @@ vector<td_api::object_ptr<td_api::groupCallRecentSpeaker>> GroupCallManager::get
recent_speaker_update_timeout_.add_timeout_in(group_call->group_call_id.get(), next_timeout);
}
auto get_result = [recent_speaker_users, messages_manager = td_->messages_manager_.get()] {
return transform(recent_speaker_users, [messages_manager](const std::pair<DialogId, bool> &recent_speaker_user) {
auto get_result = [recent_speaker_users, td = td_] {
return transform(recent_speaker_users, [td](const std::pair<DialogId, bool> &recent_speaker_user) {
return td_api::make_object<td_api::groupCallRecentSpeaker>(
messages_manager->get_message_sender_object(recent_speaker_user.first, "get_recent_speakers"),
recent_speaker_user.second);
get_message_sender_object(td, recent_speaker_user.first, "get_recent_speakers"), recent_speaker_user.second);
});
};
if (recent_speakers->last_sent_users != recent_speaker_users) {

View File

@ -7,7 +7,7 @@
#include "td/telegram/GroupCallParticipant.h"
#include "td/telegram/Global.h"
#include "td/telegram/MessagesManager.h"
#include "td/telegram/MessageSender.h"
#include "td/telegram/Td.h"
#include "td/utils/logging.h"
@ -266,7 +266,7 @@ td_api::object_ptr<td_api::groupCallParticipant> GroupCallParticipant::get_group
}
return td_api::make_object<td_api::groupCallParticipant>(
td->messages_manager_->get_message_sender_object(dialog_id, "get_group_call_participant_object"), audio_source,
get_message_sender_object(td, dialog_id, "get_group_call_participant_object"), audio_source,
presentation_audio_source, video_payload.get_group_call_participant_video_info_object(),
presentation_payload.get_group_call_participant_video_info_object(), about, is_self, is_speaking,
get_is_hand_raised(), can_be_muted_for_all_users, can_be_unmuted_for_all_users, can_be_muted_only_for_self,

View File

@ -39,6 +39,7 @@
#include "td/telegram/MessageEntity.hpp"
#include "td/telegram/MessageId.h"
#include "td/telegram/MessageSearchFilter.h"
#include "td/telegram/MessageSender.h"
#include "td/telegram/MessagesManager.h"
#include "td/telegram/misc.h"
#include "td/telegram/net/DcId.h"
@ -4994,9 +4995,8 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
case MessageContentType::ProximityAlertTriggered: {
const auto *m = static_cast<const MessageProximityAlertTriggered *>(content);
return make_tl_object<td_api::messageProximityAlertTriggered>(
td->messages_manager_->get_message_sender_object(m->traveler_dialog_id, "messageProximityAlertTriggered 1"),
td->messages_manager_->get_message_sender_object(m->watcher_dialog_id, "messageProximityAlertTriggered 2"),
m->distance);
get_message_sender_object(td, m->traveler_dialog_id, "messageProximityAlertTriggered 1"),
get_message_sender_object(td, m->watcher_dialog_id, "messageProximityAlertTriggered 2"), m->distance);
}
case MessageContentType::GroupCall: {
const auto *m = static_cast<const MessageGroupCall *>(content);

View File

@ -0,0 +1,57 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
//
// 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/MessageSender.h"
#include "td/telegram/AuthManager.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/MessagesManager.h"
#include "td/telegram/Td.h"
namespace td {
td_api::object_ptr<td_api::MessageSender> get_message_sender_object_const(Td *td, UserId user_id, DialogId dialog_id,
const char *source) {
if (dialog_id.is_valid() && td->messages_manager_->have_dialog(dialog_id)) {
return td_api::make_object<td_api::messageSenderChat>(dialog_id.get());
}
if (!user_id.is_valid()) {
// can happen only if the server sends a message with wrong sender
LOG(ERROR) << "Receive message with wrong sender " << user_id << '/' << dialog_id << " from " << source;
user_id = td->contacts_manager_->add_service_notifications_user();
}
return td_api::make_object<td_api::messageSenderUser>(td->contacts_manager_->get_user_id_object(user_id, source));
}
td_api::object_ptr<td_api::MessageSender> get_message_sender_object_const(Td *td, DialogId dialog_id,
const char *source) {
if (dialog_id.get_type() == DialogType::User) {
return get_message_sender_object_const(td, dialog_id.get_user_id(), DialogId(), source);
}
return get_message_sender_object_const(td, UserId(), dialog_id, source);
}
td_api::object_ptr<td_api::MessageSender> get_message_sender_object(Td *td, UserId user_id, DialogId dialog_id,
const char *source) {
if (dialog_id.is_valid() && !td->messages_manager_->have_dialog(dialog_id)) {
LOG(ERROR) << "Failed to find " << dialog_id;
td->messages_manager_->force_create_dialog(dialog_id, source);
}
if (!user_id.is_valid() && td->auth_manager_->is_bot()) {
td->contacts_manager_->add_anonymous_bot_user();
td->contacts_manager_->add_service_notifications_user();
}
return get_message_sender_object_const(td, user_id, dialog_id, source);
}
td_api::object_ptr<td_api::MessageSender> get_message_sender_object(Td *td, DialogId dialog_id, const char *source) {
if (dialog_id.get_type() == DialogType::User) {
return get_message_sender_object(td, dialog_id.get_user_id(), DialogId(), source);
}
return get_message_sender_object(td, UserId(), dialog_id, source);
}
} // namespace td

View File

@ -0,0 +1,30 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
//
// 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/td_api.h"
#include "td/telegram/UserId.h"
#include "td/utils/common.h"
namespace td {
class Td;
td_api::object_ptr<td_api::MessageSender> get_message_sender_object_const(Td *td, UserId user_id, DialogId dialog_id,
const char *source);
td_api::object_ptr<td_api::MessageSender> get_message_sender_object_const(Td *td, DialogId dialog_id,
const char *source);
td_api::object_ptr<td_api::MessageSender> get_message_sender_object(Td *td, UserId user_id, DialogId dialog_id,
const char *source);
td_api::object_ptr<td_api::MessageSender> get_message_sender_object(Td *td, DialogId dialog_id, const char *source);
} // namespace td

View File

@ -33,6 +33,7 @@
#include "td/telegram/MessageEntity.h"
#include "td/telegram/MessageEntity.hpp"
#include "td/telegram/MessagesDb.h"
#include "td/telegram/MessageSender.h"
#include "td/telegram/misc.h"
#include "td/telegram/net/DcId.h"
#include "td/telegram/net/NetActor.h"
@ -2184,7 +2185,7 @@ class GetSearchResultCalendarQuery final : public Td::ResultHandler {
}
void on_error(Status status) final {
td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "SearchMessagesQuery");
td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetSearchResultCalendarQuery");
td_->messages_manager_->on_failed_get_message_search_result_calendar(dialog_id_, random_id_);
promise_.set_error(std::move(status));
}
@ -5859,49 +5860,6 @@ void MessagesManager::on_preload_folder_dialog_list_timeout_callback(void *messa
FolderId(narrow_cast<int32>(folder_id_int)));
}
td_api::object_ptr<td_api::MessageSender> MessagesManager::get_message_sender_object_const(UserId user_id,
DialogId dialog_id,
const char *source) const {
if (dialog_id.is_valid() && have_dialog(dialog_id)) {
return td_api::make_object<td_api::messageSenderChat>(dialog_id.get());
}
if (!user_id.is_valid()) {
// can happen only if the server sends a message with wrong sender
LOG(ERROR) << "Receive message with wrong sender " << user_id << '/' << dialog_id << " from " << source;
user_id = td_->contacts_manager_->add_service_notifications_user();
}
return td_api::make_object<td_api::messageSenderUser>(td_->contacts_manager_->get_user_id_object(user_id, source));
}
td_api::object_ptr<td_api::MessageSender> MessagesManager::get_message_sender_object(UserId user_id, DialogId dialog_id,
const char *source) {
if (dialog_id.is_valid() && !have_dialog(dialog_id)) {
LOG(ERROR) << "Failed to find " << dialog_id;
force_create_dialog(dialog_id, source);
}
if (!user_id.is_valid() && td_->auth_manager_->is_bot()) {
td_->contacts_manager_->add_anonymous_bot_user();
td_->contacts_manager_->add_service_notifications_user();
}
return get_message_sender_object_const(user_id, dialog_id, source);
}
td_api::object_ptr<td_api::MessageSender> MessagesManager::get_message_sender_object_const(DialogId dialog_id,
const char *source) const {
if (dialog_id.get_type() == DialogType::User) {
return get_message_sender_object_const(dialog_id.get_user_id(), DialogId(), source);
}
return get_message_sender_object_const(UserId(), dialog_id, source);
}
td_api::object_ptr<td_api::MessageSender> MessagesManager::get_message_sender_object(DialogId dialog_id,
const char *source) {
if (dialog_id.get_type() == DialogType::User) {
return get_message_sender_object(dialog_id.get_user_id(), DialogId(), source);
}
return get_message_sender_object(UserId(), dialog_id, source);
}
BufferSlice MessagesManager::get_dialog_database_value(const Dialog *d) {
// can't use log_event_store, because it tries to parse stored Dialog
LogEventStorerCalcLength storer_calc_length;
@ -16940,8 +16898,8 @@ void MessagesManager::on_get_blocked_dialogs(int32 offset, int32 limit, int32 to
total_count = offset + narrow_cast<int32>(dialog_ids.size());
}
auto senders = transform(dialog_ids, [this](DialogId dialog_id) {
return get_message_sender_object(dialog_id, "on_get_blocked_dialogs");
auto senders = transform(dialog_ids, [td = td_](DialogId dialog_id) {
return get_message_sender_object(td, dialog_id, "on_get_blocked_dialogs");
});
promise.set_value(td_api::make_object<td_api::messageSenders>(total_count, std::move(senders)));
}
@ -20248,7 +20206,7 @@ td_api::object_ptr<td_api::videoChat> MessagesManager::get_video_chat_object(con
auto active_group_call_id = td_->group_call_manager_->get_group_call_id(d->active_group_call_id, d->dialog_id);
auto default_participant_alias =
d->default_join_group_call_as_dialog_id.is_valid()
? get_message_sender_object_const(d->default_join_group_call_as_dialog_id, "get_video_chat_object")
? get_message_sender_object_const(td_, d->default_join_group_call_as_dialog_id, "get_video_chat_object")
: nullptr;
return make_tl_object<td_api::videoChat>(active_group_call_id.get(),
active_group_call_id.is_valid() ? !d->is_group_call_empty : false,
@ -23553,7 +23511,7 @@ tl_object_ptr<td_api::message> MessagesManager::get_message_object(DialogId dial
} else {
ttl = 0;
}
auto sender = get_message_sender_object_const(m->sender_user_id, m->sender_dialog_id, source);
auto sender = get_message_sender_object_const(td_, m->sender_user_id, m->sender_dialog_id, source);
auto scheduling_state = is_scheduled ? get_message_scheduling_state_object(m->date) : nullptr;
auto forward_info = get_message_forward_info_object(m->forward_info);
auto interaction_info = get_message_interaction_info_object(dialog_id, m);

View File

@ -142,17 +142,6 @@ class MessagesManager final : public Actor {
MessagesManager &operator=(MessagesManager &&) = delete;
~MessagesManager() final;
td_api::object_ptr<td_api::MessageSender> get_message_sender_object_const(UserId user_id, DialogId dialog_id,
const char *source) const;
td_api::object_ptr<td_api::MessageSender> get_message_sender_object(UserId user_id, DialogId dialog_id,
const char *source);
td_api::object_ptr<td_api::MessageSender> get_message_sender_object_const(DialogId dialog_id,
const char *source) const;
td_api::object_ptr<td_api::MessageSender> get_message_sender_object(DialogId dialog_id, const char *source);
static vector<MessageId> get_message_ids(const vector<int64> &input_message_ids);
static vector<int32> get_server_message_ids(const vector<MessageId> &message_ids);

View File

@ -18,6 +18,7 @@
#include "td/telegram/files/FileManager.h"
#include "td/telegram/Global.h"
#include "td/telegram/logevent/LogEvent.h"
#include "td/telegram/MessageSender.h"
#include "td/telegram/MessagesManager.h"
#include "td/telegram/misc.h"
#include "td/telegram/net/ConnectionCreator.h"

View File

@ -10,6 +10,7 @@
#include "td/telegram/AudiosManager.h"
#include "td/telegram/DocumentsManager.h"
#include "td/telegram/Global.h"
#include "td/telegram/MessageSender.h"
#include "td/telegram/MessagesManager.h"
#include "td/telegram/StickersManager.h"
#include "td/telegram/Td.h"
@ -335,8 +336,8 @@ class NotificationTypePushMessage final : public NotificationType {
}
td_api::object_ptr<td_api::NotificationType> get_notification_type_object(DialogId dialog_id) const final {
auto sender = G()->td().get_actor_unsafe()->messages_manager_->get_message_sender_object(
sender_user_id_, sender_dialog_id_, "get_notification_type_object");
auto sender = get_message_sender_object(G()->td().get_actor_unsafe(), sender_user_id_, sender_dialog_id_,
"get_notification_type_object");
return td_api::make_object<td_api::notificationTypeNewPushMessage>(
message_id_.get(), std::move(sender), sender_name_, is_outgoing_,
get_push_message_content_object(key_, arg_, photo_, document_));