Don't add themed premium statuses to recent.

This commit is contained in:
levlam 2022-09-02 15:39:07 +03:00
parent 2eba57276a
commit 03af40bc08
5 changed files with 39 additions and 5 deletions

View File

@ -6629,7 +6629,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);
add_recent_emoji_status(td_, 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

@ -8,6 +8,7 @@
#include "td/telegram/Global.h"
#include "td/telegram/logevent/LogEvent.h"
#include "td/telegram/StickersManager.h"
#include "td/telegram/Td.h"
#include "td/telegram/TdDb.h"
@ -292,11 +293,16 @@ 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) {
void add_recent_emoji_status(Td *td, EmojiStatus emoji_status) {
if (emoji_status.is_empty()) {
return;
}
if (td->stickers_manager_->is_default_emoji_status(emoji_status.get_custom_emoji_id())) {
LOG(INFO) << "Skip adding themed premium status to recents";
return;
}
emoji_status.clear_until_date();
auto statuses = load_emoji_statuses(get_recent_emoji_statuses_database_key());
if (!statuses.emoji_statuses_.empty() && statuses.emoji_statuses_[0] == emoji_status) {

View File

@ -43,6 +43,10 @@ class EmojiStatus {
return custom_emoji_id_ == 0;
}
int64 get_custom_emoji_id() const {
return custom_emoji_id_;
}
int32 get_until_date() const {
return until_date_;
}
@ -53,11 +57,15 @@ class EmojiStatus {
template <class StorerT>
void store(StorerT &storer) const {
bool has_custom_emoji_id = custom_emoji_id_ != 0;
bool has_until_date = until_date_ != 0;
BEGIN_STORE_FLAGS();
STORE_FLAG(has_custom_emoji_id);
STORE_FLAG(has_until_date);
END_STORE_FLAGS();
td::store(custom_emoji_id_, storer);
if (has_custom_emoji_id) {
td::store(custom_emoji_id_, storer);
}
if (has_until_date) {
td::store(until_date_, storer);
}
@ -65,11 +73,15 @@ class EmojiStatus {
template <class ParserT>
void parse(ParserT &parser) {
bool has_custom_emoji_id;
bool has_until_date;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(has_custom_emoji_id);
PARSE_FLAG(has_until_date);
END_PARSE_FLAGS();
td::parse(custom_emoji_id_, parser);
if (has_custom_emoji_id) {
td::parse(custom_emoji_id_, parser);
}
if (has_until_date) {
td::parse(until_date_, parser);
}
@ -90,7 +102,7 @@ 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 add_recent_emoji_status(Td *td, EmojiStatus emoji_status);
void clear_recent_emoji_statuses(Td *td, Promise<Unit> &&promise);

View File

@ -5496,6 +5496,20 @@ void StickersManager::get_default_emoji_statuses(bool is_recursive,
promise.set_value(td_api::make_object<td_api::premiumStatuses>(std::move(statuses)));
}
bool StickersManager::is_default_emoji_status(int64 custom_emoji_id) {
auto &special_sticker_set = add_special_sticker_set(SpecialStickerSetType::default_statuses());
auto sticker_set = get_sticker_set(special_sticker_set.id_);
if (sticker_set == nullptr || !sticker_set->was_loaded_) {
return false;
}
for (auto sticker_id : sticker_set->sticker_ids_) {
if (get_custom_emoji_id(sticker_id) == custom_emoji_id) {
return true;
}
}
return false;
}
void StickersManager::load_custom_emoji_sticker_from_database(int64 custom_emoji_id, Promise<Unit> &&promise) {
CHECK(custom_emoji_id != 0);
auto &queries = custom_emoji_load_queries_[custom_emoji_id];

View File

@ -105,6 +105,8 @@ class StickersManager final : public Actor {
void get_default_emoji_statuses(bool is_recursive, Promise<td_api::object_ptr<td_api::premiumStatuses>> &&promise);
bool is_default_emoji_status(int64 custom_emoji_id);
void get_custom_emoji_stickers(vector<int64> &&document_ids, bool use_database,
Promise<td_api::object_ptr<td_api::stickers>> &&promise);