Add information about Story to web page.

This commit is contained in:
levlam 2023-06-13 15:45:10 +03:00
parent deee074e2f
commit 62e7640701
7 changed files with 78 additions and 11 deletions

View File

@ -1136,8 +1136,8 @@ messageSendingStateFailed error_code:int32 error_message:string can_retry:Bool n
//@message_id The identifier of the replied message //@message_id The identifier of the replied message
messageReplyToMessage chat_id:int53 message_id:int53 = MessageReplyTo; messageReplyToMessage chat_id:int53 message_id:int53 = MessageReplyTo;
//@description Describes a replied story @sender_user_id The identifier of the sender of the replied story. Currently, stories can be replied only in the corresponding private chats @story_id The identifier of the replied story //@description Describes a replied story @story_sender_user_id The identifier of the sender of the replied story. Currently, stories can be replied only in the corresponding private chats @story_id The identifier of the replied story
messageReplyToStory sender_user_id:int53 story_id:int32 = MessageReplyTo; messageReplyToStory story_sender_user_id:int53 story_id:int32 = MessageReplyTo;
//@description Describes a message //@description Describes a message
@ -1986,8 +1986,10 @@ webPageInstantView page_blocks:vector<PageBlock> view_count:int32 version:int32
//@video Preview of the content as a video, if available; may be null //@video Preview of the content as a video, if available; may be null
//@video_note Preview of the content as a video note, if available; may be null //@video_note Preview of the content as a video note, if available; may be null
//@voice_note Preview of the content as a voice note, if available; may be null //@voice_note Preview of the content as a voice note, if available; may be null
//@story_sender_user_id The identifier of the sender of the previewed story; 0 if none
//@story_id The identifier of the previewed story; 0 if none
//@instant_view_version Version of web page instant view (currently, can be 1 or 2); 0 if none //@instant_view_version Version of web page instant view (currently, can be 1 or 2); 0 if none
webPage url:string display_url:string type:string site_name:string title:string description:formattedText photo:photo embed_url:string embed_type:string embed_width:int32 embed_height:int32 duration:int32 author:string animation:animation audio:audio document:document sticker:sticker video:video video_note:videoNote voice_note:voiceNote instant_view_version:int32 = WebPage; webPage url:string display_url:string type:string site_name:string title:string description:formattedText photo:photo embed_url:string embed_type:string embed_width:int32 embed_height:int32 duration:int32 author:string animation:animation audio:audio document:document sticker:sticker video:video video_note:videoNote voice_note:voiceNote story_sender_user_id:int53 story_id:int32 instant_view_version:int32 = WebPage;
//@description Contains information about a country //@description Contains information about a country

View File

@ -23,7 +23,7 @@ MessageInputReplyTo::MessageInputReplyTo(const td_api::object_ptr<td_api::Messag
} }
case td_api::messageReplyToStory::ID: { case td_api::messageReplyToStory::ID: {
auto reply_to = static_cast<const td_api::messageReplyToStory *>(reply_to_ptr.get()); auto reply_to = static_cast<const td_api::messageReplyToStory *>(reply_to_ptr.get());
story_full_id_ = {DialogId(reply_to->sender_user_id_), StoryId(reply_to->story_id_)}; story_full_id_ = {DialogId(reply_to->story_sender_user_id_), StoryId(reply_to->story_id_)};
break; break;
} }
default: default:

View File

@ -24556,7 +24556,7 @@ MessageInputReplyTo MessagesManager::get_message_input_reply_to(Dialog *d, Messa
CHECK(!for_draft); CHECK(!for_draft);
auto reply_to_story = td_api::move_object_as<td_api::messageReplyToStory>(reply_to); auto reply_to_story = td_api::move_object_as<td_api::messageReplyToStory>(reply_to);
auto story_id = StoryId(reply_to_story->story_id_); auto story_id = StoryId(reply_to_story->story_id_);
auto sender_user_id = UserId(reply_to_story->sender_user_id_); auto sender_user_id = UserId(reply_to_story->story_sender_user_id_);
if (d->dialog_id != DialogId(sender_user_id)) { if (d->dialog_id != DialogId(sender_user_id)) {
LOG(INFO) << "Ignore reply to story from " << sender_user_id << " in a wrong " << d->dialog_id; LOG(INFO) << "Ignore reply to story from " << sender_user_id << " in a wrong " << d->dialog_id;
return {}; return {};

View File

@ -612,6 +612,11 @@ bool StoryManager::have_story(StoryFullId story_full_id) const {
return get_story(story_full_id) != nullptr; return get_story(story_full_id) != nullptr;
} }
bool StoryManager::have_story_force(StoryFullId story_full_id) const {
// TODO try load story
return have_story(story_full_id);
}
bool StoryManager::is_inaccessible_story(StoryFullId story_full_id) const { bool StoryManager::is_inaccessible_story(StoryFullId story_full_id) const {
return inaccessible_story_full_ids_.count(story_full_id) > 0; return inaccessible_story_full_ids_.count(story_full_id) > 0;
} }

View File

@ -110,6 +110,8 @@ class StoryManager final : public Actor {
bool have_story(StoryFullId story_full_id) const; bool have_story(StoryFullId story_full_id) const;
bool have_story_force(StoryFullId story_full_id) const;
bool is_inaccessible_story(StoryFullId story_full_id) const; bool is_inaccessible_story(StoryFullId story_full_id) const;
int32 get_story_duration(StoryFullId story_full_id) const; int32 get_story_duration(StoryFullId story_full_id) const;

View File

@ -9,6 +9,8 @@
#include "td/telegram/AnimationsManager.h" #include "td/telegram/AnimationsManager.h"
#include "td/telegram/AudiosManager.h" #include "td/telegram/AudiosManager.h"
#include "td/telegram/AuthManager.h" #include "td/telegram/AuthManager.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/Dependencies.h"
#include "td/telegram/Dimensions.h" #include "td/telegram/Dimensions.h"
#include "td/telegram/Document.h" #include "td/telegram/Document.h"
#include "td/telegram/Document.hpp" #include "td/telegram/Document.hpp"
@ -25,6 +27,8 @@
#include "td/telegram/PhotoFormat.h" #include "td/telegram/PhotoFormat.h"
#include "td/telegram/secret_api.h" #include "td/telegram/secret_api.h"
#include "td/telegram/StickersManager.h" #include "td/telegram/StickersManager.h"
#include "td/telegram/StoryFullId.h"
#include "td/telegram/StoryManager.h"
#include "td/telegram/Td.h" #include "td/telegram/Td.h"
#include "td/telegram/TdDb.h" #include "td/telegram/TdDb.h"
#include "td/telegram/VideoNotesManager.h" #include "td/telegram/VideoNotesManager.h"
@ -229,6 +233,7 @@ class WebPagesManager::WebPage {
string author; string author;
Document document; Document document;
vector<Document> documents; vector<Document> documents;
vector<StoryFullId> story_full_ids;
WebPageInstantView instant_view; WebPageInstantView instant_view;
FileSourceId file_source_id; FileSourceId file_source_id;
@ -252,6 +257,7 @@ class WebPagesManager::WebPage {
bool is_instant_view_v2 = instant_view.is_v2; bool is_instant_view_v2 = instant_view.is_v2;
bool has_no_hash = true; bool has_no_hash = true;
bool has_documents = !documents.empty(); bool has_documents = !documents.empty();
bool has_story_full_ids = !story_full_ids.empty();
BEGIN_STORE_FLAGS(); BEGIN_STORE_FLAGS();
STORE_FLAG(has_type); STORE_FLAG(has_type);
STORE_FLAG(has_site_name); STORE_FLAG(has_site_name);
@ -267,6 +273,7 @@ class WebPagesManager::WebPage {
STORE_FLAG(has_no_hash); STORE_FLAG(has_no_hash);
STORE_FLAG(is_instant_view_v2); STORE_FLAG(is_instant_view_v2);
STORE_FLAG(has_documents); STORE_FLAG(has_documents);
STORE_FLAG(has_story_full_ids);
END_STORE_FLAGS(); END_STORE_FLAGS();
store(url, storer); store(url, storer);
@ -305,6 +312,9 @@ class WebPagesManager::WebPage {
if (has_documents) { if (has_documents) {
store(documents, storer); store(documents, storer);
} }
if (has_story_full_ids) {
store(story_full_ids, storer);
}
} }
template <class ParserT> template <class ParserT>
@ -324,6 +334,7 @@ class WebPagesManager::WebPage {
bool is_instant_view_v2; bool is_instant_view_v2;
bool has_no_hash; bool has_no_hash;
bool has_documents; bool has_documents;
bool has_story_full_ids;
BEGIN_PARSE_FLAGS(); BEGIN_PARSE_FLAGS();
PARSE_FLAG(has_type); PARSE_FLAG(has_type);
PARSE_FLAG(has_site_name); PARSE_FLAG(has_site_name);
@ -339,6 +350,7 @@ class WebPagesManager::WebPage {
PARSE_FLAG(has_no_hash); PARSE_FLAG(has_no_hash);
PARSE_FLAG(is_instant_view_v2); PARSE_FLAG(is_instant_view_v2);
PARSE_FLAG(has_documents); PARSE_FLAG(has_documents);
PARSE_FLAG(has_story_full_ids);
END_PARSE_FLAGS(); END_PARSE_FLAGS();
parse(url, parser); parse(url, parser);
@ -381,6 +393,9 @@ class WebPagesManager::WebPage {
if (has_documents) { if (has_documents) {
parse(documents, parser); parse(documents, parser);
} }
if (has_story_full_ids) {
parse(story_full_ids, parser);
}
if (has_instant_view) { if (has_instant_view) {
instant_view.is_empty = false; instant_view.is_empty = false;
@ -396,8 +411,8 @@ class WebPagesManager::WebPage {
lhs.photo == rhs.photo && lhs.type == rhs.type && lhs.embed_url == rhs.embed_url && lhs.photo == rhs.photo && lhs.type == rhs.type && lhs.embed_url == rhs.embed_url &&
lhs.embed_type == rhs.embed_type && lhs.embed_dimensions == rhs.embed_dimensions && lhs.embed_type == rhs.embed_type && lhs.embed_dimensions == rhs.embed_dimensions &&
lhs.duration == rhs.duration && lhs.author == rhs.author && lhs.document == rhs.document && lhs.duration == rhs.duration && lhs.author == rhs.author && lhs.document == rhs.document &&
lhs.documents == rhs.documents && lhs.instant_view.is_empty == rhs.instant_view.is_empty && lhs.documents == rhs.documents && lhs.story_full_ids == rhs.story_full_ids &&
lhs.instant_view.is_v2 == rhs.instant_view.is_v2; lhs.instant_view.is_empty == rhs.instant_view.is_empty && lhs.instant_view.is_v2 == rhs.instant_view.is_v2;
} }
}; };
@ -507,7 +522,6 @@ WebPageId WebPagesManager::on_get_web_page(tl_object_ptr<telegram_api::WebPage>
page->document = std::move(parsed_document); page->document = std::move(parsed_document);
} }
} }
page->documents.clear();
for (auto &attribute_ptr : web_page->attributes_) { for (auto &attribute_ptr : web_page->attributes_) {
CHECK(attribute_ptr != nullptr); CHECK(attribute_ptr != nullptr);
switch (attribute_ptr->get_id()) { switch (attribute_ptr->get_id()) {
@ -527,7 +541,21 @@ WebPageId WebPagesManager::on_get_web_page(tl_object_ptr<telegram_api::WebPage>
break; break;
} }
case telegram_api::webPageAttributeStory::ID: { case telegram_api::webPageAttributeStory::ID: {
// auto attribute = telegram_api::move_object_as<telegram_api::webPageAttributeStory>(attribute_ptr); auto attribute = telegram_api::move_object_as<telegram_api::webPageAttributeStory>(attribute_ptr);
auto dialog_id = DialogId(UserId(attribute->user_id_));
auto story_id = StoryId(attribute->id_);
if (!dialog_id.is_valid() || !story_id.is_valid()) {
LOG(ERROR) << "Receive " << to_string(attribute);
break;
}
auto story_full_id = StoryFullId(dialog_id, story_id);
if (attribute->story_ != nullptr) {
auto actual_story_id = td_->story_manager_->on_get_story(dialog_id, std::move(attribute->story_));
if (story_id != actual_story_id) {
LOG(ERROR) << "Receive " << actual_story_id << " instead of " << story_id;
}
}
page->story_full_ids.push_back(story_full_id);
break; break;
} }
} }
@ -554,6 +582,24 @@ void WebPagesManager::update_web_page(unique_ptr<WebPage> web_page, WebPageId we
LOG(INFO) << "Update " << web_page_id << (from_database ? " from database" : (from_binlog ? " from binlog" : "")); LOG(INFO) << "Update " << web_page_id << (from_database ? " from database" : (from_binlog ? " from binlog" : ""));
CHECK(web_page != nullptr); CHECK(web_page != nullptr);
if (from_binlog || from_database) {
if (!web_page->story_full_ids.empty()) {
Dependencies dependencies;
for (auto story_full_id : web_page->story_full_ids) {
auto story_sender_dialog_id = story_full_id.get_dialog_id();
dependencies.add_message_sender_dependencies(story_sender_dialog_id);
}
if (!dependencies.resolve_force(td_, "update_web_page")) {
web_page->story_full_ids = {};
}
for (auto story_full_id : web_page->story_full_ids) {
if (!td_->story_manager_->have_story_force(story_full_id)) {
LOG(INFO) << "Have unknown story " << story_full_id << " in " << web_page_id;
}
}
}
}
auto &page = web_pages_[web_page_id]; auto &page = web_pages_[web_page_id];
auto old_file_ids = get_web_page_file_ids(page.get()); auto old_file_ids = get_web_page_file_ids(page.get());
WebPageInstantView old_instant_view; WebPageInstantView old_instant_view;
@ -1231,6 +1277,14 @@ tl_object_ptr<td_api::webPage> WebPagesManager::get_web_page_object(WebPageId we
} }
auto duration = get_web_page_media_duration(web_page); auto duration = get_web_page_media_duration(web_page);
UserId story_sender_user_id;
StoryId story_id;
if (web_page->story_full_ids.size() == 1) {
DialogId story_sender_dialog_id = web_page->story_full_ids[0].get_dialog_id();
CHECK(story_sender_dialog_id.get_type() == DialogType::User);
story_sender_user_id = story_sender_dialog_id.get_user_id();
story_id = web_page->story_full_ids[0].get_story_id();
}
return make_tl_object<td_api::webPage>( return make_tl_object<td_api::webPage>(
web_page->url, web_page->display_url, web_page->type, web_page->site_name, web_page->title, web_page->url, web_page->display_url, web_page->type, web_page->site_name, web_page->title,
get_formatted_text_object(description, true, duration == 0 ? std::numeric_limits<int32>::max() : duration), get_formatted_text_object(description, true, duration == 0 ? std::numeric_limits<int32>::max() : duration),
@ -1257,6 +1311,7 @@ tl_object_ptr<td_api::webPage> WebPagesManager::get_web_page_object(WebPageId we
web_page->document.type == Document::Type::VoiceNote web_page->document.type == Document::Type::VoiceNote
? td_->voice_notes_manager_->get_voice_note_object(web_page->document.file_id) ? td_->voice_notes_manager_->get_voice_note_object(web_page->document.file_id)
: nullptr, : nullptr,
td_->contacts_manager_->get_user_id_object(story_sender_user_id, "webPage"), story_id.get(),
instant_view_version); instant_view_version);
} }
@ -1710,12 +1765,15 @@ int32 WebPagesManager::get_web_page_media_duration(WebPageId web_page_id) const
return get_web_page_media_duration(web_page); return get_web_page_media_duration(web_page);
} }
int32 WebPagesManager::get_web_page_media_duration(const WebPage *web_page) { int32 WebPagesManager::get_web_page_media_duration(const WebPage *web_page) const {
if (web_page->document.type == Document::Type::Audio || web_page->document.type == Document::Type::Video || if (web_page->document.type == Document::Type::Audio || web_page->document.type == Document::Type::Video ||
web_page->document.type == Document::Type::VideoNote || web_page->document.type == Document::Type::VoiceNote || web_page->document.type == Document::Type::VideoNote || web_page->document.type == Document::Type::VoiceNote ||
web_page->embed_type == "iframe") { web_page->embed_type == "iframe") {
return web_page->duration; return web_page->duration;
} }
if (!web_page->story_full_ids.empty()) {
return td_->story_manager_->get_story_duration(web_page->story_full_ids[0]);
}
return -1; return -1;
} }

View File

@ -156,7 +156,7 @@ class WebPagesManager final : public Actor {
void tear_down() final; void tear_down() final;
static int32 get_web_page_media_duration(const WebPage *web_page); int32 get_web_page_media_duration(const WebPage *web_page) const;
FileSourceId get_web_page_file_source_id(WebPage *web_page); FileSourceId get_web_page_file_source_id(WebPage *web_page);