Fallback to default accent color for the chat.
This commit is contained in:
parent
00a6167952
commit
adc81fcea6
@ -5774,17 +5774,17 @@ const DialogPhoto *ContactsManager::get_secret_chat_dialog_photo(SecretChatId se
|
||||
return get_user_dialog_photo(c->user_id);
|
||||
}
|
||||
|
||||
AccentColorId ContactsManager::get_user_accent_color_id(UserId user_id) const {
|
||||
int32 ContactsManager::get_user_accent_color_id_object(UserId user_id) const {
|
||||
auto u = get_user(user_id);
|
||||
if (u == nullptr || !u->accent_color_id.is_valid()) {
|
||||
return AccentColorId(user_id);
|
||||
return td_->theme_manager_->get_accent_color_id_object(AccentColorId(user_id));
|
||||
}
|
||||
|
||||
return u->accent_color_id;
|
||||
return td_->theme_manager_->get_accent_color_id_object(u->accent_color_id, AccentColorId(user_id));
|
||||
}
|
||||
|
||||
AccentColorId ContactsManager::get_chat_accent_color_id(ChatId chat_id) const {
|
||||
return AccentColorId(chat_id);
|
||||
int32 ContactsManager::get_chat_accent_color_id_object(ChatId chat_id) const {
|
||||
return td_->theme_manager_->get_accent_color_id_object(AccentColorId(chat_id));
|
||||
}
|
||||
|
||||
AccentColorId ContactsManager::get_channel_accent_color_id(ChannelId channel_id) const {
|
||||
@ -5803,12 +5803,17 @@ AccentColorId ContactsManager::get_channel_accent_color_id(ChannelId channel_id)
|
||||
return c->accent_color_id;
|
||||
}
|
||||
|
||||
AccentColorId ContactsManager::get_secret_chat_accent_color_id(SecretChatId secret_chat_id) const {
|
||||
int32 ContactsManager::get_channel_accent_color_id_object(ChannelId channel_id) const {
|
||||
return td_->theme_manager_->get_accent_color_id_object(get_channel_accent_color_id(channel_id),
|
||||
AccentColorId(channel_id));
|
||||
}
|
||||
|
||||
int32 ContactsManager::get_secret_chat_accent_color_id_object(SecretChatId secret_chat_id) const {
|
||||
auto c = get_secret_chat(secret_chat_id);
|
||||
if (c == nullptr) {
|
||||
return AccentColorId(0);
|
||||
return 5;
|
||||
}
|
||||
return get_user_accent_color_id(c->user_id);
|
||||
return get_user_accent_color_id_object(c->user_id);
|
||||
}
|
||||
|
||||
CustomEmojiId ContactsManager::get_user_background_custom_emoji_id(UserId user_id) const {
|
||||
@ -19504,9 +19509,10 @@ tl_object_ptr<td_api::user> ContactsManager::get_user_object(UserId user_id, con
|
||||
user_id.get(), u->first_name, u->last_name, u->usernames.get_usernames_object(), u->phone_number,
|
||||
get_user_status_object(user_id, u, G()->unix_time()),
|
||||
get_profile_photo_object(td_->file_manager_.get(), u->photo),
|
||||
td_->theme_manager_->get_accent_color_id_object(accent_color_id), u->background_custom_emoji_id.get(),
|
||||
std::move(emoji_status), u->is_contact, u->is_mutual_contact, u->is_close_friend, u->is_verified, u->is_premium,
|
||||
u->is_support, get_restriction_reason_description(u->restriction_reasons), u->is_scam, u->is_fake,
|
||||
td_->theme_manager_->get_accent_color_id_object(accent_color_id, AccentColorId(user_id)),
|
||||
u->background_custom_emoji_id.get(), std::move(emoji_status), u->is_contact, u->is_mutual_contact,
|
||||
u->is_close_friend, u->is_verified, u->is_premium, u->is_support,
|
||||
get_restriction_reason_description(u->restriction_reasons), u->is_scam, u->is_fake,
|
||||
u->max_active_story_id.is_valid(), get_user_has_unread_stories(u), have_access, std::move(type), u->language_code,
|
||||
u->attach_menu_enabled);
|
||||
}
|
||||
@ -19817,7 +19823,7 @@ tl_object_ptr<td_api::chatInviteLinkInfo> ContactsManager::get_chat_invite_link_
|
||||
string title;
|
||||
const DialogPhoto *photo = nullptr;
|
||||
DialogPhoto invite_link_photo;
|
||||
AccentColorId accent_color_id;
|
||||
int32 accent_color_id_object;
|
||||
string description;
|
||||
int32 participant_count = 0;
|
||||
vector<int64> member_user_ids;
|
||||
@ -19843,7 +19849,7 @@ tl_object_ptr<td_api::chatInviteLinkInfo> ContactsManager::get_chat_invite_link_
|
||||
} else {
|
||||
LOG(ERROR) << "Have no information about " << chat_id;
|
||||
}
|
||||
accent_color_id = get_chat_accent_color_id(chat_id);
|
||||
accent_color_id_object = get_chat_accent_color_id_object(chat_id);
|
||||
break;
|
||||
}
|
||||
case DialogType::Channel: {
|
||||
@ -19863,7 +19869,7 @@ tl_object_ptr<td_api::chatInviteLinkInfo> ContactsManager::get_chat_invite_link_
|
||||
} else {
|
||||
LOG(ERROR) << "Have no information about " << channel_id;
|
||||
}
|
||||
accent_color_id = get_channel_accent_color_id(channel_id);
|
||||
accent_color_id_object = get_channel_accent_color_id_object(channel_id);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -19876,7 +19882,7 @@ tl_object_ptr<td_api::chatInviteLinkInfo> ContactsManager::get_chat_invite_link_
|
||||
title = invite_link_info->title;
|
||||
invite_link_photo = as_fake_dialog_photo(invite_link_info->photo, dialog_id, false);
|
||||
photo = &invite_link_photo;
|
||||
accent_color_id = invite_link_info->accent_color_id;
|
||||
accent_color_id_object = td_->theme_manager_->get_accent_color_id_object(invite_link_info->accent_color_id);
|
||||
description = invite_link_info->description;
|
||||
participant_count = invite_link_info->participant_count;
|
||||
member_user_ids = get_user_ids_object(invite_link_info->participant_user_ids, "get_chat_invite_link_info_object");
|
||||
@ -19909,9 +19915,8 @@ tl_object_ptr<td_api::chatInviteLinkInfo> ContactsManager::get_chat_invite_link_
|
||||
|
||||
return td_api::make_object<td_api::chatInviteLinkInfo>(
|
||||
td_->messages_manager_->get_chat_id_object(dialog_id, "chatInviteLinkInfo"), accessible_for, std::move(chat_type),
|
||||
title, get_chat_photo_info_object(td_->file_manager_.get(), photo),
|
||||
td_->theme_manager_->get_accent_color_id_object(accent_color_id), description, participant_count,
|
||||
std::move(member_user_ids), creates_join_request, is_public, is_verified, is_scam, is_fake);
|
||||
title, get_chat_photo_info_object(td_->file_manager_.get(), photo), accent_color_id_object, description,
|
||||
participant_count, std::move(member_user_ids), creates_join_request, is_public, is_verified, is_scam, is_fake);
|
||||
}
|
||||
|
||||
void ContactsManager::get_support_user(Promise<td_api::object_ptr<td_api::user>> &&promise) {
|
||||
|
@ -118,10 +118,12 @@ class ContactsManager final : public Actor {
|
||||
const DialogPhoto *get_channel_dialog_photo(ChannelId channel_id) const;
|
||||
const DialogPhoto *get_secret_chat_dialog_photo(SecretChatId secret_chat_id);
|
||||
|
||||
AccentColorId get_user_accent_color_id(UserId user_id) const;
|
||||
AccentColorId get_chat_accent_color_id(ChatId chat_id) const;
|
||||
AccentColorId get_channel_accent_color_id(ChannelId channel_id) const;
|
||||
AccentColorId get_secret_chat_accent_color_id(SecretChatId secret_chat_id) const;
|
||||
|
||||
int32 get_user_accent_color_id_object(UserId user_id) const;
|
||||
int32 get_chat_accent_color_id_object(ChatId chat_id) const;
|
||||
int32 get_channel_accent_color_id_object(ChannelId channel_id) const;
|
||||
int32 get_secret_chat_accent_color_id_object(SecretChatId secret_chat_id) const;
|
||||
|
||||
CustomEmojiId get_user_background_custom_emoji_id(UserId user_id) const;
|
||||
CustomEmojiId get_chat_background_custom_emoji_id(ChatId chat_id) const;
|
||||
|
@ -434,8 +434,8 @@ static td_api::object_ptr<td_api::ChatEventAction> get_chat_event_action_object(
|
||||
auto old_accent_color_id = AccentColorId(action->prev_value_);
|
||||
auto new_accent_color_id = AccentColorId(action->new_value_);
|
||||
return td_api::make_object<td_api::chatEventAccentColorChanged>(
|
||||
td->theme_manager_->get_accent_color_id_object(old_accent_color_id),
|
||||
td->theme_manager_->get_accent_color_id_object(new_accent_color_id));
|
||||
td->theme_manager_->get_accent_color_id_object(old_accent_color_id, AccentColorId(channel_id)),
|
||||
td->theme_manager_->get_accent_color_id_object(new_accent_color_id, AccentColorId(channel_id)));
|
||||
}
|
||||
case telegram_api::channelAdminLogEventActionChangeBackgroundEmoji::ID: {
|
||||
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionChangeBackgroundEmoji>(action_ptr);
|
||||
|
@ -74,7 +74,6 @@
|
||||
#include "td/telegram/Td.h"
|
||||
#include "td/telegram/TdDb.h"
|
||||
#include "td/telegram/telegram_api.h"
|
||||
#include "td/telegram/ThemeManager.h"
|
||||
#include "td/telegram/TopDialogCategory.h"
|
||||
#include "td/telegram/TopDialogManager.h"
|
||||
#include "td/telegram/TranslationManager.h"
|
||||
@ -20748,8 +20747,7 @@ td_api::object_ptr<td_api::chat> MessagesManager::get_chat_object(const Dialog *
|
||||
return make_tl_object<td_api::chat>(
|
||||
d->dialog_id.get(), get_chat_type_object(d->dialog_id), get_dialog_title(d->dialog_id),
|
||||
get_chat_photo_info_object(td_->file_manager_.get(), get_dialog_photo(d->dialog_id)),
|
||||
td_->theme_manager_->get_accent_color_id_object(get_dialog_accent_color_id(d->dialog_id)),
|
||||
get_dialog_background_custom_emoji_id(d->dialog_id).get(),
|
||||
get_dialog_accent_color_id_object(d->dialog_id), get_dialog_background_custom_emoji_id(d->dialog_id).get(),
|
||||
get_dialog_default_permissions(d->dialog_id).get_chat_permissions_object(),
|
||||
get_message_object(d->dialog_id, get_message(d, d->last_message_id), "get_chat_object"),
|
||||
get_chat_positions_object(d), get_default_message_sender_object(d), block_list_id.get_block_list_object(),
|
||||
@ -32435,10 +32433,10 @@ void MessagesManager::on_dialog_photo_updated(DialogId dialog_id) {
|
||||
void MessagesManager::on_dialog_accent_color_id_updated(DialogId dialog_id) {
|
||||
auto d = get_dialog(dialog_id); // called from update_user, must not create the dialog
|
||||
if (d != nullptr && d->is_update_new_chat_sent) {
|
||||
send_closure(G()->td(), &Td::send_update,
|
||||
td_api::make_object<td_api::updateChatAccentColor>(
|
||||
get_chat_id_object(dialog_id, "updateChatAccentColor"),
|
||||
td_->theme_manager_->get_accent_color_id_object(get_dialog_accent_color_id(dialog_id))));
|
||||
send_closure(
|
||||
G()->td(), &Td::send_update,
|
||||
td_api::make_object<td_api::updateChatAccentColor>(get_chat_id_object(dialog_id, "updateChatAccentColor"),
|
||||
get_dialog_accent_color_id_object(dialog_id)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -32890,20 +32888,20 @@ const DialogPhoto *MessagesManager::get_dialog_photo(DialogId dialog_id) const {
|
||||
}
|
||||
}
|
||||
|
||||
AccentColorId MessagesManager::get_dialog_accent_color_id(DialogId dialog_id) const {
|
||||
int32 MessagesManager::get_dialog_accent_color_id_object(DialogId dialog_id) const {
|
||||
switch (dialog_id.get_type()) {
|
||||
case DialogType::User:
|
||||
return td_->contacts_manager_->get_user_accent_color_id(dialog_id.get_user_id());
|
||||
return td_->contacts_manager_->get_user_accent_color_id_object(dialog_id.get_user_id());
|
||||
case DialogType::Chat:
|
||||
return td_->contacts_manager_->get_chat_accent_color_id(dialog_id.get_chat_id());
|
||||
return td_->contacts_manager_->get_chat_accent_color_id_object(dialog_id.get_chat_id());
|
||||
case DialogType::Channel:
|
||||
return td_->contacts_manager_->get_channel_accent_color_id(dialog_id.get_channel_id());
|
||||
return td_->contacts_manager_->get_channel_accent_color_id_object(dialog_id.get_channel_id());
|
||||
case DialogType::SecretChat:
|
||||
return td_->contacts_manager_->get_secret_chat_accent_color_id(dialog_id.get_secret_chat_id());
|
||||
return td_->contacts_manager_->get_secret_chat_accent_color_id_object(dialog_id.get_secret_chat_id());
|
||||
case DialogType::None:
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return AccentColorId();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2962,7 +2962,7 @@ class MessagesManager final : public Actor {
|
||||
|
||||
const DialogPhoto *get_dialog_photo(DialogId dialog_id) const;
|
||||
|
||||
AccentColorId get_dialog_accent_color_id(DialogId dialog_id) const;
|
||||
int32 get_dialog_accent_color_id_object(DialogId dialog_id) const;
|
||||
|
||||
CustomEmojiId get_dialog_background_custom_emoji_id(DialogId dialog_id) const;
|
||||
|
||||
|
@ -377,12 +377,17 @@ string ThemeManager::get_theme_parameters_json_string(const td_api::object_ptr<t
|
||||
}
|
||||
}
|
||||
|
||||
int32 ThemeManager::get_accent_color_id_object(AccentColorId accent_color_id) const {
|
||||
int32 ThemeManager::get_accent_color_id_object(AccentColorId accent_color_id,
|
||||
AccentColorId fallback_accent_color_id) const {
|
||||
CHECK(accent_color_id.is_valid());
|
||||
if (accent_color_id.is_built_in() || accent_colors_.light_colors_.count(accent_color_id) != 0) {
|
||||
return accent_color_id.get();
|
||||
}
|
||||
return 5;
|
||||
if (!fallback_accent_color_id.is_valid()) {
|
||||
return 5; // blue
|
||||
}
|
||||
CHECK(fallback_accent_color_id.is_built_in());
|
||||
return fallback_accent_color_id.get();
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::themeSettings> ThemeManager::get_theme_settings_object(const ThemeSettings &settings) const {
|
||||
|
@ -37,7 +37,8 @@ class ThemeManager final : public Actor {
|
||||
static string get_theme_parameters_json_string(const td_api::object_ptr<td_api::themeParameters> &theme,
|
||||
bool for_web_view);
|
||||
|
||||
int32 get_accent_color_id_object(AccentColorId accent_color_id) const;
|
||||
int32 get_accent_color_id_object(AccentColorId accent_color_id,
|
||||
AccentColorId fallback_accent_color_id = AccentColorId()) const;
|
||||
|
||||
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
|
||||
|
||||
|
@ -1420,14 +1420,17 @@ class WebPageBlockChatLink final : public WebPageBlock {
|
||||
DialogPhoto photo;
|
||||
string username;
|
||||
AccentColorId accent_color_id;
|
||||
ChannelId channel_id;
|
||||
|
||||
public:
|
||||
WebPageBlockChatLink() = default;
|
||||
WebPageBlockChatLink(string &&title, DialogPhoto photo, string &&username, AccentColorId accent_color_id)
|
||||
WebPageBlockChatLink(string &&title, DialogPhoto photo, string &&username, AccentColorId accent_color_id,
|
||||
ChannelId channel_id)
|
||||
: title(std::move(title))
|
||||
, photo(std::move(photo))
|
||||
, username(std::move(username))
|
||||
, accent_color_id(accent_color_id) {
|
||||
, accent_color_id(accent_color_id)
|
||||
, channel_id(channel_id) {
|
||||
}
|
||||
|
||||
Type get_type() const final {
|
||||
@ -1441,7 +1444,7 @@ class WebPageBlockChatLink final : public WebPageBlock {
|
||||
td_api::object_ptr<td_api::PageBlock> get_page_block_object(Context *context) const final {
|
||||
return make_tl_object<td_api::pageBlockChatLink>(
|
||||
title, get_chat_photo_info_object(context->td_->file_manager_.get(), &photo),
|
||||
context->td_->theme_manager_->get_accent_color_id_object(accent_color_id), username);
|
||||
context->td_->theme_manager_->get_accent_color_id_object(accent_color_id, AccentColorId(channel_id)), username);
|
||||
}
|
||||
|
||||
template <class StorerT>
|
||||
@ -1451,11 +1454,13 @@ class WebPageBlockChatLink final : public WebPageBlock {
|
||||
bool has_photo = photo.small_file_id.is_valid();
|
||||
bool has_username = !username.empty();
|
||||
bool has_accent_color_id = true;
|
||||
bool has_channel_id = channel_id.is_valid();
|
||||
BEGIN_STORE_FLAGS();
|
||||
STORE_FLAG(has_title);
|
||||
STORE_FLAG(has_photo);
|
||||
STORE_FLAG(has_username);
|
||||
STORE_FLAG(has_accent_color_id);
|
||||
STORE_FLAG(has_channel_id);
|
||||
END_STORE_FLAGS();
|
||||
if (has_title) {
|
||||
store(title, storer);
|
||||
@ -1467,6 +1472,9 @@ class WebPageBlockChatLink final : public WebPageBlock {
|
||||
store(username, storer);
|
||||
}
|
||||
store(accent_color_id, storer);
|
||||
if (has_channel_id) {
|
||||
store(channel_id, storer);
|
||||
}
|
||||
}
|
||||
|
||||
template <class ParserT>
|
||||
@ -1476,12 +1484,14 @@ class WebPageBlockChatLink final : public WebPageBlock {
|
||||
bool has_photo;
|
||||
bool has_username;
|
||||
bool has_accent_color_id = false;
|
||||
bool has_channel_id = false;
|
||||
if (parser.version() >= static_cast<int32>(Version::AddPageBlockChatLinkFlags)) {
|
||||
BEGIN_PARSE_FLAGS();
|
||||
PARSE_FLAG(has_title);
|
||||
PARSE_FLAG(has_photo);
|
||||
PARSE_FLAG(has_username);
|
||||
PARSE_FLAG(has_accent_color_id);
|
||||
PARSE_FLAG(has_channel_id);
|
||||
END_PARSE_FLAGS();
|
||||
} else {
|
||||
has_title = true;
|
||||
@ -1502,6 +1512,11 @@ class WebPageBlockChatLink final : public WebPageBlock {
|
||||
} else {
|
||||
accent_color_id = AccentColorId(5); // blue
|
||||
}
|
||||
if (has_channel_id) {
|
||||
parse(channel_id, parser);
|
||||
} else {
|
||||
channel_id = ChannelId(static_cast<int64>(5)); // blue
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -2194,7 +2209,8 @@ unique_ptr<WebPageBlock> get_web_page_block(Td *td, tl_object_ptr<telegram_api::
|
||||
return td::make_unique<WebPageBlockChatLink>(td->contacts_manager_->get_channel_title(channel_id),
|
||||
*td->contacts_manager_->get_channel_dialog_photo(channel_id),
|
||||
td->contacts_manager_->get_channel_first_username(channel_id),
|
||||
td->contacts_manager_->get_channel_accent_color_id(channel_id));
|
||||
td->contacts_manager_->get_channel_accent_color_id(channel_id),
|
||||
channel_id);
|
||||
} else {
|
||||
bool has_access_hash = (channel->flags_ & telegram_api::channel::ACCESS_HASH_MASK) != 0;
|
||||
bool has_color = (channel->flags2_ & telegram_api::channel::COLOR_MASK) != 0;
|
||||
@ -2202,7 +2218,8 @@ unique_ptr<WebPageBlock> get_web_page_block(Td *td, tl_object_ptr<telegram_api::
|
||||
std::move(channel->title_),
|
||||
get_dialog_photo(td->file_manager_.get(), DialogId(channel_id),
|
||||
has_access_hash ? channel->access_hash_ : 0, std::move(channel->photo_)),
|
||||
std::move(channel->username_), has_color ? AccentColorId(channel->color_) : AccentColorId(channel_id));
|
||||
std::move(channel->username_), has_color ? AccentColorId(channel->color_) : AccentColorId(channel_id),
|
||||
channel_id);
|
||||
}
|
||||
} else {
|
||||
LOG(ERROR) << "Receive wrong channel " << to_string(page_block->channel_);
|
||||
|
Loading…
Reference in New Issue
Block a user