Introduce fast-buttons-bots for support mode.

This commit is contained in:
John Preston
2025-01-27 17:57:12 +04:00
parent 3cebd6d923
commit da426ae03b
10 changed files with 238 additions and 24 deletions
@@ -50,6 +50,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "main/main_session.h"
#include "window/window_session_controller.h"
#include "api/api_bot.h"
#include "support/support_helper.h"
#include "styles/style_boxes.h"
#include "styles/style_chat.h"
#include "styles/style_dialogs.h" // dialogsMiniReplyStory.
@@ -880,12 +881,17 @@ void ReplyKeyboard::paint(
Assert(_width > 0);
_st->startPaint(p, st);
auto number = hasFastButtonMode() ? 1 : 0;
for (auto y = 0, rowsCount = int(_rows.size()); y != rowsCount; ++y) {
for (auto x = 0, count = int(_rows[y].size()); x != count; ++x) {
const auto guard = gsl::finally([&] { if (number) ++number; });
const auto &button = _rows[y][x];
const auto rect = button.rect;
if (rect.y() >= clip.y() + clip.height()) return;
if (rect.y() + rect.height() < clip.y()) continue;
if (rect.y() >= clip.y() + clip.height()) {
return;
} else if (rect.y() + rect.height() < clip.y()) {
continue;
}
// just ignore the buttons that didn't layout well
if (rect.x() + rect.width() > _width) break;
@@ -904,10 +910,27 @@ void ReplyKeyboard::paint(
? Corner::Large
: Corner::Small;
_st->paintButton(p, st, outerWidth, button, buttonRounding);
if (number) {
p.setFont(st::dialogsUnreadFont);
p.setPen(st->msgServiceFg());
p.drawText(
rect.x() + st::msgBotKbIconPadding,
rect.y() + st::dialogsUnreadFont->ascent,
QString::number(number));
}
}
}
}
bool ReplyKeyboard::hasFastButtonMode() const {
return _item->inlineReplyKeyboard()
&& (_item == _item->history()->lastMessage())
&& _item->history()->session().supportMode()
&& _item->history()->session().supportHelper().fastButtonMode(
_item->history()->peer);
}
ClickHandlerPtr ReplyKeyboard::getLink(QPoint point) const {
Assert(_width > 0);
@@ -927,6 +950,19 @@ ClickHandlerPtr ReplyKeyboard::getLink(QPoint point) const {
return ClickHandlerPtr();
}
ClickHandlerPtr ReplyKeyboard::getLinkByIndex(int index) const {
auto number = 1;
for (const auto &row : _rows) {
for (const auto &button : row) {
if (number == index + 1) {
return button.link;
}
++number;
}
}
return ClickHandlerPtr();
}
void ReplyKeyboard::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) {
if (!p) return;