Support extended media polling.
This commit is contained in:
parent
85f9f0481f
commit
92f9f8bdd0
@ -384,6 +384,10 @@ bool InputInvoice::update_extended_media(telegram_api::object_ptr<telegram_api::
|
|||||||
return extended_media_.update_to(td, std::move(extended_media), owner_dialog_id);
|
return extended_media_.update_to(td, std::move(extended_media), owner_dialog_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool InputInvoice::need_poll_extended_media() const {
|
||||||
|
return extended_media_.need_poll();
|
||||||
|
}
|
||||||
|
|
||||||
tl_object_ptr<td_api::formattedText> get_product_description_object(const string &description) {
|
tl_object_ptr<td_api::formattedText> get_product_description_object(const string &description) {
|
||||||
FormattedText result;
|
FormattedText result;
|
||||||
result.text = description;
|
result.text = description;
|
||||||
|
@ -97,6 +97,8 @@ struct InputInvoice {
|
|||||||
|
|
||||||
bool update_extended_media(telegram_api::object_ptr<telegram_api::MessageExtendedMedia> extended_media,
|
bool update_extended_media(telegram_api::object_ptr<telegram_api::MessageExtendedMedia> extended_media,
|
||||||
DialogId owner_dialog_id, Td *td);
|
DialogId owner_dialog_id, Td *td);
|
||||||
|
|
||||||
|
bool need_poll_extended_media() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool operator==(const InputInvoice &lhs, const InputInvoice &rhs);
|
bool operator==(const InputInvoice &lhs, const InputInvoice &rhs);
|
||||||
|
@ -5709,6 +5709,14 @@ bool update_message_content_extended_media(MessageContent *content,
|
|||||||
owner_dialog_id, td);
|
owner_dialog_id, td);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool need_poll_message_content_extended_media(const MessageContent *content) {
|
||||||
|
CHECK(content != nullptr);
|
||||||
|
if (content->get_type() != MessageContentType::Invoice) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return static_cast<const MessageInvoice *>(content)->input_invoice.need_poll_extended_media();
|
||||||
|
}
|
||||||
|
|
||||||
void get_message_content_animated_emoji_click_sticker(const MessageContent *content, FullMessageId full_message_id,
|
void get_message_content_animated_emoji_click_sticker(const MessageContent *content, FullMessageId full_message_id,
|
||||||
Td *td, Promise<td_api::object_ptr<td_api::sticker>> &&promise) {
|
Td *td, Promise<td_api::object_ptr<td_api::sticker>> &&promise) {
|
||||||
if (content->get_type() != MessageContentType::Text) {
|
if (content->get_type() != MessageContentType::Text) {
|
||||||
|
@ -234,6 +234,8 @@ bool update_message_content_extended_media(MessageContent *content,
|
|||||||
telegram_api::object_ptr<telegram_api::MessageExtendedMedia> extended_media,
|
telegram_api::object_ptr<telegram_api::MessageExtendedMedia> extended_media,
|
||||||
DialogId owner_dialog_id, Td *td);
|
DialogId owner_dialog_id, Td *td);
|
||||||
|
|
||||||
|
bool need_poll_message_content_extended_media(const MessageContent *content);
|
||||||
|
|
||||||
void get_message_content_animated_emoji_click_sticker(const MessageContent *content, FullMessageId full_message_id,
|
void get_message_content_animated_emoji_click_sticker(const MessageContent *content, FullMessageId full_message_id,
|
||||||
Td *td, Promise<td_api::object_ptr<td_api::sticker>> &&promise);
|
Td *td, Promise<td_api::object_ptr<td_api::sticker>> &&promise);
|
||||||
|
|
||||||
|
@ -78,6 +78,10 @@ class MessageExtendedMedia {
|
|||||||
return type_ == Type::Unsupported && unsupported_version_ < CURRENT_VERSION;
|
return type_ == Type::Unsupported && unsupported_version_ < CURRENT_VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool need_poll() const {
|
||||||
|
return type_ == Type::Preview;
|
||||||
|
}
|
||||||
|
|
||||||
bool has_media_timestamp() const {
|
bool has_media_timestamp() const {
|
||||||
return type_ == Type::Video;
|
return type_ == Type::Video;
|
||||||
}
|
}
|
||||||
|
@ -1956,6 +1956,42 @@ class GetMessagesViewsQuery final : public Td::ResultHandler {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class GetExtendedMediaQuery final : public Td::ResultHandler {
|
||||||
|
DialogId dialog_id_;
|
||||||
|
vector<MessageId> message_ids_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void send(DialogId dialog_id, vector<MessageId> &&message_ids) {
|
||||||
|
dialog_id_ = dialog_id;
|
||||||
|
message_ids_ = std::move(message_ids);
|
||||||
|
|
||||||
|
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
|
||||||
|
if (input_peer == nullptr) {
|
||||||
|
return on_error(Status::Error(400, "Can't access the chat"));
|
||||||
|
}
|
||||||
|
|
||||||
|
send_query(G()->net_query_creator().create(telegram_api::messages_getExtendedMedia(
|
||||||
|
std::move(input_peer), MessagesManager::get_server_message_ids(message_ids_))));
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_result(BufferSlice packet) final {
|
||||||
|
auto result_ptr = fetch_result<telegram_api::messages_getExtendedMedia>(packet);
|
||||||
|
if (result_ptr.is_error()) {
|
||||||
|
return on_error(result_ptr.move_as_error());
|
||||||
|
}
|
||||||
|
|
||||||
|
auto ptr = result_ptr.move_as_ok();
|
||||||
|
LOG(INFO) << "Receive result for GetExtendedMediaQuery: " << to_string(ptr);
|
||||||
|
td_->updates_manager_->on_get_updates(std::move(ptr), Promise<Unit>());
|
||||||
|
td_->messages_manager_->finish_get_message_extended_media(dialog_id_, message_ids_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_error(Status status) final {
|
||||||
|
td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetExtendedMediaQuery");
|
||||||
|
td_->messages_manager_->finish_get_message_extended_media(dialog_id_, message_ids_);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class ReadMessagesContentsQuery final : public Td::ResultHandler {
|
class ReadMessagesContentsQuery final : public Td::ResultHandler {
|
||||||
Promise<Unit> promise_;
|
Promise<Unit> promise_;
|
||||||
|
|
||||||
@ -12846,10 +12882,12 @@ void MessagesManager::on_update_viewed_messages_timeout(DialogId dialog_id) {
|
|||||||
CHECK(info != nullptr);
|
CHECK(info != nullptr);
|
||||||
vector<MessageId> reaction_message_ids;
|
vector<MessageId> reaction_message_ids;
|
||||||
vector<MessageId> views_message_ids;
|
vector<MessageId> views_message_ids;
|
||||||
|
vector<MessageId> extended_media_message_ids;
|
||||||
for (auto &message_it : info->message_id_to_view_id) {
|
for (auto &message_it : info->message_id_to_view_id) {
|
||||||
Message *m = get_message_force(d, message_it.first, "on_update_viewed_messages_timeout");
|
Message *m = get_message_force(d, message_it.first, "on_update_viewed_messages_timeout");
|
||||||
CHECK(m != nullptr);
|
CHECK(m != nullptr);
|
||||||
CHECK(m->message_id.is_valid());
|
CHECK(m->message_id.is_valid());
|
||||||
|
CHECK(m->message_id.is_server());
|
||||||
if (need_poll_message_reactions(d, m)) {
|
if (need_poll_message_reactions(d, m)) {
|
||||||
reaction_message_ids.push_back(m->message_id);
|
reaction_message_ids.push_back(m->message_id);
|
||||||
}
|
}
|
||||||
@ -12857,6 +12895,10 @@ void MessagesManager::on_update_viewed_messages_timeout(DialogId dialog_id) {
|
|||||||
m->has_get_message_views_query = true;
|
m->has_get_message_views_query = true;
|
||||||
views_message_ids.push_back(m->message_id);
|
views_message_ids.push_back(m->message_id);
|
||||||
}
|
}
|
||||||
|
if (need_poll_message_content_extended_media(m->content.get()) && !m->has_get_extended_media_query) {
|
||||||
|
m->has_get_extended_media_query = true;
|
||||||
|
extended_media_message_ids.push_back(m->message_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!reaction_message_ids.empty()) {
|
if (!reaction_message_ids.empty()) {
|
||||||
@ -12865,6 +12907,9 @@ void MessagesManager::on_update_viewed_messages_timeout(DialogId dialog_id) {
|
|||||||
if (!views_message_ids.empty()) {
|
if (!views_message_ids.empty()) {
|
||||||
td_->create_handler<GetMessagesViewsQuery>()->send(dialog_id, std::move(views_message_ids), false);
|
td_->create_handler<GetMessagesViewsQuery>()->send(dialog_id, std::move(views_message_ids), false);
|
||||||
}
|
}
|
||||||
|
if (!extended_media_message_ids.empty()) {
|
||||||
|
td_->create_handler<GetExtendedMediaQuery>()->send(dialog_id, std::move(extended_media_message_ids));
|
||||||
|
}
|
||||||
|
|
||||||
update_viewed_messages_timeout_.add_timeout_in(dialog_id.get(), UPDATE_VIEWED_MESSAGES_PERIOD);
|
update_viewed_messages_timeout_.add_timeout_in(dialog_id.get(), UPDATE_VIEWED_MESSAGES_PERIOD);
|
||||||
}
|
}
|
||||||
@ -21097,6 +21142,17 @@ void MessagesManager::finish_get_message_views(DialogId dialog_id, const vector<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MessagesManager::finish_get_message_extended_media(DialogId dialog_id, const vector<MessageId> &message_ids) {
|
||||||
|
Dialog *d = get_dialog(dialog_id);
|
||||||
|
CHECK(d != nullptr);
|
||||||
|
for (auto message_id : message_ids) {
|
||||||
|
auto *m = get_message(d, message_id);
|
||||||
|
if (m != nullptr) {
|
||||||
|
m->has_get_extended_media_query = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Status MessagesManager::open_message_content(FullMessageId full_message_id) {
|
Status MessagesManager::open_message_content(FullMessageId full_message_id) {
|
||||||
auto dialog_id = full_message_id.get_dialog_id();
|
auto dialog_id = full_message_id.get_dialog_id();
|
||||||
Dialog *d = get_dialog_force(dialog_id, "open_message_content");
|
Dialog *d = get_dialog_force(dialog_id, "open_message_content");
|
||||||
|
@ -716,6 +716,8 @@ class MessagesManager final : public Actor {
|
|||||||
|
|
||||||
void finish_get_message_views(DialogId dialog_id, const vector<MessageId> &message_ids);
|
void finish_get_message_views(DialogId dialog_id, const vector<MessageId> &message_ids);
|
||||||
|
|
||||||
|
void finish_get_message_extended_media(DialogId dialog_id, const vector<MessageId> &message_ids);
|
||||||
|
|
||||||
Status open_message_content(FullMessageId full_message_id) TD_WARN_UNUSED_RESULT;
|
Status open_message_content(FullMessageId full_message_id) TD_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
void click_animated_emoji_message(FullMessageId full_message_id,
|
void click_animated_emoji_message(FullMessageId full_message_id,
|
||||||
@ -1173,6 +1175,8 @@ class MessagesManager final : public Actor {
|
|||||||
bool has_get_message_views_query = false;
|
bool has_get_message_views_query = false;
|
||||||
bool need_view_counter_increment = false;
|
bool need_view_counter_increment = false;
|
||||||
|
|
||||||
|
bool has_get_extended_media_query = false;
|
||||||
|
|
||||||
DialogId real_forward_from_dialog_id; // for resend_message
|
DialogId real_forward_from_dialog_id; // for resend_message
|
||||||
MessageId real_forward_from_message_id; // for resend_message
|
MessageId real_forward_from_message_id; // for resend_message
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user