mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Support request_write_access flag in attach bots.
This commit is contained in:
parent
c647afec02
commit
7d9b999cb0
2 changed files with 59 additions and 23 deletions
|
@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/boxes/confirm_box.h"
|
#include "ui/boxes/confirm_box.h"
|
||||||
#include "ui/toasts/common_toasts.h"
|
#include "ui/toasts/common_toasts.h"
|
||||||
#include "ui/chat/attach/attach_bot_webview.h"
|
#include "ui/chat/attach/attach_bot_webview.h"
|
||||||
|
#include "ui/widgets/checkbox.h"
|
||||||
#include "ui/widgets/dropdown_menu.h"
|
#include "ui/widgets/dropdown_menu.h"
|
||||||
#include "ui/widgets/popup_menu.h"
|
#include "ui/widgets/popup_menu.h"
|
||||||
#include "ui/widgets/menu/menu_item_base.h"
|
#include "ui/widgets/menu/menu_item_base.h"
|
||||||
|
@ -41,6 +42,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "base/random.h"
|
#include "base/random.h"
|
||||||
#include "base/timer_rpl.h"
|
#include "base/timer_rpl.h"
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
|
#include "styles/style_boxes.h"
|
||||||
#include "styles/style_menu_icons.h"
|
#include "styles/style_menu_icons.h"
|
||||||
|
|
||||||
#include <QSvgRenderer>
|
#include <QSvgRenderer>
|
||||||
|
@ -121,6 +123,7 @@ struct ParsedBot {
|
||||||
.types = ResolvePeerTypes(data.vpeer_types().v),
|
.types = ResolvePeerTypes(data.vpeer_types().v),
|
||||||
.inactive = data.is_inactive(),
|
.inactive = data.is_inactive(),
|
||||||
.hasSettings = data.is_has_settings(),
|
.hasSettings = data.is_has_settings(),
|
||||||
|
.requestWriteAccess = data.is_request_write_access(),
|
||||||
} : std::optional<AttachWebViewBot>();
|
} : std::optional<AttachWebViewBot>();
|
||||||
});
|
});
|
||||||
if (result && result->icon) {
|
if (result && result->icon) {
|
||||||
|
@ -636,7 +639,7 @@ void AttachWebView::requestAddToMenu(
|
||||||
}
|
}
|
||||||
|
|
||||||
void AttachWebView::removeFromMenu(not_null<UserData*> bot) {
|
void AttachWebView::removeFromMenu(not_null<UserData*> bot) {
|
||||||
toggleInMenu(bot, false, [=] {
|
toggleInMenu(bot, ToggledState::Removed, [=] {
|
||||||
Ui::ShowMultilineToast({
|
Ui::ShowMultilineToast({
|
||||||
.text = { tr::lng_bot_remove_from_menu_done(tr::now) },
|
.text = { tr::lng_bot_remove_from_menu_done(tr::now) },
|
||||||
});
|
});
|
||||||
|
@ -965,39 +968,66 @@ void AttachWebView::started(uint64 queryId) {
|
||||||
void AttachWebView::confirmAddToMenu(
|
void AttachWebView::confirmAddToMenu(
|
||||||
AttachWebViewBot bot,
|
AttachWebViewBot bot,
|
||||||
Fn<void()> callback) {
|
Fn<void()> callback) {
|
||||||
const auto done = [=](Fn<void()> close) {
|
|
||||||
toggleInMenu(bot.user, true, [=] {
|
|
||||||
if (callback) {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
Ui::ShowMultilineToast({
|
|
||||||
.text = { tr::lng_bot_add_to_menu_done(tr::now) },
|
|
||||||
});
|
|
||||||
});
|
|
||||||
close();
|
|
||||||
};
|
|
||||||
const auto active = Core::App().activeWindow();
|
const auto active = Core::App().activeWindow();
|
||||||
if (!active) {
|
if (!active) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_confirmAddBox = active->show(Ui::MakeConfirmBox({
|
_confirmAddBox = active->show(Box([=](not_null<Ui::GenericBox*> box) {
|
||||||
tr::lng_bot_add_to_menu(
|
const auto allowed = std::make_shared<Ui::Checkbox*>();
|
||||||
tr::now,
|
const auto done = [=](Fn<void()> close) {
|
||||||
lt_bot,
|
const auto state = ((*allowed) && (*allowed)->checked())
|
||||||
Ui::Text::Bold(bot.name),
|
? ToggledState::AllowedToWrite
|
||||||
Ui::Text::WithEntities),
|
: ToggledState::Added;
|
||||||
done,
|
toggleInMenu(bot.user, state, [=] {
|
||||||
|
if (callback) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
Ui::ShowMultilineToast({
|
||||||
|
.text = { tr::lng_bot_add_to_menu_done(tr::now) },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
close();
|
||||||
|
};
|
||||||
|
Ui::ConfirmBox(box, {
|
||||||
|
tr::lng_bot_add_to_menu(
|
||||||
|
tr::now,
|
||||||
|
lt_bot,
|
||||||
|
Ui::Text::Bold(bot.name),
|
||||||
|
Ui::Text::WithEntities),
|
||||||
|
done,
|
||||||
|
});
|
||||||
|
if (bot.requestWriteAccess) {
|
||||||
|
(*allowed) = box->addRow(
|
||||||
|
object_ptr<Ui::Checkbox>(
|
||||||
|
box,
|
||||||
|
tr::lng_url_auth_allow_messages(
|
||||||
|
tr::now,
|
||||||
|
lt_bot,
|
||||||
|
Ui::Text::Bold(bot.name),
|
||||||
|
Ui::Text::WithEntities),
|
||||||
|
true,
|
||||||
|
st::urlAuthCheckbox),
|
||||||
|
style::margins(
|
||||||
|
st::boxRowPadding.left(),
|
||||||
|
st::boxPhotoCaptionSkip,
|
||||||
|
st::boxRowPadding.right(),
|
||||||
|
st::boxPhotoCaptionSkip));
|
||||||
|
(*allowed)->setAllowTextLines();
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AttachWebView::toggleInMenu(
|
void AttachWebView::toggleInMenu(
|
||||||
not_null<UserData*> bot,
|
not_null<UserData*> bot,
|
||||||
bool enabled,
|
ToggledState state,
|
||||||
Fn<void()> callback) {
|
Fn<void()> callback) {
|
||||||
|
using Flag = MTPmessages_ToggleBotInAttachMenu::Flag;
|
||||||
_session->api().request(MTPmessages_ToggleBotInAttachMenu(
|
_session->api().request(MTPmessages_ToggleBotInAttachMenu(
|
||||||
MTP_flags(0),
|
MTP_flags((state == ToggledState::AllowedToWrite)
|
||||||
|
? Flag::f_write_allowed
|
||||||
|
: Flag()),
|
||||||
bot->inputUser,
|
bot->inputUser,
|
||||||
MTP_bool(enabled)
|
MTP_bool(state != ToggledState::Removed)
|
||||||
)).done([=] {
|
)).done([=] {
|
||||||
_requestId = 0;
|
_requestId = 0;
|
||||||
requestBots();
|
requestBots();
|
||||||
|
|
|
@ -58,6 +58,7 @@ struct AttachWebViewBot {
|
||||||
PeerTypes types = 0;
|
PeerTypes types = 0;
|
||||||
bool inactive = false;
|
bool inactive = false;
|
||||||
bool hasSettings = false;
|
bool hasSettings = false;
|
||||||
|
bool requestWriteAccess = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AttachWebView final : public base::has_weak_ptr {
|
class AttachWebView final : public base::has_weak_ptr {
|
||||||
|
@ -120,9 +121,14 @@ private:
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
Fn<void()> done);
|
Fn<void()> done);
|
||||||
|
|
||||||
|
enum class ToggledState {
|
||||||
|
Removed,
|
||||||
|
Added,
|
||||||
|
AllowedToWrite,
|
||||||
|
};
|
||||||
void toggleInMenu(
|
void toggleInMenu(
|
||||||
not_null<UserData*> bot,
|
not_null<UserData*> bot,
|
||||||
bool enabled,
|
ToggledState state,
|
||||||
Fn<void()> callback = nullptr);
|
Fn<void()> callback = nullptr);
|
||||||
|
|
||||||
void show(
|
void show(
|
||||||
|
|
Loading…
Add table
Reference in a new issue