Added ability to see url of inline button in tooltip.

Fixed #5457.
This commit is contained in:
23rd 2021-01-22 02:36:22 +03:00 committed by John Preston
parent 5277080115
commit dc631ef631
2 changed files with 31 additions and 17 deletions

View file

@ -413,23 +413,13 @@ ReplyMarkupClickHandler::ReplyMarkupClickHandler(
// Copy to clipboard support. // Copy to clipboard support.
QString ReplyMarkupClickHandler::copyToClipboardText() const { QString ReplyMarkupClickHandler::copyToClipboardText() const {
if (const auto button = getButton()) { const auto button = getUrlButton();
using Type = HistoryMessageMarkupButton::Type; return button ? QString::fromUtf8(button->data) : QString();
if (button->type == Type::Url || button->type == Type::Auth) {
return QString::fromUtf8(button->data);
}
}
return QString();
} }
QString ReplyMarkupClickHandler::copyToClipboardContextItemText() const { QString ReplyMarkupClickHandler::copyToClipboardContextItemText() const {
if (const auto button = getButton()) { const auto button = getUrlButton();
using Type = HistoryMessageMarkupButton::Type; return button ? tr::lng_context_copy_link(tr::now) : QString();
if (button->type == Type::Url || button->type == Type::Auth) {
return tr::lng_context_copy_link(tr::now);
}
}
return QString();
} }
// Finds the corresponding button in the items markup struct. // Finds the corresponding button in the items markup struct.
@ -440,6 +430,17 @@ const HistoryMessageMarkupButton *ReplyMarkupClickHandler::getButton() const {
return HistoryMessageMarkupButton::Get(_owner, _itemId, _row, _column); return HistoryMessageMarkupButton::Get(_owner, _itemId, _row, _column);
} }
auto ReplyMarkupClickHandler::getUrlButton() const
-> const HistoryMessageMarkupButton* {
if (const auto button = getButton()) {
using Type = HistoryMessageMarkupButton::Type;
if (button->type == Type::Url || button->type == Type::Auth) {
return button;
}
}
return nullptr;
}
void ReplyMarkupClickHandler::onClickImpl() const { void ReplyMarkupClickHandler::onClickImpl() const {
if (const auto item = _owner->message(_itemId)) { if (const auto item = _owner->message(_itemId)) {
App::activateBotCommand(item, _row, _column); App::activateBotCommand(item, _row, _column);
@ -454,6 +455,19 @@ QString ReplyMarkupClickHandler::buttonText() const {
return QString(); return QString();
} }
QString ReplyMarkupClickHandler::tooltip() const {
const auto button = getUrlButton();
const auto url = button ? QString::fromUtf8(button->data) : QString();
const auto text = _fullDisplayed ? QString() : buttonText();
if (!url.isEmpty() && !text.isEmpty()) {
return QString("%1\n\n%2").arg(text).arg(url);
} else if (url.isEmpty() != text.isEmpty()) {
return text + url;
} else {
return QString();
}
}
ReplyKeyboard::Button::Button() = default; ReplyKeyboard::Button::Button() = default;
ReplyKeyboard::Button::Button(Button &&other) = default; ReplyKeyboard::Button::Button(Button &&other) = default;
ReplyKeyboard::Button &ReplyKeyboard::Button::operator=( ReplyKeyboard::Button &ReplyKeyboard::Button::operator=(

View file

@ -251,9 +251,7 @@ public:
int column, int column,
FullMsgId context); FullMsgId context);
QString tooltip() const override { QString tooltip() const override;
return _fullDisplayed ? QString() : buttonText();
}
void setFullDisplayed(bool full) { void setFullDisplayed(bool full) {
_fullDisplayed = full; _fullDisplayed = full;
@ -269,6 +267,8 @@ public:
// than the one was used when constructing the handler, but not a big deal. // than the one was used when constructing the handler, but not a big deal.
const HistoryMessageMarkupButton *getButton() const; const HistoryMessageMarkupButton *getButton() const;
const HistoryMessageMarkupButton *getUrlButton() const;
// We hold only FullMsgId, not HistoryItem*, because all click handlers // We hold only FullMsgId, not HistoryItem*, because all click handlers
// are activated async and the item may be already destroyed. // are activated async and the item may be already destroyed.
void setMessageId(const FullMsgId &msgId) { void setMessageId(const FullMsgId &msgId) {