Add class CustomEmojiId.
This commit is contained in:
parent
197d1de31b
commit
aa6ed42734
@ -517,6 +517,7 @@ set(TDLIB_SOURCE
|
||||
td/telegram/Contact.h
|
||||
td/telegram/ContactsManager.h
|
||||
td/telegram/CountryInfoManager.h
|
||||
td/telegram/CustomEmojiId.h
|
||||
td/telegram/DelayDispatcher.h
|
||||
td/telegram/Dependencies.h
|
||||
td/telegram/DeviceTokenManager.h
|
||||
|
@ -10397,7 +10397,7 @@ void ContactsManager::update_user(User *u, UserId user_id, bool from_binlog, boo
|
||||
} else {
|
||||
u->need_save_to_database = true;
|
||||
}
|
||||
if (u->last_sent_emoji_status != 0) {
|
||||
if (u->last_sent_emoji_status.is_valid()) {
|
||||
auto until_date = u->emoji_status.get_until_date();
|
||||
auto left_time = until_date - unix_time;
|
||||
if (left_time >= 0 && left_time < 30 * 86400) {
|
||||
@ -16832,7 +16832,7 @@ tl_object_ptr<td_api::user> ContactsManager::get_user_object(UserId user_id, con
|
||||
type = make_tl_object<td_api::userTypeRegular>();
|
||||
}
|
||||
|
||||
auto emoji_status = u->last_sent_emoji_status != 0 ? u->emoji_status.get_emoji_status_object() : nullptr;
|
||||
auto emoji_status = u->last_sent_emoji_status.is_valid() ? u->emoji_status.get_emoji_status_object() : nullptr;
|
||||
return make_tl_object<td_api::user>(
|
||||
user_id.get(), u->first_name, u->last_name, u->username, u->phone_number, get_user_status_object(user_id, u),
|
||||
get_profile_photo_object(td_->file_manager_.get(), u->photo), std::move(emoji_status), u->is_contact,
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "td/telegram/ChannelType.h"
|
||||
#include "td/telegram/ChatId.h"
|
||||
#include "td/telegram/Contact.h"
|
||||
#include "td/telegram/CustomEmojiId.h"
|
||||
#include "td/telegram/DialogAdministrator.h"
|
||||
#include "td/telegram/DialogId.h"
|
||||
#include "td/telegram/DialogInviteLink.h"
|
||||
@ -646,7 +647,7 @@ class ContactsManager final : public Actor {
|
||||
string phone_number;
|
||||
int64 access_hash = -1;
|
||||
EmojiStatus emoji_status;
|
||||
int64 last_sent_emoji_status = 0;
|
||||
CustomEmojiId last_sent_emoji_status;
|
||||
|
||||
ProfilePhoto photo;
|
||||
|
||||
|
65
td/telegram/CustomEmojiId.h
Normal file
65
td/telegram/CustomEmojiId.h
Normal file
@ -0,0 +1,65 @@
|
||||
//
|
||||
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/StringBuilder.h"
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
|
||||
namespace td {
|
||||
|
||||
class CustomEmojiId {
|
||||
int64 id = 0;
|
||||
|
||||
public:
|
||||
CustomEmojiId() = default;
|
||||
|
||||
explicit CustomEmojiId(int64 custom_emoji_id) : id(custom_emoji_id) {
|
||||
}
|
||||
template <class T, typename = std::enable_if_t<std::is_convertible<T, int64>::value>>
|
||||
CustomEmojiId(T custom_emoji_id) = delete;
|
||||
|
||||
bool is_valid() const {
|
||||
return id != 0;
|
||||
}
|
||||
|
||||
int64 get() const {
|
||||
return id;
|
||||
}
|
||||
|
||||
bool operator==(const CustomEmojiId &other) const {
|
||||
return id == other.id;
|
||||
}
|
||||
|
||||
bool operator!=(const CustomEmojiId &other) const {
|
||||
return id != other.id;
|
||||
}
|
||||
|
||||
template <class StorerT>
|
||||
void store(StorerT &storer) const {
|
||||
storer.store_long(id);
|
||||
}
|
||||
|
||||
template <class ParserT>
|
||||
void parse(ParserT &parser) {
|
||||
id = parser.fetch_long();
|
||||
}
|
||||
};
|
||||
|
||||
struct CustomEmojiIdHash {
|
||||
std::size_t operator()(CustomEmojiId custom_emoji_id) const {
|
||||
return std::hash<int64>()(custom_emoji_id.get());
|
||||
}
|
||||
};
|
||||
|
||||
inline StringBuilder &operator<<(StringBuilder &string_builder, CustomEmojiId custom_emoji_id) {
|
||||
return string_builder << "custom emoji " << custom_emoji_id.get();
|
||||
}
|
||||
|
||||
} // namespace td
|
@ -203,7 +203,7 @@ EmojiStatus::EmojiStatus(const td_api::object_ptr<td_api::emojiStatus> &emoji_st
|
||||
return;
|
||||
}
|
||||
|
||||
custom_emoji_id_ = emoji_status->custom_emoji_id_;
|
||||
custom_emoji_id_ = CustomEmojiId(emoji_status->custom_emoji_id_);
|
||||
if (duration != 0) {
|
||||
int32 current_time = G()->unix_time();
|
||||
if (duration >= std::numeric_limits<int32>::max() - current_time) {
|
||||
@ -223,12 +223,12 @@ EmojiStatus::EmojiStatus(tl_object_ptr<telegram_api::EmojiStatus> &&emoji_status
|
||||
break;
|
||||
case telegram_api::emojiStatus::ID: {
|
||||
auto status = static_cast<const telegram_api::emojiStatus *>(emoji_status.get());
|
||||
custom_emoji_id_ = status->document_id_;
|
||||
custom_emoji_id_ = CustomEmojiId(status->document_id_);
|
||||
break;
|
||||
}
|
||||
case telegram_api::emojiStatusUntil::ID: {
|
||||
auto status = static_cast<const telegram_api::emojiStatusUntil *>(emoji_status.get());
|
||||
custom_emoji_id_ = status->document_id_;
|
||||
custom_emoji_id_ = CustomEmojiId(status->document_id_);
|
||||
until_date_ = status->until_;
|
||||
break;
|
||||
}
|
||||
@ -242,24 +242,24 @@ tl_object_ptr<telegram_api::EmojiStatus> EmojiStatus::get_input_emoji_status() c
|
||||
return make_tl_object<telegram_api::emojiStatusEmpty>();
|
||||
}
|
||||
if (until_date_ != 0) {
|
||||
return make_tl_object<telegram_api::emojiStatusUntil>(custom_emoji_id_, until_date_);
|
||||
return make_tl_object<telegram_api::emojiStatusUntil>(custom_emoji_id_.get(), until_date_);
|
||||
}
|
||||
return make_tl_object<telegram_api::emojiStatus>(custom_emoji_id_);
|
||||
return make_tl_object<telegram_api::emojiStatus>(custom_emoji_id_.get());
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::emojiStatus> EmojiStatus::get_emoji_status_object() const {
|
||||
if (is_empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
return td_api::make_object<td_api::emojiStatus>(custom_emoji_id_);
|
||||
return td_api::make_object<td_api::emojiStatus>(custom_emoji_id_.get());
|
||||
}
|
||||
|
||||
int64 EmojiStatus::get_effective_custom_emoji_id(bool is_premium, int32 unix_time) const {
|
||||
CustomEmojiId EmojiStatus::get_effective_custom_emoji_id(bool is_premium, int32 unix_time) const {
|
||||
if (!is_premium) {
|
||||
return 0;
|
||||
return CustomEmojiId();
|
||||
}
|
||||
if (until_date_ != 0 && until_date_ <= unix_time) {
|
||||
return 0;
|
||||
return CustomEmojiId();
|
||||
}
|
||||
return custom_emoji_id_;
|
||||
}
|
||||
@ -268,7 +268,7 @@ StringBuilder &operator<<(StringBuilder &string_builder, const EmojiStatus &emoj
|
||||
if (emoji_status.is_empty()) {
|
||||
return string_builder << "DefaultProfileBadge";
|
||||
}
|
||||
string_builder << "CustomEmoji " << emoji_status.custom_emoji_id_;
|
||||
string_builder << emoji_status.custom_emoji_id_;
|
||||
if (emoji_status.until_date_ != 0) {
|
||||
string_builder << " until " << emoji_status.until_date_;
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "td/telegram/CustomEmojiId.h"
|
||||
#include "td/telegram/td_api.h"
|
||||
#include "td/telegram/telegram_api.h"
|
||||
|
||||
@ -19,7 +20,7 @@ namespace td {
|
||||
class Td;
|
||||
|
||||
class EmojiStatus {
|
||||
int64 custom_emoji_id_ = 0;
|
||||
CustomEmojiId custom_emoji_id_;
|
||||
int32 until_date_ = 0;
|
||||
|
||||
friend bool operator==(const EmojiStatus &lhs, const EmojiStatus &rhs);
|
||||
@ -37,13 +38,13 @@ class EmojiStatus {
|
||||
|
||||
td_api::object_ptr<td_api::emojiStatus> get_emoji_status_object() const;
|
||||
|
||||
int64 get_effective_custom_emoji_id(bool is_premium, int32 unix_time) const;
|
||||
CustomEmojiId get_effective_custom_emoji_id(bool is_premium, int32 unix_time) const;
|
||||
|
||||
bool is_empty() const {
|
||||
return custom_emoji_id_ == 0;
|
||||
return !custom_emoji_id_.is_valid();
|
||||
}
|
||||
|
||||
int64 get_custom_emoji_id() const {
|
||||
CustomEmojiId get_custom_emoji_id() const {
|
||||
return custom_emoji_id_;
|
||||
}
|
||||
|
||||
@ -57,7 +58,7 @@ class EmojiStatus {
|
||||
|
||||
template <class StorerT>
|
||||
void store(StorerT &storer) const {
|
||||
bool has_custom_emoji_id = custom_emoji_id_ != 0;
|
||||
bool has_custom_emoji_id = custom_emoji_id_.is_valid();
|
||||
bool has_until_date = until_date_ != 0;
|
||||
BEGIN_STORE_FLAGS();
|
||||
STORE_FLAG(has_custom_emoji_id);
|
||||
|
@ -1690,7 +1690,7 @@ UserId LinkManager::get_link_user_id(Slice url) {
|
||||
return UserId();
|
||||
}
|
||||
|
||||
Result<int64> LinkManager::get_link_custom_emoji_document_id(Slice url) {
|
||||
Result<CustomEmojiId> LinkManager::get_link_custom_emoji_id(Slice url) {
|
||||
string lower_cased_url = to_lower(url);
|
||||
url = lower_cased_url;
|
||||
|
||||
@ -1726,7 +1726,7 @@ Result<int64> LinkManager::get_link_custom_emoji_document_id(Slice url) {
|
||||
if (r_document_id.is_error() || r_document_id.ok() == 0) {
|
||||
return Status::Error(400, "Invalid custom emoji identifier specified");
|
||||
}
|
||||
return r_document_id.ok();
|
||||
return CustomEmojiId(r_document_id.ok());
|
||||
}
|
||||
}
|
||||
return Status::Error(400, "Custom emoji URL must have an emoji identifier");
|
||||
|
@ -6,6 +6,7 @@
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "td/telegram/CustomEmojiId.h"
|
||||
#include "td/telegram/FullMessageId.h"
|
||||
#include "td/telegram/MessageLinkInfo.h"
|
||||
#include "td/telegram/td_api.h"
|
||||
@ -86,7 +87,7 @@ class LinkManager final : public Actor {
|
||||
|
||||
static UserId get_link_user_id(Slice url);
|
||||
|
||||
static Result<int64> get_link_custom_emoji_document_id(Slice url);
|
||||
static Result<CustomEmojiId> get_link_custom_emoji_id(Slice url);
|
||||
|
||||
static Result<MessageLinkInfo> get_message_link_info(Slice url);
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "td/telegram/ChatId.h"
|
||||
#include "td/telegram/Contact.h"
|
||||
#include "td/telegram/ContactsManager.h"
|
||||
#include "td/telegram/CustomEmojiId.h"
|
||||
#include "td/telegram/Dependencies.h"
|
||||
#include "td/telegram/DialogAction.h"
|
||||
#include "td/telegram/DialogParticipant.h"
|
||||
@ -3810,14 +3811,14 @@ static bool can_be_animated_emoji(const FormattedText &text) {
|
||||
}
|
||||
if (text.entities.size() == 1 && text.entities[0].type == MessageEntity::Type::CustomEmoji &&
|
||||
text.entities[0].offset == 0 && static_cast<size_t>(text.entities[0].length) == utf8_utf16_length(text.text) &&
|
||||
text.entities[0].document_id != 0) {
|
||||
text.entities[0].custom_emoji_id.is_valid()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static int64 get_custom_emoji_id(const FormattedText &text) {
|
||||
return text.entities.empty() ? 0 : text.entities[0].document_id;
|
||||
static CustomEmojiId get_custom_emoji_id(const FormattedText &text) {
|
||||
return text.entities.empty() ? CustomEmojiId() : text.entities[0].custom_emoji_id;
|
||||
}
|
||||
|
||||
void register_message_content(Td *td, const MessageContent *content, FullMessageId full_message_id,
|
||||
@ -5995,10 +5996,10 @@ void move_message_content_sticker_set_to_top(Td *td, const MessageContent *conte
|
||||
if (text == nullptr) {
|
||||
return;
|
||||
}
|
||||
vector<int64> custom_emoji_ids;
|
||||
vector<CustomEmojiId> custom_emoji_ids;
|
||||
for (auto &entity : text->entities) {
|
||||
if (entity.type == MessageEntity::Type::CustomEmoji) {
|
||||
custom_emoji_ids.push_back(entity.document_id);
|
||||
custom_emoji_ids.push_back(entity.custom_emoji_id);
|
||||
}
|
||||
}
|
||||
if (!custom_emoji_ids.empty()) {
|
||||
|
@ -122,8 +122,8 @@ StringBuilder &operator<<(StringBuilder &string_builder, const MessageEntity &me
|
||||
if (message_entity.user_id.is_valid()) {
|
||||
string_builder << ", " << message_entity.user_id;
|
||||
}
|
||||
if (message_entity.document_id != 0) {
|
||||
string_builder << ", emoji = " << message_entity.document_id;
|
||||
if (message_entity.custom_emoji_id.is_valid()) {
|
||||
string_builder << ", " << message_entity.custom_emoji_id;
|
||||
}
|
||||
string_builder << ']';
|
||||
return string_builder;
|
||||
@ -173,7 +173,7 @@ tl_object_ptr<td_api::TextEntityType> MessageEntity::get_text_entity_type_object
|
||||
case MessageEntity::Type::Spoiler:
|
||||
return make_tl_object<td_api::textEntityTypeSpoiler>();
|
||||
case MessageEntity::Type::CustomEmoji:
|
||||
return make_tl_object<td_api::textEntityTypeCustomEmoji>(document_id);
|
||||
return make_tl_object<td_api::textEntityTypeCustomEmoji>(custom_emoji_id.get());
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return nullptr;
|
||||
@ -1421,7 +1421,7 @@ void remove_empty_entities(vector<MessageEntity> &entities) {
|
||||
case MessageEntity::Type::MentionName:
|
||||
return !entity.user_id.is_valid();
|
||||
case MessageEntity::Type::CustomEmoji:
|
||||
return entity.document_id == 0;
|
||||
return !entity.custom_emoji_id.is_valid();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@ -2126,7 +2126,7 @@ static Result<vector<MessageEntity>> do_parse_markdown_v2(CSlice text, string &r
|
||||
auto type = nested_entities.back().type;
|
||||
auto argument = std::move(nested_entities.back().argument);
|
||||
UserId user_id;
|
||||
int64 document_id = 0;
|
||||
CustomEmojiId custom_emoji_id;
|
||||
bool skip_entity = utf16_offset == nested_entities.back().entity_offset;
|
||||
switch (type) {
|
||||
case MessageEntity::Type::Bold:
|
||||
@ -2192,7 +2192,7 @@ static Result<vector<MessageEntity>> do_parse_markdown_v2(CSlice text, string &r
|
||||
return Status::Error(400, PSLICE()
|
||||
<< "Can't find end of a custom emoji URL at byte offset " << url_begin_pos);
|
||||
}
|
||||
TRY_RESULT_ASSIGN(document_id, LinkManager::get_link_custom_emoji_document_id(url));
|
||||
TRY_RESULT_ASSIGN(custom_emoji_id, LinkManager::get_link_custom_emoji_id(url));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -2205,8 +2205,8 @@ static Result<vector<MessageEntity>> do_parse_markdown_v2(CSlice text, string &r
|
||||
auto entity_length = utf16_offset - entity_offset;
|
||||
if (user_id.is_valid()) {
|
||||
entities.emplace_back(entity_offset, entity_length, user_id);
|
||||
} else if (document_id != 0) {
|
||||
entities.emplace_back(type, entity_offset, entity_length, document_id);
|
||||
} else if (custom_emoji_id.is_valid()) {
|
||||
entities.emplace_back(type, entity_offset, entity_length, custom_emoji_id);
|
||||
} else {
|
||||
entities.emplace_back(type, entity_offset, entity_length, std::move(argument));
|
||||
}
|
||||
@ -3170,7 +3170,8 @@ static Result<vector<MessageEntity>> do_parse_html(CSlice text, string &result)
|
||||
if (r_document_id.is_error() || r_document_id.ok() == 0) {
|
||||
return Status::Error(400, "Invalid custom emoji identifier specified");
|
||||
}
|
||||
entities.emplace_back(MessageEntity::Type::CustomEmoji, entity_offset, entity_length, r_document_id.ok());
|
||||
entities.emplace_back(MessageEntity::Type::CustomEmoji, entity_offset, entity_length,
|
||||
CustomEmojiId(r_document_id.ok()));
|
||||
} else if (tag_name == "a") {
|
||||
auto url = std::move(nested_entities.back().argument);
|
||||
if (url.empty()) {
|
||||
@ -3308,8 +3309,8 @@ vector<tl_object_ptr<secret_api::MessageEntity>> get_input_secret_message_entiti
|
||||
break;
|
||||
case MessageEntity::Type::CustomEmoji:
|
||||
if (layer >= static_cast<int32>(SecretChatLayer::SpoilerAndCustomEmojiEntities)) {
|
||||
result.push_back(
|
||||
make_tl_object<secret_api::messageEntityCustomEmoji>(entity.offset, entity.length, entity.document_id));
|
||||
result.push_back(make_tl_object<secret_api::messageEntityCustomEmoji>(entity.offset, entity.length,
|
||||
entity.custom_emoji_id.get()));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -3425,7 +3426,11 @@ Result<vector<MessageEntity>> get_message_entities(const ContactsManager *contac
|
||||
break;
|
||||
case td_api::textEntityTypeCustomEmoji::ID: {
|
||||
auto entity = static_cast<td_api::textEntityTypeCustomEmoji *>(input_entity->type_.get());
|
||||
entities.emplace_back(MessageEntity::Type::CustomEmoji, offset, length, entity->custom_emoji_id_);
|
||||
CustomEmojiId custom_emoji_id(entity->custom_emoji_id_);
|
||||
if (!custom_emoji_id.is_valid()) {
|
||||
return Status::Error(400, "Invalid custom emoji identifier specified");
|
||||
}
|
||||
entities.emplace_back(MessageEntity::Type::CustomEmoji, offset, length, custom_emoji_id);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -3564,7 +3569,8 @@ vector<MessageEntity> get_message_entities(const ContactsManager *contacts_manag
|
||||
}
|
||||
case telegram_api::messageEntityCustomEmoji::ID: {
|
||||
auto entity = static_cast<const telegram_api::messageEntityCustomEmoji *>(server_entity.get());
|
||||
entities.emplace_back(MessageEntity::Type::CustomEmoji, entity->offset_, entity->length_, entity->document_id_);
|
||||
entities.emplace_back(MessageEntity::Type::CustomEmoji, entity->offset_, entity->length_,
|
||||
CustomEmojiId(entity->document_id_));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -3580,7 +3586,7 @@ vector<MessageEntity> get_message_entities(Td *td, vector<tl_object_ptr<secret_a
|
||||
constexpr size_t MAX_CUSTOM_EMOJI_ENTITIES = 100;
|
||||
vector<MessageEntity> entities;
|
||||
entities.reserve(secret_entities.size());
|
||||
vector<int64> document_ids;
|
||||
vector<CustomEmojiId> custom_emoji_ids;
|
||||
for (auto &secret_entity : secret_entities) {
|
||||
switch (secret_entity->get_id()) {
|
||||
case secret_api::messageEntityUnknown::ID:
|
||||
@ -3683,11 +3689,11 @@ vector<MessageEntity> get_message_entities(Td *td, vector<tl_object_ptr<secret_a
|
||||
}
|
||||
case secret_api::messageEntityCustomEmoji::ID: {
|
||||
auto entity = static_cast<const secret_api::messageEntityCustomEmoji *>(secret_entity.get());
|
||||
if (is_premium || !td->stickers_manager_->is_premium_custom_emoji(entity->document_id_, false)) {
|
||||
if (document_ids.size() < MAX_CUSTOM_EMOJI_ENTITIES) {
|
||||
entities.emplace_back(MessageEntity::Type::CustomEmoji, entity->offset_, entity->length_,
|
||||
entity->document_id_);
|
||||
document_ids.push_back(entity->document_id_);
|
||||
CustomEmojiId custom_emoji_id(entity->document_id_);
|
||||
if (is_premium || !td->stickers_manager_->is_premium_custom_emoji(custom_emoji_id, false)) {
|
||||
if (custom_emoji_ids.size() < MAX_CUSTOM_EMOJI_ENTITIES) {
|
||||
entities.emplace_back(MessageEntity::Type::CustomEmoji, entity->offset_, entity->length_, custom_emoji_id);
|
||||
custom_emoji_ids.push_back(custom_emoji_id);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -3701,10 +3707,10 @@ vector<MessageEntity> get_message_entities(Td *td, vector<tl_object_ptr<secret_a
|
||||
}
|
||||
}
|
||||
|
||||
if (!document_ids.empty() && !is_premium) {
|
||||
if (!custom_emoji_ids.empty() && !is_premium) {
|
||||
// preload custom emoji to check that they aren't premium
|
||||
td->stickers_manager_->get_custom_emoji_stickers(
|
||||
std::move(document_ids), true,
|
||||
std::move(custom_emoji_ids), true,
|
||||
PromiseCreator::lambda(
|
||||
[promise = load_data_multipromise.get_promise()](td_api::object_ptr<td_api::stickers> result) mutable {
|
||||
promise.set_value(Unit());
|
||||
@ -4425,8 +4431,8 @@ vector<tl_object_ptr<telegram_api::MessageEntity>> get_input_message_entities(co
|
||||
break;
|
||||
}
|
||||
case MessageEntity::Type::CustomEmoji:
|
||||
result.push_back(
|
||||
make_tl_object<telegram_api::messageEntityCustomEmoji>(entity.offset, entity.length, entity.document_id));
|
||||
result.push_back(make_tl_object<telegram_api::messageEntityCustomEmoji>(entity.offset, entity.length,
|
||||
entity.custom_emoji_id.get()));
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
@ -4470,7 +4476,7 @@ vector<tl_object_ptr<telegram_api::MessageEntity>> get_input_message_entities(co
|
||||
void remove_premium_custom_emoji_entities(const Td *td, vector<MessageEntity> &entities, bool remove_unknown) {
|
||||
td::remove_if(entities, [&](const MessageEntity &entity) {
|
||||
return entity.type == MessageEntity::Type::CustomEmoji &&
|
||||
td->stickers_manager_->is_premium_custom_emoji(entity.document_id, remove_unknown);
|
||||
td->stickers_manager_->is_premium_custom_emoji(entity.custom_emoji_id, remove_unknown);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "td/telegram/CustomEmojiId.h"
|
||||
#include "td/telegram/DialogId.h"
|
||||
#include "td/telegram/secret_api.h"
|
||||
#include "td/telegram/td_api.h"
|
||||
@ -60,7 +61,7 @@ class MessageEntity {
|
||||
int32 media_timestamp = -1;
|
||||
string argument;
|
||||
UserId user_id;
|
||||
int64 document_id = 0;
|
||||
CustomEmojiId custom_emoji_id;
|
||||
|
||||
MessageEntity() = default;
|
||||
|
||||
@ -74,8 +75,8 @@ class MessageEntity {
|
||||
: type(type), offset(offset), length(length), media_timestamp(media_timestamp) {
|
||||
CHECK(type == Type::MediaTimestamp);
|
||||
}
|
||||
MessageEntity(Type type, int32 offset, int32 length, int64 document_id)
|
||||
: type(type), offset(offset), length(length), document_id(document_id) {
|
||||
MessageEntity(Type type, int32 offset, int32 length, CustomEmojiId custom_emoji_id)
|
||||
: type(type), offset(offset), length(length), custom_emoji_id(custom_emoji_id) {
|
||||
CHECK(type == Type::CustomEmoji);
|
||||
}
|
||||
|
||||
@ -84,7 +85,7 @@ class MessageEntity {
|
||||
bool operator==(const MessageEntity &other) const {
|
||||
return offset == other.offset && length == other.length && type == other.type &&
|
||||
media_timestamp == other.media_timestamp && argument == other.argument && user_id == other.user_id &&
|
||||
document_id == other.document_id;
|
||||
custom_emoji_id == other.custom_emoji_id;
|
||||
}
|
||||
|
||||
bool operator<(const MessageEntity &other) const {
|
||||
|
@ -28,7 +28,7 @@ void MessageEntity::store(StorerT &storer) const {
|
||||
store(media_timestamp, storer);
|
||||
}
|
||||
if (type == Type::CustomEmoji) {
|
||||
store(document_id, storer);
|
||||
store(custom_emoji_id, storer);
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ void MessageEntity::parse(ParserT &parser) {
|
||||
parse(media_timestamp, parser);
|
||||
}
|
||||
if (type == Type::CustomEmoji) {
|
||||
parse(document_id, parser);
|
||||
parse(custom_emoji_id, parser);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1304,7 +1304,9 @@ class GetCustomEmojiDocumentsQuery final : public Td::ResultHandler {
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(vector<int64> &&document_ids) {
|
||||
void send(vector<CustomEmojiId> &&custom_emoji_ids) {
|
||||
auto document_ids =
|
||||
transform(custom_emoji_ids, [](CustomEmojiId custom_emoji_id) { return custom_emoji_id.get(); });
|
||||
send_query(
|
||||
G()->net_query_creator().create(telegram_api::messages_getCustomEmojiDocuments(std::move(document_ids))));
|
||||
}
|
||||
@ -1891,7 +1893,7 @@ StickerType StickersManager::get_sticker_type(FileId file_id) const {
|
||||
return sticker->type_;
|
||||
}
|
||||
|
||||
bool StickersManager::is_premium_custom_emoji(int64 custom_emoji_id, bool default_result) const {
|
||||
bool StickersManager::is_premium_custom_emoji(CustomEmojiId custom_emoji_id, bool default_result) const {
|
||||
auto sticker_id = custom_emoji_to_sticker_id_.get(custom_emoji_id);
|
||||
if (!sticker_id.is_valid()) {
|
||||
return default_result;
|
||||
@ -1901,13 +1903,13 @@ bool StickersManager::is_premium_custom_emoji(int64 custom_emoji_id, bool defaul
|
||||
return s->is_premium_;
|
||||
}
|
||||
|
||||
int64 StickersManager::get_custom_emoji_id(FileId sticker_id) const {
|
||||
CustomEmojiId StickersManager::get_custom_emoji_id(FileId sticker_id) const {
|
||||
auto sticker_file_view = td_->file_manager_->get_file_view(sticker_id);
|
||||
if (sticker_file_view.is_encrypted() || !sticker_file_view.has_remote_location() ||
|
||||
!sticker_file_view.remote_location().is_document()) {
|
||||
return 0;
|
||||
return CustomEmojiId();
|
||||
}
|
||||
return sticker_file_view.remote_location().get_id();
|
||||
return CustomEmojiId(sticker_file_view.remote_location().get_id());
|
||||
}
|
||||
|
||||
vector<td_api::object_ptr<td_api::closedVectorPath>> StickersManager::get_sticker_minithumbnail(
|
||||
@ -2164,7 +2166,7 @@ tl_object_ptr<td_api::sticker> StickersManager::get_sticker_object(FileId file_i
|
||||
const PhotoSize &thumbnail = sticker->m_thumbnail_.file_id.is_valid() ? sticker->m_thumbnail_ : sticker->s_thumbnail_;
|
||||
auto thumbnail_format = PhotoFormat::Webp;
|
||||
int64 document_id = 0;
|
||||
int64 emoji_document_id = 0;
|
||||
CustomEmojiId custom_emoji_id;
|
||||
if (!sticker->set_id_.is_valid()) {
|
||||
auto sticker_file_view = td_->file_manager_->get_file_view(sticker->file_id_);
|
||||
if (sticker_file_view.is_encrypted()) {
|
||||
@ -2183,7 +2185,7 @@ tl_object_ptr<td_api::sticker> StickersManager::get_sticker_object(FileId file_i
|
||||
}
|
||||
}
|
||||
} else if (sticker->type_ == StickerType::CustomEmoji) {
|
||||
emoji_document_id = get_custom_emoji_id(sticker->file_id_);
|
||||
custom_emoji_id = get_custom_emoji_id(sticker->file_id_);
|
||||
}
|
||||
auto thumbnail_object = get_thumbnail_object(td_->file_manager_.get(), thumbnail, thumbnail_format);
|
||||
int32 width = sticker->dimensions_.width;
|
||||
@ -2207,7 +2209,7 @@ tl_object_ptr<td_api::sticker> StickersManager::get_sticker_object(FileId file_i
|
||||
: nullptr;
|
||||
return td_api::make_object<td_api::sticker>(
|
||||
sticker->set_id_.get(), width, height, sticker->alt_, get_sticker_format_object(sticker->format_),
|
||||
get_sticker_type_object(sticker->type_), std::move(mask_position), emoji_document_id,
|
||||
get_sticker_type_object(sticker->type_), std::move(mask_position), custom_emoji_id.get(),
|
||||
get_sticker_minithumbnail(sticker->minithumbnail_, sticker->set_id_, document_id, zoom),
|
||||
std::move(thumbnail_object), sticker->is_premium_, std::move(premium_animation_object),
|
||||
td_->file_manager_->get_file_object(file_id));
|
||||
@ -2582,7 +2584,7 @@ FileId StickersManager::get_animated_emoji_sound_file_id(const string &emoji) co
|
||||
return it->second;
|
||||
}
|
||||
|
||||
FileId StickersManager::get_custom_animated_emoji_sticker_id(int64 custom_emoji_id) const {
|
||||
FileId StickersManager::get_custom_animated_emoji_sticker_id(CustomEmojiId custom_emoji_id) const {
|
||||
if (disable_animated_emojis_) {
|
||||
return {};
|
||||
}
|
||||
@ -2591,12 +2593,12 @@ FileId StickersManager::get_custom_animated_emoji_sticker_id(int64 custom_emoji_
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::animatedEmoji> StickersManager::get_animated_emoji_object(const string &emoji,
|
||||
int64 custom_emoji_id) {
|
||||
CustomEmojiId custom_emoji_id) {
|
||||
if (td_->auth_manager_->is_bot() || disable_animated_emojis_) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (custom_emoji_id != 0) {
|
||||
if (custom_emoji_id.is_valid()) {
|
||||
auto it = custom_emoji_messages_.find(custom_emoji_id);
|
||||
auto sticker_id = it == custom_emoji_messages_.end() ? get_custom_animated_emoji_sticker_id(custom_emoji_id)
|
||||
: it->second->sticker_id_;
|
||||
@ -2664,14 +2666,14 @@ class StickersManager::CustomEmojiLogEvent {
|
||||
}
|
||||
};
|
||||
|
||||
string StickersManager::get_custom_emoji_database_key(int64 custom_emoji_id) {
|
||||
return PSTRING() << "emoji" << custom_emoji_id;
|
||||
string StickersManager::get_custom_emoji_database_key(CustomEmojiId custom_emoji_id) {
|
||||
return PSTRING() << "emoji" << custom_emoji_id.get();
|
||||
}
|
||||
|
||||
FileId StickersManager::on_get_sticker(unique_ptr<Sticker> new_sticker, bool replace) {
|
||||
auto file_id = new_sticker->file_id_;
|
||||
CHECK(file_id.is_valid());
|
||||
int64 updated_custom_emoji_id = 0;
|
||||
CustomEmojiId updated_custom_emoji_id;
|
||||
auto *s = get_sticker(file_id);
|
||||
if (s == nullptr) {
|
||||
s = new_sticker.get();
|
||||
@ -2681,7 +2683,7 @@ FileId StickersManager::on_get_sticker(unique_ptr<Sticker> new_sticker, bool rep
|
||||
|
||||
if (s->type_ == StickerType::CustomEmoji) {
|
||||
auto custom_emoji_id = get_custom_emoji_id(file_id);
|
||||
if (custom_emoji_id != 0 && custom_emoji_to_sticker_id_.get(custom_emoji_id) == file_id) {
|
||||
if (custom_emoji_id.is_valid() && custom_emoji_to_sticker_id_.get(custom_emoji_id) == file_id) {
|
||||
custom_emoji_to_sticker_id_.erase(custom_emoji_id);
|
||||
updated_custom_emoji_id = custom_emoji_id;
|
||||
}
|
||||
@ -2751,12 +2753,12 @@ FileId StickersManager::on_get_sticker(unique_ptr<Sticker> new_sticker, bool rep
|
||||
if (s->type_ == StickerType::CustomEmoji) {
|
||||
s->is_being_reloaded_ = false;
|
||||
auto custom_emoji_id = get_custom_emoji_id(file_id);
|
||||
if (custom_emoji_id != 0) {
|
||||
if (custom_emoji_id.is_valid()) {
|
||||
custom_emoji_to_sticker_id_.set(custom_emoji_id, file_id);
|
||||
CHECK(updated_custom_emoji_id == custom_emoji_id || updated_custom_emoji_id == 0);
|
||||
CHECK(updated_custom_emoji_id == custom_emoji_id || !updated_custom_emoji_id.is_valid());
|
||||
updated_custom_emoji_id = custom_emoji_id;
|
||||
if (!s->is_from_database_ && G()->parameters().use_file_db && !G()->close_flag()) {
|
||||
LOG(INFO) << "Save custom emoji " << custom_emoji_id << " to database";
|
||||
LOG(INFO) << "Save " << custom_emoji_id << " to database";
|
||||
s->is_from_database_ = true;
|
||||
|
||||
CustomEmojiLogEvent log_event(file_id);
|
||||
@ -2765,7 +2767,7 @@ FileId StickersManager::on_get_sticker(unique_ptr<Sticker> new_sticker, bool rep
|
||||
}
|
||||
}
|
||||
}
|
||||
if (updated_custom_emoji_id != 0) {
|
||||
if (updated_custom_emoji_id.is_valid()) {
|
||||
try_update_custom_emoji_messages(updated_custom_emoji_id);
|
||||
}
|
||||
return file_id;
|
||||
@ -5545,7 +5547,7 @@ void StickersManager::on_update_disable_animated_emojis() {
|
||||
}
|
||||
try_update_animated_emoji_messages();
|
||||
|
||||
vector<int64> custom_emoji_ids;
|
||||
vector<CustomEmojiId> custom_emoji_ids;
|
||||
for (auto &it : custom_emoji_messages_) {
|
||||
custom_emoji_ids.push_back(it.first);
|
||||
}
|
||||
@ -5555,9 +5557,8 @@ void StickersManager::on_update_disable_animated_emojis() {
|
||||
|
||||
if (!disable_animated_emojis_) {
|
||||
for (size_t i = 0; i < custom_emoji_ids.size(); i += MAX_GET_CUSTOM_EMOJI_STICKERS) {
|
||||
auto end_i = i + MAX_GET_CUSTOM_EMOJI_STICKERS;
|
||||
auto end = end_i < custom_emoji_ids.size() ? custom_emoji_ids.begin() + end_i : custom_emoji_ids.end();
|
||||
get_custom_emoji_stickers({custom_emoji_ids.begin() + i, end}, true, Auto());
|
||||
auto end_i = td::min(i + MAX_GET_CUSTOM_EMOJI_STICKERS, custom_emoji_ids.size());
|
||||
get_custom_emoji_stickers({custom_emoji_ids.begin() + i, custom_emoji_ids.begin() + end_i}, true, Auto());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5588,7 +5589,7 @@ void StickersManager::try_update_animated_emoji_messages() {
|
||||
}
|
||||
}
|
||||
|
||||
void StickersManager::try_update_custom_emoji_messages(int64 custom_emoji_id) {
|
||||
void StickersManager::try_update_custom_emoji_messages(CustomEmojiId custom_emoji_id) {
|
||||
auto it = custom_emoji_messages_.find(custom_emoji_id);
|
||||
if (it == custom_emoji_messages_.end()) {
|
||||
return;
|
||||
@ -5717,16 +5718,16 @@ void StickersManager::unregister_dice(const string &emoji, int32 value, FullMess
|
||||
}
|
||||
}
|
||||
|
||||
void StickersManager::register_emoji(const string &emoji, int64 custom_emoji_id, FullMessageId full_message_id,
|
||||
void StickersManager::register_emoji(const string &emoji, CustomEmojiId custom_emoji_id, FullMessageId full_message_id,
|
||||
const char *source) {
|
||||
CHECK(!emoji.empty());
|
||||
if (td_->auth_manager_->is_bot()) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOG(INFO) << "Register emoji " << emoji << " with custom emoji " << custom_emoji_id << " from " << full_message_id
|
||||
<< " from " << source;
|
||||
if (custom_emoji_id != 0) {
|
||||
LOG(INFO) << "Register emoji " << emoji << " with " << custom_emoji_id << " from " << full_message_id << " from "
|
||||
<< source;
|
||||
if (custom_emoji_id.is_valid()) {
|
||||
auto &emoji_messages_ptr = custom_emoji_messages_[custom_emoji_id];
|
||||
if (emoji_messages_ptr == nullptr) {
|
||||
emoji_messages_ptr = make_unique<CustomEmojiMessages>();
|
||||
@ -5757,16 +5758,16 @@ void StickersManager::register_emoji(const string &emoji, int64 custom_emoji_id,
|
||||
emoji_messages.full_message_ids_.insert(full_message_id);
|
||||
}
|
||||
|
||||
void StickersManager::unregister_emoji(const string &emoji, int64 custom_emoji_id, FullMessageId full_message_id,
|
||||
const char *source) {
|
||||
void StickersManager::unregister_emoji(const string &emoji, CustomEmojiId custom_emoji_id,
|
||||
FullMessageId full_message_id, const char *source) {
|
||||
CHECK(!emoji.empty());
|
||||
if (td_->auth_manager_->is_bot()) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOG(INFO) << "Unregister emoji " << emoji << " with custom emoji " << custom_emoji_id << " from " << full_message_id
|
||||
<< " from " << source;
|
||||
if (custom_emoji_id != 0) {
|
||||
LOG(INFO) << "Unregister emoji " << emoji << " with " << custom_emoji_id << " from " << full_message_id << " from "
|
||||
<< source;
|
||||
if (custom_emoji_id.is_valid()) {
|
||||
auto it = custom_emoji_messages_.find(custom_emoji_id);
|
||||
CHECK(it != custom_emoji_messages_.end());
|
||||
auto &full_message_ids = it->second->full_message_ids_;
|
||||
@ -5902,11 +5903,11 @@ void StickersManager::get_default_emoji_statuses(bool is_recursive,
|
||||
vector<td_api::object_ptr<td_api::emojiStatus>> statuses;
|
||||
for (auto sticker_id : sticker_set->sticker_ids_) {
|
||||
auto custom_emoji_id = get_custom_emoji_id(sticker_id);
|
||||
if (custom_emoji_id == 0) {
|
||||
if (!custom_emoji_id.is_valid()) {
|
||||
LOG(ERROR) << "Ignore wrong sticker " << sticker_id;
|
||||
continue;
|
||||
}
|
||||
statuses.emplace_back(td_api::make_object<td_api::emojiStatus>(custom_emoji_id));
|
||||
statuses.emplace_back(td_api::make_object<td_api::emojiStatus>(custom_emoji_id.get()));
|
||||
if (statuses.size() >= 8) {
|
||||
break;
|
||||
}
|
||||
@ -5914,7 +5915,7 @@ void StickersManager::get_default_emoji_statuses(bool is_recursive,
|
||||
promise.set_value(td_api::make_object<td_api::emojiStatuses>(std::move(statuses)));
|
||||
}
|
||||
|
||||
bool StickersManager::is_default_emoji_status(int64 custom_emoji_id) {
|
||||
bool StickersManager::is_default_emoji_status(CustomEmojiId custom_emoji_id) {
|
||||
auto &special_sticker_set = add_special_sticker_set(SpecialStickerSetType::default_statuses());
|
||||
auto sticker_set = get_sticker_set(special_sticker_set.id_);
|
||||
if (sticker_set == nullptr || !sticker_set->was_loaded_) {
|
||||
@ -5928,32 +5929,31 @@ bool StickersManager::is_default_emoji_status(int64 custom_emoji_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void StickersManager::load_custom_emoji_sticker_from_database_force(int64 custom_emoji_id) {
|
||||
void StickersManager::load_custom_emoji_sticker_from_database_force(CustomEmojiId custom_emoji_id) {
|
||||
if (!G()->parameters().use_file_db) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto value = G()->td_db()->get_sqlite_sync_pmc()->get(get_custom_emoji_database_key(custom_emoji_id));
|
||||
if (value.empty()) {
|
||||
LOG(INFO) << "Failed to load custom emoji " << custom_emoji_id << " from database";
|
||||
LOG(INFO) << "Failed to load " << custom_emoji_id << " from database";
|
||||
return;
|
||||
}
|
||||
|
||||
LOG(INFO) << "Synchronously loaded custom emoji " << custom_emoji_id << " of size " << value.size()
|
||||
<< " from database";
|
||||
LOG(INFO) << "Synchronously loaded " << custom_emoji_id << " of size " << value.size() << " from database";
|
||||
CustomEmojiLogEvent log_event;
|
||||
if (log_event_parse(log_event, value).is_error()) {
|
||||
LOG(ERROR) << "Delete invalid custom emoji " << custom_emoji_id << " value from database";
|
||||
LOG(ERROR) << "Delete invalid " << custom_emoji_id << " value from database";
|
||||
G()->td_db()->get_sqlite_sync_pmc()->erase(get_custom_emoji_database_key(custom_emoji_id));
|
||||
}
|
||||
}
|
||||
|
||||
void StickersManager::load_custom_emoji_sticker_from_database(int64 custom_emoji_id, Promise<Unit> &&promise) {
|
||||
CHECK(custom_emoji_id != 0);
|
||||
void StickersManager::load_custom_emoji_sticker_from_database(CustomEmojiId custom_emoji_id, Promise<Unit> &&promise) {
|
||||
CHECK(custom_emoji_id.is_valid());
|
||||
auto &queries = custom_emoji_load_queries_[custom_emoji_id];
|
||||
queries.push_back(std::move(promise));
|
||||
if (queries.size() == 1) {
|
||||
LOG(INFO) << "Trying to load custom emoji " << custom_emoji_id << " from database";
|
||||
LOG(INFO) << "Trying to load " << custom_emoji_id << " from database";
|
||||
G()->td_db()->get_sqlite_pmc()->get(
|
||||
get_custom_emoji_database_key(custom_emoji_id), PromiseCreator::lambda([custom_emoji_id](string value) {
|
||||
send_closure(G()->stickers_manager(), &StickersManager::on_load_custom_emoji_from_database, custom_emoji_id,
|
||||
@ -5962,21 +5962,20 @@ void StickersManager::load_custom_emoji_sticker_from_database(int64 custom_emoji
|
||||
}
|
||||
}
|
||||
|
||||
void StickersManager::on_load_custom_emoji_from_database(int64 custom_emoji_id, string value) {
|
||||
void StickersManager::on_load_custom_emoji_from_database(CustomEmojiId custom_emoji_id, string value) {
|
||||
if (G()->close_flag()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!value.empty()) {
|
||||
LOG(INFO) << "Successfully loaded custom emoji " << custom_emoji_id << " of size " << value.size()
|
||||
<< " from database";
|
||||
LOG(INFO) << "Successfully loaded " << custom_emoji_id << " of size " << value.size() << " from database";
|
||||
CustomEmojiLogEvent log_event;
|
||||
if (log_event_parse(log_event, value).is_error()) {
|
||||
LOG(ERROR) << "Delete invalid custom emoji " << custom_emoji_id << " value from database";
|
||||
LOG(ERROR) << "Delete invalid " << custom_emoji_id << " value from database";
|
||||
G()->td_db()->get_sqlite_pmc()->erase(get_custom_emoji_database_key(custom_emoji_id), Auto());
|
||||
}
|
||||
} else {
|
||||
LOG(INFO) << "Failed to load custom emoji " << custom_emoji_id << " from database";
|
||||
LOG(INFO) << "Failed to load " << custom_emoji_id << " from database";
|
||||
}
|
||||
|
||||
auto it = custom_emoji_load_queries_.find(custom_emoji_id);
|
||||
@ -5989,19 +5988,19 @@ void StickersManager::on_load_custom_emoji_from_database(int64 custom_emoji_id,
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::stickers> StickersManager::get_custom_emoji_stickers_object(
|
||||
const vector<int64> &document_ids) {
|
||||
const vector<CustomEmojiId> &custom_emoji_ids) {
|
||||
vector<td_api::object_ptr<td_api::sticker>> stickers;
|
||||
auto update_before_date = G()->unix_time() - 86400;
|
||||
vector<int64> reload_document_ids;
|
||||
for (auto document_id : document_ids) {
|
||||
auto file_id = custom_emoji_to_sticker_id_.get(document_id);
|
||||
vector<CustomEmojiId> reload_custom_emoji_ids;
|
||||
for (auto custom_emoji_id : custom_emoji_ids) {
|
||||
auto file_id = custom_emoji_to_sticker_id_.get(custom_emoji_id);
|
||||
if (file_id.is_valid()) {
|
||||
auto s = get_sticker(file_id);
|
||||
CHECK(s != nullptr);
|
||||
CHECK(s->type_ == StickerType::CustomEmoji);
|
||||
if (s->emoji_receive_date_ < update_before_date && !s->is_being_reloaded_) {
|
||||
s->is_being_reloaded_ = true;
|
||||
reload_document_ids.push_back(document_id);
|
||||
reload_custom_emoji_ids.push_back(custom_emoji_id);
|
||||
}
|
||||
|
||||
auto sticker = get_sticker_object(file_id);
|
||||
@ -6009,69 +6008,77 @@ td_api::object_ptr<td_api::stickers> StickersManager::get_custom_emoji_stickers_
|
||||
stickers.push_back(std::move(sticker));
|
||||
}
|
||||
}
|
||||
if (!reload_document_ids.empty()) {
|
||||
LOG(INFO) << "Reload documents " << reload_document_ids;
|
||||
if (!reload_custom_emoji_ids.empty()) {
|
||||
LOG(INFO) << "Reload " << reload_custom_emoji_ids;
|
||||
auto promise = PromiseCreator::lambda(
|
||||
[actor_id =
|
||||
actor_id(this)](Result<vector<telegram_api::object_ptr<telegram_api::Document>>> r_documents) mutable {
|
||||
send_closure(actor_id, &StickersManager::on_get_custom_emoji_documents, std::move(r_documents),
|
||||
vector<int64>(), Promise<td_api::object_ptr<td_api::stickers>>());
|
||||
vector<CustomEmojiId>(), Promise<td_api::object_ptr<td_api::stickers>>());
|
||||
});
|
||||
td_->create_handler<GetCustomEmojiDocumentsQuery>(std::move(promise))->send(std::move(reload_document_ids));
|
||||
td_->create_handler<GetCustomEmojiDocumentsQuery>(std::move(promise))->send(std::move(reload_custom_emoji_ids));
|
||||
}
|
||||
return td_api::make_object<td_api::stickers>(std::move(stickers));
|
||||
}
|
||||
|
||||
void StickersManager::get_custom_emoji_stickers(vector<int64> &&document_ids, bool use_database,
|
||||
void StickersManager::get_custom_emoji_stickers(vector<CustomEmojiId> &&custom_emoji_ids, bool use_database,
|
||||
Promise<td_api::object_ptr<td_api::stickers>> &&promise) {
|
||||
TRY_STATUS_PROMISE(promise, G()->close_status());
|
||||
|
||||
if (document_ids.size() > MAX_GET_CUSTOM_EMOJI_STICKERS) {
|
||||
if (custom_emoji_ids.size() > MAX_GET_CUSTOM_EMOJI_STICKERS) {
|
||||
return promise.set_error(Status::Error(400, "Too many custom emoji identifiers specified"));
|
||||
}
|
||||
|
||||
td::unique(document_ids);
|
||||
td::remove(document_ids, 0);
|
||||
FlatHashSet<CustomEmojiId, CustomEmojiIdHash> unique_custom_emoji_ids;
|
||||
size_t j = 0;
|
||||
for (size_t i = 0; i < custom_emoji_ids.size(); i++) {
|
||||
auto custom_emoji_id = custom_emoji_ids[i];
|
||||
if (custom_emoji_id.is_valid() && unique_custom_emoji_ids.insert(custom_emoji_id).second) {
|
||||
custom_emoji_ids[j++] = custom_emoji_id;
|
||||
}
|
||||
}
|
||||
custom_emoji_ids.resize(j);
|
||||
|
||||
vector<int64> unknown_document_ids;
|
||||
for (auto document_id : document_ids) {
|
||||
if (custom_emoji_to_sticker_id_.count(document_id) == 0) {
|
||||
unknown_document_ids.push_back(document_id);
|
||||
vector<CustomEmojiId> unknown_custom_emoji_ids;
|
||||
for (auto custom_emoji_id : custom_emoji_ids) {
|
||||
if (custom_emoji_to_sticker_id_.count(custom_emoji_id) == 0) {
|
||||
unknown_custom_emoji_ids.push_back(custom_emoji_id);
|
||||
}
|
||||
}
|
||||
|
||||
if (unknown_document_ids.empty()) {
|
||||
return promise.set_value(get_custom_emoji_stickers_object(document_ids));
|
||||
if (unknown_custom_emoji_ids.empty()) {
|
||||
return promise.set_value(get_custom_emoji_stickers_object(custom_emoji_ids));
|
||||
}
|
||||
|
||||
if (use_database && G()->parameters().use_file_db) {
|
||||
MultiPromiseActorSafe mpas{"LoadCustomEmojiMultiPromiseActor"};
|
||||
mpas.add_promise(
|
||||
PromiseCreator::lambda([actor_id = actor_id(this), document_ids, promise = std::move(promise)](Unit) mutable {
|
||||
send_closure(actor_id, &StickersManager::get_custom_emoji_stickers, std::move(document_ids), false,
|
||||
mpas.add_promise(PromiseCreator::lambda(
|
||||
[actor_id = actor_id(this), custom_emoji_ids, promise = std::move(promise)](Unit) mutable {
|
||||
send_closure(actor_id, &StickersManager::get_custom_emoji_stickers, std::move(custom_emoji_ids), false,
|
||||
std::move(promise));
|
||||
}));
|
||||
|
||||
auto lock = mpas.get_promise();
|
||||
for (auto document_id : unknown_document_ids) {
|
||||
load_custom_emoji_sticker_from_database(document_id, mpas.get_promise());
|
||||
for (auto custom_emoji_id : unknown_custom_emoji_ids) {
|
||||
load_custom_emoji_sticker_from_database(custom_emoji_id, mpas.get_promise());
|
||||
}
|
||||
|
||||
return lock.set_value(Unit());
|
||||
}
|
||||
|
||||
auto query_promise = PromiseCreator::lambda(
|
||||
[actor_id = actor_id(this), document_ids = std::move(document_ids), promise = std::move(promise)](
|
||||
[actor_id = actor_id(this), custom_emoji_ids = std::move(custom_emoji_ids), promise = std::move(promise)](
|
||||
Result<vector<telegram_api::object_ptr<telegram_api::Document>>> r_documents) mutable {
|
||||
send_closure(actor_id, &StickersManager::on_get_custom_emoji_documents, std::move(r_documents),
|
||||
std::move(document_ids), std::move(promise));
|
||||
std::move(custom_emoji_ids), std::move(promise));
|
||||
});
|
||||
td_->create_handler<GetCustomEmojiDocumentsQuery>(std::move(query_promise))->send(std::move(unknown_document_ids));
|
||||
td_->create_handler<GetCustomEmojiDocumentsQuery>(std::move(query_promise))
|
||||
->send(std::move(unknown_custom_emoji_ids));
|
||||
}
|
||||
|
||||
void StickersManager::on_get_custom_emoji_documents(
|
||||
Result<vector<telegram_api::object_ptr<telegram_api::Document>>> &&r_documents, vector<int64> &&document_ids,
|
||||
Promise<td_api::object_ptr<td_api::stickers>> &&promise) {
|
||||
Result<vector<telegram_api::object_ptr<telegram_api::Document>>> &&r_documents,
|
||||
vector<CustomEmojiId> &&custom_emoji_ids, Promise<td_api::object_ptr<td_api::stickers>> &&promise) {
|
||||
TRY_STATUS_PROMISE(promise, G()->close_status());
|
||||
if (r_documents.is_error()) {
|
||||
return promise.set_error(r_documents.move_as_error());
|
||||
@ -6087,7 +6094,7 @@ void StickersManager::on_get_custom_emoji_documents(
|
||||
on_get_sticker_document(std::move(document), StickerFormat::Unknown);
|
||||
}
|
||||
|
||||
promise.set_value(get_custom_emoji_stickers_object(document_ids));
|
||||
promise.set_value(get_custom_emoji_stickers_object(custom_emoji_ids));
|
||||
}
|
||||
|
||||
void StickersManager::get_premium_gift_option_sticker(int32 month_count, bool is_recursive,
|
||||
@ -7247,7 +7254,7 @@ void StickersManager::move_sticker_set_to_top_by_sticker_id(FileId sticker_id) {
|
||||
}
|
||||
}
|
||||
|
||||
void StickersManager::move_sticker_set_to_top_by_custom_emoji_ids(const vector<int64> &custom_emoji_ids) {
|
||||
void StickersManager::move_sticker_set_to_top_by_custom_emoji_ids(const vector<CustomEmojiId> &custom_emoji_ids) {
|
||||
LOG(INFO) << "Move to top sticker set of " << custom_emoji_ids;
|
||||
StickerSetId sticker_set_id;
|
||||
for (auto custom_emoji_id : custom_emoji_ids) {
|
||||
|
@ -6,6 +6,7 @@
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "td/telegram/CustomEmojiId.h"
|
||||
#include "td/telegram/DialogId.h"
|
||||
#include "td/telegram/Dimensions.h"
|
||||
#include "td/telegram/files/FileId.h"
|
||||
@ -63,7 +64,7 @@ class StickersManager final : public Actor {
|
||||
|
||||
StickerType get_sticker_type(FileId file_id) const;
|
||||
|
||||
bool is_premium_custom_emoji(int64 custom_emoji_id, bool default_result) const;
|
||||
bool is_premium_custom_emoji(CustomEmojiId custom_emoji_id, bool default_result) const;
|
||||
|
||||
tl_object_ptr<td_api::sticker> get_sticker_object(FileId file_id, bool for_animated_emoji = false,
|
||||
bool for_clicked_animated_emoji = false) const;
|
||||
@ -82,7 +83,8 @@ class StickersManager final : public Actor {
|
||||
|
||||
td_api::object_ptr<td_api::sticker> get_premium_gift_sticker_object(int32 month_count);
|
||||
|
||||
td_api::object_ptr<td_api::animatedEmoji> get_animated_emoji_object(const string &emoji, int64 custom_emoji_id);
|
||||
td_api::object_ptr<td_api::animatedEmoji> get_animated_emoji_object(const string &emoji,
|
||||
CustomEmojiId custom_emoji_id);
|
||||
|
||||
tl_object_ptr<telegram_api::InputStickerSet> get_input_sticker_set(StickerSetId sticker_set_id) const;
|
||||
|
||||
@ -94,9 +96,11 @@ class StickersManager final : public Actor {
|
||||
|
||||
void unregister_dice(const string &emoji, int32 value, FullMessageId full_message_id, const char *source);
|
||||
|
||||
void register_emoji(const string &emoji, int64 custom_emoji_id, FullMessageId full_message_id, const char *source);
|
||||
void register_emoji(const string &emoji, CustomEmojiId custom_emoji_id, FullMessageId full_message_id,
|
||||
const char *source);
|
||||
|
||||
void unregister_emoji(const string &emoji, int64 custom_emoji_id, FullMessageId full_message_id, const char *source);
|
||||
void unregister_emoji(const string &emoji, CustomEmojiId custom_emoji_id, FullMessageId full_message_id,
|
||||
const char *source);
|
||||
|
||||
void get_animated_emoji(string emoji, bool is_recursive,
|
||||
Promise<td_api::object_ptr<td_api::animatedEmoji>> &&promise);
|
||||
@ -108,9 +112,9 @@ class StickersManager final : public Actor {
|
||||
|
||||
void get_default_emoji_statuses(bool is_recursive, Promise<td_api::object_ptr<td_api::emojiStatuses>> &&promise);
|
||||
|
||||
bool is_default_emoji_status(int64 custom_emoji_id);
|
||||
bool is_default_emoji_status(CustomEmojiId custom_emoji_id);
|
||||
|
||||
void get_custom_emoji_stickers(vector<int64> &&document_ids, bool use_database,
|
||||
void get_custom_emoji_stickers(vector<CustomEmojiId> &&custom_emoji_ids, bool use_database,
|
||||
Promise<td_api::object_ptr<td_api::stickers>> &&promise);
|
||||
|
||||
void get_premium_gift_option_sticker(int32 month_count, bool is_recursive,
|
||||
@ -263,7 +267,7 @@ class StickersManager final : public Actor {
|
||||
|
||||
void move_sticker_set_to_top_by_sticker_id(FileId sticker_id);
|
||||
|
||||
void move_sticker_set_to_top_by_custom_emoji_ids(const vector<int64> &custom_emoji_ids);
|
||||
void move_sticker_set_to_top_by_custom_emoji_ids(const vector<CustomEmojiId> &custom_emoji_ids);
|
||||
|
||||
FileId upload_sticker_file(UserId user_id, tl_object_ptr<td_api::inputSticker> &&sticker, Promise<Unit> &&promise);
|
||||
|
||||
@ -590,7 +594,7 @@ class StickersManager final : public Actor {
|
||||
|
||||
class UploadStickerFileCallback;
|
||||
|
||||
int64 get_custom_emoji_id(FileId sticker_id) const;
|
||||
CustomEmojiId get_custom_emoji_id(FileId sticker_id) const;
|
||||
|
||||
static vector<td_api::object_ptr<td_api::closedVectorPath>> get_sticker_minithumbnail(CSlice path,
|
||||
StickerSetId sticker_set_id,
|
||||
@ -614,13 +618,13 @@ class StickersManager final : public Actor {
|
||||
|
||||
void on_search_stickers_finished(const string &emoji, const FoundStickers &found_stickers);
|
||||
|
||||
static string get_custom_emoji_database_key(int64 custom_emoji_id);
|
||||
static string get_custom_emoji_database_key(CustomEmojiId custom_emoji_id);
|
||||
|
||||
void load_custom_emoji_sticker_from_database_force(int64 custom_emoji_id);
|
||||
void load_custom_emoji_sticker_from_database_force(CustomEmojiId custom_emoji_id);
|
||||
|
||||
void load_custom_emoji_sticker_from_database(int64 custom_emoji_id, Promise<Unit> &&promise);
|
||||
void load_custom_emoji_sticker_from_database(CustomEmojiId custom_emoji_id, Promise<Unit> &&promise);
|
||||
|
||||
void on_load_custom_emoji_from_database(int64 custom_emoji_id, string value);
|
||||
void on_load_custom_emoji_from_database(CustomEmojiId custom_emoji_id, string value);
|
||||
|
||||
FileId on_get_sticker(unique_ptr<Sticker> new_sticker, bool replace);
|
||||
|
||||
@ -823,14 +827,14 @@ class StickersManager final : public Actor {
|
||||
|
||||
FileId get_animated_emoji_sound_file_id(const string &emoji) const;
|
||||
|
||||
FileId get_custom_animated_emoji_sticker_id(int64 custom_emoji_id) const;
|
||||
FileId get_custom_animated_emoji_sticker_id(CustomEmojiId custom_emoji_id) const;
|
||||
|
||||
td_api::object_ptr<td_api::animatedEmoji> get_animated_emoji_object(std::pair<FileId, int> animated_sticker,
|
||||
FileId sound_file_id) const;
|
||||
|
||||
void try_update_animated_emoji_messages();
|
||||
|
||||
void try_update_custom_emoji_messages(int64 custom_emoji_id);
|
||||
void try_update_custom_emoji_messages(CustomEmojiId custom_emoji_id);
|
||||
|
||||
static int get_emoji_number(Slice emoji);
|
||||
|
||||
@ -895,10 +899,10 @@ class StickersManager final : public Actor {
|
||||
|
||||
static void add_sticker_thumbnail(Sticker *s, PhotoSize thumbnail);
|
||||
|
||||
td_api::object_ptr<td_api::stickers> get_custom_emoji_stickers_object(const vector<int64> &document_ids);
|
||||
td_api::object_ptr<td_api::stickers> get_custom_emoji_stickers_object(const vector<CustomEmojiId> &custom_emoji_ids);
|
||||
|
||||
void on_get_custom_emoji_documents(Result<vector<telegram_api::object_ptr<telegram_api::Document>>> &&r_documents,
|
||||
vector<int64> &&document_ids,
|
||||
vector<CustomEmojiId> &&custom_emoji_ids,
|
||||
Promise<td_api::object_ptr<td_api::stickers>> &&promise);
|
||||
|
||||
static const std::map<string, vector<FileId>> &get_sticker_set_keywords(const StickerSet *sticker_set);
|
||||
@ -1028,7 +1032,7 @@ class StickersManager final : public Actor {
|
||||
FlatHashMap<uint32, StickerSetLoadRequest> sticker_set_load_requests_;
|
||||
uint32 current_sticker_set_load_request_ = 0;
|
||||
|
||||
FlatHashMap<int64, vector<Promise<Unit>>> custom_emoji_load_queries_;
|
||||
FlatHashMap<CustomEmojiId, vector<Promise<Unit>>, CustomEmojiIdHash> custom_emoji_load_queries_;
|
||||
|
||||
FlatHashMap<int64, unique_ptr<PendingNewStickerSet>> pending_new_sticker_sets_;
|
||||
|
||||
@ -1098,7 +1102,7 @@ class StickersManager final : public Actor {
|
||||
WaitFreeHashSet<FullMessageId, FullMessageIdHash> full_message_ids_;
|
||||
FileId sticker_id_;
|
||||
};
|
||||
FlatHashMap<int64, unique_ptr<CustomEmojiMessages>> custom_emoji_messages_;
|
||||
FlatHashMap<CustomEmojiId, unique_ptr<CustomEmojiMessages>, CustomEmojiIdHash> custom_emoji_messages_;
|
||||
|
||||
string dice_emojis_str_;
|
||||
vector<string> dice_emojis_;
|
||||
@ -1109,7 +1113,7 @@ class StickersManager final : public Actor {
|
||||
string emoji_sounds_str_;
|
||||
FlatHashMap<string, FileId> emoji_sounds_;
|
||||
|
||||
WaitFreeHashMap<int64, FileId> custom_emoji_to_sticker_id_;
|
||||
WaitFreeHashMap<CustomEmojiId, FileId, CustomEmojiIdHash> custom_emoji_to_sticker_id_;
|
||||
|
||||
double animated_emoji_zoom_ = 0.0;
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "td/telegram/ConfigManager.h"
|
||||
#include "td/telegram/ContactsManager.h"
|
||||
#include "td/telegram/CountryInfoManager.h"
|
||||
#include "td/telegram/CustomEmojiId.h"
|
||||
#include "td/telegram/DeviceTokenManager.h"
|
||||
#include "td/telegram/DialogAction.h"
|
||||
#include "td/telegram/DialogEventLog.h"
|
||||
@ -7120,9 +7121,11 @@ void Td::on_request(uint64 id, td_api::getEmojiSuggestionsUrl &request) {
|
||||
CREATE_REQUEST(GetEmojiSuggestionsUrlRequest, std::move(request.language_code_));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::getCustomEmojiStickers &request) {
|
||||
void Td::on_request(uint64 id, const td_api::getCustomEmojiStickers &request) {
|
||||
CREATE_REQUEST_PROMISE();
|
||||
stickers_manager_->get_custom_emoji_stickers(std::move(request.custom_emoji_ids_), true, std::move(promise));
|
||||
stickers_manager_->get_custom_emoji_stickers(
|
||||
transform(request.custom_emoji_ids_, [](int64 custom_emoji_id) { return CustomEmojiId(custom_emoji_id); }), true,
|
||||
std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::getSavedAnimations &request) {
|
||||
|
@ -1146,7 +1146,7 @@ class Td final : public Actor {
|
||||
|
||||
void on_request(uint64 id, td_api::getEmojiSuggestionsUrl &request);
|
||||
|
||||
void on_request(uint64 id, td_api::getCustomEmojiStickers &request);
|
||||
void on_request(uint64 id, const td_api::getCustomEmojiStickers &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::getFavoriteStickers &request);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user