Add td_api::messageWebViewDataSent/messageWebViewDataReceived.

This commit is contained in:
levlam 2022-03-28 10:01:39 +03:00
parent 0ae8401ab5
commit e8a82f9e70
6 changed files with 144 additions and 14 deletions

View File

@ -1940,7 +1940,13 @@ messageContactRegistered = MessageContent;
//@description The current user has connected a website by logging in using Telegram Login Widget on it @domain_name Domain name of the connected website
messageWebsiteConnected domain_name:string = MessageContent;
//@description Telegram Passport data has been sent @types List of Telegram Passport element types sent
//@description Data from web view has been sent to a bot @button_text Text of the keyboardButtonTypeWebView button, which opened the web view
messageWebViewDataSent button_text:string = MessageContent;
//@description Data from web view has been received; for bots only @button_text Text of the keyboardButtonTypeWebView button, which opened the web view @data Received data
messageWebViewDataReceived button_text:string data:string = MessageContent;
//@description Telegram Passport data has been sent to a bot @types List of Telegram Passport element types sent
messagePassportDataSent types:vector<PassportElementType> = MessageContent;
//@description Telegram Passport data has been received; for bots only @elements List of received Telegram Passport elements @credentials Encrypted data credentials

View File

@ -400,6 +400,8 @@ bool DialogAction::is_canceled_by_message_of_type(MessageContentType message_con
case MessageContentType::GroupCall:
case MessageContentType::InviteToGroupCall:
case MessageContentType::ChatSetTheme:
case MessageContentType::WebViewDataSent:
case MessageContentType::WebViewDataReceived:
return false;
default:
UNREACHABLE();

View File

@ -745,6 +745,34 @@ class MessageChatSetTheme final : public MessageContent {
}
};
class MessageWebViewDataSent final : public MessageContent {
public:
string button_text;
MessageWebViewDataSent() = default;
explicit MessageWebViewDataSent(string &&button_text) : button_text(std::move(button_text)) {
}
MessageContentType get_type() const final {
return MessageContentType::WebViewDataSent;
}
};
class MessageWebViewDataReceived final : public MessageContent {
public:
string button_text;
string data;
MessageWebViewDataReceived() = default;
MessageWebViewDataReceived(string &&button_text, string &&data)
: button_text(std::move(button_text)), data(std::move(data)) {
}
MessageContentType get_type() const final {
return MessageContentType::WebViewDataReceived;
}
};
template <class StorerT>
static void store(const MessageContent *content, StorerT &storer) {
CHECK(content != nullptr);
@ -1048,6 +1076,17 @@ static void store(const MessageContent *content, StorerT &storer) {
store(m->emoji, storer);
break;
}
case MessageContentType::WebViewDataSent: {
const auto *m = static_cast<const MessageWebViewDataSent *>(content);
store(m->button_text, storer);
break;
}
case MessageContentType::WebViewDataReceived: {
const auto *m = static_cast<const MessageWebViewDataReceived *>(content);
store(m->button_text, storer);
store(m->data, storer);
break;
}
default:
UNREACHABLE();
}
@ -1468,6 +1507,19 @@ static void parse(unique_ptr<MessageContent> &content, ParserT &parser) {
content = std::move(m);
break;
}
case MessageContentType::WebViewDataSent: {
auto m = make_unique<MessageWebViewDataSent>();
parse(m->button_text, parser);
content = std::move(m);
break;
}
case MessageContentType::WebViewDataReceived: {
auto m = make_unique<MessageWebViewDataReceived>();
parse(m->button_text, parser);
parse(m->data, parser);
content = std::move(m);
break;
}
default:
LOG(FATAL) << "Have unknown message content type " << static_cast<int32>(content_type);
}
@ -2081,6 +2133,8 @@ bool can_have_input_media(const Td *td, const MessageContent *content) {
case MessageContentType::GroupCall:
case MessageContentType::InviteToGroupCall:
case MessageContentType::ChatSetTheme:
case MessageContentType::WebViewDataSent:
case MessageContentType::WebViewDataReceived:
return false;
case MessageContentType::Animation:
case MessageContentType::Audio:
@ -2196,6 +2250,8 @@ SecretInputMedia get_secret_input_media(const MessageContent *content, Td *td,
case MessageContentType::GroupCall:
case MessageContentType::InviteToGroupCall:
case MessageContentType::ChatSetTheme:
case MessageContentType::WebViewDataSent:
case MessageContentType::WebViewDataReceived:
break;
default:
UNREACHABLE();
@ -2312,6 +2368,8 @@ static tl_object_ptr<telegram_api::InputMedia> get_input_media_impl(
case MessageContentType::GroupCall:
case MessageContentType::InviteToGroupCall:
case MessageContentType::ChatSetTheme:
case MessageContentType::WebViewDataSent:
case MessageContentType::WebViewDataReceived:
break;
default:
UNREACHABLE();
@ -2476,6 +2534,8 @@ void delete_message_content_thumbnail(MessageContent *content, Td *td) {
case MessageContentType::GroupCall:
case MessageContentType::InviteToGroupCall:
case MessageContentType::ChatSetTheme:
case MessageContentType::WebViewDataSent:
case MessageContentType::WebViewDataReceived:
break;
default:
UNREACHABLE();
@ -2645,6 +2705,8 @@ Status can_send_message_content(DialogId dialog_id, const MessageContent *conten
case MessageContentType::GroupCall:
case MessageContentType::InviteToGroupCall:
case MessageContentType::ChatSetTheme:
case MessageContentType::WebViewDataSent:
case MessageContentType::WebViewDataReceived:
UNREACHABLE();
}
return Status::OK();
@ -2771,6 +2833,8 @@ static int32 get_message_content_media_index_mask(const MessageContent *content,
case MessageContentType::GroupCall:
case MessageContentType::InviteToGroupCall:
case MessageContentType::ChatSetTheme:
case MessageContentType::WebViewDataSent:
case MessageContentType::WebViewDataReceived:
return 0;
default:
UNREACHABLE();
@ -3242,10 +3306,7 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
}
need_update = true;
}
if (old_->caption != new_->caption) {
need_update = true;
}
if (old_->is_listened != new_->is_listened) {
if (old_->caption != new_->caption || old_->is_listened != new_->is_listened) {
need_update = true;
}
break;
@ -3412,10 +3473,7 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
case MessageContentType::PassportDataReceived: {
const auto *old_ = static_cast<const MessagePassportDataReceived *>(old_content);
const auto *new_ = static_cast<const MessagePassportDataReceived *>(new_content);
if (old_->values != new_->values) {
need_update = true;
}
if (old_->credentials != new_->credentials) {
if (old_->values != new_->values || old_->credentials != new_->credentials) {
need_update = true;
}
break;
@ -3476,6 +3534,22 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
}
break;
}
case MessageContentType::WebViewDataSent: {
const auto *old_ = static_cast<const MessageWebViewDataSent *>(old_content);
const auto *new_ = static_cast<const MessageWebViewDataSent *>(new_content);
if (old_->button_text != new_->button_text) {
need_update = true;
}
break;
}
case MessageContentType::WebViewDataReceived: {
const auto *old_ = static_cast<const MessageWebViewDataReceived *>(old_content);
const auto *new_ = static_cast<const MessageWebViewDataReceived *>(new_content);
if (old_->button_text != new_->button_text || old_->data != new_->data) {
need_update = true;
}
break;
}
case MessageContentType::Unsupported: {
const auto *old_ = static_cast<const MessageUnsupported *>(old_content);
const auto *new_ = static_cast<const MessageUnsupported *>(new_content);
@ -3612,6 +3686,8 @@ bool merge_message_content_file_id(Td *td, MessageContent *message_content, File
case MessageContentType::GroupCall:
case MessageContentType::InviteToGroupCall:
case MessageContentType::ChatSetTheme:
case MessageContentType::WebViewDataSent:
case MessageContentType::WebViewDataReceived:
LOG(ERROR) << "Receive new file " << new_file_id << " in a sent message of the type " << content_type;
break;
default:
@ -4522,6 +4598,8 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
case MessageContentType::GroupCall:
case MessageContentType::InviteToGroupCall:
case MessageContentType::ChatSetTheme:
case MessageContentType::WebViewDataSent:
case MessageContentType::WebViewDataReceived:
return nullptr;
default:
UNREACHABLE();
@ -4786,10 +4864,22 @@ unique_ptr<MessageContent> get_action_message_content(Td *td, tl_object_ptr<tele
}
case telegram_api::messageActionChatJoinedByRequest::ID:
return make_unique<MessageChatJoinedByLink>(true);
case telegram_api::messageActionWebViewDataSentMe::ID:
return make_unique<MessageUnsupported>();
case telegram_api::messageActionWebViewDataSent::ID:
return make_unique<MessageUnsupported>();
case telegram_api::messageActionWebViewDataSent::ID: {
if (td->auth_manager_->is_bot()) {
LOG(ERROR) << "Receive messageActionWebViewDataSent in " << owner_dialog_id;
break;
}
auto data_sent = move_tl_object_as<telegram_api::messageActionWebViewDataSent>(action);
return td::make_unique<MessageWebViewDataSent>(std::move(data_sent->text_));
}
case telegram_api::messageActionWebViewDataSentMe::ID: {
if (!td->auth_manager_->is_bot()) {
LOG(ERROR) << "Receive messageActionWebViewDataSentMe in " << owner_dialog_id;
break;
}
auto data_sent = move_tl_object_as<telegram_api::messageActionWebViewDataSentMe>(action);
return td::make_unique<MessageWebViewDataReceived>(std::move(data_sent->text_), std::move(data_sent->data_));
}
default:
UNREACHABLE();
}
@ -5038,6 +5128,14 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
const auto *m = static_cast<const MessageChatSetTheme *>(content);
return make_tl_object<td_api::messageChatSetTheme>(m->emoji);
}
case MessageContentType::WebViewDataSent: {
const auto *m = static_cast<const MessageWebViewDataSent *>(content);
return make_tl_object<td_api::messageWebViewDataSent>(m->button_text);
}
case MessageContentType::WebViewDataReceived: {
const auto *m = static_cast<const MessageWebViewDataReceived *>(content);
return make_tl_object<td_api::messageWebViewDataReceived>(m->button_text, m->data);
}
default:
UNREACHABLE();
return nullptr;
@ -5385,6 +5483,8 @@ string get_message_content_search_text(const Td *td, const MessageContent *conte
case MessageContentType::GroupCall:
case MessageContentType::InviteToGroupCall:
case MessageContentType::ChatSetTheme:
case MessageContentType::WebViewDataSent:
case MessageContentType::WebViewDataReceived:
return string();
default:
UNREACHABLE();
@ -5632,6 +5732,10 @@ void add_message_content_dependencies(Dependencies &dependencies, const MessageC
}
case MessageContentType::ChatSetTheme:
break;
case MessageContentType::WebViewDataSent:
break;
case MessageContentType::WebViewDataReceived:
break;
default:
UNREACHABLE();
break;

View File

@ -104,6 +104,10 @@ StringBuilder &operator<<(StringBuilder &string_builder, MessageContentType cont
return string_builder << "InviteToGroupCall";
case MessageContentType::ChatSetTheme:
return string_builder << "ChatSetTheme";
case MessageContentType::WebViewDataSent:
return string_builder << "WebViewDataSent";
case MessageContentType::WebViewDataReceived:
return string_builder << "WebViewDataReceived";
default:
UNREACHABLE();
return string_builder;
@ -159,6 +163,8 @@ bool is_allowed_media_group_content(MessageContentType content_type) {
case MessageContentType::GroupCall:
case MessageContentType::InviteToGroupCall:
case MessageContentType::ChatSetTheme:
case MessageContentType::WebViewDataSent:
case MessageContentType::WebViewDataReceived:
return false;
default:
UNREACHABLE();
@ -222,6 +228,8 @@ bool is_secret_message_content(int32 ttl, MessageContentType content_type) {
case MessageContentType::GroupCall:
case MessageContentType::InviteToGroupCall:
case MessageContentType::ChatSetTheme:
case MessageContentType::WebViewDataSent:
case MessageContentType::WebViewDataReceived:
return false;
default:
UNREACHABLE();
@ -278,6 +286,8 @@ bool is_service_message_content(MessageContentType content_type) {
case MessageContentType::GroupCall:
case MessageContentType::InviteToGroupCall:
case MessageContentType::ChatSetTheme:
case MessageContentType::WebViewDataSent:
case MessageContentType::WebViewDataReceived:
return true;
default:
UNREACHABLE();
@ -334,6 +344,8 @@ bool can_have_message_content_caption(MessageContentType content_type) {
case MessageContentType::GroupCall:
case MessageContentType::InviteToGroupCall:
case MessageContentType::ChatSetTheme:
case MessageContentType::WebViewDataSent:
case MessageContentType::WebViewDataReceived:
return false;
default:
UNREACHABLE();

View File

@ -61,7 +61,9 @@ enum class MessageContentType : int32 {
ProximityAlertTriggered,
GroupCall,
InviteToGroupCall,
ChatSetTheme
ChatSetTheme,
WebViewDataSent,
WebViewDataReceived
};
StringBuilder &operator<<(StringBuilder &string_builder, MessageContentType content_type);

View File

@ -26984,6 +26984,8 @@ bool MessagesManager::can_edit_message(DialogId dialog_id, const Message *m, boo
case MessageContentType::GroupCall:
case MessageContentType::InviteToGroupCall:
case MessageContentType::ChatSetTheme:
case MessageContentType::WebViewDataSent:
case MessageContentType::WebViewDataReceived:
return false;
default:
UNREACHABLE();
@ -30183,6 +30185,8 @@ bool MessagesManager::is_message_notification_disabled(const Dialog *d, const Me
case MessageContentType::ExpiredVideo:
case MessageContentType::PassportDataSent:
case MessageContentType::PassportDataReceived:
case MessageContentType::WebViewDataSent:
case MessageContentType::WebViewDataReceived:
VLOG(notifications) << "Disable notification for " << m->message_id << " in " << d->dialog_id
<< " with content of type " << m->content->get_type();
return true;