mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Check if bot supports Telegram Business.
This commit is contained in:
parent
f65bc7c0bd
commit
0d740c21a2
4 changed files with 30 additions and 12 deletions
|
@ -2316,6 +2316,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_chatbots_reply_about" = "The bot will be able to view all new incoming messages, but not the messages that had been sent before you added the bot.";
|
"lng_chatbots_reply_about" = "The bot will be able to view all new incoming messages, but not the messages that had been sent before you added the bot.";
|
||||||
"lng_chatbots_remove" = "Remove Bot";
|
"lng_chatbots_remove" = "Remove Bot";
|
||||||
"lng_chatbots_not_found" = "Chatbot not found.";
|
"lng_chatbots_not_found" = "Chatbot not found.";
|
||||||
|
"lng_chatbots_not_supported" = "This bot doesn't support Telegram Business yet.";
|
||||||
"lng_chatbots_add" = "Add";
|
"lng_chatbots_add" = "Add";
|
||||||
"lng_chatbots_info_url" = "https://telegram.org/privacy";
|
"lng_chatbots_info_url" = "https://telegram.org/privacy";
|
||||||
"lng_chatbot_status_can_reply" = "bot manages this chat";
|
"lng_chatbot_status_can_reply" = "bot manages this chat";
|
||||||
|
|
|
@ -722,6 +722,7 @@ not_null<UserData*> Session::processUser(const MTPUser &data) {
|
||||||
result->botInfo->inlinePlaceholder = QString();
|
result->botInfo->inlinePlaceholder = QString();
|
||||||
}
|
}
|
||||||
result->botInfo->supportsAttachMenu = data.is_bot_attach_menu();
|
result->botInfo->supportsAttachMenu = data.is_bot_attach_menu();
|
||||||
|
result->botInfo->supportsBusiness = data.is_bot_business();
|
||||||
result->botInfo->canEditInformation = data.is_bot_can_edit();
|
result->botInfo->canEditInformation = data.is_bot_can_edit();
|
||||||
} else {
|
} else {
|
||||||
result->setBotInfoVersion(-1);
|
result->setBotInfoVersion(-1);
|
||||||
|
|
|
@ -22,13 +22,6 @@ struct BusinessDetails;
|
||||||
struct BotInfo {
|
struct BotInfo {
|
||||||
BotInfo();
|
BotInfo();
|
||||||
|
|
||||||
bool inited = false;
|
|
||||||
bool readsAllHistory = false;
|
|
||||||
bool cantJoinGroups = false;
|
|
||||||
bool supportsAttachMenu = false;
|
|
||||||
bool canEditInformation = false;
|
|
||||||
int version = 0;
|
|
||||||
int descriptionVersion = 0;
|
|
||||||
QString description;
|
QString description;
|
||||||
QString inlinePlaceholder;
|
QString inlinePlaceholder;
|
||||||
std::vector<Data::BotCommand> commands;
|
std::vector<Data::BotCommand> commands;
|
||||||
|
@ -44,6 +37,15 @@ struct BotInfo {
|
||||||
|
|
||||||
ChatAdminRights groupAdminRights;
|
ChatAdminRights groupAdminRights;
|
||||||
ChatAdminRights channelAdminRights;
|
ChatAdminRights channelAdminRights;
|
||||||
|
|
||||||
|
int version = 0;
|
||||||
|
int descriptionVersion = 0;
|
||||||
|
bool inited : 1 = false;
|
||||||
|
bool readsAllHistory : 1 = false;
|
||||||
|
bool cantJoinGroups : 1 = false;
|
||||||
|
bool supportsAttachMenu : 1 = false;
|
||||||
|
bool canEditInformation : 1 = false;
|
||||||
|
bool supportsBusiness : 1 = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class UserDataFlag : uint32 {
|
enum class UserDataFlag : uint32 {
|
||||||
|
|
|
@ -38,6 +38,7 @@ constexpr auto kDebounceTimeout = crl::time(400);
|
||||||
enum class LookupState {
|
enum class LookupState {
|
||||||
Empty,
|
Empty,
|
||||||
Loading,
|
Loading,
|
||||||
|
Unsupported,
|
||||||
Ready,
|
Ready,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -247,9 +248,14 @@ Main::Session &PreviewController::session() const {
|
||||||
return rpl::single(BotState());
|
return rpl::single(BotState());
|
||||||
} else if (const auto peer = owner->peerByUsername(extracted)) {
|
} else if (const auto peer = owner->peerByUsername(extracted)) {
|
||||||
if (const auto user = peer->asUser(); user && user->isBot()) {
|
if (const auto user = peer->asUser(); user && user->isBot()) {
|
||||||
|
if (user->botInfo->supportsBusiness) {
|
||||||
|
return rpl::single(BotState{
|
||||||
|
.bot = user,
|
||||||
|
.state = LookupState::Ready,
|
||||||
|
});
|
||||||
|
}
|
||||||
return rpl::single(BotState{
|
return rpl::single(BotState{
|
||||||
.bot = user,
|
.state = LookupState::Unsupported,
|
||||||
.state = LookupState::Ready,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return rpl::single(BotState{
|
return rpl::single(BotState{
|
||||||
|
@ -314,7 +320,10 @@ Main::Session &PreviewController::session() const {
|
||||||
std::move(state) | rpl::filter([=](BotState state) {
|
std::move(state) | rpl::filter([=](BotState state) {
|
||||||
return state.state != LookupState::Loading;
|
return state.state != LookupState::Loading;
|
||||||
}) | rpl::start_with_next([=](BotState state) {
|
}) | rpl::start_with_next([=](BotState state) {
|
||||||
raw->toggle(state.state == LookupState::Ready, anim::type::normal);
|
raw->toggle(
|
||||||
|
(state.state == LookupState::Ready
|
||||||
|
|| state.state == LookupState::Unsupported),
|
||||||
|
anim::type::normal);
|
||||||
if (state.bot) {
|
if (state.bot) {
|
||||||
const auto delegate = parent->lifetime().make_state<
|
const auto delegate = parent->lifetime().make_state<
|
||||||
PeerListContentDelegateSimple
|
PeerListContentDelegateSimple
|
||||||
|
@ -330,11 +339,14 @@ Main::Session &PreviewController::session() const {
|
||||||
controller->setDelegate(delegate);
|
controller->setDelegate(delegate);
|
||||||
delete base::take(*child);
|
delete base::take(*child);
|
||||||
*child = content;
|
*child = content;
|
||||||
} else if (state.state == LookupState::Ready) {
|
} else if (state.state == LookupState::Ready
|
||||||
|
|| state.state == LookupState::Unsupported) {
|
||||||
const auto content = Ui::CreateChild<Ui::RpWidget>(inner);
|
const auto content = Ui::CreateChild<Ui::RpWidget>(inner);
|
||||||
const auto label = Ui::CreateChild<Ui::FlatLabel>(
|
const auto label = Ui::CreateChild<Ui::FlatLabel>(
|
||||||
content,
|
content,
|
||||||
tr::lng_chatbots_not_found(),
|
(state.state == LookupState::Unsupported
|
||||||
|
? tr::lng_chatbots_not_supported()
|
||||||
|
: tr::lng_chatbots_not_found()),
|
||||||
st::settingsChatbotsNotFound);
|
st::settingsChatbotsNotFound);
|
||||||
content->resize(
|
content->resize(
|
||||||
inner->width(),
|
inner->width(),
|
||||||
|
@ -483,6 +495,8 @@ void Chatbots::save() {
|
||||||
const auto fail = [=](QString error) {
|
const auto fail = [=](QString error) {
|
||||||
if (error == u"BUSINESS_RECIPIENTS_EMPTY"_q) {
|
if (error == u"BUSINESS_RECIPIENTS_EMPTY"_q) {
|
||||||
show->showToast(tr::lng_greeting_recipients_empty(tr::now));
|
show->showToast(tr::lng_greeting_recipients_empty(tr::now));
|
||||||
|
} else if (error == u"BOT_BUSINESS_MISSING"_q) {
|
||||||
|
show->showToast(tr::lng_chatbots_not_supported(tr::now));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
controller()->session().data().chatbots().save({
|
controller()->session().data().chatbots().save({
|
||||||
|
|
Loading…
Add table
Reference in a new issue