2021-11-21 19:48:08 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2023-01-10 18:56:20 +00:00
|
|
|
namespace Ui {
|
|
|
|
struct PreparedList;
|
|
|
|
struct PreparedFile;
|
|
|
|
} // namespace Ui
|
2022-07-18 20:35:16 +00:00
|
|
|
|
2021-11-21 19:48:08 +00:00
|
|
|
enum class ChatAdminRight {
|
|
|
|
ChangeInfo = (1 << 0),
|
|
|
|
PostMessages = (1 << 1),
|
|
|
|
EditMessages = (1 << 2),
|
|
|
|
DeleteMessages = (1 << 3),
|
|
|
|
BanUsers = (1 << 4),
|
2022-10-24 09:13:21 +00:00
|
|
|
InviteByLinkOrAdd = (1 << 5),
|
2022-10-24 11:52:43 +00:00
|
|
|
PinMessages = (1 << 7),
|
2021-11-21 19:48:08 +00:00
|
|
|
AddAdmins = (1 << 9),
|
|
|
|
Anonymous = (1 << 10),
|
|
|
|
ManageCall = (1 << 11),
|
|
|
|
Other = (1 << 12),
|
2022-10-24 07:23:21 +00:00
|
|
|
ManageTopics = (1 << 13),
|
2021-11-21 19:48:08 +00:00
|
|
|
};
|
|
|
|
inline constexpr bool is_flag_type(ChatAdminRight) { return true; }
|
|
|
|
using ChatAdminRights = base::flags<ChatAdminRight>;
|
|
|
|
|
|
|
|
enum class ChatRestriction {
|
|
|
|
ViewMessages = (1 << 0),
|
2023-01-10 18:56:20 +00:00
|
|
|
|
2021-11-21 19:48:08 +00:00
|
|
|
SendStickers = (1 << 3),
|
|
|
|
SendGifs = (1 << 4),
|
|
|
|
SendGames = (1 << 5),
|
|
|
|
SendInline = (1 << 6),
|
|
|
|
SendPolls = (1 << 8),
|
2023-01-10 18:56:20 +00:00
|
|
|
SendPhotos = (1 << 19),
|
|
|
|
SendVideos = (1 << 20),
|
|
|
|
SendVideoMessages = (1 << 21),
|
|
|
|
SendMusic = (1 << 22),
|
|
|
|
SendVoiceMessages = (1 << 23),
|
|
|
|
SendFiles = (1 << 24),
|
|
|
|
SendOther = (1 << 25),
|
|
|
|
|
|
|
|
EmbedLinks = (1 << 7),
|
|
|
|
|
2021-11-21 19:48:08 +00:00
|
|
|
ChangeInfo = (1 << 10),
|
2022-10-24 09:13:21 +00:00
|
|
|
AddParticipants = (1 << 15),
|
2021-11-21 19:48:08 +00:00
|
|
|
PinMessages = (1 << 17),
|
2022-10-24 09:13:21 +00:00
|
|
|
CreateTopics = (1 << 18),
|
2021-11-21 19:48:08 +00:00
|
|
|
};
|
|
|
|
inline constexpr bool is_flag_type(ChatRestriction) { return true; }
|
|
|
|
using ChatRestrictions = base::flags<ChatRestriction>;
|
|
|
|
|
|
|
|
struct ChatAdminRightsInfo {
|
|
|
|
ChatAdminRightsInfo() = default;
|
|
|
|
explicit ChatAdminRightsInfo(ChatAdminRights flags) : flags(flags) {
|
|
|
|
}
|
|
|
|
explicit ChatAdminRightsInfo(const MTPChatAdminRights &rights);
|
|
|
|
|
|
|
|
ChatAdminRights flags;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ChatRestrictionsInfo {
|
|
|
|
ChatRestrictionsInfo() = default;
|
|
|
|
ChatRestrictionsInfo(ChatRestrictions flags, TimeId until)
|
|
|
|
: flags(flags)
|
|
|
|
, until(until) {
|
|
|
|
}
|
|
|
|
explicit ChatRestrictionsInfo(const MTPChatBannedRights &rights);
|
|
|
|
|
|
|
|
ChatRestrictions flags;
|
|
|
|
TimeId until = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace Data {
|
|
|
|
|
2023-01-10 18:56:20 +00:00
|
|
|
class Thread;
|
|
|
|
|
2022-10-24 07:23:21 +00:00
|
|
|
struct AdminRightsSetOptions {
|
|
|
|
bool isGroup : 1 = false;
|
|
|
|
bool isForum : 1 = false;
|
|
|
|
bool anyoneCanAddMembers : 1 = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RestrictionsSetOptions {
|
|
|
|
bool isForum = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
[[nodiscard]] std::vector<ChatRestrictions> ListOfRestrictions(
|
|
|
|
RestrictionsSetOptions options);
|
2021-11-21 19:48:08 +00:00
|
|
|
|
2023-01-10 18:56:20 +00:00
|
|
|
[[nodiscard]] inline constexpr auto AllSendRestrictionsList() {
|
|
|
|
return std::array{
|
|
|
|
ChatRestriction::SendOther,
|
|
|
|
ChatRestriction::SendStickers,
|
|
|
|
ChatRestriction::SendGifs,
|
|
|
|
ChatRestriction::SendGames,
|
|
|
|
ChatRestriction::SendInline,
|
|
|
|
ChatRestriction::SendPolls,
|
|
|
|
ChatRestriction::SendPhotos,
|
|
|
|
ChatRestriction::SendVideos,
|
|
|
|
ChatRestriction::SendVideoMessages,
|
|
|
|
ChatRestriction::SendMusic,
|
|
|
|
ChatRestriction::SendVoiceMessages,
|
|
|
|
ChatRestriction::SendFiles,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
[[nodiscard]] inline constexpr auto FilesSendRestrictionsList() {
|
|
|
|
return std::array{
|
|
|
|
ChatRestriction::SendStickers,
|
|
|
|
ChatRestriction::SendGifs,
|
|
|
|
ChatRestriction::SendPhotos,
|
|
|
|
ChatRestriction::SendVideos,
|
|
|
|
ChatRestriction::SendMusic,
|
|
|
|
ChatRestriction::SendFiles,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
[[nodiscard]] inline constexpr auto TabbedPanelSendRestrictionsList() {
|
|
|
|
return std::array{
|
|
|
|
ChatRestriction::SendStickers,
|
|
|
|
ChatRestriction::SendGifs,
|
|
|
|
ChatRestriction::SendOther,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
[[nodiscard]] ChatRestrictions AllSendRestrictions();
|
|
|
|
[[nodiscard]] ChatRestrictions FilesSendRestrictions();
|
|
|
|
[[nodiscard]] ChatRestrictions TabbedPanelSendRestrictions();
|
|
|
|
|
|
|
|
[[nodiscard]] bool CanSendAnyOf(
|
2023-02-07 12:28:59 +00:00
|
|
|
not_null<const Thread*> thread,
|
2023-01-10 18:56:20 +00:00
|
|
|
ChatRestrictions rights,
|
|
|
|
bool forbidInForums = true);
|
|
|
|
[[nodiscard]] bool CanSendAnyOf(
|
2023-02-07 12:28:59 +00:00
|
|
|
not_null<const PeerData*> peer,
|
2023-01-10 18:56:20 +00:00
|
|
|
ChatRestrictions rights,
|
|
|
|
bool forbidInForums = true);
|
|
|
|
|
|
|
|
[[nodiscard]] inline bool CanSend(
|
2023-02-07 12:28:59 +00:00
|
|
|
not_null<const Thread*> thread,
|
2023-01-10 18:56:20 +00:00
|
|
|
ChatRestriction right,
|
|
|
|
bool forbidInForums = true) {
|
|
|
|
return CanSendAnyOf(thread, right, forbidInForums);
|
|
|
|
}
|
|
|
|
[[nodiscard]] inline bool CanSend(
|
2023-02-07 12:28:59 +00:00
|
|
|
not_null<const PeerData*> peer,
|
2023-01-10 18:56:20 +00:00
|
|
|
ChatRestriction right,
|
|
|
|
bool forbidInForums = true) {
|
|
|
|
return CanSendAnyOf(peer, right, forbidInForums);
|
|
|
|
}
|
|
|
|
[[nodiscard]] inline bool CanSendTexts(
|
2023-02-07 12:28:59 +00:00
|
|
|
not_null<const Thread*> thread,
|
2023-01-10 18:56:20 +00:00
|
|
|
bool forbidInForums = true) {
|
|
|
|
return CanSend(thread, ChatRestriction::SendOther, forbidInForums);
|
|
|
|
}
|
|
|
|
[[nodiscard]] inline bool CanSendTexts(
|
2023-02-07 12:28:59 +00:00
|
|
|
not_null<const PeerData*> peer,
|
2023-01-10 18:56:20 +00:00
|
|
|
bool forbidInForums = true) {
|
|
|
|
return CanSend(peer, ChatRestriction::SendOther, forbidInForums);
|
|
|
|
}
|
|
|
|
[[nodiscard]] inline bool CanSendAnything(
|
2023-02-07 12:28:59 +00:00
|
|
|
not_null<const Thread*> thread,
|
2023-01-10 18:56:20 +00:00
|
|
|
bool forbidInForums = true) {
|
|
|
|
return CanSendAnyOf(thread, AllSendRestrictions(), forbidInForums);
|
|
|
|
}
|
|
|
|
[[nodiscard]] inline bool CanSendAnything(
|
2023-02-07 12:28:59 +00:00
|
|
|
not_null<const PeerData*> peer,
|
2023-01-10 18:56:20 +00:00
|
|
|
bool forbidInForums = true) {
|
|
|
|
return CanSendAnyOf(peer, AllSendRestrictions(), forbidInForums);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] std::optional<QString> RestrictionError(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
ChatRestriction restriction);
|
|
|
|
[[nodiscard]] std::optional<QString> AnyFileRestrictionError(
|
|
|
|
not_null<PeerData*> peer);
|
|
|
|
[[nodiscard]] std::optional<QString> FileRestrictionError(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
const Ui::PreparedList &list,
|
|
|
|
std::optional<bool> compress);
|
|
|
|
[[nodiscard]] std::optional<QString> FileRestrictionError(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
const Ui::PreparedFile &file,
|
|
|
|
std::optional<bool> compress);
|
|
|
|
|
2021-11-21 19:48:08 +00:00
|
|
|
} // namespace Data
|