diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index e78b6c65db..e830ee5dbc 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -1549,14 +1549,6 @@ bool Element::unwrapped() const { return true; } -bool Element::hasFastReply() const { - return false; -} - -bool Element::displayFastReply() const { - return false; -} - std::optional Element::rightActionSize() const { return std::nullopt; } diff --git a/Telegram/SourceFiles/history/view/history_view_element.h b/Telegram/SourceFiles/history/view/history_view_element.h index de00c0f48d..af62b3f3b6 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.h +++ b/Telegram/SourceFiles/history/view/history_view_element.h @@ -484,8 +484,6 @@ public: [[nodiscard]] virtual int minWidthForMedia() const { return 0; } - [[nodiscard]] virtual bool hasFastReply() const; - [[nodiscard]] virtual bool displayFastReply() const; [[nodiscard]] virtual std::optional rightActionSize() const; virtual void drawRightAction( Painter &p, diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 5e8d1c05b7..591e8b37d4 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -334,10 +334,19 @@ int KeyboardStyle::minButtonWidth( return result; } +QString FastForwardText() { + return u"Forward"_q; +} + QString FastReplyText() { return tr::lng_fast_reply(tr::now); } +bool ShowFastForwardFor(const QString &username) { + return !username.compare(u"ReviewInsightsBot"_q, Qt::CaseInsensitive) + || !username.compare(u"reviews_bot"_q, Qt::CaseInsensitive); +} + [[nodiscard]] ClickHandlerPtr MakeTopicButtonLink( not_null topic, MsgId messageId) { @@ -966,7 +975,9 @@ QSize Message::performCountOptimalSize() { namew += st::msgServiceFont->spacew + via->maxWidth + (_fromNameStatus ? st::msgServiceFont->spacew : 0); } - const auto replyWidth = hasFastReply() + const auto replyWidth = hasFastForward() + ? st::msgFont->width(FastForwardText()) + : hasFastReply() ? st::msgFont->width(FastReplyText()) : 0; if (!_rightBadge.isEmpty()) { @@ -1783,8 +1794,12 @@ void Message::paintFromName( } const auto badgeWidth = _rightBadge.isEmpty() ? 0 : _rightBadge.maxWidth(); const auto replyWidth = [&] { - if (isUnderCursor() && displayFastReply()) { - return st::msgFont->width(FastReplyText()); + if (isUnderCursor()) { + if (displayFastForward()) { + return st::msgFont->width(FastForwardText()); + } else if (displayFastReply()) { + return st::msgFont->width(FastReplyText()); + } } return 0; }(); @@ -1883,7 +1898,7 @@ void Message::paintFromName( p.drawText( trect.left() + trect.width() - rightWidth, trect.top() + st::msgFont->ascent, - FastReplyText()); + hasFastForward() ? FastForwardText() : FastReplyText()); } else { const auto shift = QPoint(trect.width() - rightWidth, 0); const auto pen = !_rightBadgeHasBoosts @@ -2796,8 +2811,12 @@ bool Message::getStateFromName( return false; } const auto replyWidth = [&] { - if (isUnderCursor() && displayFastReply()) { - return st::msgFont->width(FastReplyText()); + if (isUnderCursor()) { + if (displayFastForward()) { + return st::msgFont->width(FastForwardText()); + } else if (displayFastReply()) { + return st::msgFont->width(FastReplyText()); + } } return 0; }(); @@ -3838,6 +3857,22 @@ bool Message::hasFastReply() const { return !hasOutLayout() && (peer->isChat() || peer->isMegagroup()); } +bool Message::hasFastForward() const { + if (context() != Context::History) { + return false; + } + const auto item = data(); + const auto from = item->from()->asUser(); + if (!from || !from->isBot() || !ShowFastForwardFor(from->username())) { + return false; + } + const auto peer = item->history()->peer; + if (!peer->isChat() && !peer->isMegagroup()) { + return false; + } + return !hasOutLayout(); +} + bool Message::displayFastReply() const { const auto canSendAnything = [&] { const auto item = data(); @@ -3854,6 +3889,12 @@ bool Message::displayFastReply() const { && !delegate()->elementInSelectionMode(this).inSelectionMode; } +bool Message::displayFastForward() const { + return hasFastForward() + && data()->allowsForward() + && !delegate()->elementInSelectionMode(this).inSelectionMode; +} + bool Message::displayRightActionComments() const { return !isPinnedContext() && (context() != Context::SavedSublist) @@ -4122,9 +4163,22 @@ ClickHandlerPtr Message::fastReplyLink() const { return _fastReplyLink; } const auto itemId = data()->fullId(); - _fastReplyLink = std::make_shared([=] { - delegate()->elementReplyTo({ itemId }); - }); + const auto sessionId = data()->history()->session().uniqueId(); + _fastReplyLink = hasFastForward() + ? std::make_shared([=](ClickContext context) { + const auto controller = ExtractController(context); + const auto session = controller + ? &controller->session() + : nullptr; + if (!session || session->uniqueId() != sessionId) { + return; + } else if (const auto item = session->data().message(itemId)) { + FastShareMessage(controller, item); + } + }) + : std::make_shared(crl::guard(this, [=] { + delegate()->elementReplyTo({ itemId }); + })); return _fastReplyLink; } @@ -4213,7 +4267,9 @@ void Message::updateMediaInBubbleState() { void Message::fromNameUpdated(int width) const { const auto item = data(); - const auto replyWidth = hasFastReply() + const auto replyWidth = hasFastForward() + ? st::msgFont->width(FastForwardText()) + : hasFastReply() ? st::msgFont->width(FastReplyText()) : 0; if (!_rightBadge.isEmpty()) { diff --git a/Telegram/SourceFiles/history/view/history_view_message.h b/Telegram/SourceFiles/history/view/history_view_message.h index b33b29edc8..a68c5fa971 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.h +++ b/Telegram/SourceFiles/history/view/history_view_message.h @@ -129,8 +129,6 @@ public: TopicButton *displayedTopicButton() const override; bool unwrapped() const override; int minWidthForMedia() const override; - bool hasFastReply() const override; - bool displayFastReply() const override; bool displayRightActionComments() const; std::optional rightActionSize() const override; void drawRightAction( @@ -275,6 +273,10 @@ private: [[nodiscard]] int visibleMediaTextLength() const; [[nodiscard]] bool needInfoDisplay() const; [[nodiscard]] bool invertMedia() const; + [[nodiscard]] bool hasFastReply() const; + [[nodiscard]] bool hasFastForward() const; + [[nodiscard]] bool displayFastReply() const; + [[nodiscard]] bool displayFastForward() const; [[nodiscard]] bool isPinnedContext() const;