Add add_story_dependencies.

This commit is contained in:
levlam 2023-07-03 20:03:26 +03:00
parent fac13ff3a3
commit 9345dc2799
8 changed files with 69 additions and 0 deletions

View File

@ -6,6 +6,7 @@
//
#include "td/telegram/StoryContent.h"
#include "td/telegram/Dependencies.h"
#include "td/telegram/Dimensions.h"
#include "td/telegram/Document.h"
#include "td/telegram/DocumentsManager.h"
@ -170,6 +171,20 @@ void parse_story_content(unique_ptr<StoryContent> &content, LogEventParser &pars
parse(content, parser);
}
void add_story_content_dependencies(Dependencies &dependencies, const StoryContent *story_content) {
switch (story_content->get_type()) {
case StoryContentType::Photo:
break;
case StoryContentType::Video:
break;
case StoryContentType::Unsupported:
break;
default:
UNREACHABLE();
break;
}
}
unique_ptr<StoryContent> get_story_content(Td *td, tl_object_ptr<telegram_api::MessageMedia> &&media_ptr,
DialogId owner_dialog_id) {
CHECK(media_ptr != nullptr);

View File

@ -18,6 +18,7 @@
namespace td {
class Dependencies;
class Td;
class StoryContent {
@ -38,6 +39,8 @@ void store_story_content(const StoryContent *content, LogEventStorerUnsafe &stor
void parse_story_content(unique_ptr<StoryContent> &content, LogEventParser &parser);
void add_story_content_dependencies(Dependencies &dependencies, const StoryContent *story_content);
unique_ptr<StoryContent> get_story_content(Td *td, telegram_api::object_ptr<telegram_api::MessageMedia> &&media_ptr,
DialogId owner_dialog_id);

View File

@ -7,6 +7,7 @@
#include "td/telegram/StoryInteractionInfo.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/Dependencies.h"
#include "td/telegram/Td.h"
#include "td/utils/algorithm.h"
@ -37,6 +38,12 @@ StoryInteractionInfo::StoryInteractionInfo(Td *td, telegram_api::object_ptr<tele
}
}
void StoryInteractionInfo::add_dependencies(Dependencies &dependencies) const {
for (auto user_id : recent_viewer_user_ids_) {
dependencies.add(user_id);
}
}
void StoryInteractionInfo::set_recent_viewer_user_ids(vector<UserId> &&user_ids) {
if (user_ids.size() > MAX_RECENT_VIEWERS) {
user_ids.resize(MAX_RECENT_VIEWERS);

View File

@ -15,6 +15,7 @@
namespace td {
class Dependencies;
class Td;
class StoryInteractionInfo {
@ -36,6 +37,8 @@ class StoryInteractionInfo {
return view_count_ < 0;
}
void add_dependencies(Dependencies &dependencies) const;
bool set_view_count(int32 view_count) {
if (view_count > view_count_) {
view_count = view_count_;

View File

@ -10,6 +10,7 @@
#include "td/telegram/AuthManager.h"
#include "td/telegram/ConfigManager.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/Dependencies.h"
#include "td/telegram/FileReferenceManager.h"
#include "td/telegram/files/FileManager.h"
#include "td/telegram/Global.h"
@ -938,6 +939,20 @@ StoryManager::ActiveStories *StoryManager::get_active_stories_editable(DialogId
return active_stories_.get_pointer(owner_dialog_id);
}
void StoryManager::add_story_dependencies(Dependencies &dependencies, const Story *story) {
story->interaction_info_.add_dependencies(dependencies);
story->privacy_rules_.add_dependencies(dependencies);
if (story->content_ != nullptr) {
add_story_content_dependencies(dependencies, story->content_.get());
}
add_formatted_text_dependencies(dependencies, &story->caption_);
}
void StoryManager::add_pending_story_dependencies(Dependencies &dependencies, const PendingStory *pending_story) {
dependencies.add_dialog_and_dependencies(pending_story->dialog_id_);
add_story_dependencies(dependencies, pending_story->story_.get());
}
void StoryManager::load_active_stories(const td_api::object_ptr<td_api::StoryList> &story_list_ptr,
Promise<Unit> &&promise) {
if (story_list_ptr == nullptr) {

View File

@ -39,6 +39,7 @@
namespace td {
struct BinlogEvent;
class Dependencies;
class ReportReason;
class StoryContent;
class Td;
@ -259,6 +260,10 @@ class StoryManager final : public Actor {
bool are_dialog_stories_hidden(DialogId owner_dialog_id) const;
void add_story_dependencies(Dependencies &dependencies, const Story *story);
void add_pending_story_dependencies(Dependencies &dependencies, const PendingStory *pending_story);
const Story *get_story(StoryFullId story_full_id) const;
Story *get_story_editable(StoryFullId story_full_id);

View File

@ -9,6 +9,7 @@
#include "td/telegram/ChannelId.h"
#include "td/telegram/ChatId.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/Dependencies.h"
#include "td/telegram/MessagesManager.h"
#include "td/telegram/Td.h"
@ -246,6 +247,15 @@ vector<UserId> UserPrivacySettingRule::get_restricted_user_ids() const {
return {};
}
void UserPrivacySettingRule::add_dependencies(Dependencies &dependencies) const {
for (auto user_id : user_ids_) {
dependencies.add(user_id);
}
for (auto dialog_id : dialog_ids_) {
dependencies.add_dialog_and_dependencies(dialog_id);
}
}
UserPrivacySettingRules UserPrivacySettingRules::get_user_privacy_setting_rules(
Td *td, telegram_api::object_ptr<telegram_api::account_privacyRules> rules) {
td->contacts_manager_->on_get_users(std::move(rules->users_), "on get privacy rules");
@ -306,4 +316,10 @@ vector<UserId> UserPrivacySettingRules::get_restricted_user_ids() const {
return result;
}
void UserPrivacySettingRules::add_dependencies(Dependencies &dependencies) const {
for (auto &rule : rules_) {
rule.add_dependencies(dependencies);
}
}
} // namespace td

View File

@ -17,6 +17,7 @@
namespace td {
class Dependencies;
class Td;
class UserPrivacySettingRule {
@ -37,6 +38,8 @@ class UserPrivacySettingRule {
vector<UserId> get_restricted_user_ids() const;
void add_dependencies(Dependencies &dependencies) const;
template <class StorerT>
void store(StorerT &storer) const {
td::store(type_, storer);
@ -124,6 +127,8 @@ class UserPrivacySettingRules {
vector<UserId> get_restricted_user_ids() const;
void add_dependencies(Dependencies &dependencies) const;
template <class StorerT>
void store(StorerT &storer) const {
td::store(rules_, storer);