Add getForumTopicDefaultIcons.

This commit is contained in:
levlam 2022-10-27 10:06:13 +03:00
parent ac144ce2e4
commit e33dac507d
9 changed files with 63 additions and 2 deletions

View File

@ -5291,7 +5291,11 @@ editInlineMessageReplyMarkup inline_message_id:string reply_markup:ReplyMarkup =
editMessageSchedulingState chat_id:int53 message_id:int53 scheduling_state:MessageSchedulingState = Ok;
//@description Creates a topic in a forum supergroup chat; requires can_manage_topics rights in the supergroup @chat_id Identifier of the chat @title Title of the topic @icon Icon of the topic. Icon color must be one of 0x6FB9F0, 0xFFD67E, 0xCB86DB, 0x8EEE98, 0xFF93B2, or 0xFB6F5F. Icon custom emoji can be added only by Telegram Premium users
//@description Returns list of custom emojis, which can be used as forum topic icon by all users
getForumTopicDefaultIcons = Stickers;
//@description Creates a topic in a forum supergroup chat; requires can_manage_topics rights in the supergroup @chat_id Identifier of the chat @title Title of the topic
//@icon Icon of the topic. Icon color must be one of 0x6FB9F0, 0xFFD67E, 0xCB86DB, 0x8EEE98, 0xFF93B2, or 0xFB6F5F. Telegram Premium users can use any custom emoji as topic icon, other users can use only a custom emoji returned by getForumTopicDefaultIcons
createForumTopic chat_id:int53 title:string icon:forumTopicIcon = ForumTopicInfo;

View File

@ -37,6 +37,10 @@ SpecialStickerSetType SpecialStickerSetType::default_statuses() {
return SpecialStickerSetType("default_statuses_sticker_set");
}
SpecialStickerSetType SpecialStickerSetType::default_topic_icons() {
return SpecialStickerSetType("default_topic_icons_sticker_set");
}
SpecialStickerSetType::SpecialStickerSetType(
const telegram_api::object_ptr<telegram_api::InputStickerSet> &input_sticker_set) {
CHECK(input_sticker_set != nullptr);
@ -60,7 +64,7 @@ SpecialStickerSetType::SpecialStickerSetType(
*this = default_statuses();
break;
case telegram_api::inputStickerSetEmojiDefaultTopicIcons::ID:
*this = default_statuses();
*this = default_topic_icons();
break;
default:
UNREACHABLE();
@ -92,6 +96,9 @@ telegram_api::object_ptr<telegram_api::InputStickerSet> SpecialStickerSetType::g
if (*this == default_statuses()) {
return telegram_api::make_object<telegram_api::inputStickerSetEmojiDefaultStatuses>();
}
if (*this == default_topic_icons()) {
return telegram_api::make_object<telegram_api::inputStickerSetEmojiDefaultTopicIcons>();
}
auto emoji = get_dice_emoji();
if (!emoji.empty()) {
return telegram_api::make_object<telegram_api::inputStickerSetDice>(emoji);

View File

@ -35,6 +35,8 @@ class SpecialStickerSetType {
static SpecialStickerSetType default_statuses();
static SpecialStickerSetType default_topic_icons();
string get_dice_emoji() const;
bool is_empty() const {

View File

@ -1518,6 +1518,10 @@ void StickersManager::init() {
auto &sticker_set = add_special_sticker_set(SpecialStickerSetType::default_statuses());
load_special_sticker_set_info_from_binlog(sticker_set);
}
{
auto &sticker_set = add_special_sticker_set(SpecialStickerSetType::default_topic_icons());
load_special_sticker_set_info_from_binlog(sticker_set);
}
dice_emojis_str_ =
td_->option_manager_->get_option_string("dice_emojis", "🎲\x01🎯\x01🏀\x01\x01⚽️\x01🎰\x01🎳");
@ -1828,6 +1832,10 @@ void StickersManager::on_load_special_sticker_set(const SpecialStickerSetType &t
set_promises(pending_get_default_statuses_queries_);
return;
}
if (type == SpecialStickerSetType::default_topic_icons()) {
set_promises(pending_get_default_topic_icons_queries_);
return;
}
CHECK(special_sticker_set.id_.is_valid());
auto sticker_set = get_sticker_set(special_sticker_set.id_);
@ -5935,6 +5943,32 @@ bool StickersManager::is_default_emoji_status(CustomEmojiId custom_emoji_id) {
return false;
}
void StickersManager::get_default_topic_icons(bool is_recursive,
Promise<td_api::object_ptr<td_api::stickers>> &&promise) {
TRY_STATUS_PROMISE(promise, G()->close_status());
auto &special_sticker_set = add_special_sticker_set(SpecialStickerSetType::default_topic_icons());
auto sticker_set = get_sticker_set(special_sticker_set.id_);
if (sticker_set == nullptr || !sticker_set->was_loaded_) {
if (is_recursive) {
return promise.set_value(td_api::make_object<td_api::stickers>());
}
pending_get_default_topic_icons_queries_.push_back(PromiseCreator::lambda(
[actor_id = actor_id(this), promise = std::move(promise)](Result<Unit> &&result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {
send_closure(actor_id, &StickersManager::get_default_topic_icons, true, std::move(promise));
}
}));
load_special_sticker_set(special_sticker_set);
return;
}
promise.set_value(get_stickers_object(sticker_set->sticker_ids_));
}
void StickersManager::load_custom_emoji_sticker_from_database_force(CustomEmojiId custom_emoji_id) {
if (!G()->parameters().use_file_db) {
return;

View File

@ -116,6 +116,8 @@ class StickersManager final : public Actor {
bool is_default_emoji_status(CustomEmojiId custom_emoji_id);
void get_default_topic_icons(bool is_recursive, Promise<td_api::object_ptr<td_api::stickers>> &&promise);
void get_custom_emoji_stickers(vector<CustomEmojiId> &&custom_emoji_ids, bool use_database,
Promise<td_api::object_ptr<td_api::stickers>> &&promise);
@ -1046,6 +1048,7 @@ class StickersManager final : public Actor {
vector<Promise<Unit>> pending_get_premium_gift_option_sticker_queries_;
vector<Promise<Unit>> pending_get_generic_animations_queries_;
vector<Promise<Unit>> pending_get_default_statuses_queries_;
vector<Promise<Unit>> pending_get_default_topic_icons_queries_;
double next_click_animated_emoji_message_time_ = 0;
double next_update_animated_emoji_clicked_time_ = 0;

View File

@ -5509,6 +5509,12 @@ void Td::on_request(uint64 id, td_api::editMessageSchedulingState &request) {
std::move(request.scheduling_state_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getForumTopicDefaultIcons &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
stickers_manager_->get_default_topic_icons(false, std::move(promise));
}
void Td::on_request(uint64 id, td_api::createForumTopic &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.title_);

View File

@ -730,6 +730,8 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::editMessageSchedulingState &request);
void on_request(uint64 id, const td_api::getForumTopicDefaultIcons &request);
void on_request(uint64 id, td_api::createForumTopic &request);
void on_request(uint64 id, td_api::setGameScore &request);

View File

@ -1795,6 +1795,7 @@ void UpdatesManager::try_reload_data() {
td_->stickers_manager_->reload_special_sticker_set_by_type(SpecialStickerSetType::premium_gifts());
td_->stickers_manager_->reload_special_sticker_set_by_type(SpecialStickerSetType::generic_animations());
td_->stickers_manager_->reload_special_sticker_set_by_type(SpecialStickerSetType::default_statuses());
td_->stickers_manager_->reload_special_sticker_set_by_type(SpecialStickerSetType::default_topic_icons());
schedule_data_reload();
}

View File

@ -3842,6 +3842,8 @@ class CliClient final : public Actor {
get_args(args, chat_id, message_id, date);
send_request(td_api::make_object<td_api::editMessageSchedulingState>(chat_id, message_id,
as_message_scheduling_state(date)));
} else if (op == "gftdi") {
send_request(td_api::make_object<td_api::getForumTopicDefaultIcons>());
} else if (op == "cft") {
ChatId chat_id;
string title;