Partial support of new MessageDice.

GitOrigin-RevId: 075d457a264bb00d28194e80b709205711b32c69
This commit is contained in:
levlam 2020-04-18 08:45:41 +03:00
parent 06135cccf9
commit 4a5320e2e5
5 changed files with 70 additions and 48 deletions

View File

@ -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;

Binary file not shown.

View File

@ -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 <class StorerT>
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<const MessageDice *>(content);
store(m->emoji, storer);
store(m->dice_value, storer);
break;
}
@ -1262,6 +1269,11 @@ static void parse(unique_ptr<MessageContent> &content, ParserT &parser) {
}
case MessageContentType::Dice: {
auto m = make_unique<MessageDice>();
if (parser.version() >= static_cast<int32>(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<InputMessageContent> create_input_message_content(
break;
}
case td_api::inputMessageDice::ID: {
auto input_dice = static_cast<const td_api::inputMessageDice *>(input_message_content.get());
content = make_unique<MessageDice>();
auto input_dice = static_cast<td_api::inputMessageDice *>(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<MessageDice>(std::move(input_dice->emoji_), 0);
clear_draft = input_dice->clear_draft_;
break;
}
@ -1615,37 +1630,37 @@ static Result<InputMessageContent> create_input_message_content(
return Status::Error(400, "Invoices can be sent only by bots");
}
auto input_message_invoice = move_tl_object_as<td_api::inputMessageInvoice>(input_message_content);
if (!clean_input_string(input_message_invoice->title_)) {
auto input_invoice = move_tl_object_as<td_api::inputMessageInvoice>(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<MessageInvoice>();
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<InputMessageContent> 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<InputMessageContent> 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<InputMessageContent> 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<telegram_api::InputMedia> get_input_media_impl(
auto m = static_cast<const MessageContact *>(content);
return m->contact.get_input_media_contact();
}
case MessageContentType::Dice:
return make_tl_object<telegram_api::inputMediaDice>("");
case MessageContentType::Dice: {
auto m = static_cast<const MessageDice *>(content);
return make_tl_object<telegram_api::inputMediaDice>(m->emoji);
}
case MessageContentType::Document: {
auto m = static_cast<const MessageDocument *>(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<const MessageDice *>(old_content);
auto new_ = static_cast<const MessageDice *>(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<MessageContent> get_message_content(Td *td, FormattedText message,
case telegram_api::messageMediaDice::ID: {
auto message_dice = move_tl_object_as<telegram_api::messageMediaDice>(media);
auto m = make_unique<MessageDice>(message_dice->value_);
auto m = td::make_unique<MessageDice>(message_dice->emoticon_, message_dice->value_);
if (m->dice_value < 0 || m->dice_value > 6) {
break;
}
@ -3916,12 +3932,13 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
}
case MessageContentType::Contact:
return make_unique<MessageContact>(*static_cast<const MessageContact *>(content));
case MessageContentType::Dice:
case MessageContentType::Dice: {
auto result = td::make_unique<MessageDice>(*static_cast<const MessageDice *>(content));
if (type != MessageContentDupType::Forward) {
return make_unique<MessageDice>();
} else {
return make_unique<MessageDice>(*static_cast<const MessageDice *>(content));
result->dice_value = 0;
}
return std::move(result);
}
case MessageContentType::Document: {
auto result = make_unique<MessageDocument>(*static_cast<const MessageDocument *>(content));
if (remove_caption) {
@ -4453,7 +4470,7 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
}
case MessageContentType::Dice: {
const MessageDice *m = static_cast<const MessageDice *>(content);
return make_tl_object<td_api::messageDice>(m->dice_value);
return make_tl_object<td_api::messageDice>(m->emoji, m->dice_value);
}
default:
UNREACHABLE();

View File

@ -36,6 +36,7 @@ enum class Version : int32 {
AddPhotoSizeSource,
AddFolders,
SupportPolls2_0,
AddDiceEmoji,
Next
};

View File

@ -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<td_api::inputMessageDice>(op == "sdicecd"));
string chat_id;
string emoji;
std::tie(chat_id, emoji) = split(args);
send_message(chat_id, td_api::make_object<td_api::inputMessageDice>(emoji, op == "sdicecd"));
} else if (op == "sd") {
string chat_id;
string document_path;