diff --git a/Telegram/SourceFiles/core/click_handler.cpp b/Telegram/SourceFiles/core/click_handler.cpp index cca577868..9ff9c89aa 100644 --- a/Telegram/SourceFiles/core/click_handler.cpp +++ b/Telegram/SourceFiles/core/click_handler.cpp @@ -50,11 +50,7 @@ bool ClickHandler::setActive(const ClickHandlerPtr &p, ClickHandlerHost *host) { return true; } -QString ClickHandler::getExpandedLinkText(ExpandLinksMode mode, const QStringRef &textPart) const { - return QString(); -} - -TextWithEntities ClickHandler::getExpandedLinkTextWithEntities(ExpandLinksMode mode, int entityOffset, const QStringRef &textPart) const { +TextWithEntities ClickHandler::getExpandedLinkTextWithEntities(int entityOffset, const QStringRef &textPart) const { return { QString(), EntitiesInText() }; } diff --git a/Telegram/SourceFiles/core/click_handler.h b/Telegram/SourceFiles/core/click_handler.h index 9ca86b910..2cbfdfd88 100644 --- a/Telegram/SourceFiles/core/click_handler.h +++ b/Telegram/SourceFiles/core/click_handler.h @@ -16,10 +16,8 @@ struct ClickContext { }; enum ExpandLinksMode { - ExpandLinksNone, ExpandLinksShortened, ExpandLinksAll, - ExpandLinksUrlOnly, // For custom urls leaves only url instead of text. }; class ClickHandlerHost { @@ -63,8 +61,7 @@ public: // Entities in text support. // This method returns empty string if just textPart should be used (nothing to expand). - virtual QString getExpandedLinkText(ExpandLinksMode mode, const QStringRef &textPart) const; - virtual TextWithEntities getExpandedLinkTextWithEntities(ExpandLinksMode mode, int entityOffset, const QStringRef &textPart) const; + virtual TextWithEntities getExpandedLinkTextWithEntities(int entityOffset, const QStringRef &textPart) const; // This method should be called on mouse over a click handler. // It returns true if the active handler was changed or false otherwise. diff --git a/Telegram/SourceFiles/core/click_handler_types.cpp b/Telegram/SourceFiles/core/click_handler_types.cpp index d5175165c..a4e250027 100644 --- a/Telegram/SourceFiles/core/click_handler_types.cpp +++ b/Telegram/SourceFiles/core/click_handler_types.cpp @@ -133,22 +133,13 @@ void UrlClickHandler::Open(QString url, QVariant context) { } } -QString UrlClickHandler::getExpandedLinkText(ExpandLinksMode mode, const QStringRef &textPart) const { - QString result; - if (mode != ExpandLinksNone) { - result = _originalUrl; - } - return result; -} - -TextWithEntities UrlClickHandler::getExpandedLinkTextWithEntities(ExpandLinksMode mode, int entityOffset, const QStringRef &textPart) const { - TextWithEntities result; - auto entityType = isEmail(_originalUrl) ? EntityInTextEmail : EntityInTextUrl; - int entityLength = textPart.size(); - if (mode != ExpandLinksNone) { - result.text = _originalUrl; - entityLength = _originalUrl.size(); - } +TextWithEntities UrlClickHandler::getExpandedLinkTextWithEntities(int entityOffset, const QStringRef &textPart) const { + auto result = TextWithEntities(); + result.text = _originalUrl; + const auto entityLength = _originalUrl.size(); + const auto entityType = isEmail(_originalUrl) + ? EntityInTextEmail + : EntityInTextUrl; result.entities.push_back({ entityType, entityOffset, entityLength }); return result; } @@ -209,28 +200,8 @@ void BotGameUrlClickHandler::onClick(ClickContext context) const { } } -QString HiddenUrlClickHandler::getExpandedLinkText(ExpandLinksMode mode, const QStringRef &textPart) const { - QString result; - if (mode == ExpandLinksAll) { - result = textPart.toString() + qsl(" (") + url() + ')'; - } else if (mode == ExpandLinksUrlOnly) { - result = url(); - } - return result; -} - -TextWithEntities HiddenUrlClickHandler::getExpandedLinkTextWithEntities(ExpandLinksMode mode, int entityOffset, const QStringRef &textPart) const { - TextWithEntities result; - if (mode == ExpandLinksUrlOnly) { - result.text = url(); - result.entities.push_back({ EntityInTextUrl, entityOffset, result.text.size() }); - } else { - result.entities.push_back({ EntityInTextCustomUrl, entityOffset, textPart.size(), url() }); - if (mode == ExpandLinksAll) { - result.text = textPart.toString() + qsl(" (") + url() + ')'; - } - } - return result; +TextWithEntities HiddenUrlClickHandler::getExpandedLinkTextWithEntities(int entityOffset, const QStringRef &textPart) const { + return simpleTextWithEntity({ EntityInTextCustomUrl, entityOffset, textPart.size(), url() }); } QString MentionClickHandler::copyToClipboardContextItemText() const { @@ -244,7 +215,7 @@ void MentionClickHandler::onClick(ClickContext context) const { } } -TextWithEntities MentionClickHandler::getExpandedLinkTextWithEntities(ExpandLinksMode mode, int entityOffset, const QStringRef &textPart) const { +TextWithEntities MentionClickHandler::getExpandedLinkTextWithEntities(int entityOffset, const QStringRef &textPart) const { return simpleTextWithEntity({ EntityInTextMention, entityOffset, textPart.size() }); } @@ -257,7 +228,7 @@ void MentionNameClickHandler::onClick(ClickContext context) const { } } -TextWithEntities MentionNameClickHandler::getExpandedLinkTextWithEntities(ExpandLinksMode mode, int entityOffset, const QStringRef &textPart) const { +TextWithEntities MentionNameClickHandler::getExpandedLinkTextWithEntities(int entityOffset, const QStringRef &textPart) const { auto data = QString::number(_userId) + '.' + QString::number(_accessHash); return simpleTextWithEntity({ EntityInTextMentionName, entityOffset, textPart.size(), data }); } @@ -283,7 +254,7 @@ void HashtagClickHandler::onClick(ClickContext context) const { } } -TextWithEntities HashtagClickHandler::getExpandedLinkTextWithEntities(ExpandLinksMode mode, int entityOffset, const QStringRef &textPart) const { +TextWithEntities HashtagClickHandler::getExpandedLinkTextWithEntities(int entityOffset, const QStringRef &textPart) const { return simpleTextWithEntity({ EntityInTextHashtag, entityOffset, textPart.size() }); } @@ -299,7 +270,6 @@ void CashtagClickHandler::onClick(ClickContext context) const { } TextWithEntities CashtagClickHandler::getExpandedLinkTextWithEntities( - ExpandLinksMode mode, int entityOffset, const QStringRef &textPart) const { return simpleTextWithEntity({ EntityInTextCashtag, entityOffset, textPart.size() }); @@ -334,6 +304,6 @@ void BotCommandClickHandler::onClick(ClickContext context) const { } } -TextWithEntities BotCommandClickHandler::getExpandedLinkTextWithEntities(ExpandLinksMode mode, int entityOffset, const QStringRef &textPart) const { +TextWithEntities BotCommandClickHandler::getExpandedLinkTextWithEntities(int entityOffset, const QStringRef &textPart) const { return simpleTextWithEntity({ EntityInTextBotCommand, entityOffset, textPart.size() }); } diff --git a/Telegram/SourceFiles/core/click_handler_types.h b/Telegram/SourceFiles/core/click_handler_types.h index e87f4b0fd..a0070660d 100644 --- a/Telegram/SourceFiles/core/click_handler_types.h +++ b/Telegram/SourceFiles/core/click_handler_types.h @@ -47,11 +47,7 @@ public: return url(); } - QString getExpandedLinkText( - ExpandLinksMode mode, - const QStringRef &textPart) const override; TextWithEntities getExpandedLinkTextWithEntities( - ExpandLinksMode mode, int entityOffset, const QStringRef &textPart) const override; @@ -100,11 +96,7 @@ public: } } - QString getExpandedLinkText( - ExpandLinksMode mode, - const QStringRef &textPart) const override; TextWithEntities getExpandedLinkTextWithEntities( - ExpandLinksMode mode, int entityOffset, const QStringRef &textPart) const override; @@ -137,7 +129,6 @@ public: QString copyToClipboardContextItemText() const override; TextWithEntities getExpandedLinkTextWithEntities( - ExpandLinksMode mode, int entityOffset, const QStringRef &textPart) const override; @@ -162,7 +153,6 @@ public: void onClick(ClickContext context) const override; TextWithEntities getExpandedLinkTextWithEntities( - ExpandLinksMode mode, int entityOffset, const QStringRef &textPart) const override; @@ -189,7 +179,6 @@ public: QString copyToClipboardContextItemText() const override; TextWithEntities getExpandedLinkTextWithEntities( - ExpandLinksMode mode, int entityOffset, const QStringRef &textPart) const override; @@ -217,7 +206,6 @@ public: QString copyToClipboardContextItemText() const override; TextWithEntities getExpandedLinkTextWithEntities( - ExpandLinksMode mode, int entityOffset, const QStringRef &textPart) const override; @@ -252,7 +240,6 @@ public: } TextWithEntities getExpandedLinkTextWithEntities( - ExpandLinksMode mode, int entityOffset, const QStringRef &textPart) const override; diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index bf67d0b86..02d9264a3 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -471,7 +471,7 @@ QString InnerWidget::tooltipText() const { && _mouseAction == MouseAction::None) { if (const auto view = App::hoveredItem()) { if (const auto forwarded = view->data()->Get()) { - return forwarded->text.originalText(AllTextSelection, ExpandLinksNone); + return forwarded->text.toString(); } } } else if (const auto lnk = ClickHandler::getActive()) { diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 14741d1ee..339df02b9 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -3103,7 +3103,7 @@ QString HistoryInner::tooltipText() const { && _mouseAction == MouseAction::None) { if (const auto view = App::hoveredItem()) { if (const auto forwarded = view->data()->Get()) { - return forwarded->text.originalText(AllTextSelection, ExpandLinksNone); + return forwarded->text.toString(); } } } else if (const auto lnk = ClickHandler::getActive()) { diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index b8225cf83..5e925d639 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -43,6 +43,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace { +constexpr auto kNotificationTextLimit = 255; + enum class MediaCheckResult { Good, Unsupported, @@ -686,20 +688,17 @@ bool HistoryItem::isEmpty() const { } QString HistoryItem::notificationText() const { - auto getText = [this]() { + const auto result = [&] { if (_media) { return _media->notificationText(); } else if (!emptyText()) { - return _text.originalText(); + return _text.toString(); } return QString(); - }; - - auto result = getText(); - if (result.size() > 0xFF) { - result = result.mid(0, 0xFF) + qsl("..."); - } - return result; + }(); + return (result.size() <= kNotificationTextLimit) + ? result + : result.mid(0, kNotificationTextLimit) + qsl("..."); } QString HistoryItem::inDialogsText(DrawInDialog way) const { @@ -710,7 +709,7 @@ QString HistoryItem::inDialogsText(DrawInDialog way) const { } return _media->chatListText(); } else if (!emptyText()) { - return TextUtilities::Clean(_text.originalText()); + return TextUtilities::Clean(_text.toString()); } return QString(); }; diff --git a/Telegram/SourceFiles/history/history_item_text.cpp b/Telegram/SourceFiles/history/history_item_text.cpp index e5f10588c..df9f44e5f 100644 --- a/Telegram/SourceFiles/history/history_item_text.cpp +++ b/Telegram/SourceFiles/history/history_item_text.cpp @@ -39,7 +39,7 @@ TextWithEntities WrapAsReply( TextWithEntities WrapAsForwarded( TextWithEntities &&text, not_null forwarded) { - auto info = forwarded->text.originalTextWithEntities( + auto info = forwarded->text.toTextWithEntities( AllTextSelection, ExpandLinksAll); auto result = TextWithEntities(); diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index ea78985bc..e2d09310a 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -1093,14 +1093,14 @@ TextWithEntities HistoryMessage::originalText() const { if (emptyText()) { return { QString(), EntitiesInText() }; } - return _text.originalTextWithEntities(); + return _text.toTextWithEntities(); } TextWithEntities HistoryMessage::clipboardText() const { if (emptyText()) { return { QString(), EntitiesInText() }; } - return _text.originalTextWithEntities(AllTextSelection, ExpandLinksAll); + return _text.toTextWithEntities(AllTextSelection, ExpandLinksAll); } bool HistoryMessage::textHasLinks() const { diff --git a/Telegram/SourceFiles/history/media/history_media_contact.cpp b/Telegram/SourceFiles/history/media/history_media_contact.cpp index 459581cb9..bc03593b1 100644 --- a/Telegram/SourceFiles/history/media/history_media_contact.cpp +++ b/Telegram/SourceFiles/history/media/history_media_contact.cpp @@ -99,7 +99,7 @@ QSize HistoryContact::countOptimalSize() { if (_contact) { _contact->loadUserpic(); } else { - const auto full = _name.originalText(); + const auto full = _name.toString(); _photoEmpty = std::make_unique( Data::PeerUserpicColor(_userId ? peerFromUser(_userId) diff --git a/Telegram/SourceFiles/history/media/history_media_document.cpp b/Telegram/SourceFiles/history/media/history_media_document.cpp index fb4203168..98a4fc20b 100644 --- a/Telegram/SourceFiles/history/media/history_media_document.cpp +++ b/Telegram/SourceFiles/history/media/history_media_document.cpp @@ -654,7 +654,7 @@ bool HistoryDocument::hasTextForCopy() const { TextWithEntities HistoryDocument::selectedText(TextSelection selection) const { if (const auto captioned = Get()) { const auto &caption = captioned->_caption; - return caption.originalTextWithEntities(selection, ExpandLinksAll); + return caption.toTextWithEntities(selection, ExpandLinksAll); } return TextWithEntities(); } @@ -838,7 +838,7 @@ void HistoryDocument::parentTextUpdated() { TextWithEntities HistoryDocument::getCaption() const { if (const auto captioned = Get()) { - return captioned->_caption.originalTextWithEntities(); + return captioned->_caption.toTextWithEntities(); } return TextWithEntities(); } diff --git a/Telegram/SourceFiles/history/media/history_media_game.cpp b/Telegram/SourceFiles/history/media/history_media_game.cpp index 09a33821f..84a22597d 100644 --- a/Telegram/SourceFiles/history/media/history_media_game.cpp +++ b/Telegram/SourceFiles/history/media/history_media_game.cpp @@ -368,10 +368,10 @@ void HistoryGame::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pres } TextWithEntities HistoryGame::selectedText(TextSelection selection) const { - auto titleResult = _title.originalTextWithEntities( + auto titleResult = _title.toTextWithEntities( selection, ExpandLinksAll); - auto descriptionResult = _description.originalTextWithEntities( + auto descriptionResult = _description.toTextWithEntities( toDescriptionSelection(selection), ExpandLinksAll); if (titleResult.text.isEmpty()) { diff --git a/Telegram/SourceFiles/history/media/history_media_gif.cpp b/Telegram/SourceFiles/history/media/history_media_gif.cpp index 4cc35a755..b6a17480c 100644 --- a/Telegram/SourceFiles/history/media/history_media_gif.cpp +++ b/Telegram/SourceFiles/history/media/history_media_gif.cpp @@ -681,7 +681,7 @@ TextState HistoryGif::textState(QPoint point, StateRequest request) const { } TextWithEntities HistoryGif::selectedText(TextSelection selection) const { - return _caption.originalTextWithEntities(selection, ExpandLinksAll); + return _caption.toTextWithEntities(selection, ExpandLinksAll); } bool HistoryGif::uploading() const { diff --git a/Telegram/SourceFiles/history/media/history_media_gif.h b/Telegram/SourceFiles/history/media/history_media_gif.h index 453859493..f2b061c0d 100644 --- a/Telegram/SourceFiles/history/media/history_media_gif.h +++ b/Telegram/SourceFiles/history/media/history_media_gif.h @@ -57,7 +57,7 @@ public: void stopAnimation() override; TextWithEntities getCaption() const override { - return _caption.originalTextWithEntities(); + return _caption.toTextWithEntities(); } bool needsBubble() const override; bool customInfoLayout() const override { diff --git a/Telegram/SourceFiles/history/media/history_media_grouped.cpp b/Telegram/SourceFiles/history/media/history_media_grouped.cpp index 517a3f579..2a0cd3ac3 100644 --- a/Telegram/SourceFiles/history/media/history_media_grouped.cpp +++ b/Telegram/SourceFiles/history/media/history_media_grouped.cpp @@ -306,7 +306,7 @@ TextSelection HistoryGroupedMedia::adjustSelection( TextWithEntities HistoryGroupedMedia::selectedText( TextSelection selection) const { - return _caption.originalTextWithEntities(selection, ExpandLinksAll); + return _caption.toTextWithEntities(selection, ExpandLinksAll); } void HistoryGroupedMedia::clickHandlerActiveChanged( diff --git a/Telegram/SourceFiles/history/media/history_media_invoice.cpp b/Telegram/SourceFiles/history/media/history_media_invoice.cpp index bac6d6509..a7f090010 100644 --- a/Telegram/SourceFiles/history/media/history_media_invoice.cpp +++ b/Telegram/SourceFiles/history/media/history_media_invoice.cpp @@ -359,10 +359,10 @@ void HistoryInvoice::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool p } TextWithEntities HistoryInvoice::selectedText(TextSelection selection) const { - auto titleResult = _title.originalTextWithEntities( + auto titleResult = _title.toTextWithEntities( selection, ExpandLinksAll); - auto descriptionResult = _description.originalTextWithEntities( + auto descriptionResult = _description.toTextWithEntities( toDescriptionSelection(selection), ExpandLinksAll); if (titleResult.text.isEmpty()) { diff --git a/Telegram/SourceFiles/history/media/history_media_invoice.h b/Telegram/SourceFiles/history/media/history_media_invoice.h index c003faebb..2c20920c8 100644 --- a/Telegram/SourceFiles/history/media/history_media_invoice.h +++ b/Telegram/SourceFiles/history/media/history_media_invoice.h @@ -25,7 +25,7 @@ public: return _receiptMsgId; } QString getTitle() const { - return _title.originalText(); + return _title.toString(); } bool hideMessageText() const override { diff --git a/Telegram/SourceFiles/history/media/history_media_location.cpp b/Telegram/SourceFiles/history/media/history_media_location.cpp index 420b77f8f..afca5f7bf 100644 --- a/Telegram/SourceFiles/history/media/history_media_location.cpp +++ b/Telegram/SourceFiles/history/media/history_media_location.cpp @@ -279,8 +279,8 @@ TextSelection HistoryLocation::adjustSelection(TextSelection selection, TextSele } TextWithEntities HistoryLocation::selectedText(TextSelection selection) const { - auto titleResult = _title.originalTextWithEntities(selection); - auto descriptionResult = _description.originalTextWithEntities(toDescriptionSelection(selection)); + auto titleResult = _title.toTextWithEntities(selection); + auto descriptionResult = _description.toTextWithEntities(toDescriptionSelection(selection)); if (titleResult.text.isEmpty()) { return descriptionResult; } else if (descriptionResult.text.isEmpty()) { diff --git a/Telegram/SourceFiles/history/media/history_media_photo.cpp b/Telegram/SourceFiles/history/media/history_media_photo.cpp index 9e1642732..7946a7c15 100644 --- a/Telegram/SourceFiles/history/media/history_media_photo.cpp +++ b/Telegram/SourceFiles/history/media/history_media_photo.cpp @@ -536,7 +536,7 @@ void HistoryPhoto::validateGroupedCache( } TextWithEntities HistoryPhoto::selectedText(TextSelection selection) const { - return _caption.originalTextWithEntities(selection, ExpandLinksAll); + return _caption.toTextWithEntities(selection, ExpandLinksAll); } bool HistoryPhoto::needsBubble() const { diff --git a/Telegram/SourceFiles/history/media/history_media_photo.h b/Telegram/SourceFiles/history/media/history_media_photo.h index 568396af9..f9c13f67b 100644 --- a/Telegram/SourceFiles/history/media/history_media_photo.h +++ b/Telegram/SourceFiles/history/media/history_media_photo.h @@ -58,7 +58,7 @@ public: StateRequest request) const override; TextWithEntities getCaption() const override { - return _caption.originalTextWithEntities(); + return _caption.toTextWithEntities(); } bool needsBubble() const override; bool customInfoLayout() const override { diff --git a/Telegram/SourceFiles/history/media/history_media_poll.cpp b/Telegram/SourceFiles/history/media/history_media_poll.cpp index 9af486f01..4d9d27605 100644 --- a/Telegram/SourceFiles/history/media/history_media_poll.cpp +++ b/Telegram/SourceFiles/history/media/history_media_poll.cpp @@ -183,7 +183,7 @@ HistoryPoll::Answer::Answer() : text(st::msgMinWidth / 2) { } void HistoryPoll::Answer::fillText(const PollAnswer &original) { - if (!text.isEmpty() && text.originalText() == original.text) { + if (!text.isEmpty() && text.toString() == original.text) { return; } text.setText( @@ -320,7 +320,7 @@ void HistoryPoll::updateTexts() { const auto willStartAnimation = checkAnimationStart(); - if (_question.originalText() != _poll->question) { + if (_question.toString() != _poll->question) { _question.setText( st::historyPollQuestionStyle, _poll->question, diff --git a/Telegram/SourceFiles/history/media/history_media_video.cpp b/Telegram/SourceFiles/history/media/history_media_video.cpp index 4aadff044..e2f8ed17f 100644 --- a/Telegram/SourceFiles/history/media/history_media_video.cpp +++ b/Telegram/SourceFiles/history/media/history_media_video.cpp @@ -577,7 +577,7 @@ void HistoryVideo::setStatusSize(int newSize) const { } TextWithEntities HistoryVideo::selectedText(TextSelection selection) const { - return _caption.originalTextWithEntities(selection, ExpandLinksAll); + return _caption.toTextWithEntities(selection, ExpandLinksAll); } bool HistoryVideo::needsBubble() const { diff --git a/Telegram/SourceFiles/history/media/history_media_video.h b/Telegram/SourceFiles/history/media/history_media_video.h index 0cfbd445a..aa960b06b 100644 --- a/Telegram/SourceFiles/history/media/history_media_video.h +++ b/Telegram/SourceFiles/history/media/history_media_video.h @@ -55,7 +55,7 @@ public: bool uploading() const override; TextWithEntities getCaption() const override { - return _caption.originalTextWithEntities(); + return _caption.toTextWithEntities(); } bool needsBubble() const override; bool customInfoLayout() const override { diff --git a/Telegram/SourceFiles/history/media/history_media_web_page.cpp b/Telegram/SourceFiles/history/media/history_media_web_page.cpp index 6d97fceed..aef89cc47 100644 --- a/Telegram/SourceFiles/history/media/history_media_web_page.cpp +++ b/Telegram/SourceFiles/history/media/history_media_web_page.cpp @@ -686,10 +686,10 @@ bool HistoryWebPage::isDisplayed() const { } TextWithEntities HistoryWebPage::selectedText(TextSelection selection) const { - auto titleResult = _title.originalTextWithEntities( + auto titleResult = _title.toTextWithEntities( selection, ExpandLinksAll); - auto descriptionResult = _description.originalTextWithEntities( + auto descriptionResult = _description.toTextWithEntities( toDescriptionSelection(selection), ExpandLinksAll); if (titleResult.text.isEmpty()) { diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index abafab781..bc019638e 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -1070,9 +1070,7 @@ QString ListWidget::tooltipText() const { QLocale::system().dateTimeFormat(QLocale::LongFormat)); } else if (_mouseCursorState == CursorState::Forwarded && item) { if (const auto forwarded = item->Get()) { - return forwarded->text.originalText( - AllTextSelection, - ExpandLinksNone); + return forwarded->text.toString(); } } else if (const auto link = ClickHandler::getActive()) { return link->tooltip(); diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 4e0d864ef..0ab1082f8 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -1059,7 +1059,7 @@ TextWithEntities Message::selectedText(TextSelection selection) const { const auto media = this->media(); TextWithEntities logEntryOriginalResult; - auto textResult = item->_text.originalTextWithEntities( + auto textResult = item->_text.toTextWithEntities( selection, ExpandLinksAll); auto skipped = skipTextSelection(selection); @@ -1783,7 +1783,7 @@ void Message::refreshEditedBadge() { if (const auto msgsigned = item->Get()) { const auto text = (!edited || !editDate) ? dateText - : edited->text.originalText(); + : edited->text.toString(); msgsigned->refresh(text); } initTime(); diff --git a/Telegram/SourceFiles/history/view/history_view_service_message.cpp b/Telegram/SourceFiles/history/view/history_view_service_message.cpp index 2e9fc6db8..074571382 100644 --- a/Telegram/SourceFiles/history/view/history_view_service_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_service_message.cpp @@ -531,7 +531,7 @@ void Service::updatePressed(QPoint point) { } TextWithEntities Service::selectedText(TextSelection selection) const { - return message()->_text.originalTextWithEntities(selection); + return message()->_text.toTextWithEntities(selection); } TextSelection Service::adjustSelection( diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index 1390065a2..613f73ea1 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -743,7 +743,7 @@ void TopBarWidget::updateOnlineDisplay() { text = lang(lng_chat_status_unaccessible); } else if (chat->participants.empty()) { if (!_titlePeerText.isEmpty()) { - text = _titlePeerText.originalText(); + text = _titlePeerText.toString(); } else if (chat->count <= 0) { text = lang(lng_group_status); } else { @@ -800,7 +800,7 @@ void TopBarWidget::updateOnlineDisplay() { text = lang(channel->isMegagroup() ? lng_group_status : lng_channel_status); } } - if (_titlePeerText.originalText() != text) { + if (_titlePeerText.toString() != text) { _titlePeerText.setText(st::dialogsTextStyle, text); _titlePeerTextOnline = titlePeerTextOnline; updateMembersShowArea(); diff --git a/Telegram/SourceFiles/ui/text/text.cpp b/Telegram/SourceFiles/ui/text/text.cpp index bc4d3d57b..94a55078b 100644 --- a/Telegram/SourceFiles/ui/text/text.cpp +++ b/Telegram/SourceFiles/ui/text/text.cpp @@ -3046,12 +3046,14 @@ void Text::enumerateText(TextSelection selection, AppendPartCallback appendPartC } } -TextWithEntities Text::originalTextWithEntities(TextSelection selection, ExpandLinksMode mode) const { + + +TextWithEntities Text::toTextWithEntities(TextSelection selection, ExpandLinksMode mode) const { TextWithEntities result; result.text.reserve(_text.size()); int lnkStart = 0, italicStart = 0, boldStart = 0, codeStart = 0, preStart = 0; - auto flagsChangeCallback = [&result, &italicStart, &boldStart, &codeStart, &preStart](int32 oldFlags, int32 newFlags) { + auto flagsChangeCallback = [&](int32 oldFlags, int32 newFlags) { if ((oldFlags & TextBlockFItalic) && !(newFlags & TextBlockFItalic)) { // write italic result.entities.push_back(EntityInText(EntityInTextItalic, italicStart, result.text.size() - italicStart)); } else if ((newFlags & TextBlockFItalic) && !(oldFlags & TextBlockFItalic)) { @@ -3073,12 +3075,17 @@ TextWithEntities Text::originalTextWithEntities(TextSelection selection, ExpandL preStart = result.text.size(); } }; - auto clickHandlerStartCallback = [&result, &lnkStart]() { + auto clickHandlerStartCallback = [&] { lnkStart = result.text.size(); }; - auto clickHandlerFinishCallback = [mode, &result, &lnkStart](const QStringRef &r, const ClickHandlerPtr &handler) { - auto expanded = handler->getExpandedLinkTextWithEntities(mode, lnkStart, r); - if (expanded.text.isEmpty()) { + auto clickHandlerFinishCallback = [&](const QStringRef &r, const ClickHandlerPtr &handler) { + const auto expanded = handler->getExpandedLinkTextWithEntities(lnkStart, r); + if (mode == ExpandLinksAll + && !expanded.entities.isEmpty() + && expanded.entities[0].type() == EntityInTextCustomUrl) { + result.text += r; + result.text += qsl(" (") + expanded.entities[0].data() + ')'; + } else if (expanded.text.isEmpty()) { result.text += r; } else { result.text += expanded.text; @@ -3087,7 +3094,7 @@ TextWithEntities Text::originalTextWithEntities(TextSelection selection, ExpandL result.entities.append(expanded.entities); } }; - auto appendPartCallback = [&result](const QStringRef &r) { + auto appendPartCallback = [&](const QStringRef &r) { result.text += r; }; @@ -3096,29 +3103,8 @@ TextWithEntities Text::originalTextWithEntities(TextSelection selection, ExpandL return result; } -QString Text::originalText(TextSelection selection, ExpandLinksMode mode) const { - QString result; - result.reserve(_text.size()); - - auto appendPartCallback = [&result](const QStringRef &r) { - result += r; - }; - auto clickHandlerStartCallback = []() { - }; - auto clickHandlerFinishCallback = [mode, &result](const QStringRef &r, const ClickHandlerPtr &handler) { - auto expanded = handler->getExpandedLinkText(mode, r); - if (expanded.isEmpty()) { - result += r; - } else { - result += expanded; - } - }; - auto flagsChangeCallback = [](int32 oldFlags, int32 newFlags) { - }; - - enumerateText(selection, appendPartCallback, clickHandlerStartCallback, clickHandlerFinishCallback, flagsChangeCallback); - - return result; +QString Text::toString(TextSelection selection, ExpandLinksMode mode) const { + return toTextWithEntities(selection, mode).text; } void Text::clear() { diff --git a/Telegram/SourceFiles/ui/text/text.h b/Telegram/SourceFiles/ui/text/text.h index d3af7fab9..169269ca8 100644 --- a/Telegram/SourceFiles/ui/text/text.h +++ b/Telegram/SourceFiles/ui/text/text.h @@ -165,8 +165,8 @@ public: return _text.size(); } - TextWithEntities originalTextWithEntities(TextSelection selection = AllTextSelection, ExpandLinksMode mode = ExpandLinksShortened) const; - QString originalText(TextSelection selection = AllTextSelection, ExpandLinksMode mode = ExpandLinksShortened) const; + QString toString(TextSelection selection = AllTextSelection, ExpandLinksMode mode = ExpandLinksShortened) const; + TextWithEntities toTextWithEntities(TextSelection selection = AllTextSelection, ExpandLinksMode mode = ExpandLinksShortened) const; bool lastDots(int32 dots, int32 maxdots = 3) { // hack for typing animation if (_text.size() < maxdots) return false; diff --git a/Telegram/SourceFiles/ui/widgets/labels.cpp b/Telegram/SourceFiles/ui/widgets/labels.cpp index 26a6be340..a76a9dea5 100644 --- a/Telegram/SourceFiles/ui/widgets/labels.cpp +++ b/Telegram/SourceFiles/ui/widgets/labels.cpp @@ -571,14 +571,14 @@ void FlatLabel::showContextMenu(QContextMenuEvent *e, ContextMenuReason reason) } void FlatLabel::onCopySelectedText() { - auto selection = _selection.empty() ? (_contextMenu ? _savedSelection : _selection) : _selection; + const auto selection = _selection.empty() ? (_contextMenu ? _savedSelection : _selection) : _selection; if (!selection.empty()) { - QApplication::clipboard()->setText(_text.originalText(selection, _contextExpandLinksMode)); + QApplication::clipboard()->setText(_text.toString(selection, _contextExpandLinksMode)); } } void FlatLabel::onCopyContextText() { - QApplication::clipboard()->setText(_text.originalText({ 0, 0xFFFF }, _contextExpandLinksMode)); + QApplication::clipboard()->setText(_text.toString(AllTextSelection, _contextExpandLinksMode)); } void FlatLabel::onTouchSelect() { @@ -606,7 +606,7 @@ void FlatLabel::onExecuteDrag() { ClickHandlerPtr pressedHandler = ClickHandler::getPressed(); QString selectedText; if (uponSelected) { - selectedText = _text.originalText(_selection, ExpandLinksAll); + selectedText = _text.toString(_selection, ExpandLinksAll); } else if (pressedHandler) { selectedText = pressedHandler->dragText(); } diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor_block.cpp b/Telegram/SourceFiles/window/themes/window_theme_editor_block.cpp index 0e38d6907..a4b1e0932 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor_block.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_editor_block.cpp @@ -43,7 +43,7 @@ public: } QString description() const { - return _description.originalText(); + return _description.toString(); } const Text &descriptionText() const { return _description; @@ -152,7 +152,7 @@ void EditorBlock::Row::fillValueString() { void EditorBlock::Row::fillSearchIndex() { _searchWords.clear(); _searchStartChars.clear(); - auto toIndex = _name + ' ' + _copyOf + ' ' + TextUtilities::RemoveAccents(_description.originalText()) + ' ' + _valueString; + auto toIndex = _name + ' ' + _copyOf + ' ' + TextUtilities::RemoveAccents(_description.toString()) + ' ' + _valueString; auto words = toIndex.toLower().split(SearchSplitter, QString::SkipEmptyParts); for_const (auto &word, words) { _searchWords.insert(word);