Pass SpecialStickerSetType to add_special_sticker_set.
This commit is contained in:
parent
ab153e306a
commit
37d5a59422
@ -12,17 +12,17 @@
|
||||
|
||||
namespace td {
|
||||
|
||||
string SpecialStickerSetType::animated_emoji() {
|
||||
return "animated_emoji_sticker_set";
|
||||
SpecialStickerSetType SpecialStickerSetType::animated_emoji() {
|
||||
return SpecialStickerSetType("animated_emoji_sticker_set");
|
||||
}
|
||||
|
||||
string SpecialStickerSetType::animated_emoji_click() {
|
||||
return "animated_emoji_click_sticker_set";
|
||||
SpecialStickerSetType SpecialStickerSetType::animated_emoji_click() {
|
||||
return SpecialStickerSetType("animated_emoji_click_sticker_set");
|
||||
}
|
||||
|
||||
string SpecialStickerSetType::animated_dice(const string &emoji) {
|
||||
SpecialStickerSetType SpecialStickerSetType::animated_dice(const string &emoji) {
|
||||
CHECK(!emoji.empty());
|
||||
return PSTRING() << "animated_dice_sticker_set#" << emoji;
|
||||
return SpecialStickerSetType(PSTRING() << "animated_dice_sticker_set#" << emoji);
|
||||
}
|
||||
|
||||
SpecialStickerSetType::SpecialStickerSetType(
|
||||
@ -30,13 +30,13 @@ SpecialStickerSetType::SpecialStickerSetType(
|
||||
CHECK(input_sticker_set != nullptr);
|
||||
switch (input_sticker_set->get_id()) {
|
||||
case telegram_api::inputStickerSetAnimatedEmoji::ID:
|
||||
type_ = animated_emoji();
|
||||
*this = animated_emoji();
|
||||
break;
|
||||
case telegram_api::inputStickerSetAnimatedEmojiAnimations::ID:
|
||||
type_ = animated_emoji_click();
|
||||
*this = animated_emoji_click();
|
||||
break;
|
||||
case telegram_api::inputStickerSetDice::ID:
|
||||
type_ = animated_dice(static_cast<const telegram_api::inputStickerSetDice *>(input_sticker_set.get())->emoticon_);
|
||||
*this = animated_dice(static_cast<const telegram_api::inputStickerSetDice *>(input_sticker_set.get())->emoticon_);
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
@ -45,17 +45,18 @@ SpecialStickerSetType::SpecialStickerSetType(
|
||||
}
|
||||
|
||||
string SpecialStickerSetType::get_dice_emoji() const {
|
||||
if (begins_with(type_, "animated_dice_sticker_set#")) {
|
||||
return type_.substr(Slice("animated_dice_sticker_set#").size());
|
||||
auto prefix = Slice("animated_dice_sticker_set#");
|
||||
if (begins_with(type_, prefix)) {
|
||||
return type_.substr(prefix.size());
|
||||
}
|
||||
return string();
|
||||
}
|
||||
|
||||
telegram_api::object_ptr<telegram_api::InputStickerSet> SpecialStickerSetType::get_input_sticker_set() const {
|
||||
if (type_ == animated_emoji()) {
|
||||
if (*this == animated_emoji()) {
|
||||
return telegram_api::make_object<telegram_api::inputStickerSetAnimatedEmoji>();
|
||||
}
|
||||
if (type_ == animated_emoji_click()) {
|
||||
if (*this == animated_emoji_click()) {
|
||||
return telegram_api::make_object<telegram_api::inputStickerSetAnimatedEmojiAnimations>();
|
||||
}
|
||||
auto emoji = get_dice_emoji();
|
||||
|
@ -10,19 +10,31 @@
|
||||
|
||||
#include "td/utils/common.h"
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace td {
|
||||
|
||||
struct SpecialStickerSetType {
|
||||
class SpecialStickerSetType {
|
||||
explicit SpecialStickerSetType(string type) : type_(type) {
|
||||
}
|
||||
|
||||
friend struct SpecialStickerSetTypeHash;
|
||||
|
||||
public:
|
||||
string type_;
|
||||
|
||||
static string animated_emoji();
|
||||
static SpecialStickerSetType animated_emoji();
|
||||
|
||||
static string animated_emoji_click();
|
||||
static SpecialStickerSetType animated_emoji_click();
|
||||
|
||||
static string animated_dice(const string &emoji);
|
||||
static SpecialStickerSetType animated_dice(const string &emoji);
|
||||
|
||||
string get_dice_emoji() const;
|
||||
|
||||
bool is_empty() const {
|
||||
return type_.empty();
|
||||
}
|
||||
|
||||
SpecialStickerSetType() = default;
|
||||
|
||||
explicit SpecialStickerSetType(const telegram_api::object_ptr<telegram_api::InputStickerSet> &input_sticker_set);
|
||||
@ -30,4 +42,18 @@ struct SpecialStickerSetType {
|
||||
telegram_api::object_ptr<telegram_api::InputStickerSet> get_input_sticker_set() const;
|
||||
};
|
||||
|
||||
inline bool operator==(const SpecialStickerSetType &lhs, const SpecialStickerSetType &rhs) {
|
||||
return lhs.type_ == rhs.type_;
|
||||
}
|
||||
|
||||
inline bool operator!=(const SpecialStickerSetType &lhs, const SpecialStickerSetType &rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
struct SpecialStickerSetTypeHash {
|
||||
std::size_t operator()(SpecialStickerSetType type) const {
|
||||
return std::hash<string>()(type.type_);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace td
|
||||
|
@ -1313,12 +1313,12 @@ void StickersManager::init() {
|
||||
G()->shared_config().set_option_empty("animated_dice_sticker_set_name"); // legacy
|
||||
}
|
||||
|
||||
StickersManager::SpecialStickerSet &StickersManager::add_special_sticker_set(const string &type) {
|
||||
StickersManager::SpecialStickerSet &StickersManager::add_special_sticker_set(const SpecialStickerSetType &type) {
|
||||
auto &result = special_sticker_sets_[type];
|
||||
if (result.type_.type_.empty()) {
|
||||
result.type_.type_ = type;
|
||||
if (result.type_.is_empty()) {
|
||||
result.type_ = type;
|
||||
} else {
|
||||
CHECK(result.type_.type_ == type);
|
||||
CHECK(result.type_ == type);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -1367,7 +1367,7 @@ void StickersManager::load_special_sticker_set_by_type(const SpecialStickerSetTy
|
||||
return;
|
||||
}
|
||||
|
||||
auto &sticker_set = add_special_sticker_set(type.type_);
|
||||
auto &sticker_set = add_special_sticker_set(type);
|
||||
CHECK(sticker_set.is_being_loaded_);
|
||||
sticker_set.is_being_loaded_ = false;
|
||||
load_special_sticker_set(sticker_set);
|
||||
@ -1407,7 +1407,7 @@ void StickersManager::on_load_special_sticker_set(const SpecialStickerSetType &t
|
||||
return;
|
||||
}
|
||||
|
||||
auto &special_sticker_set = add_special_sticker_set(type.type_);
|
||||
auto &special_sticker_set = add_special_sticker_set(type);
|
||||
if (!special_sticker_set.is_being_loaded_) {
|
||||
return;
|
||||
}
|
||||
@ -1424,7 +1424,7 @@ void StickersManager::on_load_special_sticker_set(const SpecialStickerSetType &t
|
||||
|
||||
special_sticker_set.is_being_loaded_ = false;
|
||||
|
||||
if (type.type_ == SpecialStickerSetType::animated_emoji()) {
|
||||
if (type == SpecialStickerSetType::animated_emoji()) {
|
||||
auto promises = std::move(pending_get_animated_emoji_queries_);
|
||||
reset_to_empty(pending_get_animated_emoji_queries_);
|
||||
for (auto &promise : promises) {
|
||||
@ -1438,7 +1438,7 @@ void StickersManager::on_load_special_sticker_set(const SpecialStickerSetType &t
|
||||
CHECK(sticker_set != nullptr);
|
||||
CHECK(sticker_set->was_loaded);
|
||||
|
||||
if (type.type_ == SpecialStickerSetType::animated_emoji_click()) {
|
||||
if (type == SpecialStickerSetType::animated_emoji_click()) {
|
||||
auto pending_get_requests = std::move(pending_get_animated_emoji_click_stickers_);
|
||||
reset_to_empty(pending_get_animated_emoji_click_stickers_);
|
||||
for (auto &pending_request : pending_get_requests) {
|
||||
@ -2222,7 +2222,7 @@ StickerSetId StickersManager::get_sticker_set_id(const tl_object_ptr<telegram_ap
|
||||
case telegram_api::inputStickerSetAnimatedEmoji::ID:
|
||||
case telegram_api::inputStickerSetAnimatedEmojiAnimations::ID:
|
||||
LOG(ERROR) << "Receive special sticker set " << to_string(set_ptr);
|
||||
return add_special_sticker_set(SpecialStickerSetType(set_ptr).type_).id_;
|
||||
return add_special_sticker_set(SpecialStickerSetType(set_ptr)).id_;
|
||||
case telegram_api::inputStickerSetDice::ID:
|
||||
LOG(ERROR) << "Receive special sticker set " << to_string(set_ptr);
|
||||
return StickerSetId();
|
||||
@ -2251,7 +2251,7 @@ StickerSetId StickersManager::add_sticker_set(tl_object_ptr<telegram_api::InputS
|
||||
case telegram_api::inputStickerSetAnimatedEmoji::ID:
|
||||
case telegram_api::inputStickerSetAnimatedEmojiAnimations::ID:
|
||||
LOG(ERROR) << "Receive special sticker set " << to_string(set_ptr);
|
||||
return add_special_sticker_set(SpecialStickerSetType(set_ptr).type_).id_;
|
||||
return add_special_sticker_set(SpecialStickerSetType(set_ptr)).id_;
|
||||
case telegram_api::inputStickerSetDice::ID:
|
||||
LOG(ERROR) << "Receive special sticker set " << to_string(set_ptr);
|
||||
return StickerSetId();
|
||||
@ -2438,7 +2438,7 @@ StickerSetId StickersManager::on_get_input_sticker_set(FileId sticker_file_id,
|
||||
}
|
||||
case telegram_api::inputStickerSetAnimatedEmoji::ID:
|
||||
case telegram_api::inputStickerSetAnimatedEmojiAnimations::ID:
|
||||
return add_special_sticker_set(SpecialStickerSetType(set_ptr).type_).id_;
|
||||
return add_special_sticker_set(SpecialStickerSetType(set_ptr)).id_;
|
||||
case telegram_api::inputStickerSetDice::ID:
|
||||
return StickerSetId();
|
||||
default:
|
||||
@ -3017,7 +3017,7 @@ void StickersManager::on_get_special_sticker_set(const SpecialStickerSetType &ty
|
||||
|
||||
LOG(INFO) << "Receive special sticker set " << type.type_ << ": " << sticker_set_id << ' ' << s->access_hash << ' '
|
||||
<< s->short_name;
|
||||
auto &sticker_set = add_special_sticker_set(type.type_);
|
||||
auto &sticker_set = add_special_sticker_set(type);
|
||||
if (sticker_set_id == sticker_set.id_ && s->access_hash == sticker_set.access_hash_ &&
|
||||
s->short_name == sticker_set.short_name_ && !s->short_name.empty()) {
|
||||
on_load_special_sticker_set(type, Status::OK());
|
||||
@ -3031,7 +3031,7 @@ void StickersManager::on_get_special_sticker_set(const SpecialStickerSetType &ty
|
||||
|
||||
G()->td_db()->get_binlog_pmc()->set(type.type_, PSTRING() << sticker_set.id_.get() << ' ' << sticker_set.access_hash_
|
||||
<< ' ' << sticker_set.short_name_);
|
||||
if (type.type_ == SpecialStickerSetType::animated_emoji()) {
|
||||
if (type == SpecialStickerSetType::animated_emoji()) {
|
||||
G()->shared_config().set_option_string(PSLICE() << type.type_ << "_name", sticker_set.short_name_);
|
||||
try_update_animated_emoji_messages();
|
||||
} else if (!type.get_dice_emoji().empty()) {
|
||||
|
@ -654,7 +654,7 @@ class StickersManager final : public Actor {
|
||||
|
||||
void tear_down() final;
|
||||
|
||||
SpecialStickerSet &add_special_sticker_set(const string &type);
|
||||
SpecialStickerSet &add_special_sticker_set(const SpecialStickerSetType &type);
|
||||
|
||||
static void init_special_sticker_set(SpecialStickerSet &sticker_set, int64 sticker_set_id, int64 access_hash,
|
||||
string name);
|
||||
@ -782,7 +782,7 @@ class StickersManager final : public Actor {
|
||||
int32 recent_stickers_limit_ = 200;
|
||||
int32 favorite_stickers_limit_ = 5;
|
||||
|
||||
std::unordered_map<string, SpecialStickerSet> special_sticker_sets_;
|
||||
std::unordered_map<SpecialStickerSetType, SpecialStickerSet, SpecialStickerSetTypeHash> special_sticker_sets_;
|
||||
|
||||
struct StickerSetLoadRequest {
|
||||
Promise<Unit> promise;
|
||||
|
Loading…
Reference in New Issue
Block a user