mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 22:54:01 +02:00
Replace Reply with Forward for specific bots.
This commit is contained in:
parent
0d346610a2
commit
eb4ef8b3d7
4 changed files with 70 additions and 22 deletions
|
@ -1549,14 +1549,6 @@ bool Element::unwrapped() const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Element::hasFastReply() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Element::displayFastReply() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::optional<QSize> Element::rightActionSize() const {
|
std::optional<QSize> Element::rightActionSize() const {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
|
@ -484,8 +484,6 @@ public:
|
||||||
[[nodiscard]] virtual int minWidthForMedia() const {
|
[[nodiscard]] virtual int minWidthForMedia() const {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
[[nodiscard]] virtual bool hasFastReply() const;
|
|
||||||
[[nodiscard]] virtual bool displayFastReply() const;
|
|
||||||
[[nodiscard]] virtual std::optional<QSize> rightActionSize() const;
|
[[nodiscard]] virtual std::optional<QSize> rightActionSize() const;
|
||||||
virtual void drawRightAction(
|
virtual void drawRightAction(
|
||||||
Painter &p,
|
Painter &p,
|
||||||
|
|
|
@ -334,10 +334,19 @@ int KeyboardStyle::minButtonWidth(
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString FastForwardText() {
|
||||||
|
return u"Forward"_q;
|
||||||
|
}
|
||||||
|
|
||||||
QString FastReplyText() {
|
QString FastReplyText() {
|
||||||
return tr::lng_fast_reply(tr::now);
|
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(
|
[[nodiscard]] ClickHandlerPtr MakeTopicButtonLink(
|
||||||
not_null<Data::ForumTopic*> topic,
|
not_null<Data::ForumTopic*> topic,
|
||||||
MsgId messageId) {
|
MsgId messageId) {
|
||||||
|
@ -966,7 +975,9 @@ QSize Message::performCountOptimalSize() {
|
||||||
namew += st::msgServiceFont->spacew + via->maxWidth
|
namew += st::msgServiceFont->spacew + via->maxWidth
|
||||||
+ (_fromNameStatus ? st::msgServiceFont->spacew : 0);
|
+ (_fromNameStatus ? st::msgServiceFont->spacew : 0);
|
||||||
}
|
}
|
||||||
const auto replyWidth = hasFastReply()
|
const auto replyWidth = hasFastForward()
|
||||||
|
? st::msgFont->width(FastForwardText())
|
||||||
|
: hasFastReply()
|
||||||
? st::msgFont->width(FastReplyText())
|
? st::msgFont->width(FastReplyText())
|
||||||
: 0;
|
: 0;
|
||||||
if (!_rightBadge.isEmpty()) {
|
if (!_rightBadge.isEmpty()) {
|
||||||
|
@ -1783,8 +1794,12 @@ void Message::paintFromName(
|
||||||
}
|
}
|
||||||
const auto badgeWidth = _rightBadge.isEmpty() ? 0 : _rightBadge.maxWidth();
|
const auto badgeWidth = _rightBadge.isEmpty() ? 0 : _rightBadge.maxWidth();
|
||||||
const auto replyWidth = [&] {
|
const auto replyWidth = [&] {
|
||||||
if (isUnderCursor() && displayFastReply()) {
|
if (isUnderCursor()) {
|
||||||
return st::msgFont->width(FastReplyText());
|
if (displayFastForward()) {
|
||||||
|
return st::msgFont->width(FastForwardText());
|
||||||
|
} else if (displayFastReply()) {
|
||||||
|
return st::msgFont->width(FastReplyText());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}();
|
}();
|
||||||
|
@ -1883,7 +1898,7 @@ void Message::paintFromName(
|
||||||
p.drawText(
|
p.drawText(
|
||||||
trect.left() + trect.width() - rightWidth,
|
trect.left() + trect.width() - rightWidth,
|
||||||
trect.top() + st::msgFont->ascent,
|
trect.top() + st::msgFont->ascent,
|
||||||
FastReplyText());
|
hasFastForward() ? FastForwardText() : FastReplyText());
|
||||||
} else {
|
} else {
|
||||||
const auto shift = QPoint(trect.width() - rightWidth, 0);
|
const auto shift = QPoint(trect.width() - rightWidth, 0);
|
||||||
const auto pen = !_rightBadgeHasBoosts
|
const auto pen = !_rightBadgeHasBoosts
|
||||||
|
@ -2796,8 +2811,12 @@ bool Message::getStateFromName(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const auto replyWidth = [&] {
|
const auto replyWidth = [&] {
|
||||||
if (isUnderCursor() && displayFastReply()) {
|
if (isUnderCursor()) {
|
||||||
return st::msgFont->width(FastReplyText());
|
if (displayFastForward()) {
|
||||||
|
return st::msgFont->width(FastForwardText());
|
||||||
|
} else if (displayFastReply()) {
|
||||||
|
return st::msgFont->width(FastReplyText());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}();
|
}();
|
||||||
|
@ -3838,6 +3857,22 @@ bool Message::hasFastReply() const {
|
||||||
return !hasOutLayout() && (peer->isChat() || peer->isMegagroup());
|
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 {
|
bool Message::displayFastReply() const {
|
||||||
const auto canSendAnything = [&] {
|
const auto canSendAnything = [&] {
|
||||||
const auto item = data();
|
const auto item = data();
|
||||||
|
@ -3854,6 +3889,12 @@ bool Message::displayFastReply() const {
|
||||||
&& !delegate()->elementInSelectionMode(this).inSelectionMode;
|
&& !delegate()->elementInSelectionMode(this).inSelectionMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Message::displayFastForward() const {
|
||||||
|
return hasFastForward()
|
||||||
|
&& data()->allowsForward()
|
||||||
|
&& !delegate()->elementInSelectionMode(this).inSelectionMode;
|
||||||
|
}
|
||||||
|
|
||||||
bool Message::displayRightActionComments() const {
|
bool Message::displayRightActionComments() const {
|
||||||
return !isPinnedContext()
|
return !isPinnedContext()
|
||||||
&& (context() != Context::SavedSublist)
|
&& (context() != Context::SavedSublist)
|
||||||
|
@ -4122,9 +4163,22 @@ ClickHandlerPtr Message::fastReplyLink() const {
|
||||||
return _fastReplyLink;
|
return _fastReplyLink;
|
||||||
}
|
}
|
||||||
const auto itemId = data()->fullId();
|
const auto itemId = data()->fullId();
|
||||||
_fastReplyLink = std::make_shared<LambdaClickHandler>([=] {
|
const auto sessionId = data()->history()->session().uniqueId();
|
||||||
delegate()->elementReplyTo({ itemId });
|
_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;
|
return _fastReplyLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4213,7 +4267,9 @@ void Message::updateMediaInBubbleState() {
|
||||||
|
|
||||||
void Message::fromNameUpdated(int width) const {
|
void Message::fromNameUpdated(int width) const {
|
||||||
const auto item = data();
|
const auto item = data();
|
||||||
const auto replyWidth = hasFastReply()
|
const auto replyWidth = hasFastForward()
|
||||||
|
? st::msgFont->width(FastForwardText())
|
||||||
|
: hasFastReply()
|
||||||
? st::msgFont->width(FastReplyText())
|
? st::msgFont->width(FastReplyText())
|
||||||
: 0;
|
: 0;
|
||||||
if (!_rightBadge.isEmpty()) {
|
if (!_rightBadge.isEmpty()) {
|
||||||
|
|
|
@ -129,8 +129,6 @@ public:
|
||||||
TopicButton *displayedTopicButton() const override;
|
TopicButton *displayedTopicButton() const override;
|
||||||
bool unwrapped() const override;
|
bool unwrapped() const override;
|
||||||
int minWidthForMedia() const override;
|
int minWidthForMedia() const override;
|
||||||
bool hasFastReply() const override;
|
|
||||||
bool displayFastReply() const override;
|
|
||||||
bool displayRightActionComments() const;
|
bool displayRightActionComments() const;
|
||||||
std::optional<QSize> rightActionSize() const override;
|
std::optional<QSize> rightActionSize() const override;
|
||||||
void drawRightAction(
|
void drawRightAction(
|
||||||
|
@ -275,6 +273,10 @@ private:
|
||||||
[[nodiscard]] int visibleMediaTextLength() const;
|
[[nodiscard]] int visibleMediaTextLength() const;
|
||||||
[[nodiscard]] bool needInfoDisplay() const;
|
[[nodiscard]] bool needInfoDisplay() const;
|
||||||
[[nodiscard]] bool invertMedia() 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;
|
[[nodiscard]] bool isPinnedContext() const;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue