mirror of
https://github.com/Qz3rK/tdesktop.git
synced 2026-07-03 14:15:08 +02:00
Implement new business bots permissions.
This commit is contained in:
@@ -8,10 +8,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "data/business/data_business_chatbots.h"
|
||||
|
||||
#include "apiwrap.h"
|
||||
#include "boxes/peers/edit_peer_permissions_box.h"
|
||||
#include "data/business/data_business_common.h"
|
||||
#include "data/business/data_business_info.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_user.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "main/main_session.h"
|
||||
|
||||
namespace Data {
|
||||
@@ -41,7 +43,7 @@ void Chatbots::preload() {
|
||||
_settings = ChatbotsSettings{
|
||||
.bot = _owner->session().data().user(botId),
|
||||
.recipients = FromMTP(_owner, bot.vrecipients()),
|
||||
.repliesAllowed = bot.vrights().data().is_reply(),
|
||||
.permissions = FromMTP(bot.vrights()),
|
||||
};
|
||||
} else {
|
||||
_settings.force_assign(ChatbotsSettings());
|
||||
@@ -83,9 +85,7 @@ void Chatbots::save(
|
||||
const auto api = &_owner->session().api();
|
||||
api->request(MTPaccount_UpdateConnectedBot(
|
||||
MTP_flags(!settings.bot ? Flag::f_deleted : Flag::f_rights),
|
||||
MTP_businessBotRights(MTP_flags(settings.repliesAllowed
|
||||
? RightFlag::f_reply
|
||||
: RightFlag())),
|
||||
ToMTP(settings.permissions),
|
||||
(settings.bot ? settings.bot : was.bot)->inputUser,
|
||||
ForBotsToMTP(settings.recipients)
|
||||
)).done([=](const MTPUpdates &result) {
|
||||
@@ -180,4 +180,39 @@ void Chatbots::reload() {
|
||||
preload();
|
||||
}
|
||||
|
||||
EditFlagsDescriptor<ChatbotsPermissions> ChatbotsPermissionsLabels() {
|
||||
using Flag = ChatbotsPermission;
|
||||
|
||||
using PermissionLabel = EditFlagsLabel<ChatbotsPermissions>;
|
||||
auto messages = std::vector<PermissionLabel>{
|
||||
{ Flag::ViewMessages, tr::lng_chatbots_read(tr::now) },
|
||||
{ Flag::ReplyToMessages, tr::lng_chatbots_reply(tr::now) },
|
||||
{ Flag::MarkAsRead, tr::lng_chatbots_mark_as_read(tr::now) },
|
||||
{ Flag::DeleteSent, tr::lng_chatbots_delete_sent(tr::now) },
|
||||
{ Flag::DeleteReceived, tr::lng_chatbots_delete_received(tr::now) },
|
||||
};
|
||||
auto manage = std::vector<PermissionLabel>{
|
||||
{ Flag::EditName, tr::lng_chatbots_edit_name(tr::now) },
|
||||
{ Flag::EditBio, tr::lng_chatbots_edit_bio(tr::now) },
|
||||
{ Flag::EditUserpic, tr::lng_chatbots_edit_userpic(tr::now) },
|
||||
{ Flag::EditUsername, tr::lng_chatbots_edit_username(tr::now) },
|
||||
};
|
||||
auto gifts = std::vector<PermissionLabel>{
|
||||
{ Flag::ViewGifts, tr::lng_chatbots_view_gifts(tr::now) },
|
||||
{ Flag::SellGifts, tr::lng_chatbots_sell_gifts(tr::now) },
|
||||
{ Flag::GiftSettings, tr::lng_chatbots_gift_settings(tr::now) },
|
||||
{ Flag::TransferGifts, tr::lng_chatbots_transfer_gifts(tr::now) },
|
||||
{ Flag::TransferStars, tr::lng_chatbots_transfer_stars(tr::now) },
|
||||
};
|
||||
auto stories = std::vector<PermissionLabel>{
|
||||
{ Flag::ManageStories, tr::lng_chatbots_manage_stories(tr::now) },
|
||||
};
|
||||
return { .labels = {
|
||||
{ tr::lng_chatbots_manage_messages(), std::move(messages) },
|
||||
{ tr::lng_chatbots_manage_profile(), std::move(manage) },
|
||||
{ tr::lng_chatbots_manage_gifts(), std::move(gifts) },
|
||||
{ std::nullopt, std::move(stories) },
|
||||
}, .st = nullptr };
|
||||
}
|
||||
|
||||
} // namespace Data
|
||||
|
||||
@@ -11,6 +11,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
|
||||
class UserData;
|
||||
|
||||
template <typename Flags>
|
||||
struct EditFlagsDescriptor;
|
||||
|
||||
namespace Data {
|
||||
|
||||
class Session;
|
||||
@@ -18,7 +21,7 @@ class Session;
|
||||
struct ChatbotsSettings {
|
||||
UserData *bot = nullptr;
|
||||
BusinessRecipients recipients;
|
||||
bool repliesAllowed = false;
|
||||
ChatbotsPermissions permissions;
|
||||
|
||||
friend inline bool operator==(
|
||||
const ChatbotsSettings &,
|
||||
@@ -67,4 +70,7 @@ private:
|
||||
|
||||
};
|
||||
|
||||
[[nodiscard]] auto ChatbotsPermissionsLabels()
|
||||
-> EditFlagsDescriptor<ChatbotsPermissions>;
|
||||
|
||||
} // namespace Data
|
||||
|
||||
@@ -159,6 +159,47 @@ BusinessRecipients FromMTP(
|
||||
return result;
|
||||
}
|
||||
|
||||
ChatbotsPermissions FromMTP(const MTPBusinessBotRights &rights) {
|
||||
using Flag = ChatbotsPermission;
|
||||
const auto &data = rights.data();
|
||||
|
||||
return Flag::ViewMessages
|
||||
| (data.is_reply() ? Flag::ReplyToMessages : Flag())
|
||||
| (data.is_read_messages() ? Flag::MarkAsRead : Flag())
|
||||
| (data.is_delete_sent_messages() ? Flag::DeleteSent : Flag())
|
||||
| (data.is_delete_received_messages() ? Flag::DeleteReceived : Flag())
|
||||
| (data.is_edit_name() ? Flag::EditName : Flag())
|
||||
| (data.is_edit_bio() ? Flag::EditBio : Flag())
|
||||
| (data.is_edit_profile_photo() ? Flag::EditUserpic : Flag())
|
||||
| (data.is_edit_username() ? Flag::EditUsername : Flag())
|
||||
| (data.is_view_gifts() ? Flag::ViewGifts : Flag())
|
||||
| (data.is_sell_gifts() ? Flag::SellGifts : Flag())
|
||||
| (data.is_change_gift_settings() ? Flag::GiftSettings : Flag())
|
||||
| (data.is_transfer_and_upgrade_gifts() ? Flag::TransferGifts : Flag())
|
||||
| (data.is_transfer_stars() ? Flag::TransferStars : Flag())
|
||||
| (data.is_manage_stories() ? Flag::ManageStories : Flag());
|
||||
}
|
||||
|
||||
MTPBusinessBotRights ToMTP(ChatbotsPermissions rights) {
|
||||
using Flag = MTPDbusinessBotRights::Flag;
|
||||
using Right = ChatbotsPermission;
|
||||
return MTP_businessBotRights(MTP_flags(Flag()
|
||||
| ((rights & Right::ReplyToMessages) ? Flag::f_reply : Flag())
|
||||
| ((rights & Right::MarkAsRead) ? Flag::f_read_messages : Flag())
|
||||
| ((rights & Right::DeleteSent) ? Flag::f_delete_sent_messages : Flag())
|
||||
| ((rights & Right::DeleteReceived) ? Flag::f_delete_received_messages : Flag())
|
||||
| ((rights & Right::EditName) ? Flag::f_edit_name : Flag())
|
||||
| ((rights & Right::EditBio) ? Flag::f_edit_bio : Flag())
|
||||
| ((rights & Right::EditUserpic) ? Flag::f_edit_profile_photo : Flag())
|
||||
| ((rights & Right::EditUsername) ? Flag::f_edit_username : Flag())
|
||||
| ((rights & Right::ViewGifts) ? Flag::f_view_gifts : Flag())
|
||||
| ((rights & Right::SellGifts) ? Flag::f_sell_gifts : Flag())
|
||||
| ((rights & Right::GiftSettings) ? Flag::f_change_gift_settings : Flag())
|
||||
| ((rights & Right::TransferGifts) ? Flag::f_transfer_and_upgrade_gifts : Flag())
|
||||
| ((rights & Right::TransferStars) ? Flag::f_transfer_stars : Flag())
|
||||
| ((rights & Right::ManageStories) ? Flag::f_manage_stories : Flag())));
|
||||
}
|
||||
|
||||
BusinessDetails FromMTP(
|
||||
not_null<Session*> owner,
|
||||
const tl::conditional<MTPBusinessWorkHours> &hours,
|
||||
|
||||
@@ -57,6 +57,26 @@ enum class BusinessRecipientsType : uchar {
|
||||
Bots,
|
||||
};
|
||||
|
||||
enum class ChatbotsPermission {
|
||||
ViewMessages = 0x0001,
|
||||
ReplyToMessages = 0x0002,
|
||||
MarkAsRead = 0x0004,
|
||||
DeleteSent = 0x0008,
|
||||
DeleteReceived = 0x0010,
|
||||
EditName = 0x0020,
|
||||
EditBio = 0x0040,
|
||||
EditUserpic = 0x0080,
|
||||
EditUsername = 0x0100,
|
||||
ViewGifts = 0x0200,
|
||||
SellGifts = 0x0400,
|
||||
GiftSettings = 0x0800,
|
||||
TransferGifts = 0x1000,
|
||||
TransferStars = 0x2000,
|
||||
ManageStories = 0x4000,
|
||||
};
|
||||
inline constexpr bool is_flag_type(ChatbotsPermission) { return true; }
|
||||
using ChatbotsPermissions = base::flags<ChatbotsPermission>;
|
||||
|
||||
[[nodiscard]] MTPInputBusinessRecipients ForMessagesToMTP(
|
||||
const BusinessRecipients &data);
|
||||
[[nodiscard]] MTPInputBusinessBotRecipients ForBotsToMTP(
|
||||
@@ -67,6 +87,9 @@ enum class BusinessRecipientsType : uchar {
|
||||
[[nodiscard]] BusinessRecipients FromMTP(
|
||||
not_null<Session*> owner,
|
||||
const MTPBusinessBotRecipients &recipients);
|
||||
[[nodiscard]] ChatbotsPermissions FromMTP(
|
||||
const MTPBusinessBotRights &rights);
|
||||
[[nodiscard]] MTPBusinessBotRights ToMTP(ChatbotsPermissions rights);
|
||||
|
||||
struct Timezone {
|
||||
QString id;
|
||||
|
||||
Reference in New Issue
Block a user