Register GiftPremium messages.
This commit is contained in:
parent
da7d302dec
commit
61fe5d0df5
@ -3817,6 +3817,9 @@ void register_message_content(Td *td, const MessageContent *content, FullMessage
|
||||
auto dice = static_cast<const MessageDice *>(content);
|
||||
return td->stickers_manager_->register_dice(dice->emoji, dice->dice_value, full_message_id, source);
|
||||
}
|
||||
case MessageContentType::GiftPremium:
|
||||
return td->stickers_manager_->register_gift_premium(static_cast<const MessageGiftPremium *>(content)->months,
|
||||
full_message_id, source);
|
||||
default:
|
||||
return;
|
||||
}
|
||||
@ -3858,6 +3861,12 @@ void reregister_message_content(Td *td, const MessageContent *old_content, const
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case MessageContentType::GiftPremium:
|
||||
if (static_cast<const MessageGiftPremium *>(old_content)->months ==
|
||||
static_cast<const MessageGiftPremium *>(new_content)->months) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
@ -3888,6 +3897,9 @@ void unregister_message_content(Td *td, const MessageContent *content, FullMessa
|
||||
auto dice = static_cast<const MessageDice *>(content);
|
||||
return td->stickers_manager_->unregister_dice(dice->emoji, dice->dice_value, full_message_id, source);
|
||||
}
|
||||
case MessageContentType::GiftPremium:
|
||||
return td->stickers_manager_->unregister_gift_premium(static_cast<const MessageGiftPremium *>(content)->months,
|
||||
full_message_id, source);
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
@ -1367,10 +1367,11 @@ StickersManager::StickersManager(Td *td, ActorShared<> parent) : td_(td), parent
|
||||
}
|
||||
|
||||
StickersManager::~StickersManager() {
|
||||
Scheduler::instance()->destroy_on_scheduler(
|
||||
G()->get_gc_scheduler_id(), stickers_, sticker_sets_, short_name_to_sticker_set_id_, attached_sticker_sets_,
|
||||
found_stickers_, found_sticker_sets_, emoji_language_codes_, emoji_language_code_versions_,
|
||||
emoji_language_code_last_difference_times_, reloaded_emoji_keywords_, dice_messages_, emoji_messages_);
|
||||
Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), stickers_, sticker_sets_,
|
||||
short_name_to_sticker_set_id_, attached_sticker_sets_, found_stickers_,
|
||||
found_sticker_sets_, emoji_language_codes_, emoji_language_code_versions_,
|
||||
emoji_language_code_last_difference_times_, reloaded_emoji_keywords_,
|
||||
gift_premium_messages_, dice_messages_, emoji_messages_);
|
||||
}
|
||||
|
||||
void StickersManager::start_up() {
|
||||
@ -4799,6 +4800,50 @@ void StickersManager::try_update_animated_emoji_messages() {
|
||||
}
|
||||
}
|
||||
|
||||
void StickersManager::register_gift_premium(int32 months, FullMessageId full_message_id, const char *source) {
|
||||
if (td_->auth_manager_->is_bot() || months == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOG(INFO) << "Register premium gift for " << months << " months from " << full_message_id << " from " << source;
|
||||
bool is_inserted = gift_premium_messages_[months].insert(full_message_id).second;
|
||||
LOG_CHECK(is_inserted) << source << " " << months << " " << full_message_id;
|
||||
|
||||
auto &special_sticker_set = add_special_sticker_set(SpecialStickerSetType::premium_gifts());
|
||||
bool need_load = false;
|
||||
StickerSet *sticker_set = nullptr;
|
||||
if (!special_sticker_set.id_.is_valid()) {
|
||||
need_load = true;
|
||||
} else {
|
||||
sticker_set = get_sticker_set(special_sticker_set.id_);
|
||||
CHECK(sticker_set != nullptr);
|
||||
need_load = !sticker_set->was_loaded;
|
||||
}
|
||||
|
||||
if (need_load) {
|
||||
LOG(INFO) << "Waiting for a premium gifts sticker set needed in " << full_message_id;
|
||||
load_special_sticker_set(special_sticker_set);
|
||||
} else {
|
||||
// TODO reload once in a while
|
||||
// reload_special_sticker_set(special_sticker_set, sticker_set->is_loaded ? sticker_set->hash : 0);
|
||||
}
|
||||
}
|
||||
|
||||
void StickersManager::unregister_gift_premium(int32 months, FullMessageId full_message_id, const char *source) {
|
||||
if (td_->auth_manager_->is_bot() || months == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOG(INFO) << "Unregister premium gift for " << months << " months from " << full_message_id << " from " << source;
|
||||
auto &message_ids = gift_premium_messages_[months];
|
||||
auto is_deleted = message_ids.erase(full_message_id) > 0;
|
||||
LOG_CHECK(is_deleted) << source << " " << months << " " << full_message_id;
|
||||
|
||||
if (message_ids.empty()) {
|
||||
gift_premium_messages_.erase(months);
|
||||
}
|
||||
}
|
||||
|
||||
void StickersManager::register_dice(const string &emoji, int32 value, FullMessageId full_message_id,
|
||||
const char *source) {
|
||||
CHECK(!emoji.empty());
|
||||
|
@ -80,6 +80,10 @@ class StickersManager final : public Actor {
|
||||
|
||||
tl_object_ptr<telegram_api::InputStickerSet> get_input_sticker_set(StickerSetId sticker_set_id) const;
|
||||
|
||||
void register_gift_premium(int32 months, FullMessageId full_message_id, const char *source);
|
||||
|
||||
void unregister_gift_premium(int32 months, FullMessageId full_message_id, const char *source);
|
||||
|
||||
void register_dice(const string &emoji, int32 value, FullMessageId full_message_id, const char *source);
|
||||
|
||||
void unregister_dice(const string &emoji, int32 value, FullMessageId full_message_id, const char *source);
|
||||
@ -937,6 +941,8 @@ class StickersManager final : public Actor {
|
||||
FlatHashMap<string, vector<Promise<Unit>>> load_language_codes_queries_;
|
||||
FlatHashMap<int64, string> emoji_suggestions_urls_;
|
||||
|
||||
FlatHashMap<int32, FlatHashSet<FullMessageId, FullMessageIdHash>> gift_premium_messages_;
|
||||
|
||||
FlatHashMap<string, FlatHashSet<FullMessageId, FullMessageIdHash>> dice_messages_;
|
||||
|
||||
struct EmojiMessages {
|
||||
|
Loading…
Reference in New Issue
Block a user