Add td_api::clearSearchedForHashtags.

This commit is contained in:
levlam 2024-05-25 20:35:21 +03:00
parent c1873564dc
commit 9caaff98d6
6 changed files with 37 additions and 13 deletions

View File

@ -8077,6 +8077,9 @@ getSearchedForHashtags prefix:string limit:int32 = Hashtags;
//@description Removes a hashtag from the list of recently searched for hashtags @hashtag Hashtag to delete
removeSearchedForHashtag hashtag:string = Ok;
//@description Clears the list of recently searched for hashtags
clearSearchedForHashtags = Ok;
//@description Deletes all call messages @revoke Pass true to delete the messages for all users
deleteAllCallMessages revoke:Bool = Ok;

View File

@ -36,13 +36,12 @@ void HashtagHints::hashtag_used(const string &hashtag) {
}
hashtag_used_impl(hashtag);
G()->td_db()->get_sqlite_pmc()->set(get_key(), serialize(keys_to_strings(hints_.search_empty(101).second)),
Promise<>());
Promise<Unit>());
}
void HashtagHints::remove_hashtag(string hashtag, Promise<> promise) {
void HashtagHints::remove_hashtag(string hashtag, Promise<Unit> promise) {
if (!sync_with_db_) {
promise.set_value(Unit());
return;
return promise.set_value(Unit());
}
if (hashtag[0] == '#') {
hashtag = hashtag.substr(1);
@ -51,16 +50,25 @@ void HashtagHints::remove_hashtag(string hashtag, Promise<> promise) {
if (hints_.has_key(key)) {
hints_.remove(key);
G()->td_db()->get_sqlite_pmc()->set(get_key(), serialize(keys_to_strings(hints_.search_empty(101).second)),
Promise<>());
Promise<Unit>());
promise.set_value(Unit()); // set promise explicitly, because sqlite_pmc waits for too long before setting promise
} else {
promise.set_value(Unit());
}
}
void HashtagHints::query(const string &prefix, int32 limit, Promise<std::vector<string>> promise) {
void HashtagHints::clear(Promise<Unit> promise) {
if (!sync_with_db_) {
promise.set_value(std::vector<string>());
return promise.set_value(Unit());
}
hints_ = {};
G()->td_db()->get_sqlite_pmc()->set(get_key(), serialize(vector<string>()), Promise<Unit>());
promise.set_value(Unit());
}
void HashtagHints::query(const string &prefix, int32 limit, Promise<vector<string>> promise) {
if (!sync_with_db_) {
promise.set_value(vector<string>());
return;
}
@ -92,7 +100,7 @@ void HashtagHints::from_db(Result<string> data, bool dummy) {
if (data.is_error() || data.ok().empty()) {
return;
}
std::vector<string> hashtags;
vector<string> hashtags;
auto status = unserialize(hashtags, data.ok());
if (status.is_error()) {
LOG(ERROR) << "Failed to unserialize hashtag hints: " << status;
@ -104,12 +112,13 @@ void HashtagHints::from_db(Result<string> data, bool dummy) {
}
}
std::vector<string> HashtagHints::keys_to_strings(const std::vector<int64> &keys) {
std::vector<string> result;
vector<string> HashtagHints::keys_to_strings(const vector<int64> &keys) {
vector<string> result;
result.reserve(keys.size());
for (auto &it : keys) {
result.push_back(hints_.key_to_string(it));
}
return result;
}
} // namespace td

View File

@ -21,9 +21,11 @@ class HashtagHints final : public Actor {
void hashtag_used(const string &hashtag);
void remove_hashtag(string hashtag, Promise<> promise);
void remove_hashtag(string hashtag, Promise<Unit> promise);
void query(const string &prefix, int32 limit, Promise<std::vector<string>> promise);
void clear(Promise<Unit> promise);
void query(const string &prefix, int32 limit, Promise<vector<string>> promise);
private:
string mode_;
@ -39,7 +41,7 @@ class HashtagHints final : public Actor {
void hashtag_used_impl(const string &hashtag);
void from_db(Result<string> data, bool dummy);
std::vector<string> keys_to_strings(const std::vector<int64> &keys);
vector<string> keys_to_strings(const vector<int64> &keys);
};
} // namespace td

View File

@ -5388,6 +5388,12 @@ void Td::on_request(uint64 id, td_api::removeSearchedForHashtag &request) {
send_closure(hashtag_search_hints_, &HashtagHints::remove_hashtag, std::move(request.hashtag_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::clearSearchedForHashtags &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
send_closure(hashtag_search_hints_, &HashtagHints::clear, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::deleteAllCallMessages &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();

View File

@ -800,6 +800,8 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::removeSearchedForHashtag &request);
void on_request(uint64 id, td_api::clearSearchedForHashtags &request);
void on_request(uint64 id, const td_api::deleteAllCallMessages &request);
void on_request(uint64 id, const td_api::searchChatRecentLocationMessages &request);

View File

@ -3073,6 +3073,8 @@ class CliClient final : public Actor {
string hashtag;
get_args(args, hashtag);
send_request(td_api::make_object<td_api::removeSearchedForHashtag>(hashtag));
} else if (op == "csfh") {
send_request(td_api::make_object<td_api::clearSearchedForHashtags>());
} else if (op == "DeleteAllCallMessages") {
bool revoke = as_bool(args);
send_request(td_api::make_object<td_api::deleteAllCallMessages>(revoke));