Add ContactsManager::are_suitable_recommended_dialogs.

This commit is contained in:
levlam 2023-11-21 13:39:32 +03:00
parent 21222604d0
commit cf882ccc77
2 changed files with 19 additions and 13 deletions

View File

@ -9602,6 +9602,15 @@ bool ContactsManager::is_suitable_recommended_channel(ChannelId channel_id) cons
return have_input_peer_channel(c, channel_id, AccessRights::Read) && !get_channel_status(c).is_member();
}
bool ContactsManager::are_suitable_recommended_dialogs(const RecommendedDialogs &recommended_dialogs) const {
for (auto recommended_dialog_id : recommended_dialogs.dialog_ids_) {
if (!is_suitable_recommended_channel(recommended_dialog_id)) {
return false;
}
}
return true;
}
void ContactsManager::get_channel_recommendations(DialogId dialog_id,
Promise<td_api::object_ptr<td_api::chats>> &&promise) {
if (!td_->messages_manager_->have_dialog_force(dialog_id, "get_channel_recommendations")) {
@ -9616,17 +9625,11 @@ void ContactsManager::get_channel_recommendations(DialogId dialog_id,
}
auto it = channel_recommended_dialogs_.find(channel_id);
if (it != channel_recommended_dialogs_.end()) {
bool is_valid = true;
for (auto recommended_dialog_id : it->second.dialog_ids_) {
if (!is_suitable_recommended_channel(recommended_dialog_id)) {
is_valid = false;
break;
}
}
if (is_valid) {
if (are_suitable_recommended_dialogs(it->second)) {
auto next_reload_time = it->second.next_reload_time_;
promise.set_value(
td_->messages_manager_->get_chats_object(-1, it->second.dialog_ids_, "get_channel_recommendations"));
if (it->second.next_reload_time_ > Time::now()) {
if (next_reload_time > Time::now()) {
return;
}
promise = {};

View File

@ -1205,6 +1205,11 @@ class ContactsManager final : public Actor {
}
};
struct RecommendedDialogs {
vector<DialogId> dialog_ids_;
double next_reload_time_ = 0.0;
};
class UserLogEvent;
class ChatLogEvent;
class ChannelLogEvent;
@ -1715,6 +1720,8 @@ class ContactsManager final : public Actor {
bool is_suitable_recommended_channel(ChannelId channel_id) const;
bool are_suitable_recommended_dialogs(const RecommendedDialogs &recommended_dialogs) const;
void reload_channel_recommendations(ChannelId channel_id, Promise<td_api::object_ptr<td_api::chats>> &&promise);
void on_get_channel_recommendations(ChannelId channel_id,
@ -2000,10 +2007,6 @@ class ContactsManager final : public Actor {
FlatHashMap<string, unique_ptr<InviteLinkInfo>> invite_link_infos_;
FlatHashMap<DialogId, DialogAccessByInviteLink, DialogIdHash> dialog_access_by_invite_link_;
struct RecommendedDialogs {
vector<DialogId> dialog_ids_;
double next_reload_time_ = 0.0;
};
FlatHashMap<ChannelId, RecommendedDialogs, ChannelIdHash> channel_recommended_dialogs_;
FlatHashMap<ChannelId, vector<Promise<td_api::object_ptr<td_api::chats>>>, ChannelIdHash>
get_channel_recommendations_queries_;