Move get_months_by_star_count to StarManager.

This commit is contained in:
levlam 2024-07-30 13:51:53 +03:00
parent f2d5a2e3bf
commit de8dbf00b4
3 changed files with 11 additions and 9 deletions

View File

@ -5798,10 +5798,6 @@ static bool need_register_message_content_for_bots(MessageContentType content_ty
return content_type == MessageContentType::Poll; return content_type == MessageContentType::Poll;
} }
static int32 get_months_by_star_count(int64 star_count) {
return star_count <= 1000 ? 3 : (star_count < 2500 ? 6 : 12);
}
void register_message_content(Td *td, const MessageContent *content, MessageFullId message_full_id, void register_message_content(Td *td, const MessageContent *content, MessageFullId message_full_id,
const char *source) { const char *source) {
auto content_type = content->get_type(); auto content_type = content->get_type();
@ -5849,8 +5845,8 @@ void register_message_content(Td *td, const MessageContent *content, MessageFull
message_full_id, {}, source); message_full_id, {}, source);
case MessageContentType::GiftStars: { case MessageContentType::GiftStars: {
auto star_count = static_cast<const MessageGiftStars *>(content)->star_count; auto star_count = static_cast<const MessageGiftStars *>(content)->star_count;
return td->stickers_manager_->register_premium_gift(get_months_by_star_count(star_count), message_full_id, return td->stickers_manager_->register_premium_gift(StarManager::get_months_by_star_count(star_count),
source); message_full_id, source);
} }
default: default:
return; return;
@ -5984,8 +5980,8 @@ void unregister_message_content(Td *td, const MessageContent *content, MessageFu
message_full_id, {}, source); message_full_id, {}, source);
case MessageContentType::GiftStars: { case MessageContentType::GiftStars: {
auto star_count = static_cast<const MessageGiftStars *>(content)->star_count; auto star_count = static_cast<const MessageGiftStars *>(content)->star_count;
return td->stickers_manager_->unregister_premium_gift(get_months_by_star_count(star_count), message_full_id, return td->stickers_manager_->unregister_premium_gift(StarManager::get_months_by_star_count(star_count),
source); message_full_id, source);
} }
default: default:
return; return;
@ -7960,7 +7956,7 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
return td_api::make_object<td_api::messageGiftedStars>( return td_api::make_object<td_api::messageGiftedStars>(
gifter_user_id, receiver_user_id, m->currency, m->amount, m->crypto_currency, m->crypto_amount, m->star_count, gifter_user_id, receiver_user_id, m->currency, m->amount, m->crypto_currency, m->crypto_amount, m->star_count,
m->transaction_id, m->transaction_id,
td->stickers_manager_->get_premium_gift_sticker_object(get_months_by_star_count(m->star_count))); td->stickers_manager_->get_premium_gift_sticker_object(StarManager::get_months_by_star_count(m->star_count)));
} }
default: default:
UNREACHABLE(); UNREACHABLE();

View File

@ -666,4 +666,8 @@ int64 StarManager::get_star_count(int64 amount, bool allow_negative) {
return amount; return amount;
} }
int32 StarManager::get_months_by_star_count(int64 star_count) {
return star_count <= 1000 ? 3 : (star_count < 2500 ? 6 : 12);
}
} // namespace td } // namespace td

View File

@ -54,6 +54,8 @@ class StarManager final : public Actor {
static int64 get_star_count(int64 amount, bool allow_negative = false); static int64 get_star_count(int64 amount, bool allow_negative = false);
static int32 get_months_by_star_count(int64 star_count);
private: private:
void tear_down() final; void tear_down() final;