Merge remote-tracking branch 'td/master'

This commit is contained in:
Andrea Cavalli 2021-08-03 19:56:27 +02:00
commit d341c79aa8
12 changed files with 70 additions and 47 deletions

View File

@ -332,7 +332,7 @@ bool AnimationsManager::merge_animations(FileId new_id, FileId old_id, bool can_
if (old_->thumbnail != new_->thumbnail) { if (old_->thumbnail != new_->thumbnail) {
// LOG_STATUS(td_->file_manager_->merge(new_->thumbnail.file_id, old_->thumbnail.file_id)); // LOG_STATUS(td_->file_manager_->merge(new_->thumbnail.file_id, old_->thumbnail.file_id));
} }
if (old_->mime_type == "image/gif" && new_->mime_type == "video/mp4") { if (new_->file_name.size() == old_->file_name.size() + 4 && new_->file_name == old_->file_name + ".mp4") {
need_merge = false; need_merge = false;
} }
} }

View File

@ -11564,7 +11564,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); td_->messages_manager_->force_create_dialog(dialog_id, "get_chat_member_object", true);
} }
return td_api::make_object<td_api::chatMember>( 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"), 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()); dialog_participant.joined_date, dialog_participant.status.get_chat_member_status_object());
} }

View File

@ -81,7 +81,8 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo
switch (attribute->get_id()) { switch (attribute->get_id()) {
case telegram_api::documentAttributeImageSize::ID: { case telegram_api::documentAttributeImageSize::ID: {
auto image_size = move_tl_object_as<telegram_api::documentAttributeImageSize>(attribute); auto image_size = move_tl_object_as<telegram_api::documentAttributeImageSize>(attribute);
dimensions = get_dimensions(image_size->w_, image_size->h_, "documentAttributeImageSize"); dimensions =
get_dimensions(image_size->w_, image_size->h_, oneline(to_string(remote_document.document)).c_str());
break; break;
} }
case telegram_api::documentAttributeAnimated::ID: case telegram_api::documentAttributeAnimated::ID:

View File

@ -113,7 +113,8 @@ class GetGroupCallJoinAsQuery final : public Td::ResultHandler {
td->messages_manager_->force_create_dialog(dialog_id, "GetGroupCallJoinAsQuery"); 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()), promise_.set_value(td_api::make_object<td_api::messageSenders>(static_cast<int32>(participant_aliaces.size()),
@ -4710,7 +4711,8 @@ vector<td_api::object_ptr<td_api::groupCallRecentSpeaker>> GroupCallManager::get
auto get_result = [recent_speaker_users, messages_manager = td_->messages_manager_.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 transform(recent_speaker_users, [messages_manager](const std::pair<DialogId, bool> &recent_speaker_user) {
return td_api::make_object<td_api::groupCallRecentSpeaker>( 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) { 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>( return td_api::make_object<td_api::groupCallParticipant>(
td->messages_manager_->get_message_sender_object(dialog_id), audio_source, presentation_audio_source, td->messages_manager_->get_message_sender_object(dialog_id, "get_group_call_participant_object"), audio_source,
video_payload.get_group_call_participant_video_info_object(), 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, 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, 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(), can_be_unmuted_only_for_self, get_is_muted_for_all_users(), get_is_muted_locally(), get_is_muted_by_themselves(),

View File

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

View File

@ -384,7 +384,7 @@ static vector<Slice> match_cashtags(Slice str) {
const unsigned char *end = str.uend(); const unsigned char *end = str.uend();
const unsigned char *ptr = begin; const unsigned char *ptr = begin;
// '/(?<=^|[^$\d_\pL\x{200c}])\$([A-Z]{3,8})(?![$\d_\pL\x{200c}])/u' // '/(?<=^|[^$\d_\pL\x{200c}])\$(1INCH|[A-Z]{1,8})(?![$\d_\pL\x{200c}])/u'
UnicodeSimpleCategory category; UnicodeSimpleCategory category;
while (true) { while (true) {
@ -404,12 +404,16 @@ static vector<Slice> match_cashtags(Slice str) {
} }
auto cashtag_begin = ++ptr; auto cashtag_begin = ++ptr;
while (ptr != end && 'Z' >= *ptr && *ptr >= 'A') { if (end - ptr >= 5 && Slice(ptr, ptr + 5) == Slice("1INCH")) {
ptr++; ptr += 5;
} else {
while (ptr != end && 'Z' >= *ptr && *ptr >= 'A') {
ptr++;
}
} }
auto cashtag_end = ptr; auto cashtag_end = ptr;
auto cashtag_size = cashtag_end - cashtag_begin; auto cashtag_size = cashtag_end - cashtag_begin;
if (cashtag_size < 3 || cashtag_size > 8) { if (cashtag_size < 1 || cashtag_size > 8) {
continue; continue;
} }

View File

@ -5988,44 +5988,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, 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)) { if (dialog_id.is_valid() && have_dialog(dialog_id)) {
return td_api::make_object<td_api::messageSenderChat>(dialog_id.get()); return td_api::make_object<td_api::messageSenderChat>(dialog_id.get());
} }
if (!user_id.is_valid()) { if (!user_id.is_valid()) {
// can happen only if the server sends a message with wrong sender // 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(); user_id = td_->contacts_manager_->add_service_notifications_user();
} }
return td_api::make_object<td_api::messageSenderUser>( return td_api::make_object<td_api::messageSenderUser>(td_->contacts_manager_->get_user_id_object(user_id, source));
td_->contacts_manager_->get_user_id_object(user_id, "get_message_sender_object"));
} }
td_api::object_ptr<td_api::MessageSender> MessagesManager::get_message_sender_object(UserId user_id, td_api::object_ptr<td_api::MessageSender> MessagesManager::get_message_sender_object(UserId user_id, DialogId dialog_id,
DialogId dialog_id) { const char *source) {
if (dialog_id.is_valid() && !have_dialog(dialog_id)) { if (dialog_id.is_valid() && !have_dialog(dialog_id)) {
LOG(ERROR) << "Failed to find " << 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()) { if (!user_id.is_valid() && td_->auth_manager_->is_bot()) {
td_->contacts_manager_->add_anonymous_bot_user(); td_->contacts_manager_->add_anonymous_bot_user();
td_->contacts_manager_->add_service_notifications_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) { 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) { 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) { BufferSlice MessagesManager::get_dialog_database_value(const Dialog *d) {
@ -20074,9 +20076,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 { 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 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() auto default_participant_alias =
? get_message_sender_object_const(d->default_join_group_call_as_dialog_id) d->default_join_group_call_as_dialog_id.is_valid()
: nullptr; ? 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(), return make_tl_object<td_api::voiceChat>(active_group_call_id.get(),
active_group_call_id.is_valid() ? !d->is_group_call_empty : false, active_group_call_id.is_valid() ? !d->is_group_call_empty : false,
std::move(default_participant_alias)); std::move(default_participant_alias));
@ -23148,11 +23151,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 edit_date = m->hide_edit_date ? 0 : m->edit_date;
auto is_pinned = for_event_log || is_scheduled ? false : m->is_pinned; 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); 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>( 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(), m->message_id.get(), get_message_sender_object_const(m->sender_user_id, m->sender_dialog_id, source.c_str()),
std::move(sending_state), std::move(scheduling_state), is_outgoing, is_pinned, can_be_edited, can_be_forwarded, dialog_id.get(), std::move(sending_state), std::move(scheduling_state), is_outgoing, is_pinned, can_be_edited,
can_delete_for_self, can_delete_for_all_users, can_get_statistics, can_get_message_thread, m->is_channel_post, can_be_forwarded, can_delete_for_self, can_delete_for_all_users, can_get_statistics, can_get_message_thread,
contains_unread_mention, date, edit_date, get_message_forward_info_object(m->forward_info), 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, 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, 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), get_restriction_reason_description(m->restriction_reasons),
@ -31674,7 +31678,7 @@ tl_object_ptr<td_api::ChatEventAction> MessagesManager::get_chat_event_action_ob
return nullptr; return nullptr;
} }
return make_tl_object<td_api::chatEventMemberRestricted>( 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(), old_dialog_participant.status.get_chat_member_status_object(),
new_dialog_participant.status.get_chat_member_status_object()); new_dialog_participant.status.get_chat_member_status_object());
} }
@ -31896,7 +31900,7 @@ tl_object_ptr<td_api::ChatEventAction> MessagesManager::get_chat_event_action_ob
return nullptr; return nullptr;
} }
return make_tl_object<td_api::chatEventVoiceChatParticipantIsMutedToggled>( 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: { case telegram_api::channelAdminLogEventActionParticipantUnmute::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionParticipantUnmute>(action_ptr); auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionParticipantUnmute>(action_ptr);
@ -31905,7 +31909,7 @@ tl_object_ptr<td_api::ChatEventAction> MessagesManager::get_chat_event_action_ob
return nullptr; return nullptr;
} }
return make_tl_object<td_api::chatEventVoiceChatParticipantIsMutedToggled>( 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: { case telegram_api::channelAdminLogEventActionParticipantVolume::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionParticipantVolume>(action_ptr); auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionParticipantVolume>(action_ptr);
@ -31914,7 +31918,8 @@ tl_object_ptr<td_api::ChatEventAction> MessagesManager::get_chat_event_action_ob
return nullptr; return nullptr;
} }
return make_tl_object<td_api::chatEventVoiceChatParticipantVolumeLevelChanged>( 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: { case telegram_api::channelAdminLogEventActionToggleGroupCallSetting::ID: {
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionToggleGroupCallSetting>(action_ptr); auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionToggleGroupCallSetting>(action_ptr);

View File

@ -143,13 +143,16 @@ class MessagesManager final : public Actor {
void memory_stats(vector<string> &output); void memory_stats(vector<string> &output);
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); 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 { td_api::object_ptr<td_api::NotificationType> get_notification_type_object(DialogId dialog_id) const final {
auto sender = auto sender = G()->td().get_actor_unsafe()->messages_manager_->get_message_sender_object(
G()->td().get_actor_unsafe()->messages_manager_->get_message_sender_object(sender_user_id_, sender_dialog_id_); sender_user_id_, sender_dialog_id_, "get_notification_type_object");
return td_api::make_object<td_api::notificationTypeNewPushMessage>( return td_api::make_object<td_api::notificationTypeNewPushMessage>(
message_id_.get(), std::move(sender), sender_name_, is_outgoing_, message_id_.get(), std::move(sender), sender_name_, is_outgoing_,
get_push_message_content_object(key_, arg_, photo_, document_)); get_push_message_content_object(key_, arg_, photo_, document_));

View File

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

View File

@ -137,8 +137,9 @@ TEST(MessageEntities, cashtag) {
check_cashtag("$ab", {}); check_cashtag("$ab", {});
check_cashtag("$abc", {}); check_cashtag("$abc", {});
check_cashtag("$", {}); check_cashtag("$", {});
check_cashtag("$A", {}); check_cashtag("$A", {"$A"});
check_cashtag("$AB", {}); check_cashtag("$AB", {"$AB"});
check_cashtag("$ABС", {});
check_cashtag("$АBC", {}); check_cashtag("$АBC", {});
check_cashtag("$АВС", {}); check_cashtag("$АВС", {});
check_cashtag("$ABC", {"$ABC"}); check_cashtag("$ABC", {"$ABC"});
@ -160,6 +161,12 @@ TEST(MessageEntities, cashtag) {
check_cashtag(" А$ABC ", {}); check_cashtag(" А$ABC ", {});
check_cashtag("$ABC$DEF $GHI $KLM", {"$GHI", "$KLM"}); check_cashtag("$ABC$DEF $GHI $KLM", {"$GHI", "$KLM"});
check_cashtag("$TEST", {"$TEST"}); check_cashtag("$TEST", {"$TEST"});
check_cashtag("$1INC", {});
check_cashtag("$1INCH", {"$1INCH"});
check_cashtag("...$1INCH...", {"$1INCH"});
check_cashtag("$1inch", {});
check_cashtag("$1INCHA", {});
check_cashtag("$1INCHА", {});
check_cashtag(u8"$ABC\u2122", {"$ABC"}); check_cashtag(u8"$ABC\u2122", {"$ABC"});
check_cashtag(u8"\u2122$ABC", {"$ABC"}); check_cashtag(u8"\u2122$ABC", {"$ABC"});
check_cashtag(u8"\u2122$ABC\u2122", {"$ABC"}); check_cashtag(u8"\u2122$ABC\u2122", {"$ABC"});