2023-01-24 16:11:02 +01:00
|
|
|
//
|
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
|
|
|
//
|
|
|
|
// 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 {
|
|
|
|
|
|
|
|
EmojiGroup::EmojiGroup(telegram_api::object_ptr<telegram_api::emojiGroup> &&emoji_group)
|
|
|
|
: title_(std::move(emoji_group->title_))
|
|
|
|
, icon_custom_emoji_id_(emoji_group->icon_emoji_id_)
|
|
|
|
, emojis_(std::move(emoji_group->emoticons_)) {
|
|
|
|
}
|
|
|
|
|
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,
|
2023-01-24 16:11:02 +01:00
|
|
|
vector<telegram_api::object_ptr<telegram_api::emojiGroup>> &&emoji_groups)
|
|
|
|
: used_language_codes_(std::move(used_language_codes))
|
|
|
|
, hash_(hash)
|
|
|
|
, emoji_groups_(transform(std::move(emoji_groups),
|
|
|
|
[](telegram_api::object_ptr<telegram_api::emojiGroup> &&emoji_group) {
|
|
|
|
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
|