Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make custom text replaces work without replace emoji being enabled #242

Merged
merged 2 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions Telegram/SourceFiles/boxes/add_contact_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,7 @@ void GroupInfoBox::prepare() {
: tr::lng_dlg_new_group_name)(),
_initialTitle);
_title->setMaxLength(Ui::EditPeer::kMaxGroupChannelTitle);
_title->setInstantReplaces(Ui::InstantReplaces::Default());
_title->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
_title->setInstantReplaces(Core::App().settings().instantReplacesValue());
Ui::Emoji::SuggestionsController::Init(
getDelegate()->outerContainer(),
_title,
Expand All @@ -519,9 +517,7 @@ void GroupInfoBox::prepare() {
tr::lng_create_group_description());
_description->show();
_description->setMaxLength(Ui::EditPeer::kMaxChannelDescription);
_description->setInstantReplaces(Ui::InstantReplaces::Default());
_description->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
_description->setInstantReplaces(Core::App().settings().instantReplacesValue());
_description->setSubmitSettings(
Core::App().settings().sendSubmitWay());

Expand Down
8 changes: 2 additions & 6 deletions Telegram/SourceFiles/boxes/create_poll_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,7 @@ void InitField(
not_null<QWidget*> container,
not_null<Ui::InputField*> field,
not_null<Main::Session*> session) {
field->setInstantReplaces(Ui::InstantReplaces::Default());
field->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
field->setInstantReplaces(Core::App().settings().instantReplacesValue());
auto options = Ui::Emoji::SuggestionsController::Options();
options.suggestExactFirstWord = false;
Ui::Emoji::SuggestionsController::Init(
Expand Down Expand Up @@ -842,9 +840,7 @@ not_null<Ui::InputField*> CreatePollBox::setupSolution(
st::createPollFieldPadding);
InitField(getDelegate()->outerContainer(), solution, session);
solution->setMaxLength(kSolutionLimit + kErrorLimit);
solution->setInstantReplaces(Ui::InstantReplaces::Default());
solution->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
solution->setInstantReplaces(Core::App().settings().instantReplacesValue());
solution->setMarkdownReplacesEnabled(rpl::single(true));
solution->setEditLinkCallback(
DefaultEditLinkCallback(_controller, solution));
Expand Down
4 changes: 1 addition & 3 deletions Telegram/SourceFiles/boxes/edit_caption_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,7 @@ void EditCaptionBox::setupField() {
_controller->session().serverConfig().captionLengthMax);
_field->setSubmitSettings(
Core::App().settings().sendSubmitWay());
_field->setInstantReplaces(Ui::InstantReplaces::Default());
_field->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
_field->setInstantReplaces(Core::App().settings().instantReplacesValue());
_field->setMarkdownReplacesEnabled(rpl::single(true));
_field->setEditLinkCallback(
DefaultEditLinkCallback(_controller, _field));
Expand Down
4 changes: 1 addition & 3 deletions Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,9 +627,7 @@ void EditFilterBox(
if (!isLocal) {
name->setMaxLength(kMaxFilterTitleLength);
}
name->setInstantReplaces(Ui::InstantReplaces::Default());
name->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
name->setInstantReplaces(Core::App().settings().instantReplacesValue());
Ui::Emoji::SuggestionsController::Init(
box->getDelegate()->outerContainer(),
name,
Expand Down
8 changes: 2 additions & 6 deletions Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,7 @@ object_ptr<Ui::RpWidget> Controller::createTitleEdit() {
_peer->name),
st::editPeerTitleMargins);
result->entity()->setMaxLength(Ui::EditPeer::kMaxGroupChannelTitle);
result->entity()->setInstantReplaces(Ui::InstantReplaces::Default());
result->entity()->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
result->entity()->setInstantReplaces(Core::App().settings().instantReplacesValue());
Ui::Emoji::SuggestionsController::Init(
_wrap->window(),
result->entity(),
Expand Down Expand Up @@ -515,9 +513,7 @@ object_ptr<Ui::RpWidget> Controller::createDescriptionEdit() {
_peer->about()),
st::editPeerDescriptionMargins);
result->entity()->setMaxLength(Ui::EditPeer::kMaxChannelDescription);
result->entity()->setInstantReplaces(Ui::InstantReplaces::Default());
result->entity()->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
result->entity()->setInstantReplaces(Core::App().settings().instantReplacesValue());
result->entity()->setSubmitSettings(Core::App().settings().sendSubmitWay());
Ui::Emoji::SuggestionsController::Init(
_wrap->window(),
Expand Down
4 changes: 1 addition & 3 deletions Telegram/SourceFiles/boxes/send_files_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,9 +706,7 @@ void SendFilesBox::setupCaption() {
}
Unexpected("action in MimeData hook.");
});
_caption->setInstantReplaces(Ui::InstantReplaces::Default());
_caption->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
_caption->setInstantReplaces(Core::App().settings().instantReplacesValue());
_caption->setMarkdownReplacesEnabled(rpl::single(true));
_caption->setEditLinkCallback(
DefaultEditLinkCallback(_controller, _caption));
Expand Down
4 changes: 1 addition & 3 deletions Telegram/SourceFiles/boxes/share_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,7 @@ void ShareBox::prepareCommentField() {
submit({});
});

field->setInstantReplaces(Ui::InstantReplaces::Default());
field->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
field->setInstantReplaces(Core::App().settings().instantReplacesValue());
field->setMarkdownReplacesEnabled(rpl::single(true));
if (_descriptor.initEditLink) {
_descriptor.initEditLink(field);
Expand Down
8 changes: 2 additions & 6 deletions Telegram/SourceFiles/chat_helpers/message_field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ void EditLinkBox::prepare() {
tr::lng_formatting_link_text(),
_startText),
st::markdownLinkFieldPadding);
text->setInstantReplaces(Ui::InstantReplaces::Default());
text->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
text->setInstantReplaces(Core::App().settings().instantReplacesValue());
Ui::Emoji::SuggestionsController::Init(
getDelegate()->outerContainer(),
text,
Expand Down Expand Up @@ -306,9 +304,7 @@ void InitMessageField(
field->setAdditionalMargin(style::ConvertScale(4) - 4);

field->customTab(true);
field->setInstantReplaces(Ui::InstantReplaces::Default());
field->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
field->setInstantReplaces(Core::App().settings().instantReplacesValue());
field->setMarkdownReplacesEnabled(rpl::single(true));
field->setEditLinkCallback(DefaultEditLinkCallback(controller, field));
}
Expand Down
34 changes: 34 additions & 0 deletions Telegram/SourceFiles/core/core_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ For license and copyright information please follow this link:
#include "base/platform/base_platform_info.h"
#include "core/core_settings_proxy.h"
#include "window/themes/window_themes_embedded.h"
#include "ui/widgets/input_fields.h"
#include "ui/chat/attach/attach_send_files_way.h"
#include "platform/platform_notifications_manager.h"
#include "base/flags.h"
Expand Down Expand Up @@ -357,6 +358,9 @@ class Settings final {
}
void setReplaceEmoji(bool value) {
_replaceEmoji = value;
setInstantReplaces(value
? Ui::InstantReplaces::Default()
: Ui::InstantReplaces::Custom());
}
[[nodiscard]] bool replaceEmoji() const {
return _replaceEmoji.current();
Expand All @@ -367,6 +371,34 @@ class Settings final {
[[nodiscard]] rpl::producer<bool> replaceEmojiChanges() const {
return _replaceEmoji.changes();
}
void setInstantReplaces(Ui::InstantReplaces replaces) {
_instantReplaces = replaces;
_instantReplacesSet = true;
}
[[nodiscard]] Ui::InstantReplaces instantReplaces() {
if (!_instantReplacesSet) {
setInstantReplaces(replaceEmoji()
? Ui::InstantReplaces::Default()
: Ui::InstantReplaces::Custom());
}
return _instantReplaces.current();
}
[[nodiscard]] rpl::producer<Ui::InstantReplaces> instantReplacesValue() {
if (!_instantReplacesSet) {
setInstantReplaces(replaceEmoji()
? Ui::InstantReplaces::Default()
: Ui::InstantReplaces::Custom());
}
return _instantReplaces.value();
}
[[nodiscard]] rpl::producer<Ui::InstantReplaces> instantReplacesChanges() {
if (!_instantReplacesSet) {
setInstantReplaces(replaceEmoji()
? Ui::InstantReplaces::Default()
: Ui::InstantReplaces::Custom());
}
return _instantReplaces.changes();
}
[[nodiscard]] bool suggestEmoji() const {
return _suggestEmoji;
}
Expand Down Expand Up @@ -727,6 +759,8 @@ class Settings final {
bool _loopAnimatedStickers = true;
rpl::variable<bool> _largeEmoji = true;
rpl::variable<bool> _replaceEmoji = true;
rpl::variable<Ui::InstantReplaces> _instantReplaces;
bool _instantReplacesSet = false;
bool _suggestEmoji = true;
bool _suggestStickersByEmoji = true;
rpl::variable<bool> _spellcheckerEnabled = true;
Expand Down
4 changes: 1 addition & 3 deletions Telegram/SourceFiles/settings/settings_information.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,7 @@ void SetupBio(
save();
});
QObject::connect(bio, &Ui::InputField::changed, updated);
bio->setInstantReplaces(Ui::InstantReplaces::Default());
bio->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
bio->setInstantReplaces(Core::App().settings().instantReplacesValue());
Ui::Emoji::SuggestionsController::Init(
container->window(),
bio,
Expand Down
4 changes: 1 addition & 3 deletions Telegram/SourceFiles/support/support_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ EditInfoBox::EditInfoBox(
_field->setMaxLength(kMaxSupportInfoLength);
_field->setSubmitSettings(
Core::App().settings().sendSubmitWay());
_field->setInstantReplaces(Ui::InstantReplaces::Default());
_field->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
_field->setInstantReplaces(Core::App().settings().instantReplacesValue());
_field->setMarkdownReplacesEnabled(rpl::single(true));
_field->setEditLinkCallback(DefaultEditLinkCallback(controller, _field));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -949,9 +949,7 @@ void Notification::showReplyField() {
_replyArea->setFocus();
_replyArea->setMaxLength(MaxMessageSize);
_replyArea->setSubmitSettings(Ui::InputField::SubmitSettings::Both);
_replyArea->setInstantReplaces(Ui::InstantReplaces::Default());
_replyArea->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
_replyArea->setInstantReplaces(Core::App().settings().instantReplacesValue());
_replyArea->setMarkdownReplacesEnabled(rpl::single(true));

// Catch mouse press event to activate the window.
Expand Down