From 5f6bb81e28d41c770c5164dc340f0e06d51aca9b Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 2 Jun 2024 01:11:32 +0300 Subject: [PATCH] Support cashtags in getSearchedForHashtags and removeSearchedForHashtag. --- td/generate/scheme/td_api.tl | 4 ++-- td/telegram/HashtagHints.cpp | 8 +++++--- td/telegram/HashtagHints.h | 3 ++- td/telegram/Td.cpp | 13 +++++++------ 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index f8aff4746..e1c2ff6b2 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -8071,10 +8071,10 @@ searchOutgoingDocumentMessages query:string limit:int32 = FoundMessages; //@limit The maximum number of messages to be returned; up to 100. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit searchPublicHashtagMessages hashtag:string offset:string limit:int32 = FoundMessages; -//@description Returns recently searched for hashtags by their prefix @prefix Prefix of hashtags to return @limit The maximum number of hashtags to be returned +//@description Returns recently searched for hashtags or cashtags by their prefix @prefix Prefix of hashtags or cashtags to return @limit The maximum number of items to be returned getSearchedForHashtags prefix:string limit:int32 = Hashtags; -//@description Removes a hashtag from the list of recently searched for hashtags @hashtag Hashtag to delete +//@description Removes a hashtag or a cashtag from the list of recently searched for hashtags or cashtags @hashtag Hashtag or cashtag to delete removeSearchedForHashtag hashtag:string = Ok; //@description Clears the list of recently searched for hashtags diff --git a/td/telegram/HashtagHints.cpp b/td/telegram/HashtagHints.cpp index c33ee8001..05a74fe28 100644 --- a/td/telegram/HashtagHints.cpp +++ b/td/telegram/HashtagHints.cpp @@ -18,7 +18,8 @@ namespace td { -HashtagHints::HashtagHints(string mode, ActorShared<> parent) : mode_(std::move(mode)), parent_(std::move(parent)) { +HashtagHints::HashtagHints(string mode, char first_character, ActorShared<> parent) + : mode_(std::move(mode)), first_character_(first_character), parent_(std::move(parent)) { } void HashtagHints::start_up() { @@ -43,7 +44,7 @@ void HashtagHints::remove_hashtag(string hashtag, Promise promise) { if (!sync_with_db_) { return promise.set_value(Unit()); } - if (hashtag[0] == '#') { + if (hashtag[0] == first_character_) { hashtag = hashtag.substr(1); } auto key = Hash()(hashtag); @@ -72,7 +73,8 @@ void HashtagHints::query(const string &prefix, int32 limit, Promise parent); + HashtagHints(string mode, char first_character, ActorShared<> parent); void hashtag_used(const string &hashtag); @@ -30,6 +30,7 @@ class HashtagHints final : public Actor { private: string mode_; Hints hints_; + char first_character_ = '#'; bool sync_with_db_ = false; int64 counter_ = 0; diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 3f180a92a..671f30340 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -3926,10 +3926,10 @@ void Td::init_managers() { void Td::init_pure_actor_managers() { call_manager_ = create_actor("CallManager", create_reference()); G()->set_call_manager(call_manager_.get()); - cashtag_search_hints_ = create_actor("CashtagSearchHints", "cashtag_search", create_reference()); + cashtag_search_hints_ = create_actor("CashtagSearchHints", "cashtag_search", '$', create_reference()); device_token_manager_ = create_actor("DeviceTokenManager", create_reference()); - hashtag_hints_ = create_actor("HashtagHints", "text", create_reference()); - hashtag_search_hints_ = create_actor("HashtagSearchHints", "search", create_reference()); + hashtag_hints_ = create_actor("HashtagHints", "text", '#', create_reference()); + hashtag_search_hints_ = create_actor("HashtagSearchHints", "search", '#', create_reference()); language_pack_manager_ = create_actor("LanguagePackManager", create_reference()); G()->set_language_pack_manager(language_pack_manager_.get()); password_manager_ = create_actor("PasswordManager", create_reference()); @@ -5385,15 +5385,16 @@ void Td::on_request(uint64 id, td_api::getSearchedForHashtags &request) { promise.set_value(td_api::make_object(result.move_as_ok())); } }); - send_closure(hashtag_search_hints_, &HashtagHints::query, std::move(request.prefix_), request.limit_, - std::move(query_promise)); + send_closure(request.prefix_[0] == '$' ? cashtag_search_hints_ : hashtag_search_hints_, &HashtagHints::query, + std::move(request.prefix_), request.limit_, std::move(query_promise)); } void Td::on_request(uint64 id, td_api::removeSearchedForHashtag &request) { CHECK_IS_USER(); CLEAN_INPUT_STRING(request.hashtag_); CREATE_OK_REQUEST_PROMISE(); - send_closure(hashtag_search_hints_, &HashtagHints::remove_hashtag, std::move(request.hashtag_), std::move(promise)); + send_closure(request.hashtag_[0] == '$' ? cashtag_search_hints_ : hashtag_search_hints_, + &HashtagHints::remove_hashtag, std::move(request.hashtag_), std::move(promise)); } void Td::on_request(uint64 id, td_api::clearSearchedForHashtags &request) {