mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 13:47:05 +02:00
parent
8a99de16f6
commit
7877463468
7 changed files with 70 additions and 10 deletions
|
@ -279,11 +279,11 @@ void SendBotCallbackDataWithPassword(
|
|||
|
||||
bool SwitchInlineBotButtonReceived(
|
||||
not_null<Window::SessionController*> controller,
|
||||
const QString &query,
|
||||
const QByteArray &queryWithPeerTypes,
|
||||
UserData *samePeerBot,
|
||||
MsgId samePeerReplyTo) {
|
||||
return controller->content()->notify_switchInlineBotButtonReceived(
|
||||
query,
|
||||
QString::fromUtf8(queryWithPeerTypes),
|
||||
samePeerBot,
|
||||
samePeerReplyTo);
|
||||
}
|
||||
|
@ -441,14 +441,14 @@ void ActivateBotCommand(ClickHandlerContext context, int row, int column) {
|
|||
if (samePeer) {
|
||||
SwitchInlineBotButtonReceived(
|
||||
controller,
|
||||
QString::fromUtf8(button->data),
|
||||
button->data,
|
||||
bot,
|
||||
item->id);
|
||||
return true;
|
||||
} else if (bot->isBot() && bot->botInfo->inlineReturnTo.key) {
|
||||
const auto switched = SwitchInlineBotButtonReceived(
|
||||
controller,
|
||||
QString::fromUtf8(button->data));
|
||||
button->data);
|
||||
if (switched) {
|
||||
return true;
|
||||
}
|
||||
|
@ -466,7 +466,9 @@ void ActivateBotCommand(ClickHandlerContext context, int row, int column) {
|
|||
Window::ShowChooseRecipientBox(
|
||||
controller,
|
||||
chosen,
|
||||
tr::lng_inline_switch_choose());
|
||||
tr::lng_inline_switch_choose(),
|
||||
nullptr,
|
||||
button->peerTypes);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
|
|
@ -30,7 +30,7 @@ void SendBotCallbackDataWithPassword(
|
|||
|
||||
bool SwitchInlineBotButtonReceived(
|
||||
not_null<Window::SessionController*> controller,
|
||||
const QString &query,
|
||||
const QByteArray &queryWithPeerTypes,
|
||||
UserData *samePeerBot = nullptr,
|
||||
MsgId samePeerReplyTo = 0);
|
||||
|
||||
|
|
|
@ -117,7 +117,7 @@ void CheckForSwitchInlineButton(not_null<HistoryItem*> item) {
|
|||
if (!windows.empty()) {
|
||||
Api::SwitchInlineBotButtonReceived(
|
||||
windows.front(),
|
||||
QString::fromUtf8(button.data));
|
||||
button.data);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -10,9 +10,32 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_session.h"
|
||||
#include "history/history_item.h"
|
||||
#include "history/history_item_components.h"
|
||||
#include "inline_bots/bot_attach_web_view.h"
|
||||
|
||||
namespace {
|
||||
|
||||
[[nodiscard]] InlineBots::PeerTypes PeerTypesFromMTP(
|
||||
const MTPvector<MTPInlineQueryPeerType> &types) {
|
||||
using namespace InlineBots;
|
||||
auto result = PeerTypes(0);
|
||||
for (const auto &type : types.v) {
|
||||
result |= type.match([&](const MTPDinlineQueryPeerTypePM &data) {
|
||||
return PeerType::User;
|
||||
}, [&](const MTPDinlineQueryPeerTypeChat &data) {
|
||||
return PeerType::Group;
|
||||
}, [&](const MTPDinlineQueryPeerTypeMegagroup &data) {
|
||||
return PeerType::Group;
|
||||
}, [&](const MTPDinlineQueryPeerTypeBroadcast &data) {
|
||||
return PeerType::Broadcast;
|
||||
}, [&](const MTPDinlineQueryPeerTypeBotPM &data) {
|
||||
return PeerType::Bot;
|
||||
}, [&](const MTPDinlineQueryPeerTypeSameBotPM &data) {
|
||||
return PeerType();
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
[[nodiscard]] RequestPeerQuery RequestPeerQueryFromTL(
|
||||
const MTPRequestPeerType &query) {
|
||||
using Type = RequestPeerQuery::Type;
|
||||
|
@ -134,6 +157,9 @@ void HistoryMessageMarkupData::fillRows(
|
|||
// Optimization flag.
|
||||
// Fast check on all new messages if there is a switch button to auto-click it.
|
||||
flags |= ReplyMarkupFlag::HasSwitchInlineButton;
|
||||
if (const auto types = data.vpeer_types()) {
|
||||
row.back().peerTypes = PeerTypesFromMTP(*types);
|
||||
}
|
||||
}
|
||||
}, [&](const MTPDkeyboardButtonGame &data) {
|
||||
row.emplace_back(Type::Game, qs(data.vtext()));
|
||||
|
|
|
@ -14,6 +14,11 @@ namespace Data {
|
|||
class Session;
|
||||
} // namespace Data
|
||||
|
||||
namespace InlineBots {
|
||||
enum class PeerType : uint8;
|
||||
using PeerTypes = base::flags<PeerType>;
|
||||
} // namespace InlineBots
|
||||
|
||||
enum class ReplyMarkupFlag : uint32 {
|
||||
None = (1U << 0),
|
||||
ForceReply = (1U << 1),
|
||||
|
@ -89,6 +94,7 @@ struct HistoryMessageMarkupButton {
|
|||
QString text, forwardText;
|
||||
QByteArray data;
|
||||
int64 buttonId = 0;
|
||||
InlineBots::PeerTypes peerTypes = 0;
|
||||
mutable mtpRequestId requestId = 0;
|
||||
|
||||
};
|
||||
|
|
|
@ -32,6 +32,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "boxes/peers/edit_forum_topic_box.h"
|
||||
#include "boxes/peers/edit_contact_box.h"
|
||||
#include "calls/calls_instance.h"
|
||||
#include "inline_bots/bot_attach_web_view.h" // InlineBots::PeerType.
|
||||
#include "ui/boxes/report_box.h"
|
||||
#include "ui/toast/toast.h"
|
||||
#include "ui/text/format_values.h"
|
||||
|
@ -1602,7 +1603,8 @@ QPointer<Ui::BoxContent> ShowChooseRecipientBox(
|
|||
not_null<Window::SessionNavigation*> navigation,
|
||||
FnMut<bool(not_null<Data::Thread*>)> &&chosen,
|
||||
rpl::producer<QString> titleOverride,
|
||||
FnMut<void()> &&successCallback) {
|
||||
FnMut<void()> &&successCallback,
|
||||
InlineBots::PeerTypes typesRestriction) {
|
||||
const auto weak = std::make_shared<QPointer<Ui::BoxContent>>();
|
||||
auto callback = [
|
||||
chosen = std::move(chosen),
|
||||
|
@ -1618,6 +1620,23 @@ QPointer<Ui::BoxContent> ShowChooseRecipientBox(
|
|||
success();
|
||||
}
|
||||
};
|
||||
auto filter = typesRestriction
|
||||
? [=](not_null<Data::Thread*> thread) -> bool {
|
||||
using namespace InlineBots;
|
||||
const auto peer = thread->peer();
|
||||
if (const auto user = peer->asUser()) {
|
||||
if (user->isBot()) {
|
||||
return (typesRestriction & PeerType::Bot);
|
||||
} else {
|
||||
return (typesRestriction & PeerType::User);
|
||||
}
|
||||
} else if (peer->isBroadcast()) {
|
||||
return (typesRestriction & PeerType::Broadcast);
|
||||
} else {
|
||||
return (typesRestriction & PeerType::Group);
|
||||
}
|
||||
}
|
||||
: Fn<bool(not_null<Data::Thread*>)>();
|
||||
auto initBox = [=](not_null<PeerListBox*> box) {
|
||||
box->addButton(tr::lng_cancel(), [box] {
|
||||
box->closeBox();
|
||||
|
@ -1629,7 +1648,8 @@ QPointer<Ui::BoxContent> ShowChooseRecipientBox(
|
|||
*weak = navigation->parentController()->show(Box<PeerListBox>(
|
||||
std::make_unique<ChooseRecipientBoxController>(
|
||||
&navigation->session(),
|
||||
std::move(callback)),
|
||||
std::move(callback),
|
||||
std::move(filter)),
|
||||
std::move(initBox)));
|
||||
return weak->data();
|
||||
}
|
||||
|
|
|
@ -38,6 +38,11 @@ namespace ChatHelpers {
|
|||
class Show;
|
||||
} // namespace ChatHelpers
|
||||
|
||||
namespace InlineBots {
|
||||
enum class PeerType : uint8;
|
||||
using PeerTypes = base::flags<PeerType>;
|
||||
} // namespace InlineBots
|
||||
|
||||
namespace Window {
|
||||
|
||||
class Controller;
|
||||
|
@ -122,7 +127,8 @@ QPointer<Ui::BoxContent> ShowChooseRecipientBox(
|
|||
not_null<Window::SessionNavigation*> navigation,
|
||||
FnMut<bool(not_null<Data::Thread*>)> &&chosen,
|
||||
rpl::producer<QString> titleOverride = nullptr,
|
||||
FnMut<void()> &&successCallback = nullptr);
|
||||
FnMut<void()> &&successCallback = nullptr,
|
||||
InlineBots::PeerTypes typesRestriction = 0);
|
||||
QPointer<Ui::BoxContent> ShowForwardMessagesBox(
|
||||
std::shared_ptr<ChatHelpers::Show> show,
|
||||
Data::ForwardDraft &&draft,
|
||||
|
|
Loading…
Add table
Reference in a new issue