Skip to content

Commit b4272c3

Browse files
committed
Get rid of registerImageEmoji/registerInternalEmoji.
1 parent b876605 commit b4272c3

File tree

56 files changed

+402
-720
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+402
-720
lines changed

Telegram/SourceFiles/boxes/boxes.style

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,8 +1116,16 @@ moderateBoxExpandInnerSkip: 2px;
11161116
moderateBoxExpandFont: font(11px);
11171117
moderateBoxExpandToggleSize: 4px;
11181118
moderateBoxExpandToggleFourStrokes: 3px;
1119-
moderateBoxExpandIcon: icon{{ "info/edit/expand_arrow_small-flip_vertical", windowActiveTextFg }};
1120-
moderateBoxExpandIconDown: icon{{ "info/edit/expand_arrow_small", windowActiveTextFg }};
1119+
moderateBoxExpandIcon: IconEmoji{
1120+
icon: icon{{ "info/edit/expand_arrow_small-flip_vertical", windowActiveTextFg }};
1121+
padding: margins(-2px, -1px, 0px, 0px);
1122+
useIconColor: true;
1123+
}
1124+
moderateBoxExpandIconDown: IconEmoji{
1125+
icon: icon{{ "info/edit/expand_arrow_small", windowActiveTextFg }};
1126+
padding: margins(-2px, -1px, 0px, 0px);
1127+
useIconColor: true;
1128+
}
11211129
moderateBoxDividerLabel: FlatLabel(boxDividerLabel) {
11221130
palette: TextPalette(defaultTextPalette) {
11231131
selectLinkFg: windowActiveTextFg;

Telegram/SourceFiles/boxes/moderate_messages_box.cpp

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -403,22 +403,10 @@ void CreateModerateMessagesBox(
403403
const auto container = wrap->entity();
404404
wrap->toggle(false, anim::type::instant);
405405

406-
const auto session = &participants.front()->session();
407-
const auto emojiMargin = QMargins(
408-
-st::moderateBoxExpandInnerSkip,
409-
-st::moderateBoxExpandInnerSkip / 2,
410-
0,
411-
0);
412-
const auto emojiUp = Ui::Text::SingleCustomEmoji(
413-
session->data().customEmojiManager().registerInternalEmoji(
414-
st::moderateBoxExpandIcon,
415-
emojiMargin,
416-
false));
417-
const auto emojiDown = Ui::Text::SingleCustomEmoji(
418-
session->data().customEmojiManager().registerInternalEmoji(
419-
st::moderateBoxExpandIconDown,
420-
emojiMargin,
421-
false));
406+
const auto emojiUp = Ui::Text::IconEmoji(
407+
&st::moderateBoxExpandIcon);
408+
const auto emojiDown = Ui::Text::IconEmoji(
409+
&st::moderateBoxExpandIconDown);
422410

423411
auto label = object_ptr<Ui::FlatLabel>(
424412
inner,
@@ -463,9 +451,7 @@ void CreateModerateMessagesBox(
463451
Ui::Text::WithEntities);
464452
}) | rpl::flatten_latest(
465453
) | rpl::start_with_next([=](const TextWithEntities &text) {
466-
raw->setMarkedText(
467-
Ui::Text::Link(text, u"internal:"_q),
468-
Core::TextContext({ .session = session }));
454+
raw->setMarkedText(Ui::Text::Link(text, u"internal:"_q));
469455
}, label->lifetime());
470456

471457
Ui::AddSkip(inner);

Telegram/SourceFiles/boxes/peers/edit_peer_color_box.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ For license and copyright information please follow this link:
1515
#include "boxes/background_box.h"
1616
#include "boxes/stickers_box.h"
1717
#include "chat_helpers/compose/compose_show.h"
18-
#include "core/ui_integration.h" // TextContext
1918
#include "data/stickers/data_custom_emoji.h"
2019
#include "data/stickers/data_stickers.h"
2120
#include "data/data_changes.h"
@@ -164,7 +163,6 @@ class LevelBadge final : public Ui::RpWidget {
164163
void updateText();
165164

166165
const uint32 _level;
167-
const TextWithEntities _icon;
168166
const Ui::Text::MarkedContext _context;
169167
Ui::Text::String _text;
170168
bool _minimal = false;
@@ -460,22 +458,12 @@ LevelBadge::LevelBadge(
460458
uint32 level,
461459
not_null<Main::Session*> session)
462460
: Ui::RpWidget(parent)
463-
, _level(level)
464-
, _icon(Ui::Text::SingleCustomEmoji(
465-
session->data().customEmojiManager().registerInternalEmoji(
466-
st::settingsLevelBadgeLock,
467-
QMargins(0, st::settingsLevelBadgeLockSkip, 0, 0),
468-
false)))
469-
, _context(Core::TextContext({
470-
.session = session,
471-
.repaint = [this] { update(); },
472-
})) {
461+
, _level(level) {
473462
updateText();
474463
}
475464

476465
void LevelBadge::updateText() {
477-
auto text = _icon;
478-
text.append(' ');
466+
auto text = Ui::Text::IconEmoji(&st::settingsLevelBadgeLock).append(' ');
479467
if (!_minimal) {
480468
text.append(tr::lng_boost_level(
481469
tr::now,
@@ -490,7 +478,7 @@ void LevelBadge::updateText() {
490478
st,
491479
text,
492480
kMarkupTextOptions,
493-
_context);
481+
Ui::Text::MarkedContext{ .repaint = [=] { update(); } });
494482
const auto &padding = st::settingsColorSamplePadding;
495483
QWidget::resize(
496484
_text.maxWidth() + rect::m::sum::h(padding),

Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ For license and copyright information please follow this link:
2929
#include "history/history.h"
3030
#include "history/history_item_helpers.h" // GetErrorForSending.
3131
#include "history/view/history_view_group_call_bar.h" // GenerateUserpics...
32+
#include "info/channel_statistics/earn/earn_icons.h"
3233
#include "lang/lang_keys.h"
3334
#include "main/main_session.h"
3435
#include "qr/qr_generate.h"
@@ -42,6 +43,7 @@ For license and copyright information please follow this link:
4243
#include "ui/controls/userpic_button.h"
4344
#include "ui/painter.h"
4445
#include "ui/rect.h"
46+
#include "ui/text/custom_emoji_helper.h"
4547
#include "ui/text/format_values.h"
4648
#include "ui/text/text_utilities.h"
4749
#include "ui/toast/toast.h"
@@ -247,6 +249,9 @@ class Controller final
247249
const Role _role = Role::Joined;
248250
rpl::variable<LinkData> _data;
249251

252+
Ui::Text::CustomEmojiHelper _emojiHelper;
253+
TextWithEntities _creditsEmoji;
254+
250255
base::unique_qptr<Ui::PopupMenu> _menu;
251256
rpl::event_stream<Processed> _processed;
252257

@@ -408,6 +413,8 @@ Controller::Controller(
408413
const auto current = _data.current();
409414
_link = current.link;
410415
_revoked = current.revoked;
416+
_creditsEmoji = _emojiHelper.paletteDependent(
417+
Ui::Earn::IconCreditsEmoji());
411418
}
412419

413420
rpl::producer<LinkData> Controller::dataValue() const {
@@ -725,7 +732,7 @@ void Controller::setupAboveJoinedWidget() {
725732
? tr::lng_group_invite_subscription_info_title(
726733
tr::now,
727734
lt_emoji,
728-
session().data().customEmojiManager().creditsEmoji(),
735+
_creditsEmoji,
729736
lt_price,
730737
{ QString::number(current.subscription.credits) },
731738
lt_multiplier,
@@ -736,15 +743,12 @@ void Controller::setupAboveJoinedWidget() {
736743
: tr::lng_group_invite_subscription_info_title_none(
737744
tr::now,
738745
lt_emoji,
739-
session().data().customEmojiManager().creditsEmoji(),
746+
_creditsEmoji,
740747
lt_price,
741748
{ QString::number(current.subscription.credits) },
742749
Ui::Text::WithEntities),
743750
kMarkupTextOptions,
744-
Core::TextContext({
745-
.session = &session(),
746-
.repaint = [=] { widget->update(); },
747-
}));
751+
_emojiHelper.context([=] { widget->update(); }));
748752
auto &lifetime = widget->lifetime();
749753
const auto rateValue = lifetime.make_state<rpl::variable<float64>>(
750754
session().credits().rateValue(_peer));
@@ -991,11 +995,11 @@ void Controller::rowClicked(not_null<PeerListRow*> row) {
991995
tr::lng_credits_subscription_subtitle(
992996
tr::now,
993997
lt_emoji,
994-
session->data().customEmojiManager().creditsEmoji(),
998+
_creditsEmoji,
995999
lt_cost,
9961000
{ QString::number(data.subscription.credits) },
9971001
Ui::Text::WithEntities),
998-
Core::TextContext({ .session = session }));
1002+
_emojiHelper.context());
9991003
const auto subtitle2 = box->addRow(
10001004
object_ptr<Ui::CenterWrap<Ui::FlatLabel>>(
10011005
box,

Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -886,32 +886,18 @@ rpl::producer<int> AddSlowmodeSlider(
886886
return secondsCount->value();
887887
}
888888

889-
void AddBoostsUnrestrictLabels(
890-
not_null<Ui::VerticalLayout*> container,
891-
not_null<Main::Session*> session) {
889+
void AddBoostsUnrestrictLabels(not_null<Ui::VerticalLayout*> container) {
892890
const auto labels = container->add(
893891
object_ptr<Ui::FixedHeightWidget>(container, st::normalFont->height),
894892
st::slowmodeLabelsMargin);
895-
const auto manager = &session->data().customEmojiManager();
896-
const auto one = Ui::Text::SingleCustomEmoji(
897-
manager->registerInternalEmoji(
898-
st::boostMessageIcon,
899-
st::boostMessageIconPadding));
900-
const auto many = Ui::Text::SingleCustomEmoji(
901-
manager->registerInternalEmoji(
902-
st::boostsMessageIcon,
903-
st::boostsMessageIconPadding));
904-
const auto context = Core::TextContext({
905-
.session = session,
906-
.customEmojiLoopLimit = 1,
907-
});
893+
const auto one = Ui::Text::IconEmoji(&st::boostMessageIcon);
894+
const auto many = Ui::Text::IconEmoji(&st::boostsMessageIcon);
908895
for (auto i = 0; i != kBoostsUnrestrictValues; ++i) {
909896
const auto label = Ui::CreateChild<Ui::FlatLabel>(
910897
labels,
911898
st::boostsUnrestrictLabel);
912899
label->setMarkedText(
913-
TextWithEntities(i ? many : one).append(QString::number(i + 1)),
914-
context);
900+
TextWithEntities(i ? many : one).append(QString::number(i + 1)));
915901
rpl::combine(
916902
labels->widthValue(),
917903
label->widthValue()
@@ -977,7 +963,7 @@ rpl::producer<int> AddBoostsUnrestrictSlider(
977963

978964
const auto inner = outer->entity();
979965

980-
AddBoostsUnrestrictLabels(inner, &peer->session());
966+
AddBoostsUnrestrictLabels(inner);
981967

982968
const auto slider = inner->add(
983969
object_ptr<Ui::MediaSlider>(inner, st::localStorageLimitSlider),

Telegram/SourceFiles/boxes/send_credits_box.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ void SendCreditsBox(
455455
lt_count,
456456
rpl::single(form->invoice.amount) | tr::to_count(),
457457
lt_emoji,
458-
rpl::single(CreditsEmojiSmall(session)),
458+
rpl::single(CreditsEmojiSmall()),
459459
Ui::Text::RichLangValue),
460460
state->confirmButtonBusy.value()
461461
) | rpl::map([](TextWithEntities &&text, bool busy) {
@@ -502,16 +502,13 @@ void SendCreditsBox(
502502
}
503503
}
504504

505-
TextWithEntities CreditsEmoji(not_null<Main::Session*> session) {
506-
return Ui::Text::SingleCustomEmoji(
507-
session->data().customEmojiManager().registerInternalEmoji(
508-
st::settingsPremiumIconStar,
509-
QMargins{ 0, -st::moderateBoxExpandInnerSkip, 0, 0 },
510-
true),
505+
TextWithEntities CreditsEmoji() {
506+
return Ui::Text::IconEmoji(
507+
&st::starIconEmojiLarge,
511508
QString(QChar(0x2B50)));
512509
}
513510

514-
TextWithEntities CreditsEmojiSmall(not_null<Main::Session*> session) {
511+
TextWithEntities CreditsEmojiSmall() {
515512
return Ui::Text::IconEmoji(
516513
&st::starIconEmoji,
517514
QString(QChar(0x2B50)));

Telegram/SourceFiles/boxes/send_credits_box.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ void SendCreditsBox(
3232
std::shared_ptr<Payments::CreditsFormData> data,
3333
Fn<void()> sent);
3434

35-
[[nodiscard]] TextWithEntities CreditsEmoji(
36-
not_null<Main::Session*> session);
35+
[[nodiscard]] TextWithEntities CreditsEmoji();
3736

38-
[[nodiscard]] TextWithEntities CreditsEmojiSmall(
39-
not_null<Main::Session*> session);
37+
[[nodiscard]] TextWithEntities CreditsEmojiSmall();
4038

4139
not_null<FlatLabel*> SetButtonMarkedLabel(
4240
not_null<RpWidget*> button,

Telegram/SourceFiles/boxes/send_files_box.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -843,9 +843,8 @@ void SendFilesBox::refreshPriceTag() {
843843
QPainter(raw).drawImage(0, 0, _priceTagBg);
844844
}, raw->lifetime());
845845

846-
const auto session = &_show->session();
847846
auto price = _price.value() | rpl::map([=](uint64 amount) {
848-
auto result = Ui::Text::Colorized(Ui::CreditsEmoji(session));
847+
auto result = Ui::Text::Colorized(Ui::CreditsEmoji());
849848
result.append(Lang::FormatCountDecimal(amount));
850849
return result;
851850
});
@@ -857,10 +856,10 @@ void SendFilesBox::refreshPriceTag() {
857856
raw,
858857
QString(),
859858
st::paidTagLabel);
860-
std::move(text) | rpl::start_with_next([=](TextWithEntities &&text) {
861-
label->setMarkedText(text, Core::TextContext({
862-
.session = session,
863-
}));
859+
std::move(
860+
text
861+
) | rpl::start_with_next([=](const TextWithEntities &text) {
862+
label->setMarkedText(text);
864863
}, label->lifetime());
865864
label->show();
866865
label->sizeValue() | rpl::start_with_next([=](QSize size) {

0 commit comments

Comments
 (0)