Add messageDice.success_animation_frame_number.
GitOrigin-RevId: d0afff34c7d74fe5e06b008b7a8438be4aebe88b
This commit is contained in:
parent
7336134ff3
commit
851d23f06c
@ -1385,8 +1385,8 @@ messageContact contact:contact = MessageContent;
|
||||
//@final_state_sticker The animated sticker with the final dice animation; may be null if unknown. updateMessageContent will be sent when the sticker became known
|
||||
//@emoji Emoji on which the dice throw animation is based
|
||||
//@value The dice value. If the value is 0, the dice don't have final state yet
|
||||
//@need_success_animation True, if a success animation like a shower of confetti needs to be shown on updateMessageSendSucceeded
|
||||
messageDice initial_state_sticker:sticker final_state_sticker:sticker emoji:string value:int32 need_success_animation:Bool = MessageContent;
|
||||
//@success_animation_frame_number Number of frame after which a success animation like a shower of confetti needs to be shown on updateMessageSendSucceeded
|
||||
messageDice initial_state_sticker:sticker final_state_sticker:sticker emoji:string value:int32 success_animation_frame_number:int32 = MessageContent;
|
||||
|
||||
//@description A message with a game @game The game description
|
||||
messageGame game:game = MessageContent;
|
||||
|
Binary file not shown.
@ -57,6 +57,7 @@
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
|
||||
namespace td {
|
||||
@ -1292,7 +1293,8 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
|
||||
string wallet_config;
|
||||
string ignored_restriction_reasons;
|
||||
vector<string> dice_emojis;
|
||||
string dice_success_values;
|
||||
std::unordered_map<string, size_t> dice_emoji_index;
|
||||
std::unordered_map<string, string> dice_emoji_success_value;
|
||||
if (config->get_id() == telegram_api::jsonObject::ID) {
|
||||
for (auto &key_value : static_cast<telegram_api::jsonObject *>(config.get())->value_) {
|
||||
Slice key = key_value->key_;
|
||||
@ -1348,6 +1350,7 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
|
||||
if (emoji->get_id() == telegram_api::jsonString::ID) {
|
||||
Slice emoji_text = static_cast<telegram_api::jsonString *>(emoji.get())->value_;
|
||||
if (!emoji_text.empty()) {
|
||||
dice_emoji_index[emoji_text.str()] = dice_emojis.size();
|
||||
dice_emojis.push_back(emoji_text.str());
|
||||
} else {
|
||||
LOG(ERROR) << "Receive empty dice emoji";
|
||||
@ -1362,16 +1365,32 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
|
||||
continue;
|
||||
}
|
||||
if (key == "emojies_send_dice_success") {
|
||||
if (value->get_id() == telegram_api::jsonArray::ID) {
|
||||
auto success_values = std::move(static_cast<telegram_api::jsonArray *>(value)->value_);
|
||||
if (value->get_id() == telegram_api::jsonObject::ID) {
|
||||
auto success_values = std::move(static_cast<telegram_api::jsonObject *>(value)->value_);
|
||||
for (auto &success_value : success_values) {
|
||||
CHECK(success_value != nullptr);
|
||||
if (success_value->get_id() == telegram_api::jsonNumber::ID) {
|
||||
int32 dice_value = static_cast<int32>(static_cast<telegram_api::jsonNumber *>(success_value.get())->value_);
|
||||
if (!dice_success_values.empty()) {
|
||||
dice_success_values += ',';
|
||||
if (success_value->value_->get_id() == telegram_api::jsonObject::ID) {
|
||||
int32 dice_value = -1;
|
||||
int32 frame_start = -1;
|
||||
for (auto &dice_key_value :
|
||||
static_cast<telegram_api::jsonObject *>(success_value->value_.get())->value_) {
|
||||
if (dice_key_value->value_->get_id() != telegram_api::jsonNumber::ID) {
|
||||
continue;
|
||||
}
|
||||
auto current_value =
|
||||
static_cast<int32>(static_cast<telegram_api::jsonNumber *>(dice_key_value->value_.get())->value_);
|
||||
if (dice_key_value->key_ == "value") {
|
||||
dice_value = current_value;
|
||||
}
|
||||
if (dice_key_value->key_ == "frame_start") {
|
||||
frame_start = current_value;
|
||||
}
|
||||
}
|
||||
if (dice_value < 0 || frame_start < 0) {
|
||||
LOG(ERROR) << "Receive unexpected dice success value " << to_string(success_value);
|
||||
} else {
|
||||
dice_emoji_success_value[success_value->key_] = PSTRING() << dice_value << ':' << frame_start;
|
||||
}
|
||||
dice_success_values += to_string(dice_value);
|
||||
} else {
|
||||
LOG(ERROR) << "Receive unexpected dice success value " << to_string(success_value);
|
||||
}
|
||||
@ -1414,9 +1433,15 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
|
||||
|
||||
if (!dice_emojis.empty()) {
|
||||
shared_config.set_option_string("dice_emojis", implode(dice_emojis, '\x01'));
|
||||
}
|
||||
if (!dice_success_values.empty()) {
|
||||
shared_config.set_option_string("dice_success_values", dice_success_values);
|
||||
vector<string> dice_success_values(dice_emojis.size());
|
||||
for (auto &it : dice_emoji_success_value) {
|
||||
if (dice_emoji_index.find(it.first) == dice_emoji_index.end()) {
|
||||
LOG(ERROR) << "Can't find emoji " << it.first;
|
||||
continue;
|
||||
}
|
||||
dice_success_values[dice_emoji_index[it.first]] = it.second;
|
||||
}
|
||||
shared_config.set_option_string("dice_success_values", implode(dice_success_values, ','));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4499,9 +4499,10 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
|
||||
auto initial_state = td->stickers_manager_->get_dice_sticker_object(m->emoji, 0);
|
||||
auto final_state =
|
||||
m->dice_value == 0 ? nullptr : td->stickers_manager_->get_dice_sticker_object(m->emoji, m->dice_value);
|
||||
auto need_success_animation = td->stickers_manager_->need_dice_success_animation(m->emoji, m->dice_value);
|
||||
auto success_animation_frame_number =
|
||||
td->stickers_manager_->get_dice_success_animation_frame_number(m->emoji, m->dice_value);
|
||||
return make_tl_object<td_api::messageDice>(std::move(initial_state), std::move(final_state), m->emoji,
|
||||
m->dice_value, need_success_animation);
|
||||
m->dice_value, success_animation_frame_number);
|
||||
}
|
||||
default:
|
||||
UNREACHABLE();
|
||||
|
@ -1377,19 +1377,20 @@ tl_object_ptr<td_api::sticker> StickersManager::get_dice_sticker_object(const st
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool StickersManager::need_dice_success_animation(const string &emoji, int32 value) const {
|
||||
int32 StickersManager::get_dice_success_animation_frame_number(const string &emoji, int32 value) const {
|
||||
if (td_->auth_manager_->is_bot()) {
|
||||
return false;
|
||||
return std::numeric_limits<int32>::max();
|
||||
}
|
||||
if (value == 0 || !td::contains(dice_emojis_, emoji)) {
|
||||
return false;
|
||||
return std::numeric_limits<int32>::max();
|
||||
}
|
||||
auto pos = static_cast<size_t>(std::find(dice_emojis_.begin(), dice_emojis_.end(), emoji) - dice_emojis_.begin());
|
||||
if (pos >= dice_success_values_.size()) {
|
||||
return false;
|
||||
return std::numeric_limits<int32>::max();
|
||||
}
|
||||
|
||||
return dice_success_values_[pos] == value;
|
||||
auto &result = dice_success_values_[pos];
|
||||
return result.first == value ? result.second : std::numeric_limits<int32>::max();
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::stickerSet> StickersManager::get_sticker_set_object(StickerSetId sticker_set_id) const {
|
||||
@ -3391,7 +3392,10 @@ void StickersManager::on_update_dice_success_values() {
|
||||
return;
|
||||
}
|
||||
dice_success_values_str_ = std::move(dice_success_values_str);
|
||||
dice_success_values_ = transform(full_split(dice_success_values_str_, ','), to_integer<int32>);
|
||||
dice_success_values_ = transform(full_split(dice_success_values_str_, ','), [](Slice value) {
|
||||
auto result = split(value, ':');
|
||||
return std::make_pair(to_integer<int32>(result.first), to_integer<int32>(result.second));
|
||||
});
|
||||
}
|
||||
|
||||
void StickersManager::on_update_sticker_sets() {
|
||||
|
@ -54,7 +54,7 @@ class StickersManager : public Actor {
|
||||
|
||||
tl_object_ptr<td_api::sticker> get_dice_sticker_object(const string &emoji, int32 value) const;
|
||||
|
||||
bool need_dice_success_animation(const string &emoji, int32 value) const;
|
||||
int32 get_dice_success_animation_frame_number(const string &emoji, int32 value) const;
|
||||
|
||||
tl_object_ptr<td_api::stickerSet> get_sticker_set_object(StickerSetId sticker_set_id) const;
|
||||
|
||||
@ -716,7 +716,7 @@ class StickersManager : public Actor {
|
||||
vector<string> dice_emojis_;
|
||||
|
||||
string dice_success_values_str_;
|
||||
vector<int32> dice_success_values_;
|
||||
vector<std::pair<int32, int32>> dice_success_values_;
|
||||
};
|
||||
|
||||
} // namespace td
|
||||
|
@ -27,11 +27,11 @@ char *str_dup(Slice str) {
|
||||
|
||||
string implode(const vector<string> &v, char delimiter) {
|
||||
string result;
|
||||
for (auto &str : v) {
|
||||
if (!result.empty()) {
|
||||
for (size_t i = 0; i < v.size(); i++) {
|
||||
if (i != 0) {
|
||||
result += delimiter;
|
||||
}
|
||||
result += str;
|
||||
result += v[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user