Add source to get_message_sender_object.

This commit is contained in:
levlam 2021-08-03 01:58:02 +03:00
parent 48ce26b6c2
commit 0dc42e4410
8 changed files with 50 additions and 39 deletions

View File

@ -11552,7 +11552,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),
td_->messages_manager_->get_message_sender_object_const(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

@ -110,7 +110,8 @@ 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));
participant_aliaces.push_back(
td->messages_manager_->get_message_sender_object(dialog_id, "GetGroupCallJoinAsQuery"));
}
promise_.set_value(td_api::make_object<td_api::messageSenders>(static_cast<int32>(participant_aliaces.size()),
@ -4629,7 +4630,8 @@ vector<td_api::object_ptr<td_api::groupCallRecentSpeaker>> GroupCallManager::get
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) {
return td_api::make_object<td_api::groupCallRecentSpeaker>(
messages_manager->get_message_sender_object(recent_speaker_user.first), recent_speaker_user.second);
messages_manager->get_message_sender_object(recent_speaker_user.first, "get_recent_speakers"),
recent_speaker_user.second);
});
};
if (recent_speakers->last_sent_users != recent_speaker_users) {

View File

@ -266,8 +266,8 @@ 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), audio_source, presentation_audio_source,
video_payload.get_group_call_participant_video_info_object(),
td->messages_manager_->get_message_sender_object(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,
can_be_unmuted_only_for_self, get_is_muted_for_all_users(), get_is_muted_locally(), get_is_muted_by_themselves(),

View File

@ -4846,8 +4846,9 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
case MessageContentType::ProximityAlertTriggered: {
const MessageProximityAlertTriggered *m = static_cast<const MessageProximityAlertTriggered *>(content);
return make_tl_object<td_api::messageProximityAlertTriggered>(
td->messages_manager_->get_message_sender_object(m->traveler_dialog_id),
td->messages_manager_->get_message_sender_object(m->watcher_dialog_id), m->distance);
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);
}
case MessageContentType::GroupCall: {
auto *m = static_cast<const MessageGroupCall *>(content);

View File

@ -5970,44 +5970,46 @@ void MessagesManager::on_preload_folder_dialog_list_timeout_callback(void *messa
}
td_api::object_ptr<td_api::MessageSender> MessagesManager::get_message_sender_object_const(UserId user_id,
DialogId dialog_id) const {
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;
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, "get_message_sender_object"));
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) {
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, "get_message_sender_object");
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);
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 {
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());
return get_message_sender_object_const(dialog_id.get_user_id(), DialogId(), source);
}
return get_message_sender_object_const(UserId(), dialog_id);
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) {
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());
return get_message_sender_object(dialog_id.get_user_id(), DialogId(), source);
}
return get_message_sender_object(UserId(), dialog_id);
return get_message_sender_object(UserId(), dialog_id, source);
}
BufferSlice MessagesManager::get_dialog_database_value(const Dialog *d) {
@ -19763,9 +19765,10 @@ td_api::object_ptr<td_api::ChatActionBar> MessagesManager::get_chat_action_bar_o
td_api::object_ptr<td_api::voiceChat> MessagesManager::get_voice_chat_object(const Dialog *d) const {
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)
: nullptr;
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_voice_chat_object")
: nullptr;
return make_tl_object<td_api::voiceChat>(active_group_call_id.get(),
active_group_call_id.is_valid() ? !d->is_group_call_empty : false,
std::move(default_participant_alias));
@ -22806,11 +22809,12 @@ tl_object_ptr<td_api::message> MessagesManager::get_message_object(DialogId dial
auto edit_date = m->hide_edit_date ? 0 : m->edit_date;
auto is_pinned = for_event_log || is_scheduled ? false : m->is_pinned;
bool skip_bot_commands = for_event_log || need_skip_bot_commands(dialog_id, m);
string source = PSTRING() << dialog_id << ' ' << m->message_id;
return make_tl_object<td_api::message>(
m->message_id.get(), get_message_sender_object_const(m->sender_user_id, m->sender_dialog_id), dialog_id.get(),
std::move(sending_state), std::move(scheduling_state), is_outgoing, is_pinned, can_be_edited, can_be_forwarded,
can_delete_for_self, can_delete_for_all_users, can_get_statistics, can_get_message_thread, m->is_channel_post,
contains_unread_mention, date, edit_date, get_message_forward_info_object(m->forward_info),
m->message_id.get(), get_message_sender_object_const(m->sender_user_id, m->sender_dialog_id, source.c_str()),
dialog_id.get(), std::move(sending_state), std::move(scheduling_state), is_outgoing, is_pinned, can_be_edited,
can_be_forwarded, can_delete_for_self, can_delete_for_all_users, can_get_statistics, can_get_message_thread,
m->is_channel_post, contains_unread_mention, date, edit_date, get_message_forward_info_object(m->forward_info),
get_message_interaction_info_object(dialog_id, m), reply_in_dialog_id.get(), reply_to_message_id,
top_thread_message_id, ttl, ttl_expires_in, via_bot_user_id, m->author_signature, media_album_id,
get_restriction_reason_description(m->restriction_reasons),
@ -31259,7 +31263,7 @@ tl_object_ptr<td_api::ChatEventAction> MessagesManager::get_chat_event_action_ob
return nullptr;
}
return make_tl_object<td_api::chatEventMemberRestricted>(
get_message_sender_object(old_dialog_participant.dialog_id),
get_message_sender_object(old_dialog_participant.dialog_id, "chatEventMemberRestricted"),
old_dialog_participant.status.get_chat_member_status_object(),
new_dialog_participant.status.get_chat_member_status_object());
}
@ -31481,7 +31485,7 @@ tl_object_ptr<td_api::ChatEventAction> MessagesManager::get_chat_event_action_ob
return nullptr;
}
return make_tl_object<td_api::chatEventVoiceChatParticipantIsMutedToggled>(
get_message_sender_object(participant.dialog_id), true);
get_message_sender_object(participant.dialog_id, "chatEventVoiceChatParticipantIsMutedToggled"), true);
}
case telegram_api::channelAdminLogEventActionParticipantUnmute::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionParticipantUnmute>(action_ptr);
@ -31490,7 +31494,7 @@ tl_object_ptr<td_api::ChatEventAction> MessagesManager::get_chat_event_action_ob
return nullptr;
}
return make_tl_object<td_api::chatEventVoiceChatParticipantIsMutedToggled>(
get_message_sender_object(participant.dialog_id), false);
get_message_sender_object(participant.dialog_id, "chatEventVoiceChatParticipantIsMutedToggled"), false);
}
case telegram_api::channelAdminLogEventActionParticipantVolume::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionParticipantVolume>(action_ptr);
@ -31499,7 +31503,8 @@ tl_object_ptr<td_api::ChatEventAction> MessagesManager::get_chat_event_action_ob
return nullptr;
}
return make_tl_object<td_api::chatEventVoiceChatParticipantVolumeLevelChanged>(
get_message_sender_object(participant.dialog_id), participant.volume_level);
get_message_sender_object(participant.dialog_id, "chatEventVoiceChatParticipantVolumeLevelChanged"),
participant.volume_level);
}
case telegram_api::channelAdminLogEventActionToggleGroupCallSetting::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionToggleGroupCallSetting>(action_ptr);

View File

@ -139,13 +139,16 @@ 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;
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);
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;
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);
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);

View File

@ -328,8 +328,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_);
auto sender = G()->td().get_actor_unsafe()->messages_manager_->get_message_sender_object(
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_));

View File

@ -2063,7 +2063,7 @@ class GetBlockedMessageSendersRequest final : public RequestActor<> {
void do_send_result() final {
auto senders =
transform(message_senders_.second, [messages_manager = td->messages_manager_.get()](DialogId dialog_id) {
return messages_manager->get_message_sender_object(dialog_id);
return messages_manager->get_message_sender_object(dialog_id, "GetBlockedMessageSendersRequest");
});
send_result(td_api::make_object<td_api::messageSenders>(message_senders_.first, std::move(senders)));
}