From 27d84befa8651bd8e60aad1c4e1d6b3433407676 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 28 Jul 2019 15:39:06 +0200 Subject: [PATCH] Remove emoji from custom admin ranks. --- .../boxes/peers/edit_participant_box.cpp | 15 +++++++++------ .../SourceFiles/history/history_message.cpp | 2 +- Telegram/SourceFiles/ui/text/text_entity.cpp | 17 +++++++++++++++++ Telegram/SourceFiles/ui/text/text_entity.h | 1 + .../SourceFiles/ui/widgets/input_fields.cpp | 14 ++++++++++++++ Telegram/SourceFiles/ui/widgets/input_fields.h | 1 + 6 files changed, 43 insertions(+), 7 deletions(-) diff --git a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp index 3809c0d73..7184fb310 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp @@ -427,14 +427,17 @@ not_null EditAdminBox::addRankInput() { this, st::customBadgeField, (isOwner ? tr::lng_owner_badge : tr::lng_admin_badge)(), - _oldRank), + TextUtilities::RemoveEmoji(_oldRank)), st::rightsAboutMargin); result->setMaxLength(kAdminRoleLimit); - result->setInstantReplaces(Ui::InstantReplaces::Default()); - result->setInstantReplacesEnabled(Global::ReplaceEmojiValue()); - Ui::Emoji::SuggestionsController::Init( - getDelegate()->outerContainer(), - result); + result->setInstantReplaces(Ui::InstantReplaces::TextOnly()); + connect(result, &Ui::InputField::changed, [=] { + const auto text = result->getLastText(); + const auto removed = TextUtilities::RemoveEmoji(text); + if (removed != text) { + result->setText(removed); + } + }); addControl( object_ptr( diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index dcee0afc6..8be10b8cf 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -674,7 +674,7 @@ void HistoryMessage::refreshMessageBadge() { } else { _messageBadge.setText( st::defaultTextStyle, - TextUtilities::SingleLine(text)); + TextUtilities::RemoveEmoji(TextUtilities::SingleLine(text))); } } diff --git a/Telegram/SourceFiles/ui/text/text_entity.cpp b/Telegram/SourceFiles/ui/text/text_entity.cpp index 2cb1b3c76..7100889b2 100644 --- a/Telegram/SourceFiles/ui/text/text_entity.cpp +++ b/Telegram/SourceFiles/ui/text/text_entity.cpp @@ -1302,6 +1302,23 @@ QString RemoveAccents(const QString &text) { return (i < result.size()) ? result.mid(0, i) : result; } +QString RemoveEmoji(const QString &text) { + auto result = QString(); + result.reserve(text.size()); + + auto begin = text.data(); + const auto end = begin + text.size(); + while (begin != end) { + auto length = 0; + if (Ui::Emoji::Find(begin, end, &length)) { + begin += length; + } else { + result.append(*begin++); + } + } + return result; +} + QStringList PrepareSearchWords(const QString &query, const QRegularExpression *SplitterOverride) { auto clean = RemoveAccents(query.trimmed().toLower()); auto result = QStringList(); diff --git a/Telegram/SourceFiles/ui/text/text_entity.h b/Telegram/SourceFiles/ui/text/text_entity.h index d227204a4..56ebcb9c0 100644 --- a/Telegram/SourceFiles/ui/text/text_entity.h +++ b/Telegram/SourceFiles/ui/text/text_entity.h @@ -281,6 +281,7 @@ QString Clean(const QString &text); QString EscapeForRichParsing(const QString &text); QString SingleLine(const QString &text); QString RemoveAccents(const QString &text); +QString RemoveEmoji(const QString &text); QStringList PrepareSearchWords(const QString &query, const QRegularExpression *SplitterOverride = nullptr); bool CutPart(TextWithEntities &sending, TextWithEntities &left, int limit); diff --git a/Telegram/SourceFiles/ui/widgets/input_fields.cpp b/Telegram/SourceFiles/ui/widgets/input_fields.cpp index 5fc342e3c..9b12b33f8 100644 --- a/Telegram/SourceFiles/ui/widgets/input_fields.cpp +++ b/Telegram/SourceFiles/ui/widgets/input_fields.cpp @@ -936,6 +936,20 @@ const InstantReplaces &InstantReplaces::Default() { return result; } +const InstantReplaces &InstantReplaces::TextOnly() { + static const auto result = [] { + auto result = InstantReplaces(); + result.add("--", QString(1, QChar(8212))); + result.add("<<", QString(1, QChar(171))); + result.add(">>", QString(1, QChar(187))); + result.add( + ":shrug:", + QChar(175) + QString("\\_(") + QChar(12484) + ")_/" + QChar(175)); + return result; + }(); + return result; +} + FlatInput::FlatInput( QWidget *parent, const style::FlatInput &st, diff --git a/Telegram/SourceFiles/ui/widgets/input_fields.h b/Telegram/SourceFiles/ui/widgets/input_fields.h index 850d7fd4e..9d33a2c5d 100644 --- a/Telegram/SourceFiles/ui/widgets/input_fields.h +++ b/Telegram/SourceFiles/ui/widgets/input_fields.h @@ -28,6 +28,7 @@ struct InstantReplaces { void add(const QString &what, const QString &with); static const InstantReplaces &Default(); + static const InstantReplaces &TextOnly(); int maxLength = 0; Node reverseMap;