mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Push click handler context to Api::ActivateBotCommand.
This commit is contained in:
parent
8e8a209aad
commit
8bb3cd7e65
8 changed files with 85 additions and 45 deletions
|
@ -276,11 +276,15 @@ bool SwitchInlineBotButtonReceived(
|
||||||
samePeerReplyTo);
|
samePeerReplyTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActivateBotCommand(
|
void ActivateBotCommand(ClickHandlerContext context, int row, int column) {
|
||||||
not_null<Window::SessionController*> controller,
|
const auto controller = context.sessionWindow.get();
|
||||||
not_null<HistoryItem*> item,
|
if (!controller) {
|
||||||
int row,
|
return;
|
||||||
int column) {
|
}
|
||||||
|
const auto item = controller->session().data().message(context.itemId);
|
||||||
|
if (!item) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const auto button = HistoryMessageMarkupButton::Get(
|
const auto button = HistoryMessageMarkupButton::Get(
|
||||||
&item->history()->owner(),
|
&item->history()->owner(),
|
||||||
item->fullId(),
|
item->fullId(),
|
||||||
|
@ -330,13 +334,11 @@ void ActivateBotCommand(
|
||||||
skipConfirmation = true;
|
skipConfirmation = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const auto context = QVariant::fromValue(ClickHandlerContext{
|
const auto variant = QVariant::fromValue(context);
|
||||||
.sessionWindow = controller.get(),
|
|
||||||
});
|
|
||||||
if (skipConfirmation) {
|
if (skipConfirmation) {
|
||||||
UrlClickHandler::Open(url, context);
|
UrlClickHandler::Open(url, variant);
|
||||||
} else {
|
} else {
|
||||||
HiddenUrlClickHandler::Open(url, context);
|
HiddenUrlClickHandler::Open(url, variant);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
struct ClickHandlerContext;
|
||||||
class HistoryItem;
|
class HistoryItem;
|
||||||
|
|
||||||
namespace Window {
|
namespace Window {
|
||||||
|
@ -33,10 +34,6 @@ bool SwitchInlineBotButtonReceived(
|
||||||
UserData *samePeerBot = nullptr,
|
UserData *samePeerBot = nullptr,
|
||||||
MsgId samePeerReplyTo = 0);
|
MsgId samePeerReplyTo = 0);
|
||||||
|
|
||||||
void ActivateBotCommand(
|
void ActivateBotCommand(ClickHandlerContext context, int row, int column);
|
||||||
not_null<Window::SessionController*> controller,
|
|
||||||
not_null<HistoryItem*> item,
|
|
||||||
int row,
|
|
||||||
int column);
|
|
||||||
|
|
||||||
} // namespace Api
|
} // namespace Api
|
||||||
|
|
|
@ -169,7 +169,9 @@ void BotKeyboard::leaveEventHook(QEvent *e) {
|
||||||
clearSelection();
|
clearSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BotKeyboard::moderateKeyActivate(int key) {
|
bool BotKeyboard::moderateKeyActivate(
|
||||||
|
int key,
|
||||||
|
Fn<ClickContext(FullMsgId)> context) {
|
||||||
const auto &data = _controller->session().data();
|
const auto &data = _controller->session().data();
|
||||||
|
|
||||||
const auto botCommand = [](int key) {
|
const auto botCommand = [](int key) {
|
||||||
|
@ -202,7 +204,11 @@ bool BotKeyboard::moderateKeyActivate(int key) {
|
||||||
if (!markup->data.rows.empty()
|
if (!markup->data.rows.empty()
|
||||||
&& index >= 0
|
&& index >= 0
|
||||||
&& index < int(markup->data.rows.front().size())) {
|
&& index < int(markup->data.rows.front().size())) {
|
||||||
Api::ActivateBotCommand(_controller, item, 0, index);
|
Api::ActivateBotCommand(
|
||||||
|
context(
|
||||||
|
_wasForMsgId).other.value<ClickHandlerContext>(),
|
||||||
|
0,
|
||||||
|
index);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (const auto user = item->history()->peer->asUser()) {
|
} else if (const auto user = item->history()->peer->asUser()) {
|
||||||
|
|
|
@ -29,7 +29,7 @@ public:
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
QWidget *parent);
|
QWidget *parent);
|
||||||
|
|
||||||
bool moderateKeyActivate(int index);
|
bool moderateKeyActivate(int index, Fn<ClickContext(FullMsgId)> context);
|
||||||
|
|
||||||
// With force=true the markup is updated even if it is
|
// With force=true the markup is updated even if it is
|
||||||
// already shown for the passed history item.
|
// already shown for the passed history item.
|
||||||
|
|
|
@ -1793,23 +1793,10 @@ void HistoryInner::mouseActionFinish(
|
||||||
? pressedItemView->data()->fullId()
|
? pressedItemView->data()->fullId()
|
||||||
: FullMsgId();
|
: FullMsgId();
|
||||||
const auto weak = base::make_weak(_controller.get());
|
const auto weak = base::make_weak(_controller.get());
|
||||||
ActivateClickHandler(window(), activated, {
|
ActivateClickHandler(
|
||||||
button,
|
window(),
|
||||||
QVariant::fromValue(ClickHandlerContext{
|
activated,
|
||||||
.itemId = pressedItemId,
|
prepareClickContext(button, pressedItemId));
|
||||||
.elementDelegate = [=]() -> HistoryView::ElementDelegate* {
|
|
||||||
if (const auto strong = weak.get()) {
|
|
||||||
auto &data = strong->session().data();
|
|
||||||
if (const auto item = data.message(pressedItemId)) {
|
|
||||||
const auto history = item->history();
|
|
||||||
return history->delegateMixin()->delegate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
},
|
|
||||||
.sessionWindow = weak,
|
|
||||||
})
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((_mouseAction == MouseAction::PrepareSelect)
|
if ((_mouseAction == MouseAction::PrepareSelect)
|
||||||
|
@ -4110,6 +4097,39 @@ void HistoryInner::onParentGeometryChanged() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Fn<HistoryView::ElementDelegate*()> HistoryInner::elementDelegateFactory(
|
||||||
|
FullMsgId itemId) const {
|
||||||
|
const auto weak = base::make_weak(_controller.get());
|
||||||
|
return [=]() -> HistoryView::ElementDelegate* {
|
||||||
|
if (const auto strong = weak.get()) {
|
||||||
|
auto &data = strong->session().data();
|
||||||
|
if (const auto item = data.message(itemId)) {
|
||||||
|
const auto history = item->history();
|
||||||
|
return history->delegateMixin()->delegate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
ClickHandlerContext HistoryInner::prepareClickHandlerContext(
|
||||||
|
FullMsgId itemId) const {
|
||||||
|
return ClickHandlerContext{
|
||||||
|
.itemId = itemId,
|
||||||
|
.elementDelegate = elementDelegateFactory(itemId),
|
||||||
|
.sessionWindow = base::make_weak(_controller.get()),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
ClickContext HistoryInner::prepareClickContext(
|
||||||
|
Qt::MouseButton button,
|
||||||
|
FullMsgId itemId) const {
|
||||||
|
return {
|
||||||
|
button,
|
||||||
|
QVariant::fromValue(prepareClickHandlerContext(itemId)),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
auto HistoryInner::DelegateMixin()
|
auto HistoryInner::DelegateMixin()
|
||||||
-> std::unique_ptr<HistoryMainElementDelegateMixin> {
|
-> std::unique_ptr<HistoryMainElementDelegateMixin> {
|
||||||
return std::make_unique<HistoryMainElementDelegate>();
|
return std::make_unique<HistoryMainElementDelegate>();
|
||||||
|
|
|
@ -15,6 +15,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/widgets/scroll_area.h"
|
#include "ui/widgets/scroll_area.h"
|
||||||
#include "history/view/history_view_top_bar_widget.h"
|
#include "history/view/history_view_top_bar_widget.h"
|
||||||
|
|
||||||
|
struct ClickContext;
|
||||||
|
struct ClickHandlerContext;
|
||||||
|
|
||||||
namespace Data {
|
namespace Data {
|
||||||
struct Group;
|
struct Group;
|
||||||
class CloudImageView;
|
class CloudImageView;
|
||||||
|
@ -189,6 +192,14 @@ public:
|
||||||
|
|
||||||
void onParentGeometryChanged();
|
void onParentGeometryChanged();
|
||||||
|
|
||||||
|
[[nodiscard]] Fn<HistoryView::ElementDelegate*()> elementDelegateFactory(
|
||||||
|
FullMsgId itemId) const;
|
||||||
|
[[nodiscard]] ClickHandlerContext prepareClickHandlerContext(
|
||||||
|
FullMsgId itemId) const;
|
||||||
|
[[nodiscard]] ClickContext prepareClickContext(
|
||||||
|
Qt::MouseButton button,
|
||||||
|
FullMsgId itemId) const;
|
||||||
|
|
||||||
[[nodiscard]] static auto DelegateMixin()
|
[[nodiscard]] static auto DelegateMixin()
|
||||||
-> std::unique_ptr<HistoryMainElementDelegateMixin>;
|
-> std::unique_ptr<HistoryMainElementDelegateMixin>;
|
||||||
|
|
||||||
|
|
|
@ -523,12 +523,9 @@ void ReplyMarkupClickHandler::onClick(ClickContext context) const {
|
||||||
if (context.button != Qt::LeftButton) {
|
if (context.button != Qt::LeftButton) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto my = context.other.value<ClickHandlerContext>();
|
auto my = context.other.value<ClickHandlerContext>();
|
||||||
if (const auto controller = my.sessionWindow.get()) {
|
my.itemId = _itemId;
|
||||||
if (const auto item = _owner->message(_itemId)) {
|
Api::ActivateBotCommand(my, _row, _column);
|
||||||
Api::ActivateBotCommand(controller, item, _row, _column);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the full text of the corresponding button.
|
// Returns the full text of the corresponding button.
|
||||||
|
|
|
@ -428,9 +428,12 @@ HistoryWidget::HistoryWidget(
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
_fieldAutocomplete->setModerateKeyActivateCallback([=](int key) {
|
_fieldAutocomplete->setModerateKeyActivateCallback([=](int key) {
|
||||||
return _keyboard->isHidden()
|
const auto context = [=](FullMsgId itemId) {
|
||||||
? false
|
return _list->prepareClickContext(Qt::LeftButton, itemId);
|
||||||
: _keyboard->moderateKeyActivate(key);
|
};
|
||||||
|
return !_keyboard->isHidden() && _keyboard->moderateKeyActivate(
|
||||||
|
key,
|
||||||
|
context);
|
||||||
});
|
});
|
||||||
|
|
||||||
_fieldAutocomplete->choosingProcesses(
|
_fieldAutocomplete->choosingProcesses(
|
||||||
|
@ -6356,6 +6359,7 @@ void HistoryWidget::setupPinnedTracker() {
|
||||||
|
|
||||||
void HistoryWidget::checkPinnedBarState() {
|
void HistoryWidget::checkPinnedBarState() {
|
||||||
Expects(_pinnedTracker != nullptr);
|
Expects(_pinnedTracker != nullptr);
|
||||||
|
Expects(_list != nullptr);
|
||||||
|
|
||||||
const auto hiddenId = _peer->canPinMessages()
|
const auto hiddenId = _peer->canPinMessages()
|
||||||
? MsgId(0)
|
? MsgId(0)
|
||||||
|
@ -6522,7 +6526,10 @@ void HistoryWidget::refreshPinnedBarButton(bool many, HistoryItem *item) {
|
||||||
Ui::RoundButton::TextTransform::NoTransform);
|
Ui::RoundButton::TextTransform::NoTransform);
|
||||||
button->setFullRadius(true);
|
button->setFullRadius(true);
|
||||||
button->setClickedCallback([=] {
|
button->setClickedCallback([=] {
|
||||||
Api::ActivateBotCommand(controller(), item, 0, 0);
|
Api::ActivateBotCommand(
|
||||||
|
_list->prepareClickHandlerContext(item->fullId()),
|
||||||
|
0,
|
||||||
|
0);
|
||||||
});
|
});
|
||||||
if (button->width() > st::historyPinnedBotButtonMaxWidth) {
|
if (button->width() > st::historyPinnedBotButtonMaxWidth) {
|
||||||
button->setFullWidth(st::historyPinnedBotButtonMaxWidth);
|
button->setFullWidth(st::historyPinnedBotButtonMaxWidth);
|
||||||
|
|
Loading…
Add table
Reference in a new issue