Store title and photo of min-channels.

This commit is contained in:
levlam 2021-12-22 16:09:34 +03:00
parent 7b84f42e87
commit 758a391e55
4 changed files with 84 additions and 8 deletions

View File

@ -567,6 +567,7 @@ set(TDLIB_SOURCE
td/telegram/MessageSender.h
td/telegram/MessagesManager.h
td/telegram/MessageTtl.h
td/telegram/MinChannel.h
td/telegram/misc.h
td/telegram/net/AuthDataShared.h
td/telegram/net/ConnectionCreator.h

View File

@ -25,6 +25,7 @@
#include "td/telegram/MessageSender.h"
#include "td/telegram/MessagesManager.h"
#include "td/telegram/MessageTtl.h"
#include "td/telegram/MinChannel.h"
#include "td/telegram/misc.h"
#include "td/telegram/net/NetQuery.h"
#include "td/telegram/NotificationManager.h"
@ -14552,6 +14553,14 @@ bool ContactsManager::have_min_channel(ChannelId channel_id) const {
return min_channels_.count(channel_id) > 0;
}
const MinChannel *ContactsManager::get_min_channel(ChannelId channel_id) const {
auto it = min_channels_.find(channel_id);
if (it == min_channels_.end()) {
return nullptr;
}
return it->second.get();
}
const ContactsManager::Channel *ContactsManager::get_channel(ChannelId channel_id) const {
auto p = channels_.find(channel_id);
if (p == channels_.end()) {
@ -15585,8 +15594,8 @@ void ContactsManager::on_chat_update(telegram_api::channel &channel, const char
Channel *c = get_channel_force(channel_id);
LOG(ERROR) << "Receive empty " << to_string(channel) << " from " << source << ", have "
<< to_string(get_supergroup_object(channel_id, c));
if (c == nullptr) {
min_channels_.insert(channel_id);
if (c == nullptr && !have_min_channel(channel_id)) {
min_channels_[channel_id] = td::make_unique<MinChannel>();
}
return;
}
@ -15654,7 +15663,6 @@ void ContactsManager::on_chat_update(telegram_api::channel &channel, const char
}();
if (is_min) {
// TODO there can be better support for min channels
Channel *c = get_channel_force(channel_id);
if (c != nullptr) {
LOG(DEBUG) << "Receive known min " << channel_id;
@ -15689,7 +15697,15 @@ void ContactsManager::on_chat_update(telegram_api::channel &channel, const char
update_channel(c, channel_id);
} else {
min_channels_.insert(channel_id);
auto min_channel = td::make_unique<MinChannel>();
min_channel->photo_ =
get_dialog_photo(td_->file_manager_.get(), DialogId(channel_id), access_hash, std::move(channel.photo_));
if (td_->auth_manager_->is_bot()) {
min_channel->photo_.minithumbnail.clear();
}
min_channel->title_ = std::move(channel.title_);
min_channels_[channel_id] = std::move(min_channel);
}
return;
}
@ -15789,8 +15805,8 @@ void ContactsManager::on_chat_update(telegram_api::channelForbidden &channel, co
Channel *c = get_channel_force(channel_id);
LOG(ERROR) << "Receive empty " << to_string(channel) << " from " << source << ", have "
<< to_string(get_supergroup_object(channel_id, c));
if (c == nullptr) {
min_channels_.insert(channel_id);
if (c == nullptr && !have_min_channel(channel_id)) {
min_channels_[channel_id] = td::make_unique<MinChannel>();
}
return;
}

View File

@ -55,6 +55,8 @@ namespace td {
struct BinlogEvent;
struct MinChannel;
class Td;
class ContactsManager final : public Actor {
@ -490,8 +492,10 @@ class ContactsManager final : public Actor {
DialogParticipantStatus get_chat_permissions(ChatId chat_id) const;
bool is_appointed_chat_administrator(ChatId chat_id) const;
bool have_channel(ChannelId channel_id) const;
bool have_min_channel(ChannelId channel_id) const;
const MinChannel *get_min_channel(ChannelId channel_id) const;
bool have_channel(ChannelId channel_id) const;
bool have_channel_force(ChannelId channel_id);
bool get_channel(ChannelId channel_id, int left_tries, Promise<Unit> &&promise);
void reload_channel(ChannelId channel_id, Promise<Unit> &&promise);
@ -1645,7 +1649,7 @@ class ContactsManager final : public Actor {
mutable std::unordered_set<ChatId, ChatIdHash> unknown_chats_;
std::unordered_map<ChatId, FileSourceId, ChatIdHash> chat_full_file_source_ids_;
std::unordered_set<ChannelId, ChannelIdHash> min_channels_;
std::unordered_map<ChannelId, unique_ptr<MinChannel>, ChannelIdHash> min_channels_;
std::unordered_map<ChannelId, unique_ptr<Channel>, ChannelIdHash> channels_;
std::unordered_map<ChannelId, unique_ptr<ChannelFull>, ChannelIdHash> channels_full_;
mutable std::unordered_set<ChannelId, ChannelIdHash> unknown_channels_;

55
td/telegram/MinChannel.h Normal file
View File

@ -0,0 +1,55 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once
#include "td/telegram/Photo.h"
#include "td/utils/common.h"
#include "td/utils/tl_helpers.h"
namespace td {
struct MinChannel {
string title_;
DialogPhoto photo_;
template <class StorerT>
void store(StorerT &storer) const {
using td::store;
bool has_title = !title_.empty();
bool has_photo = photo_.small_file_id.is_valid();
BEGIN_STORE_FLAGS();
STORE_FLAG(has_title);
STORE_FLAG(has_photo);
END_STORE_FLAGS();
if (has_title) {
store(title_, storer);
}
if (has_photo) {
store(photo_, storer);
}
}
template <class ParserT>
void parse(ParserT &parser) {
using td::parse;
bool has_title;
bool has_photo;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(has_title);
PARSE_FLAG(has_photo);
END_PARSE_FLAGS();
if (has_title) {
parse(title_, parser);
}
if (has_photo) {
parse(photo_, parser);
}
}
};
} // namespace td