mirror of
https://github.com/tdlight-team/tdlight-telegram-bot-api.git
synced 2024-12-25 03:35:50 +01:00
Store full chatPhoto and compare it with chatPhotoInfo.
This commit is contained in:
parent
4925532c25
commit
b4f0ebbaab
2
td
2
td
@ -1 +1 @@
|
|||||||
Subproject commit 3f54c301ead1bbe6529df4ecfb63c7f645dd181c
|
Subproject commit 054a823c1a812ee3e038f702c6d8ba3e6974be9c
|
@ -619,6 +619,7 @@ class Client::JsonChat final : public Jsonable {
|
|||||||
CHECK(chat_info != nullptr);
|
CHECK(chat_info != nullptr);
|
||||||
auto object = scope->enter_object();
|
auto object = scope->enter_object();
|
||||||
object("id", chat_id_);
|
object("id", chat_id_);
|
||||||
|
const td_api::chatPhoto *photo = nullptr;
|
||||||
switch (chat_info->type) {
|
switch (chat_info->type) {
|
||||||
case ChatInfo::Type::Private: {
|
case ChatInfo::Type::Private: {
|
||||||
auto user_info = client_->get_user_info(chat_info->user_id);
|
auto user_info = client_->get_user_info(chat_info->user_id);
|
||||||
@ -639,6 +640,7 @@ class Client::JsonChat final : public Jsonable {
|
|||||||
object("has_private_forwards", td::JsonTrue());
|
object("has_private_forwards", td::JsonTrue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
photo = user_info->photo.get();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ChatInfo::Type::Group: {
|
case ChatInfo::Type::Group: {
|
||||||
@ -663,6 +665,7 @@ class Client::JsonChat final : public Jsonable {
|
|||||||
permissions->can_add_web_page_previews_ && permissions->can_change_info_ &&
|
permissions->can_add_web_page_previews_ && permissions->can_change_info_ &&
|
||||||
permissions->can_invite_users_ && permissions->can_pin_messages_;
|
permissions->can_invite_users_ && permissions->can_pin_messages_;
|
||||||
object("all_members_are_administrators", td::JsonBool(everyone_is_administrator));
|
object("all_members_are_administrators", td::JsonBool(everyone_is_administrator));
|
||||||
|
photo = group_info->photo.get();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ChatInfo::Type::Supergroup: {
|
case ChatInfo::Type::Supergroup: {
|
||||||
@ -710,6 +713,7 @@ class Client::JsonChat final : public Jsonable {
|
|||||||
object("location", JsonChatLocation(supergroup_info->location.get()));
|
object("location", JsonChatLocation(supergroup_info->location.get()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
photo = supergroup_info->photo.get();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ChatInfo::Type::Unknown:
|
case ChatInfo::Type::Unknown:
|
||||||
@ -717,8 +721,34 @@ class Client::JsonChat final : public Jsonable {
|
|||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
if (is_full_) {
|
if (is_full_) {
|
||||||
if (chat_info->photo != nullptr) {
|
if (photo != nullptr) {
|
||||||
object("photo", JsonChatPhotoInfo(chat_info->photo.get()));
|
const td_api::file *small_file = nullptr;
|
||||||
|
const td_api::file *big_file = nullptr;
|
||||||
|
for (auto &size : photo->sizes_) {
|
||||||
|
if (size->type_ == "a") {
|
||||||
|
small_file = size->photo_.get();
|
||||||
|
} else if (size->type_ == "c") {
|
||||||
|
big_file = size->photo_.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (small_file == nullptr || big_file == nullptr) {
|
||||||
|
LOG(ERROR) << "Failed to convert chatPhoto to chatPhotoInfo for " << chat_id_ << ": " << to_string(*photo);
|
||||||
|
} else {
|
||||||
|
if (chat_info->photo_info == nullptr) {
|
||||||
|
LOG(ERROR) << "Have chatPhoto without chatPhotoInfo for " << chat_id_;
|
||||||
|
} else {
|
||||||
|
if (small_file->remote_->unique_id_ != chat_info->photo_info->small_->remote_->unique_id_ ||
|
||||||
|
big_file->remote_->unique_id_ != chat_info->photo_info->big_->remote_->unique_id_) {
|
||||||
|
LOG(ERROR) << "Have different chatPhoto and chatPhotoInfo for " << chat_id_ << ": " << to_string(*photo)
|
||||||
|
<< ' ' << to_string(chat_info->photo_info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (chat_info->photo_info != nullptr) {
|
||||||
|
LOG(ERROR) << "Have chatPhotoInfo without chatPhoto for " << chat_id_;
|
||||||
|
}
|
||||||
|
if (chat_info->photo_info != nullptr) {
|
||||||
|
object("photo", JsonChatPhotoInfo(chat_info->photo_info.get()));
|
||||||
}
|
}
|
||||||
if (pinned_message_id_ != 0) {
|
if (pinned_message_id_ != 0) {
|
||||||
CHECK(pinned_message_id_ != -1);
|
CHECK(pinned_message_id_ != -1);
|
||||||
@ -1687,10 +1717,7 @@ void Client::JsonMessage::store(JsonValueScope *scope) const {
|
|||||||
}
|
}
|
||||||
case td_api::messagePhoto::ID: {
|
case td_api::messagePhoto::ID: {
|
||||||
auto message_photo = static_cast<const td_api::messagePhoto *>(message_->content.get());
|
auto message_photo = static_cast<const td_api::messagePhoto *>(message_->content.get());
|
||||||
if (message_photo->photo_ == nullptr) {
|
CHECK(message_photo->photo_ != nullptr);
|
||||||
LOG(ERROR) << "Got empty messagePhoto";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
object("photo", JsonPhoto(message_photo->photo_.get(), client_));
|
object("photo", JsonPhoto(message_photo->photo_.get(), client_));
|
||||||
add_caption(object, message_photo->caption_);
|
add_caption(object, message_photo->caption_);
|
||||||
break;
|
break;
|
||||||
@ -4355,7 +4382,7 @@ void Client::on_update(object_ptr<td_api::Object> result) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
chat_info->title = std::move(chat->title_);
|
chat_info->title = std::move(chat->title_);
|
||||||
chat_info->photo = std::move(chat->photo_);
|
chat_info->photo_info = std::move(chat->photo_);
|
||||||
chat_info->permissions = std::move(chat->permissions_);
|
chat_info->permissions = std::move(chat->permissions_);
|
||||||
chat_info->message_auto_delete_time = chat->message_ttl_;
|
chat_info->message_auto_delete_time = chat->message_ttl_;
|
||||||
chat_info->has_protected_content = chat->has_protected_content_;
|
chat_info->has_protected_content = chat->has_protected_content_;
|
||||||
@ -4372,7 +4399,7 @@ void Client::on_update(object_ptr<td_api::Object> result) {
|
|||||||
auto update = move_object_as<td_api::updateChatPhoto>(result);
|
auto update = move_object_as<td_api::updateChatPhoto>(result);
|
||||||
auto chat_info = add_chat(update->chat_id_);
|
auto chat_info = add_chat(update->chat_id_);
|
||||||
CHECK(chat_info->type != ChatInfo::Type::Unknown);
|
CHECK(chat_info->type != ChatInfo::Type::Unknown);
|
||||||
chat_info->photo = std::move(update->photo_);
|
chat_info->photo_info = std::move(update->photo_);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case td_api::updateChatPermissions::ID: {
|
case td_api::updateChatPermissions::ID: {
|
||||||
@ -4405,8 +4432,10 @@ void Client::on_update(object_ptr<td_api::Object> result) {
|
|||||||
case td_api::updateUserFullInfo::ID: {
|
case td_api::updateUserFullInfo::ID: {
|
||||||
auto update = move_object_as<td_api::updateUserFullInfo>(result);
|
auto update = move_object_as<td_api::updateUserFullInfo>(result);
|
||||||
auto user_id = update->user_id_;
|
auto user_id = update->user_id_;
|
||||||
set_user_bio(user_id, std::move(update->user_full_info_->bio_));
|
auto full_info = update->user_full_info_.get();
|
||||||
set_user_has_private_forwards(user_id, update->user_full_info_->has_private_forwards_);
|
set_user_photo(user_id, std::move(full_info->photo_));
|
||||||
|
set_user_bio(user_id, std::move(full_info->bio_));
|
||||||
|
set_user_has_private_forwards(user_id, full_info->has_private_forwards_);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case td_api::updateBasicGroup::ID: {
|
case td_api::updateBasicGroup::ID: {
|
||||||
@ -4418,7 +4447,8 @@ void Client::on_update(object_ptr<td_api::Object> result) {
|
|||||||
case td_api::updateBasicGroupFullInfo::ID: {
|
case td_api::updateBasicGroupFullInfo::ID: {
|
||||||
auto update = move_object_as<td_api::updateBasicGroupFullInfo>(result);
|
auto update = move_object_as<td_api::updateBasicGroupFullInfo>(result);
|
||||||
auto group_id = update->basic_group_id_;
|
auto group_id = update->basic_group_id_;
|
||||||
auto full_info = std::move(update->basic_group_full_info_);
|
auto full_info = update->basic_group_full_info_.get();
|
||||||
|
set_group_photo(group_id, std::move(full_info->photo_));
|
||||||
set_group_description(group_id, std::move(full_info->description_));
|
set_group_description(group_id, std::move(full_info->description_));
|
||||||
set_group_invite_link(group_id, full_info->invite_link_ != nullptr
|
set_group_invite_link(group_id, full_info->invite_link_ != nullptr
|
||||||
? std::move(full_info->invite_link_->invite_link_)
|
? std::move(full_info->invite_link_->invite_link_)
|
||||||
@ -4434,7 +4464,8 @@ void Client::on_update(object_ptr<td_api::Object> result) {
|
|||||||
case td_api::updateSupergroupFullInfo::ID: {
|
case td_api::updateSupergroupFullInfo::ID: {
|
||||||
auto update = move_object_as<td_api::updateSupergroupFullInfo>(result);
|
auto update = move_object_as<td_api::updateSupergroupFullInfo>(result);
|
||||||
auto supergroup_id = update->supergroup_id_;
|
auto supergroup_id = update->supergroup_id_;
|
||||||
auto full_info = std::move(update->supergroup_full_info_);
|
auto full_info = update->supergroup_full_info_.get();
|
||||||
|
set_supergroup_photo(supergroup_id, std::move(full_info->photo_));
|
||||||
set_supergroup_description(supergroup_id, std::move(full_info->description_));
|
set_supergroup_description(supergroup_id, std::move(full_info->description_));
|
||||||
set_supergroup_invite_link(supergroup_id, full_info->invite_link_ != nullptr
|
set_supergroup_invite_link(supergroup_id, full_info->invite_link_ != nullptr
|
||||||
? std::move(full_info->invite_link_->invite_link_)
|
? std::move(full_info->invite_link_->invite_link_)
|
||||||
@ -8495,6 +8526,10 @@ const Client::UserInfo *Client::get_user_info(int64 user_id) const {
|
|||||||
return it == users_.end() ? nullptr : it->second.get();
|
return it == users_.end() ? nullptr : it->second.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Client::set_user_photo(int64 user_id, object_ptr<td_api::chatPhoto> &&photo) {
|
||||||
|
add_user_info(user_id)->photo = std::move(photo);
|
||||||
|
}
|
||||||
|
|
||||||
void Client::set_user_bio(int64 user_id, td::string &&bio) {
|
void Client::set_user_bio(int64 user_id, td::string &&bio) {
|
||||||
add_user_info(user_id)->bio = std::move(bio);
|
add_user_info(user_id)->bio = std::move(bio);
|
||||||
}
|
}
|
||||||
@ -8530,6 +8565,10 @@ const Client::GroupInfo *Client::get_group_info(int64 group_id) const {
|
|||||||
return it == groups_.end() ? nullptr : it->second.get();
|
return it == groups_.end() ? nullptr : it->second.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Client::set_group_photo(int64 group_id, object_ptr<td_api::chatPhoto> &&photo) {
|
||||||
|
add_group_info(group_id)->photo = std::move(photo);
|
||||||
|
}
|
||||||
|
|
||||||
void Client::set_group_description(int64 group_id, td::string &&descripton) {
|
void Client::set_group_description(int64 group_id, td::string &&descripton) {
|
||||||
add_group_info(group_id)->description = std::move(descripton);
|
add_group_info(group_id)->description = std::move(descripton);
|
||||||
}
|
}
|
||||||
@ -8546,6 +8585,10 @@ void Client::add_supergroup(SupergroupInfo *supergroup_info, object_ptr<td_api::
|
|||||||
supergroup_info->has_location = supergroup->has_location_;
|
supergroup_info->has_location = supergroup->has_location_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Client::set_supergroup_photo(int64 supergroup_id, object_ptr<td_api::chatPhoto> &&photo) {
|
||||||
|
add_supergroup_info(supergroup_id)->photo = std::move(photo);
|
||||||
|
}
|
||||||
|
|
||||||
void Client::set_supergroup_description(int64 supergroup_id, td::string &&descripton) {
|
void Client::set_supergroup_description(int64 supergroup_id, td::string &&descripton) {
|
||||||
add_supergroup_info(supergroup_id)->description = std::move(descripton);
|
add_supergroup_info(supergroup_id)->description = std::move(descripton);
|
||||||
}
|
}
|
||||||
|
@ -580,6 +580,7 @@ class Client final : public WebhookActor::Callback {
|
|||||||
td::string username;
|
td::string username;
|
||||||
td::string language_code;
|
td::string language_code;
|
||||||
|
|
||||||
|
object_ptr<td_api::chatPhoto> photo;
|
||||||
td::string bio;
|
td::string bio;
|
||||||
|
|
||||||
bool have_access = false;
|
bool have_access = false;
|
||||||
@ -589,12 +590,14 @@ class Client final : public WebhookActor::Callback {
|
|||||||
bool has_private_forwards = false;
|
bool has_private_forwards = false;
|
||||||
};
|
};
|
||||||
static void add_user(UserInfo *user_info, object_ptr<td_api::user> &&user);
|
static void add_user(UserInfo *user_info, object_ptr<td_api::user> &&user);
|
||||||
|
void set_user_photo(int64 user_id, object_ptr<td_api::chatPhoto> &&photo);
|
||||||
void set_user_bio(int64 user_id, td::string &&bio);
|
void set_user_bio(int64 user_id, td::string &&bio);
|
||||||
void set_user_has_private_forwards(int64 user_id, bool has_private_forwards);
|
void set_user_has_private_forwards(int64 user_id, bool has_private_forwards);
|
||||||
UserInfo *add_user_info(int64 user_id);
|
UserInfo *add_user_info(int64 user_id);
|
||||||
const UserInfo *get_user_info(int64 user_id) const;
|
const UserInfo *get_user_info(int64 user_id) const;
|
||||||
|
|
||||||
struct GroupInfo {
|
struct GroupInfo {
|
||||||
|
object_ptr<td_api::chatPhoto> photo;
|
||||||
td::string description;
|
td::string description;
|
||||||
td::string invite_link;
|
td::string invite_link;
|
||||||
int32 member_count = 0;
|
int32 member_count = 0;
|
||||||
@ -604,6 +607,7 @@ class Client final : public WebhookActor::Callback {
|
|||||||
int64 upgraded_to_supergroup_id = 0;
|
int64 upgraded_to_supergroup_id = 0;
|
||||||
};
|
};
|
||||||
static void add_group(GroupInfo *group_info, object_ptr<td_api::basicGroup> &&group);
|
static void add_group(GroupInfo *group_info, object_ptr<td_api::basicGroup> &&group);
|
||||||
|
void set_group_photo(int64 group_id, object_ptr<td_api::chatPhoto> &&photo);
|
||||||
void set_group_description(int64 group_id, td::string &&descripton);
|
void set_group_description(int64 group_id, td::string &&descripton);
|
||||||
void set_group_invite_link(int64 group_id, td::string &&invite_link);
|
void set_group_invite_link(int64 group_id, td::string &&invite_link);
|
||||||
GroupInfo *add_group_info(int64 group_id);
|
GroupInfo *add_group_info(int64 group_id);
|
||||||
@ -611,6 +615,7 @@ class Client final : public WebhookActor::Callback {
|
|||||||
|
|
||||||
struct SupergroupInfo {
|
struct SupergroupInfo {
|
||||||
td::string username;
|
td::string username;
|
||||||
|
object_ptr<td_api::chatPhoto> photo;
|
||||||
td::string description;
|
td::string description;
|
||||||
td::string invite_link;
|
td::string invite_link;
|
||||||
int64 sticker_set_id = 0;
|
int64 sticker_set_id = 0;
|
||||||
@ -624,6 +629,7 @@ class Client final : public WebhookActor::Callback {
|
|||||||
bool has_location = false;
|
bool has_location = false;
|
||||||
};
|
};
|
||||||
static void add_supergroup(SupergroupInfo *supergroup_info, object_ptr<td_api::supergroup> &&supergroup);
|
static void add_supergroup(SupergroupInfo *supergroup_info, object_ptr<td_api::supergroup> &&supergroup);
|
||||||
|
void set_supergroup_photo(int64 supergroup_id, object_ptr<td_api::chatPhoto> &&photo);
|
||||||
void set_supergroup_description(int64 supergroup_id, td::string &&descripton);
|
void set_supergroup_description(int64 supergroup_id, td::string &&descripton);
|
||||||
void set_supergroup_invite_link(int64 supergroup_id, td::string &&invite_link);
|
void set_supergroup_invite_link(int64 supergroup_id, td::string &&invite_link);
|
||||||
void set_supergroup_sticker_set_id(int64 supergroup_id, int64 sticker_set_id);
|
void set_supergroup_sticker_set_id(int64 supergroup_id, int64 sticker_set_id);
|
||||||
@ -640,7 +646,7 @@ class Client final : public WebhookActor::Callback {
|
|||||||
td::string title;
|
td::string title;
|
||||||
int32 message_auto_delete_time = 0;
|
int32 message_auto_delete_time = 0;
|
||||||
bool has_protected_content = false;
|
bool has_protected_content = false;
|
||||||
object_ptr<td_api::chatPhotoInfo> photo;
|
object_ptr<td_api::chatPhotoInfo> photo_info;
|
||||||
object_ptr<td_api::chatPermissions> permissions;
|
object_ptr<td_api::chatPermissions> permissions;
|
||||||
union {
|
union {
|
||||||
int64 user_id;
|
int64 user_id;
|
||||||
|
Loading…
Reference in New Issue
Block a user