Add td_api::reactionTypePaid.

This commit is contained in:
levlam 2024-07-26 15:11:41 +03:00
parent 3ba783158f
commit 1438e1bd88
6 changed files with 44 additions and 4 deletions

View File

@ -1479,6 +1479,9 @@ reactionTypeEmoji emoji:string = ReactionType;
//@description A reaction with a custom emoji @custom_emoji_id Unique identifier of the custom emoji
reactionTypeCustomEmoji custom_emoji_id:int64 = ReactionType;
//@description The paid reaction in a channel chat
reactionTypePaid = ReactionType;
//@description Contains information about a forwarded message
//@origin Origin of the forwarded message

View File

@ -964,8 +964,11 @@ void ReactionManager::set_default_reaction(ReactionType reaction_type, Promise<U
if (reaction_type.is_empty()) {
return promise.set_error(Status::Error(400, "Default reaction must be non-empty"));
}
if (reaction_type.is_paid_reaction()) {
return promise.set_error(Status::Error(400, "Can't set paid reaction as default"));
}
if (!reaction_type.is_custom_reaction() && !is_active_reaction(reaction_type)) {
return promise.set_error(Status::Error(400, "Can't set incative reaction as default"));
return promise.set_error(Status::Error(400, "Can't set inactive reaction as default"));
}
if (td_->option_manager_->get_option_string("default_reaction", "-") != reaction_type.get_string()) {

View File

@ -44,7 +44,7 @@ ReactionType::ReactionType(const telegram_api::object_ptr<telegram_api::Reaction
break;
case telegram_api::reactionEmoji::ID:
reaction_ = static_cast<const telegram_api::reactionEmoji *>(reaction.get())->emoticon_;
if (is_custom_reaction()) {
if (is_custom_reaction() || is_paid_reaction()) {
reaction_ = string();
}
break;
@ -53,6 +53,7 @@ ReactionType::ReactionType(const telegram_api::object_ptr<telegram_api::Reaction
get_custom_emoji_string(static_cast<const telegram_api::reactionCustomEmoji *>(reaction.get())->document_id_);
break;
case telegram_api::reactionPaid::ID:
reaction_ = "$";
break;
default:
UNREACHABLE();
@ -71,7 +72,7 @@ ReactionType::ReactionType(const td_api::object_ptr<td_api::ReactionType> &type)
break;
}
reaction_ = emoji;
if (is_custom_reaction()) {
if (is_custom_reaction() || is_paid_reaction()) {
reaction_ = string();
break;
}
@ -81,6 +82,9 @@ ReactionType::ReactionType(const td_api::object_ptr<td_api::ReactionType> &type)
reaction_ =
get_custom_emoji_string(static_cast<const td_api::reactionTypeCustomEmoji *>(type.get())->custom_emoji_id_);
break;
case td_api::reactionTypePaid::ID:
reaction_ = "$";
break;
default:
UNREACHABLE();
break;
@ -116,6 +120,9 @@ telegram_api::object_ptr<telegram_api::Reaction> ReactionType::get_input_reactio
if (is_custom_reaction()) {
return telegram_api::make_object<telegram_api::reactionCustomEmoji>(get_custom_emoji_id(reaction_));
}
if (is_paid_reaction()) {
return telegram_api::make_object<telegram_api::reactionPaid>();
}
return telegram_api::make_object<telegram_api::reactionEmoji>(reaction_);
}
@ -126,6 +133,9 @@ td_api::object_ptr<td_api::ReactionType> ReactionType::get_reaction_type_object(
if (is_custom_reaction()) {
return td_api::make_object<td_api::reactionTypeCustomEmoji>(get_custom_emoji_id(reaction_));
}
if (is_paid_reaction()) {
return td_api::make_object<td_api::reactionTypePaid>();
}
return td_api::make_object<td_api::reactionTypeEmoji>(reaction_);
}
@ -148,12 +158,22 @@ bool ReactionType::is_custom_reaction() const {
return reaction_[0] == '#';
}
bool ReactionType::is_paid_reaction() const {
return reaction_ == "$";
}
bool ReactionType::is_active_reaction(
const FlatHashMap<ReactionType, size_t, ReactionTypeHash> &active_reaction_pos) const {
return !is_empty() && (is_custom_reaction() || active_reaction_pos.count(*this) > 0);
return !is_empty() && (is_custom_reaction() || is_paid_reaction() || active_reaction_pos.count(*this) > 0);
}
bool operator<(const ReactionType &lhs, const ReactionType &rhs) {
if (lhs.is_paid_reaction()) {
return !rhs.is_paid_reaction();
}
if (rhs.is_paid_reaction()) {
return false;
}
return lhs.reaction_ < rhs.reaction_;
}
@ -168,6 +188,9 @@ StringBuilder &operator<<(StringBuilder &string_builder, const ReactionType &rea
if (reaction_type.is_custom_reaction()) {
return string_builder << "custom reaction " << get_custom_emoji_id(reaction_type.reaction_);
}
if (reaction_type.is_paid_reaction()) {
return string_builder << "paid reaction";
}
return string_builder << "reaction " << reaction_type.reaction_;
}
@ -179,6 +202,9 @@ int64 get_reaction_types_hash(const vector<ReactionType> &reaction_types) {
numbers.push_back(custom_emoji_id >> 32);
numbers.push_back(custom_emoji_id & 0xFFFFFFFF);
} else {
if (reaction_type.is_paid_reaction()) {
LOG(ERROR) << "Have paid reaction";
}
auto emoji = remove_emoji_selectors(reaction_type.get_string());
unsigned char hash[16];
md5(emoji, {hash, sizeof(hash)});

View File

@ -59,6 +59,8 @@ class ReactionType {
bool is_custom_reaction() const;
bool is_paid_reaction() const;
bool is_active_reaction(const FlatHashMap<ReactionType, size_t, ReactionTypeHash> &active_reaction_pos) const;
bool is_empty() const {

View File

@ -2910,6 +2910,9 @@ bool StoryManager::can_use_story_reaction(const Story *story, const ReactionType
}
return false;
}
if (reaction_type.is_paid_reaction()) {
return false;
}
return td_->reaction_manager_->is_active_reaction(reaction_type);
}

View File

@ -792,6 +792,9 @@ class CliClient final : public Actor {
if (type.empty()) {
return nullptr;
}
if (type == "$") {
return td_api::make_object<td_api::reactionTypePaid>();
}
auto r_custom_emoji_id = to_integer_safe<int64>(type);
if (r_custom_emoji_id.is_ok()) {
return td_api::make_object<td_api::reactionTypeCustomEmoji>(r_custom_emoji_id.ok());