From e0991d93767954cc3897603b8df412a1a0c31699 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 25 Oct 2025 16:51:08 +0300 Subject: [PATCH] Added simple emoji pattern selector for profile to edit peer color box. --- Telegram/Resources/langs/lang.strings | 2 + .../boxes/peers/edit_peer_color_box.cpp | 67 ++++++++++++++++--- 2 files changed, 59 insertions(+), 10 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 281ae4d846..2b3fab37da 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -996,6 +996,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_settings_color_changed" = "Your name color has been updated!"; "lng_settings_color_changed_channel" = "Your channel color has been updated!"; "lng_settings_color_apply" = "Apply Style"; +"lng_settings_color_profile_emoji" = "Add icons to Profile"; +"lng_settings_color_profile_emoji_channel" = "Profile Logo"; "lng_suggest_hide_new_title" = "Hide new chats?"; "lng_suggest_hide_new_about" = "You are receiving lots of new chats from users who are not in your Contact List.\n\nDo you want to have such chats **automatically muted** and **archived**?"; diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_color_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_color_box.cpp index 8c36d8b174..e0a34e1214 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_color_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_color_box.cpp @@ -591,13 +591,18 @@ void Apply( not_null peer, rpl::producer colorIndexValue, rpl::producer emojiIdValue, - Fn emojiIdChosen) { + Fn emojiIdChosen, + bool profileIndices) { const auto button = ButtonStyleWithRightEmoji( parent, tr::lng_settings_color_emoji_off(tr::now)); auto result = Settings::CreateButtonWithIcon( parent, - tr::lng_settings_color_emoji(), + !profileIndices + ? tr::lng_settings_color_emoji() + : peer->isChannel() + ? tr::lng_settings_color_profile_emoji_channel() + : tr::lng_settings_color_profile_emoji(), *button.st, { &st::menuBlueIconColorNames }); const auto raw = result.data(); @@ -657,9 +662,15 @@ void Apply( auto p = QPainter(right); const auto height = right->height(); if (state->emoji && state->index != kUnsetColorIndex) { - const auto colors = style->coloredValues(false, state->index); + const auto profileSet = profileIndices + ? peer->session().api().peerColors().colorProfileFor( + state->index) + : std::nullopt; + const auto textColor = profileSet && !profileSet->palette.empty() + ? profileSet->palette.front() + : style->coloredValues(false, state->index).name; state->emoji->paint(p, { - .textColor = colors.name, + .textColor = textColor, .position = QPoint(added, (height - button.emojiWidth) / 2), .internal = { .forceFirstFrame = true, @@ -677,6 +688,17 @@ void Apply( raw->setClickedCallback([=] { const auto customTextColor = [=] { + if (state->index == kUnsetColorIndex) { + return style->windowActiveTextFg()->c; + } + if (profileIndices) { + const auto colorSet + = peer->session().api().peerColors().colorProfileFor( + state->index); + if (colorSet && !colorSet->palette.empty()) { + return colorSet->palette.front(); + } + } return style->coloredValues(false, state->index).name; }; const auto controller = show->resolveWindow(); @@ -692,8 +714,11 @@ void Apply( }); if (const auto channel = peer->asChannel()) { + const auto limits = Data::LevelLimits(&channel->session()); AddLevelBadge( - Data::LevelLimits(&channel->session()).channelBgIconLevelMin(), + profileIndices + ? limits.channelProfileBgIconLevelMin() + : limits.channelBgIconLevelMin(), raw, right, channel, @@ -1392,7 +1417,8 @@ void EditPeerColorSection( peer, state->index.value(), state->emojiId.value(), - [=](DocumentId id) { state->emojiId = id; })); + [=](DocumentId id) { state->emojiId = id; }, + false)); Ui::AddSkip(iconInner, st::settingsColorSampleSkip); Ui::AddDividerText( @@ -1734,10 +1760,19 @@ void EditPeerProfileColorSection( struct State { rpl::variable index = kUnsetColorIndex; + rpl::variable patternEmojiId; Ui::ColorSelector *selector = nullptr; }; const auto state = button->lifetime().make_state(); - state->index = peer->colorProfileIndex().value_or(kUnsetColorIndex); + state->patternEmojiId = peer->profileBackgroundEmojiId(); + + const auto setIndex = [=](uint8 index) { + state->index = index; + preview->setColorProfileIndex(index == kUnsetColorIndex + ? std::nullopt + : std::make_optional(index)); + }; + setIndex(peer->colorProfileIndex().value_or(kUnsetColorIndex)); const auto margin = st::settingsColorRadioMargin; const auto skip = st::settingsColorRadioSkip; @@ -1746,15 +1781,27 @@ void EditPeerProfileColorSection( box, indices, state->index.current(), - [=](uint8 index) { - state->index = index; - }, + setIndex, [=](uint8 index) { return peerColors->colorProfileFor(index).value_or( Data::ColorProfileSet{}); }), { margin, skip, margin, skip }); + Ui::AddSkip(container, st::settingsColorSampleSkip); + container->add(CreateEmojiIconButton( + container, + show, + style, + peer, + state->index.value(), + state->patternEmojiId.value(), + [=](DocumentId id) { + state->patternEmojiId = id; + preview->setPatternEmojiId(id); + }, + true)); + state->index.value( ) | rpl::start_with_next([=](uint8 index) { if (state->selector) {