Replace Reply with Forward for specific bots.

This commit is contained in:
John Preston 2025-03-18 14:19:43 +04:00
parent 0d346610a2
commit eb4ef8b3d7
4 changed files with 70 additions and 22 deletions

View file

@ -1549,14 +1549,6 @@ bool Element::unwrapped() const {
return true;
}
bool Element::hasFastReply() const {
return false;
}
bool Element::displayFastReply() const {
return false;
}
std::optional<QSize> Element::rightActionSize() const {
return std::nullopt;
}

View file

@ -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<QSize> rightActionSize() const;
virtual void drawRightAction(
Painter &p,

View file

@ -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<Data::ForumTopic*> 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<LambdaClickHandler>([=] {
delegate()->elementReplyTo({ itemId });
});
const auto sessionId = data()->history()->session().uniqueId();
_fastReplyLink = hasFastForward()
? std::make_shared<LambdaClickHandler>([=](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<LambdaClickHandler>(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()) {

View file

@ -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<QSize> 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;