tdlight/td/telegram/EmojiGroup.cpp

89 lines
3.5 KiB
C++
Raw Normal View History

2023-01-24 16:11:02 +01:00
//
2024-01-01 01:07:21 +01:00
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
2023-01-24 16:11:02 +01:00
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include "td/telegram/EmojiGroup.h"
2023-03-06 14:59:18 +01:00
2023-02-09 20:47:44 +01:00
#include "td/telegram/StickersManager.h"
2023-01-24 16:11:02 +01:00
#include "td/utils/algorithm.h"
2023-03-06 18:36:56 +01:00
#include "td/utils/logging.h"
2023-01-24 16:11:02 +01:00
#include "td/utils/Time.h"
namespace td {
2024-04-21 20:57:10 +02:00
EmojiGroup::EmojiGroup(telegram_api::object_ptr<telegram_api::EmojiGroup> &&emoji_group_ptr) {
switch (emoji_group_ptr->get_id()) {
case telegram_api::emojiGroup::ID: {
auto emoji_group = telegram_api::move_object_as<telegram_api::emojiGroup>(emoji_group_ptr);
title_ = std::move(emoji_group->title_);
icon_custom_emoji_id_ = CustomEmojiId(emoji_group->icon_emoji_id_);
emojis_ = std::move(emoji_group->emoticons_);
break;
}
case telegram_api::emojiGroupGreeting::ID: {
auto emoji_group = telegram_api::move_object_as<telegram_api::emojiGroupGreeting>(emoji_group_ptr);
title_ = std::move(emoji_group->title_);
icon_custom_emoji_id_ = CustomEmojiId(emoji_group->icon_emoji_id_);
emojis_ = std::move(emoji_group->emoticons_);
break;
}
case telegram_api::emojiGroupPremium::ID: {
auto emoji_group = telegram_api::move_object_as<telegram_api::emojiGroupPremium>(emoji_group_ptr);
title_ = std::move(emoji_group->title_);
icon_custom_emoji_id_ = CustomEmojiId(emoji_group->icon_emoji_id_);
break;
}
default:
UNREACHABLE();
}
2023-01-24 16:11:02 +01:00
}
2023-02-09 20:47:44 +01:00
td_api::object_ptr<td_api::emojiCategory> EmojiGroup::get_emoji_category_object(
StickersManager *stickers_manager) const {
return td_api::make_object<td_api::emojiCategory>(
title_, stickers_manager->get_custom_emoji_sticker_object(icon_custom_emoji_id_), vector<string>(emojis_));
2023-01-24 16:11:02 +01:00
}
2023-01-25 14:23:34 +01:00
EmojiGroupList::EmojiGroupList(string used_language_codes, int32 hash,
2024-04-21 20:57:10 +02:00
vector<telegram_api::object_ptr<telegram_api::EmojiGroup>> &&emoji_groups)
2023-01-24 16:11:02 +01:00
: used_language_codes_(std::move(used_language_codes))
, hash_(hash)
, emoji_groups_(transform(std::move(emoji_groups),
2024-04-21 20:57:10 +02:00
[](telegram_api::object_ptr<telegram_api::EmojiGroup> &&emoji_group) {
2023-01-24 16:11:02 +01:00
return EmojiGroup(std::move(emoji_group));
}))
, next_reload_time_(Time::now() + 3600) {
}
2023-02-09 20:47:44 +01:00
td_api::object_ptr<td_api::emojiCategories> EmojiGroupList::get_emoji_categories_object(
StickersManager *stickers_manager) const {
auto emoji_categories = transform(emoji_groups_, [stickers_manager](const EmojiGroup &emoji_group) {
return emoji_group.get_emoji_category_object(stickers_manager);
});
td::remove_if(emoji_categories, [](const td_api::object_ptr<td_api::emojiCategory> &emoji_category) {
if (emoji_category->icon_ == nullptr) {
LOG(ERROR) << "Failed to get icon for emoji category " << emoji_category->name_;
return true;
}
return false;
});
return td_api::make_object<td_api::emojiCategories>(std::move(emoji_categories));
2023-01-24 16:11:02 +01:00
}
bool EmojiGroupList::is_expired() const {
return next_reload_time_ < Time::now();
}
void EmojiGroupList::update_next_reload_time() {
next_reload_time_ = Time::now() + 3600;
}
2023-02-09 20:47:44 +01:00
vector<CustomEmojiId> EmojiGroupList::get_icon_custom_emoji_ids() const {
return transform(emoji_groups_, [](const EmojiGroup &emoji_group) { return emoji_group.get_icon_custom_emoji_id(); });
}
2023-01-24 16:11:02 +01:00
} // namespace td