Locally update recent premium statuses when changing the status.

This commit is contained in:
levlam 2022-08-31 17:46:03 +03:00
parent 6f940b5e9b
commit 1890d45680
4 changed files with 20 additions and 1 deletions

View File

@ -6603,6 +6603,7 @@ void ContactsManager::set_emoji_status(EmojiStatus emoji_status, Promise<Unit> &
if (!td_->option_manager_->get_option_boolean("is_premium")) {
return promise.set_error(Status::Error(400, "The method is available only for Telegram Premium users"));
}
add_recent_emoji_status(emoji_status);
auto query_promise = PromiseCreator::lambda(
[actor_id = actor_id(this), emoji_status, promise = std::move(promise)](Result<Unit> result) mutable {
if (result.is_ok()) {

View File

@ -242,6 +242,22 @@ void get_recent_emoji_statuses(Td *td, Promise<td_api::object_ptr<td_api::premiu
td->create_handler<GetRecentEmojiStatusesQuery>(std::move(promise))->send(statuses.hash_);
}
void add_recent_emoji_status(EmojiStatus emoji_status) {
if (emoji_status.is_empty()) {
return;
}
auto statuses = load_emoji_statuses(get_recent_emoji_statuses_database_key());
if (!statuses.emoji_statuses_.empty() && statuses.emoji_statuses_[0] == emoji_status) {
return;
}
statuses.hash_ = 0;
td::remove(statuses.emoji_statuses_, emoji_status);
statuses.emoji_statuses_.insert(statuses.emoji_statuses_.begin(), emoji_status);
save_emoji_statuses(get_recent_emoji_statuses_database_key(), statuses);
}
void clear_recent_emoji_statuses(Td *td, Promise<Unit> &&promise) {
save_emoji_statuses(get_recent_emoji_statuses_database_key(), EmojiStatuses());
td->create_handler<ClearRecentEmojiStatusesQuery>(std::move(promise))->send();

View File

@ -65,6 +65,8 @@ void get_default_emoji_statuses(Td *td, Promise<td_api::object_ptr<td_api::premi
void get_recent_emoji_statuses(Td *td, Promise<td_api::object_ptr<td_api::premiumStatuses>> &&promise);
void add_recent_emoji_status(EmojiStatus emoji_status);
void clear_recent_emoji_statuses(Td *td, Promise<Unit> &&promise);
} // namespace td

View File

@ -31,7 +31,7 @@ string strip_empty_characters(string str, size_t max_length, bool strip_rtlo = f
// checks if string is empty after strip_empty_characters
bool is_empty_string(const string &str) TD_WARN_UNUSED_RESULT;
// calculates hash of list of uint32
// calculates hash of list of uint64
int64 get_vector_hash(const vector<uint64> &numbers) TD_WARN_UNUSED_RESULT;
// returns emoji corresponding to the specified number