From fc74840b55f16620c4a24da52e94db69fc0fb605 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 19 Sep 2025 14:29:33 +0400 Subject: [PATCH] Apply tags filtering and length limit. --- .../calls/group/calls_group_message_field.cpp | 45 ++++++++++++++++--- .../calls/group/calls_group_message_field.h | 1 + .../calls/group/calls_group_messages.cpp | 14 +++++- 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/Telegram/SourceFiles/calls/group/calls_group_message_field.cpp b/Telegram/SourceFiles/calls/group/calls_group_message_field.cpp index c9267e300a..f946c1ec4f 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_message_field.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_message_field.cpp @@ -34,6 +34,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_media_view.h" namespace Calls::Group { +namespace { + +constexpr auto kWarnLimit = 24; +constexpr auto kErrorLimit = 99; + +} // namespace MessageField::MessageField( not_null parent, @@ -41,7 +47,8 @@ MessageField::MessageField( PeerData *peer) : _parent(parent) , _show(std::move(show)) -, _wrap(std::make_unique(_parent)) { +, _wrap(std::make_unique(_parent)) +, _limit(128) { createControls(peer); } @@ -54,6 +61,7 @@ void MessageField::createControls(PeerData *peer) { st.field, Ui::InputField::Mode::MultiLine, tr::lng_message_ph()); + _field->setMaxLength(_limit + kErrorLimit); _field->setMinHeight( st::historySendSize.height() - 2 * st::historySendPadding); _field->setMaxHeight(st::historyComposeFieldMaxHeight); @@ -75,6 +83,13 @@ void MessageField::createControls(PeerData *peer) { }, .allowPremiumEmoji = allow, .fieldStyle = &st.files.caption, + .allowMarkdownTags = { + Ui::InputField::kTagBold, + Ui::InputField::kTagItalic, + Ui::InputField::kTagUnderline, + Ui::InputField::kTagStrikeOut, + Ui::InputField::kTagSpoiler, + }, }); Ui::Emoji::SuggestionsController::Init( _parent, @@ -152,12 +167,20 @@ void MessageField::createControls(PeerData *peer) { st::historySendPadding, st::historySendPadding, newWidth); - _send->moveToRight(0, 0, newWidth); - _emojiToggle->moveToRight(_send->width(), 0, newWidth); updateWrapSize(newWidth); }, _lifetime); - _field->heightValue() | rpl::start_with_next([=](int height) { + rpl::combine( + _width.value(), + _field->heightValue() + ) | rpl::start_with_next([=](int width, int height) { + if (width <= 0) { + return; + } + const auto minHeight = st::historySendSize.height() + - 2 * st::historySendPadding; + _send->moveToRight(0, height - minHeight, width); + _emojiToggle->moveToRight(_send->width(), height - minHeight, width); updateWrapSize(); }, _lifetime); @@ -165,11 +188,23 @@ void MessageField::createControls(PeerData *peer) { _closeRequests.fire({}); }, _lifetime); + const auto updateLimitPosition = [=](QSize parent, QSize label) { + const auto skip = st::historySendPadding; + return QPoint(parent.width() - label.width() - skip, skip); + }; + Ui::AddLengthLimitLabel(_field, _limit, { + .customParent = _wrap.get(), + .customUpdatePosition = updateLimitPosition, + }); + rpl::merge( _field->submits() | rpl::to_empty, _send->clicks() | rpl::to_empty ) | rpl::start_with_next([=] { - _submitted.fire(_field->getTextWithAppliedMarkdown()); + auto text = _field->getTextWithTags(); + if (text.text.size() <= _limit) { + _submitted.fire(std::move(text)); + } }, _lifetime); } diff --git a/Telegram/SourceFiles/calls/group/calls_group_message_field.h b/Telegram/SourceFiles/calls/group/calls_group_message_field.h index 64c0089e08..58173c419a 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_message_field.h +++ b/Telegram/SourceFiles/calls/group/calls_group_message_field.h @@ -58,6 +58,7 @@ private: const std::shared_ptr _show; const std::unique_ptr _wrap; + int _limit = 0; Ui::InputField *_field = nullptr; Ui::SendButton *_send = nullptr; Ui::EmojiButton *_emojiToggle = nullptr; diff --git a/Telegram/SourceFiles/calls/group/calls_group_messages.cpp b/Telegram/SourceFiles/calls/group/calls_group_messages.cpp index 2881e062e8..ab9d56eade 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_messages.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_messages.cpp @@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_user.h" #include "main/main_session.h" #include "mtproto/sender.h" +#include "ui/text/text_utilities.h" #include "ui/ui_utility.h" namespace Calls::Group { @@ -160,7 +161,18 @@ void Messages::received( .id = id, .date = base::unixtime::now(), .peer = peer->owner().peer(peerFromMTP(from)), - .text = Api::ParseTextWithEntities(&peer->session(), message), + .text = Ui::Text::Filtered( + Api::ParseTextWithEntities(&peer->session(), message), + { + EntityType::Code, + EntityType::Bold, + EntityType::Semibold, + EntityType::Spoiler, + EntityType::StrikeOut, + EntityType::Underline, + EntityType::Italic, + EntityType::CustomEmoji, + }), }); checkDestroying(true); }