Add class PeerColor.

This commit is contained in:
levlam 2023-12-18 15:51:11 +03:00
parent 67422ffb47
commit 9171588824
5 changed files with 78 additions and 29 deletions

View File

@ -441,14 +441,15 @@ set(TDLIB_SOURCE
td/telegram/OrderInfo.cpp td/telegram/OrderInfo.cpp
td/telegram/Payments.cpp td/telegram/Payments.cpp
td/telegram/PasswordManager.cpp td/telegram/PasswordManager.cpp
td/telegram/PeerColor.cpp
td/telegram/PhoneNumberManager.cpp td/telegram/PhoneNumberManager.cpp
td/telegram/PrivacyManager.cpp
td/telegram/Photo.cpp td/telegram/Photo.cpp
td/telegram/PhotoSize.cpp td/telegram/PhotoSize.cpp
td/telegram/PhotoSizeSource.cpp td/telegram/PhotoSizeSource.cpp
td/telegram/PollManager.cpp td/telegram/PollManager.cpp
td/telegram/Premium.cpp td/telegram/Premium.cpp
td/telegram/PremiumGiftOption.cpp td/telegram/PremiumGiftOption.cpp
td/telegram/PrivacyManager.cpp
td/telegram/QueryCombiner.cpp td/telegram/QueryCombiner.cpp
td/telegram/QueryMerger.cpp td/telegram/QueryMerger.cpp
td/telegram/ReactionManager.cpp td/telegram/ReactionManager.cpp
@ -749,6 +750,7 @@ set(TDLIB_SOURCE
td/telegram/OrderInfo.h td/telegram/OrderInfo.h
td/telegram/PasswordManager.h td/telegram/PasswordManager.h
td/telegram/Payments.h td/telegram/Payments.h
td/telegram/PeerColor.h
td/telegram/PhoneNumberManager.h td/telegram/PhoneNumberManager.h
td/telegram/Photo.h td/telegram/Photo.h
td/telegram/PhotoFormat.h td/telegram/PhotoFormat.h

View File

@ -37,6 +37,7 @@
#include "td/telegram/NotificationManager.h" #include "td/telegram/NotificationManager.h"
#include "td/telegram/OptionManager.h" #include "td/telegram/OptionManager.h"
#include "td/telegram/PasswordManager.h" #include "td/telegram/PasswordManager.h"
#include "td/telegram/PeerColor.h"
#include "td/telegram/Photo.h" #include "td/telegram/Photo.h"
#include "td/telegram/Photo.hpp" #include "td/telegram/Photo.hpp"
#include "td/telegram/PhotoSize.h" #include "td/telegram/PhotoSize.h"
@ -10950,21 +10951,12 @@ void ContactsManager::on_get_user(tl_object_ptr<telegram_api::User> &&user_ptr,
on_update_user_usernames(u, user_id, Usernames{std::move(user->username_), std::move(user->usernames_)}); on_update_user_usernames(u, user_id, Usernames{std::move(user->username_), std::move(user->usernames_)});
} }
on_update_user_emoji_status(u, user_id, EmojiStatus(std::move(user->emoji_status_))); on_update_user_emoji_status(u, user_id, EmojiStatus(std::move(user->emoji_status_)));
on_update_user_accent_color_id( PeerColor peer_color(user->color_);
u, user_id, on_update_user_accent_color_id(u, user_id, peer_color.accent_color_id_);
(user->color_ != nullptr && (user->color_->flags_ & telegram_api::peerColor::COLOR_MASK) != 0 on_update_user_background_custom_emoji_id(u, user_id, peer_color.background_custom_emoji_id_);
? AccentColorId(user->color_->color_) PeerColor profile_peer_color(user->profile_color_);
: AccentColorId())); on_update_user_profile_accent_color_id(u, user_id, profile_peer_color.accent_color_id_);
on_update_user_background_custom_emoji_id( on_update_user_profile_background_custom_emoji_id(u, user_id, profile_peer_color.background_custom_emoji_id_);
u, user_id, (user->color_ != nullptr ? CustomEmojiId(user->color_->background_emoji_id_) : CustomEmojiId()));
on_update_user_profile_accent_color_id(
u, user_id,
(user->profile_color_ != nullptr && (user->profile_color_->flags_ & telegram_api::peerColor::COLOR_MASK) != 0
? AccentColorId(user->profile_color_->color_)
: AccentColorId()));
on_update_user_profile_background_custom_emoji_id(
u, user_id,
(user->profile_color_ != nullptr ? CustomEmojiId(user->profile_color_->background_emoji_id_) : CustomEmojiId()));
if (is_me_regular_user && is_received) { if (is_me_regular_user && is_received) {
on_update_user_stories_hidden(u, user_id, stories_hidden); on_update_user_stories_hidden(u, user_id, stories_hidden);
} }
@ -19717,9 +19709,8 @@ void ContactsManager::on_get_channel(telegram_api::channel &channel, const char
if (td_->auth_manager_->is_bot()) { if (td_->auth_manager_->is_bot()) {
min_channel->photo_.minithumbnail.clear(); min_channel->photo_.minithumbnail.clear();
} }
if (channel.color_ != nullptr && (channel.color_->flags_ & telegram_api::peerColor::COLOR_MASK) != 0) { PeerColor peer_color(channel.color_);
min_channel->accent_color_id_ = AccentColorId(channel.color_->color_); min_channel->accent_color_id_ = peer_color.accent_color_id_;
}
min_channel->title_ = std::move(channel.title_); min_channel->title_ = std::move(channel.title_);
min_channel->is_megagroup_ = is_megagroup; min_channel->is_megagroup_ = is_megagroup;
@ -19793,13 +19784,12 @@ void ContactsManager::on_get_channel(telegram_api::channel &channel, const char
on_update_channel_title(c, channel_id, std::move(channel.title_)); on_update_channel_title(c, channel_id, std::move(channel.title_));
on_update_channel_photo(c, channel_id, std::move(channel.photo_)); on_update_channel_photo(c, channel_id, std::move(channel.photo_));
on_update_channel_accent_color_id( PeerColor peer_color(channel.color_);
c, channel_id, on_update_channel_accent_color_id(c, channel_id, peer_color.accent_color_id_);
(channel.color_ != nullptr && (channel.color_->flags_ & telegram_api::peerColor::COLOR_MASK) != 0 on_update_channel_background_custom_emoji_id(c, channel_id, peer_color.background_custom_emoji_id_);
? AccentColorId(channel.color_->color_) PeerColor profile_peer_color(channel.profile_color_);
: AccentColorId())); on_update_channel_profile_accent_color_id(c, channel_id, profile_peer_color.accent_color_id_);
on_update_channel_background_custom_emoji_id( on_update_channel_profile_background_custom_emoji_id(c, channel_id, profile_peer_color.background_custom_emoji_id_);
c, channel_id, channel.color_ != nullptr ? CustomEmojiId(channel.color_->background_emoji_id_) : CustomEmojiId());
on_update_channel_status(c, channel_id, std::move(status)); on_update_channel_status(c, channel_id, std::move(status));
on_update_channel_usernames( on_update_channel_usernames(
c, channel_id, c, channel_id,

33
td/telegram/PeerColor.cpp Normal file
View File

@ -0,0 +1,33 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
//
// 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)
//
#include "td/telegram/PeerColor.h"
#include "td/utils/logging.h"
namespace td {
PeerColor::PeerColor(const telegram_api::object_ptr<telegram_api::peerColor> &peer_color) {
if (peer_color == nullptr) {
return;
}
if ((peer_color->flags_ & telegram_api::peerColor::COLOR_MASK) != 0) {
accent_color_id_ = AccentColorId(peer_color->color_);
if (!accent_color_id_.is_valid()) {
LOG(ERROR) << "Receive " << to_string(peer_color);
accent_color_id_ = AccentColorId();
}
}
if ((peer_color->flags_ & telegram_api::peerColor::BACKGROUND_EMOJI_ID_MASK) != 0) {
background_custom_emoji_id_ = CustomEmojiId(peer_color->background_emoji_id_);
if (!background_custom_emoji_id_.is_valid()) {
LOG(ERROR) << "Receive " << to_string(peer_color);
background_custom_emoji_id_ = CustomEmojiId();
}
}
}
} // namespace td

24
td/telegram/PeerColor.h Normal file
View File

@ -0,0 +1,24 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
//
// 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/AccentColorId.h"
#include "td/telegram/CustomEmojiId.h"
#include "td/telegram/telegram_api.h"
namespace td {
class Td;
struct PeerColor {
AccentColorId accent_color_id_;
CustomEmojiId background_custom_emoji_id_;
explicit PeerColor(const telegram_api::object_ptr<telegram_api::peerColor> &peer_color);
};
} // namespace td

View File

@ -21,6 +21,7 @@
#include "td/telegram/files/FileId.h" #include "td/telegram/files/FileId.h"
#include "td/telegram/LinkManager.h" #include "td/telegram/LinkManager.h"
#include "td/telegram/Location.h" #include "td/telegram/Location.h"
#include "td/telegram/PeerColor.h"
#include "td/telegram/Photo.h" #include "td/telegram/Photo.h"
#include "td/telegram/Photo.hpp" #include "td/telegram/Photo.hpp"
#include "td/telegram/PhotoFormat.h" #include "td/telegram/PhotoFormat.h"
@ -2213,14 +2214,13 @@ unique_ptr<WebPageBlock> get_web_page_block(Td *td, tl_object_ptr<telegram_api::
channel_id); channel_id);
} else { } else {
bool has_access_hash = (channel->flags_ & telegram_api::channel::ACCESS_HASH_MASK) != 0; bool has_access_hash = (channel->flags_ & telegram_api::channel::ACCESS_HASH_MASK) != 0;
PeerColor peer_color(channel->color_);
return td::make_unique<WebPageBlockChatLink>( return td::make_unique<WebPageBlockChatLink>(
std::move(channel->title_), std::move(channel->title_),
get_dialog_photo(td->file_manager_.get(), DialogId(channel_id), get_dialog_photo(td->file_manager_.get(), DialogId(channel_id),
has_access_hash ? channel->access_hash_ : 0, std::move(channel->photo_)), has_access_hash ? channel->access_hash_ : 0, std::move(channel->photo_)),
std::move(channel->username_), std::move(channel->username_),
channel->color_ != nullptr && (channel->color_->flags_ & telegram_api::peerColor::COLOR_MASK) != 0 peer_color.accent_color_id_.is_valid() ? peer_color.accent_color_id_ : AccentColorId(channel_id),
? AccentColorId(channel->color_->color_)
: AccentColorId(channel_id),
channel_id); channel_id);
} }
} else { } else {