diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 86cafef99..feb454797 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -863,7 +863,8 @@ chatActionBarReportUnrelatedLocation = ChatActionBar; //@description The chat is a private or secret chat, which can be reported using the method reportChat, or the other user can be blocked using the method blockUser, or the other user can be added to the contact list using the method addContact //@can_unarchive If true, the chat was automatically archived and can be moved back to the main chat list using addChatToList simultaneously with setting chat notification settings to default using setChatNotificationSettings -chatActionBarReportAddBlock can_unarchive:Bool = ChatActionBar; +//@distance If non-negative, the current user was found by the peer through searchChatsNearby and this is the distance between the users +chatActionBarReportAddBlock can_unarchive:Bool distance:int32 = ChatActionBar; //@description The chat is a private or secret chat and the other user can be added to the contact list using the method addContact chatActionBarAddContact = ChatActionBar; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 07b8719f5..34936f698 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 71ad26b14..e52c89b6c 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -4526,6 +4526,7 @@ void MessagesManager::Dialog::store(StorerT &storer) const { STORE_FLAG(need_repair_channel_server_unread_count); STORE_FLAG(can_unarchive); STORE_FLAG(has_distance); + STORE_FLAG(hide_distance); END_STORE_FLAGS(); } @@ -4690,6 +4691,7 @@ void MessagesManager::Dialog::parse(ParserT &parser) { PARSE_FLAG(need_repair_channel_server_unread_count); PARSE_FLAG(can_unarchive); PARSE_FLAG(has_distance); + PARSE_FLAG(hide_distance); END_PARSE_FLAGS(); } else { is_folder_id_inited = false; @@ -4702,6 +4704,7 @@ void MessagesManager::Dialog::parse(ParserT &parser) { has_scheduled_database_messages = false; need_repair_channel_server_unread_count = false; can_unarchive = false; + hide_distance = false; } parse(last_new_message_id, parser); @@ -7397,7 +7400,7 @@ void MessagesManager::on_get_peer_settings(DialogId dialog_id, d->can_share_phone_number = can_share_phone_number; d->can_report_location = can_report_location; d->can_unarchive = can_unarchive; - d->distance = distance; + d->distance = distance < 0 ? -1 : distance; fix_dialog_action_bar(d); @@ -17469,7 +17472,8 @@ td_api::object_ptr MessagesManager::get_chat_action_bar_o if (d->can_block_user) { CHECK(d->dialog_id.get_type() == DialogType::User); CHECK(d->can_report_spam && d->can_add_contact); - return td_api::make_object(d->can_unarchive); + auto distance = d->hide_distance ? -1 : d->distance; + return td_api::make_object(d->can_unarchive, distance); } if (d->can_add_contact) { CHECK(d->dialog_id.get_type() == DialogType::User); @@ -29033,6 +29037,7 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq update_used_hashtags(dialog_id, m); update_top_dialogs(dialog_id, m); cancel_user_dialog_action(dialog_id, m); + try_hide_distance(dialog_id, m); } Message *result_message = treap_insert_message(&d->messages, std::move(message)); @@ -29194,6 +29199,7 @@ MessagesManager::Message *MessagesManager::add_scheduled_message_to_dialog(Dialo if (from_update) { update_sent_message_contents(dialog_id, m); update_used_hashtags(dialog_id, m); + try_hide_distance(dialog_id, m); } if (m->message_id.is_scheduled_server()) { @@ -32277,6 +32283,42 @@ void MessagesManager::update_top_dialogs(DialogId dialog_id, const Message *m) { } } +void MessagesManager::try_hide_distance(DialogId dialog_id, const Message *m) { + CHECK(m != nullptr); + if (!m->is_outgoing && dialog_id != get_my_dialog_id()) { + return; + } + + Dialog *d = nullptr; + switch (dialog_id.get_type()) { + case DialogType::User: + d = get_dialog(dialog_id); + break; + case DialogType::Chat: + case DialogType::Channel: + break; + case DialogType::SecretChat: { + auto user_id = td_->contacts_manager_->get_secret_chat_user_id(dialog_id.get_secret_chat_id()); + if (user_id.is_valid()) { + d = get_dialog_force(DialogId(user_id)); + } + break; + } + default: + UNREACHABLE(); + } + if (d == nullptr || d->hide_distance) { + return; + } + + d->hide_distance = true; + on_dialog_updated(dialog_id, "try_hide_distance"); + + if (d->distance != -1) { + send_update_chat_action_bar(d); + } +} + MessagesManager::Message *MessagesManager::continue_send_message(DialogId dialog_id, unique_ptr &&m, uint64 logevent_id) { CHECK(logevent_id != 0); diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index a8e6c6110..a1d308540 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -1131,6 +1131,7 @@ class MessagesManager : public Actor { bool can_share_phone_number = false; bool can_report_location = false; bool can_unarchive = false; + bool hide_distance = false; bool is_opened = false; @@ -2681,6 +2682,8 @@ class MessagesManager : public Actor { void update_top_dialogs(DialogId dialog_id, const Message *m); + void try_hide_distance(DialogId dialog_id, const Message *m); + string get_search_text(const Message *m) const; unique_ptr parse_message(DialogId dialog_id, const BufferSlice &value, bool is_scheduled);