From 48ce26b6c206212137e8ffd82165ccdd421b643c Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 3 Aug 2021 01:57:46 +0300 Subject: [PATCH 1/4] Improve source in get_dimensions. --- td/telegram/DocumentsManager.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/td/telegram/DocumentsManager.cpp b/td/telegram/DocumentsManager.cpp index 977c6b573..47f4931fa 100644 --- a/td/telegram/DocumentsManager.cpp +++ b/td/telegram/DocumentsManager.cpp @@ -77,7 +77,8 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo switch (attribute->get_id()) { case telegram_api::documentAttributeImageSize::ID: { auto image_size = move_tl_object_as(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; } case telegram_api::documentAttributeAnimated::ID: From 0dc42e441041563e3805655bc1eb2ffec2758739 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 3 Aug 2021 01:58:02 +0300 Subject: [PATCH 2/4] Add source to get_message_sender_object. --- td/telegram/ContactsManager.cpp | 2 +- td/telegram/GroupCallManager.cpp | 6 ++- td/telegram/GroupCallParticipant.cpp | 4 +- td/telegram/MessageContent.cpp | 5 ++- td/telegram/MessagesManager.cpp | 55 +++++++++++++++------------- td/telegram/MessagesManager.h | 11 ++++-- td/telegram/NotificationType.cpp | 4 +- td/telegram/Td.cpp | 2 +- 8 files changed, 50 insertions(+), 39 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 0b7b59cda..7fb90cd96 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -11552,7 +11552,7 @@ tl_object_ptr ContactsManager::get_chat_member_object( td_->messages_manager_->force_create_dialog(dialog_id, "get_chat_member_object", true); } return td_api::make_object( - 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()); } diff --git a/td/telegram/GroupCallManager.cpp b/td/telegram/GroupCallManager.cpp index ab1e4af2c..acc6d07ef 100644 --- a/td/telegram/GroupCallManager.cpp +++ b/td/telegram/GroupCallManager.cpp @@ -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(static_cast(participant_aliaces.size()), @@ -4629,7 +4630,8 @@ vector> GroupCallManager::get auto get_result = [recent_speaker_users, messages_manager = td_->messages_manager_.get()] { return transform(recent_speaker_users, [messages_manager](const std::pair &recent_speaker_user) { return td_api::make_object( - 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) { diff --git a/td/telegram/GroupCallParticipant.cpp b/td/telegram/GroupCallParticipant.cpp index ee0ac5e54..8f1c9270c 100644 --- a/td/telegram/GroupCallParticipant.cpp +++ b/td/telegram/GroupCallParticipant.cpp @@ -266,8 +266,8 @@ td_api::object_ptr GroupCallParticipant::get_group } return td_api::make_object( - 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(), diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 3165a7ba5..3599fb4f1 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -4846,8 +4846,9 @@ tl_object_ptr get_message_content_object(const MessageCo case MessageContentType::ProximityAlertTriggered: { const MessageProximityAlertTriggered *m = static_cast(content); return make_tl_object( - 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(content); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 5a2ecd1bb..ac56e6edc 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -5970,44 +5970,46 @@ void MessagesManager::on_preload_folder_dialog_list_timeout_callback(void *messa } td_api::object_ptr 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(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_->contacts_manager_->get_user_id_object(user_id, "get_message_sender_object")); + return td_api::make_object(td_->contacts_manager_->get_user_id_object(user_id, source)); } -td_api::object_ptr MessagesManager::get_message_sender_object(UserId user_id, - DialogId dialog_id) { +td_api::object_ptr 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 MessagesManager::get_message_sender_object_const(DialogId dialog_id) const { +td_api::object_ptr 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 MessagesManager::get_message_sender_object(DialogId dialog_id) { +td_api::object_ptr 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 MessagesManager::get_chat_action_bar_o td_api::object_ptr 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(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 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( - 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 MessagesManager::get_chat_event_action_ob return nullptr; } return make_tl_object( - 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 MessagesManager::get_chat_event_action_ob return nullptr; } return make_tl_object( - 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(action_ptr); @@ -31490,7 +31494,7 @@ tl_object_ptr MessagesManager::get_chat_event_action_ob return nullptr; } return make_tl_object( - 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(action_ptr); @@ -31499,7 +31503,8 @@ tl_object_ptr MessagesManager::get_chat_event_action_ob return nullptr; } return make_tl_object( - 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(action_ptr); diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 12d1560cf..4ede96d8c 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -139,13 +139,16 @@ class MessagesManager final : public Actor { MessagesManager &operator=(MessagesManager &&) = delete; ~MessagesManager() final; - td_api::object_ptr get_message_sender_object_const(UserId user_id, DialogId dialog_id) const; + td_api::object_ptr get_message_sender_object_const(UserId user_id, DialogId dialog_id, + const char *source) const; - td_api::object_ptr get_message_sender_object(UserId user_id, DialogId dialog_id); + td_api::object_ptr get_message_sender_object(UserId user_id, DialogId dialog_id, + const char *source); - td_api::object_ptr get_message_sender_object_const(DialogId dialog_id) const; + td_api::object_ptr get_message_sender_object_const(DialogId dialog_id, + const char *source) const; - td_api::object_ptr get_message_sender_object(DialogId dialog_id); + td_api::object_ptr get_message_sender_object(DialogId dialog_id, const char *source); static vector get_message_ids(const vector &input_message_ids); diff --git a/td/telegram/NotificationType.cpp b/td/telegram/NotificationType.cpp index 033587cde..5919a929e 100644 --- a/td/telegram/NotificationType.cpp +++ b/td/telegram/NotificationType.cpp @@ -328,8 +328,8 @@ class NotificationTypePushMessage final : public NotificationType { } td_api::object_ptr 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( message_id_.get(), std::move(sender), sender_name_, is_outgoing_, get_push_message_content_object(key_, arg_, photo_, document_)); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 64f2d8be3..49b39095d 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -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(message_senders_.first, std::move(senders))); } From 13d5854e2f99f959dbf38b2fb769b299e79d7bde Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 3 Aug 2021 02:58:12 +0300 Subject: [PATCH 3/4] Update match_cashtags. --- td/telegram/MessageEntity.cpp | 12 ++++++++---- test/message_entities.cpp | 11 +++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/td/telegram/MessageEntity.cpp b/td/telegram/MessageEntity.cpp index c284b8ad7..e4dfd459f 100644 --- a/td/telegram/MessageEntity.cpp +++ b/td/telegram/MessageEntity.cpp @@ -384,7 +384,7 @@ static vector match_cashtags(Slice str) { const unsigned char *end = str.uend(); 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; while (true) { @@ -404,12 +404,16 @@ static vector match_cashtags(Slice str) { } auto cashtag_begin = ++ptr; - while (ptr != end && 'Z' >= *ptr && *ptr >= 'A') { - ptr++; + if (end - ptr >= 5 && Slice(ptr, ptr + 5) == Slice("1INCH")) { + ptr += 5; + } else { + while (ptr != end && 'Z' >= *ptr && *ptr >= 'A') { + ptr++; + } } auto cashtag_end = ptr; auto cashtag_size = cashtag_end - cashtag_begin; - if (cashtag_size < 3 || cashtag_size > 8) { + if (cashtag_size < 1 || cashtag_size > 8) { continue; } diff --git a/test/message_entities.cpp b/test/message_entities.cpp index fd6ad997a..6583b9129 100644 --- a/test/message_entities.cpp +++ b/test/message_entities.cpp @@ -137,8 +137,9 @@ TEST(MessageEntities, cashtag) { check_cashtag("$ab", {}); check_cashtag("$abc", {}); check_cashtag("$", {}); - check_cashtag("$A", {}); - check_cashtag("$AB", {}); + check_cashtag("$A", {"$A"}); + check_cashtag("$AB", {"$AB"}); + check_cashtag("$ABС", {}); check_cashtag("$АBC", {}); check_cashtag("$АВС", {}); check_cashtag("$ABC", {"$ABC"}); @@ -160,6 +161,12 @@ TEST(MessageEntities, cashtag) { check_cashtag(" А$ABC ", {}); check_cashtag("$ABC$DEF $GHI $KLM", {"$GHI", "$KLM"}); 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"\u2122$ABC", {"$ABC"}); check_cashtag(u8"\u2122$ABC\u2122", {"$ABC"}); From f8ab675ad14080b1609b5904c366052c814d1788 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 3 Aug 2021 03:13:56 +0300 Subject: [PATCH 4/4] Better condition to skip merge of GIF and MP4 animations. --- td/telegram/AnimationsManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/td/telegram/AnimationsManager.cpp b/td/telegram/AnimationsManager.cpp index a75b554c9..f00230b44 100644 --- a/td/telegram/AnimationsManager.cpp +++ b/td/telegram/AnimationsManager.cpp @@ -312,7 +312,7 @@ bool AnimationsManager::merge_animations(FileId new_id, FileId old_id, bool can_ if (old_->thumbnail != new_->thumbnail) { // 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; } }