From 4a5320e2e52701749b465790a35bbc007ee2a3ff Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 18 Apr 2020 08:45:41 +0300 Subject: [PATCH] Partial support of new MessageDice. GitOrigin-RevId: 075d457a264bb00d28194e80b709205711b32c69 --- td/generate/scheme/td_api.tl | 8 +-- td/generate/scheme/td_api.tlo | Bin 171092 -> 171156 bytes td/telegram/MessageContent.cpp | 103 +++++++++++++++++++-------------- td/telegram/Version.h | 1 + td/telegram/cli.cpp | 6 +- 5 files changed, 70 insertions(+), 48 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index e1c5bbda3..20397f74b 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -1380,8 +1380,8 @@ messageVenue venue:venue = MessageContent; //@description A message with a user contact @contact The contact description messageContact contact:contact = MessageContent; -//@description A dice message. The dice value is randomly generated by the server @value The dice value; 0-6. If the value is 0, the dice must roll infinitely -messageDice value:int32 = MessageContent; +//@description A dice message. The dice value is randomly generated by the server @emoji Emoji on which the dice throw animation is based @value The dice value; 0-6. If the value is 0, the dice must roll infinitely +messageDice emoji:string value:int32 = MessageContent; //@description A message with a game @game The game description messageGame game:game = MessageContent; @@ -1584,8 +1584,8 @@ inputMessageVenue venue:venue = InputMessageContent; //@description A message containing a user contact @contact Contact to send inputMessageContact contact:contact = InputMessageContent; -//@description A dice message @clear_draft True, if a chat message draft should be deleted -inputMessageDice clear_draft:Bool = InputMessageContent; +//@description A dice message @emoji Emoji on which the dice throw animation is based @clear_draft True, if a chat message draft should be deleted +inputMessageDice emoji:string clear_draft:Bool = InputMessageContent; //@description A message with a game; not supported for channels or secret chats @bot_user_id User identifier of the bot that owns the game @game_short_name Short name of the game inputMessageGame bot_user_id:int32 game_short_name:string = InputMessageContent; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index c257192d790b84ca26515e05763694a8683bf394..e9f8a1b1e8fe0ab933f67255a9aab9fe5f063b23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`_6a1@7{azQp>%mmdtpo_*w6LNt#y9Zi z*H>G@m(vfHd_x}(e=@o&HZl_38+(7~qnOTH0|JDZ?c`Ioe7y5~w)^JoMK`kAPS~R5 z=12MVy6@1kTI5bUhvIj6+v&R{(^HF=7G<|_**4(hPuubIKZ<$vSjG?SsD9zYC61u~ zsqE5)?7#=`E|yk&7+fJO=AZhhsMG;L9Iw1+W*DpxjFC!+kSPmUsEiU4T9(_4)s3rQ z4CTMGY{RvisA&eZHpTC>D+s%#)e_r_zK>0hxoCpYf5kJI44K~UfLukh2Mg;h(~ z8{Ho>cw-cR(X(5rE2Y*>L0?U!V5~+LENUG#v&=+$Q(=fR(S={xwLjRVnd;k9h}5~Nh~ zGm(w|0T*9)o8K-5f9l-8b3zcDz|`|XKmAUaF7{`YR>9}Y!<&RX^wlzXRz4sU$U8GE Hl(+s1QYjk> diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 625ec6abb..bb33b1b99 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -645,10 +645,14 @@ class MessagePoll : public MessageContent { class MessageDice : public MessageContent { public: + string emoji; int32 dice_value = 0; + static constexpr const char *DEFAULT_EMOJI = "🎲"; + MessageDice() = default; - explicit MessageDice(int32 dice_value) : dice_value(dice_value) { + MessageDice(string emoji, int32 dice_value) + : emoji(emoji.empty() ? string(DEFAULT_EMOJI) : std::move(emoji)), dice_value(dice_value) { } MessageContentType get_type() const override { @@ -656,6 +660,8 @@ class MessageDice : public MessageContent { } }; +constexpr const char *MessageDice::DEFAULT_EMOJI; + template static void store(const MessageContent *content, StorerT &storer) { CHECK(content != nullptr); @@ -915,6 +921,7 @@ static void store(const MessageContent *content, StorerT &storer) { } case MessageContentType::Dice: { auto m = static_cast(content); + store(m->emoji, storer); store(m->dice_value, storer); break; } @@ -1262,6 +1269,11 @@ static void parse(unique_ptr &content, ParserT &parser) { } case MessageContentType::Dice: { auto m = make_unique(); + if (parser.version() >= static_cast(Version::AddDiceEmoji)) { + parse(m->emoji, parser); + } else { + m->emoji = MessageDice::DEFAULT_EMOJI; + } parse(m->dice_value, parser); is_bad = m->dice_value < 0 || m->dice_value > 6; content = std::move(m); @@ -1476,8 +1488,11 @@ static Result create_input_message_content( break; } case td_api::inputMessageDice::ID: { - auto input_dice = static_cast(input_message_content.get()); - content = make_unique(); + auto input_dice = static_cast(input_message_content.get()); + if (!clean_input_string(input_dice->emoji_)) { + return Status::Error(400, "Dice emoji must be encoded in UTF-8"); + } + content = td::make_unique(std::move(input_dice->emoji_), 0); clear_draft = input_dice->clear_draft_; break; } @@ -1615,37 +1630,37 @@ static Result create_input_message_content( return Status::Error(400, "Invoices can be sent only by bots"); } - auto input_message_invoice = move_tl_object_as(input_message_content); - if (!clean_input_string(input_message_invoice->title_)) { + auto input_invoice = move_tl_object_as(input_message_content); + if (!clean_input_string(input_invoice->title_)) { return Status::Error(400, "Invoice title must be encoded in UTF-8"); } - if (!clean_input_string(input_message_invoice->description_)) { + if (!clean_input_string(input_invoice->description_)) { return Status::Error(400, "Invoice description must be encoded in UTF-8"); } - if (!clean_input_string(input_message_invoice->photo_url_)) { + if (!clean_input_string(input_invoice->photo_url_)) { return Status::Error(400, "Invoice photo URL must be encoded in UTF-8"); } - if (!clean_input_string(input_message_invoice->start_parameter_)) { + if (!clean_input_string(input_invoice->start_parameter_)) { return Status::Error(400, "Invoice bot start parameter must be encoded in UTF-8"); } - if (!clean_input_string(input_message_invoice->provider_token_)) { + if (!clean_input_string(input_invoice->provider_token_)) { return Status::Error(400, "Invoice provider token must be encoded in UTF-8"); } - if (!clean_input_string(input_message_invoice->provider_data_)) { + if (!clean_input_string(input_invoice->provider_data_)) { return Status::Error(400, "Invoice provider data must be encoded in UTF-8"); } - if (!clean_input_string(input_message_invoice->invoice_->currency_)) { + if (!clean_input_string(input_invoice->invoice_->currency_)) { return Status::Error(400, "Invoice currency must be encoded in UTF-8"); } auto message_invoice = make_unique(); - message_invoice->title = std::move(input_message_invoice->title_); - message_invoice->description = std::move(input_message_invoice->description_); + message_invoice->title = std::move(input_invoice->title_); + message_invoice->description = std::move(input_invoice->description_); - auto r_http_url = parse_url(input_message_invoice->photo_url_); + auto r_http_url = parse_url(input_invoice->photo_url_); if (r_http_url.is_error()) { - if (!input_message_invoice->photo_url_.empty()) { - LOG(INFO) << "Can't register url " << input_message_invoice->photo_url_; + if (!input_invoice->photo_url_.empty()) { + LOG(INFO) << "Can't register url " << input_invoice->photo_url_; } message_invoice->photo.id = -2; } else { @@ -1659,20 +1674,20 @@ static Result create_input_message_content( PhotoSize s; s.type = 'u'; - s.dimensions = get_dimensions(input_message_invoice->photo_width_, input_message_invoice->photo_height_); - s.size = input_message_invoice->photo_size_; // TODO use invoice_file_id size + s.dimensions = get_dimensions(input_invoice->photo_width_, input_invoice->photo_height_); + s.size = input_invoice->photo_size_; // TODO use invoice_file_id size s.file_id = invoice_file_id; message_invoice->photo.photos.push_back(s); } } - message_invoice->start_parameter = std::move(input_message_invoice->start_parameter_); + message_invoice->start_parameter = std::move(input_invoice->start_parameter_); - message_invoice->invoice.currency = std::move(input_message_invoice->invoice_->currency_); - message_invoice->invoice.price_parts.reserve(input_message_invoice->invoice_->price_parts_.size()); + message_invoice->invoice.currency = std::move(input_invoice->invoice_->currency_); + message_invoice->invoice.price_parts.reserve(input_invoice->invoice_->price_parts_.size()); int64 total_amount = 0; const int64 MAX_AMOUNT = 9999'9999'9999; - for (auto &price : input_message_invoice->invoice_->price_parts_) { + for (auto &price : input_invoice->invoice_->price_parts_) { if (!clean_input_string(price->label_)) { return Status::Error(400, "Invoice price label must be encoded in UTF-8"); } @@ -1690,16 +1705,15 @@ static Result create_input_message_content( } message_invoice->total_amount = total_amount; - message_invoice->invoice.is_test = input_message_invoice->invoice_->is_test_; - message_invoice->invoice.need_name = input_message_invoice->invoice_->need_name_; - message_invoice->invoice.need_phone_number = input_message_invoice->invoice_->need_phone_number_; - message_invoice->invoice.need_email_address = input_message_invoice->invoice_->need_email_address_; - message_invoice->invoice.need_shipping_address = input_message_invoice->invoice_->need_shipping_address_; - message_invoice->invoice.send_phone_number_to_provider = - input_message_invoice->invoice_->send_phone_number_to_provider_; + message_invoice->invoice.is_test = input_invoice->invoice_->is_test_; + message_invoice->invoice.need_name = input_invoice->invoice_->need_name_; + message_invoice->invoice.need_phone_number = input_invoice->invoice_->need_phone_number_; + message_invoice->invoice.need_email_address = input_invoice->invoice_->need_email_address_; + message_invoice->invoice.need_shipping_address = input_invoice->invoice_->need_shipping_address_; + message_invoice->invoice.send_phone_number_to_provider = input_invoice->invoice_->send_phone_number_to_provider_; message_invoice->invoice.send_email_address_to_provider = - input_message_invoice->invoice_->send_email_address_to_provider_; - message_invoice->invoice.is_flexible = input_message_invoice->invoice_->is_flexible_; + input_invoice->invoice_->send_email_address_to_provider_; + message_invoice->invoice.is_flexible = input_invoice->invoice_->is_flexible_; if (message_invoice->invoice.send_phone_number_to_provider) { message_invoice->invoice.need_phone_number = true; } @@ -1710,9 +1724,9 @@ static Result create_input_message_content( message_invoice->invoice.need_shipping_address = true; } - message_invoice->payload = std::move(input_message_invoice->payload_); - message_invoice->provider_token = std::move(input_message_invoice->provider_token_); - message_invoice->provider_data = std::move(input_message_invoice->provider_data_); + message_invoice->payload = std::move(input_invoice->payload_); + message_invoice->provider_token = std::move(input_invoice->provider_token_); + message_invoice->provider_data = std::move(input_invoice->provider_data_); content = std::move(message_invoice); break; @@ -2159,8 +2173,10 @@ static tl_object_ptr get_input_media_impl( auto m = static_cast(content); return m->contact.get_input_media_contact(); } - case MessageContentType::Dice: - return make_tl_object(""); + case MessageContentType::Dice: { + auto m = static_cast(content); + return make_tl_object(m->emoji); + } case MessageContentType::Document: { auto m = static_cast(content); return td->documents_manager_->get_input_media(m->file_id, std::move(input_file), std::move(input_thumbnail)); @@ -3092,7 +3108,7 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo case MessageContentType::Dice: { auto old_ = static_cast(old_content); auto new_ = static_cast(new_content); - if (old_->dice_value != new_->dice_value) { + if (old_->emoji != new_->emoji || old_->dice_value != new_->dice_value) { need_update = true; } break; @@ -3727,7 +3743,7 @@ unique_ptr get_message_content(Td *td, FormattedText message, case telegram_api::messageMediaDice::ID: { auto message_dice = move_tl_object_as(media); - auto m = make_unique(message_dice->value_); + auto m = td::make_unique(message_dice->emoticon_, message_dice->value_); if (m->dice_value < 0 || m->dice_value > 6) { break; } @@ -3916,12 +3932,13 @@ unique_ptr dup_message_content(Td *td, DialogId dialog_id, const } case MessageContentType::Contact: return make_unique(*static_cast(content)); - case MessageContentType::Dice: + case MessageContentType::Dice: { + auto result = td::make_unique(*static_cast(content)); if (type != MessageContentDupType::Forward) { - return make_unique(); - } else { - return make_unique(*static_cast(content)); + result->dice_value = 0; } + return std::move(result); + } case MessageContentType::Document: { auto result = make_unique(*static_cast(content)); if (remove_caption) { @@ -4453,7 +4470,7 @@ tl_object_ptr get_message_content_object(const MessageCo } case MessageContentType::Dice: { const MessageDice *m = static_cast(content); - return make_tl_object(m->dice_value); + return make_tl_object(m->emoji, m->dice_value); } default: UNREACHABLE(); diff --git a/td/telegram/Version.h b/td/telegram/Version.h index 4639f8d1e..e612a36c0 100644 --- a/td/telegram/Version.h +++ b/td/telegram/Version.h @@ -36,6 +36,7 @@ enum class Version : int32 { AddPhotoSizeSource, AddFolders, SupportPolls2_0, + AddDiceEmoji, Next }; diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index cf61cdba6..bcd263a21 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3146,7 +3146,11 @@ class CliClient final : public Actor { as_message_id(from_message_id), true, op == "scopy", Random::fast(0, 1) == 0)); } else if (op == "sdice" || op == "sdicecd") { - send_message(args, td_api::make_object(op == "sdicecd")); + string chat_id; + string emoji; + std::tie(chat_id, emoji) = split(args); + + send_message(chat_id, td_api::make_object(emoji, op == "sdicecd")); } else if (op == "sd") { string chat_id; string document_path;