mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Moved ChatRestrictionsInfo and ChatAdminRightsInfo to separated file.
This commit is contained in:
parent
30cd3cb681
commit
0eee937e6d
14 changed files with 160 additions and 132 deletions
|
@ -400,6 +400,8 @@ PRIVATE
|
|||
data/data_chat.h
|
||||
data/data_chat_filters.cpp
|
||||
data/data_chat_filters.h
|
||||
data/data_chat_participant_status.cpp
|
||||
data/data_chat_participant_status.h
|
||||
data/data_changes.cpp
|
||||
data/data_changes.h
|
||||
data/data_channel.cpp
|
||||
|
|
|
@ -9,7 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "boxes/abstract_box.h"
|
||||
#include "base/unique_qptr.h"
|
||||
#include "data/data_peer.h"
|
||||
#include "data/data_chat_participant_status.h"
|
||||
|
||||
namespace MTP {
|
||||
class Error;
|
||||
|
|
|
@ -8,7 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#pragma once
|
||||
|
||||
#include "boxes/abstract_box.h"
|
||||
#include "data/data_peer.h"
|
||||
#include "data/data_chat_participant_status.h"
|
||||
|
||||
namespace Ui {
|
||||
class RoundButton;
|
||||
|
|
|
@ -774,8 +774,8 @@ void ApplyMigration(
|
|||
void ApplyChannelUpdate(
|
||||
not_null<ChannelData*> channel,
|
||||
const MTPDupdateChatDefaultBannedRights &update) {
|
||||
channel->setDefaultRestrictions(Data::ChatBannedRightsFlags(
|
||||
update.vdefault_banned_rights()));
|
||||
channel->setDefaultRestrictions(ChatRestrictionsInfo(
|
||||
update.vdefault_banned_rights()).flags);
|
||||
}
|
||||
|
||||
void ApplyChannelUpdate(
|
||||
|
|
|
@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_peer.h"
|
||||
#include "data/data_pts_waiter.h"
|
||||
#include "data/data_location.h"
|
||||
#include "data/data_chat_participant_status.h"
|
||||
|
||||
struct ChannelLocation {
|
||||
QString address;
|
||||
|
|
|
@ -47,7 +47,7 @@ void ChatData::setPhoto(const MTPChatPhoto &photo) {
|
|||
ChatAdminRightsInfo ChatData::defaultAdminRights(not_null<UserData*> user) {
|
||||
const auto isCreator = (creator == peerToUser(user->id))
|
||||
|| (user->isSelf() && amCreator());
|
||||
using Flag = AdminRight;
|
||||
using Flag = ChatAdminRight;
|
||||
return ChatAdminRightsInfo(Flag::Other
|
||||
| Flag::ChangeInfo
|
||||
| Flag::DeleteMessages
|
||||
|
@ -60,7 +60,7 @@ ChatAdminRightsInfo ChatData::defaultAdminRights(not_null<UserData*> user) {
|
|||
|
||||
bool ChatData::canWrite() const {
|
||||
// Duplicated in Data::CanWriteValue().
|
||||
return amIn() && !amRestricted(Restriction::SendMessages);
|
||||
return amIn() && !amRestricted(ChatRestriction::SendMessages);
|
||||
}
|
||||
|
||||
bool ChatData::allowsForwarding() const {
|
||||
|
@ -68,12 +68,12 @@ bool ChatData::allowsForwarding() const {
|
|||
}
|
||||
|
||||
bool ChatData::canEditInformation() const {
|
||||
return amIn() && !amRestricted(Restriction::ChangeInfo);
|
||||
return amIn() && !amRestricted(ChatRestriction::ChangeInfo);
|
||||
}
|
||||
|
||||
bool ChatData::canEditPermissions() const {
|
||||
return amIn()
|
||||
&& (amCreator() || (adminRights() & AdminRight::BanUsers));
|
||||
&& (amCreator() || (adminRights() & ChatAdminRight::BanUsers));
|
||||
}
|
||||
|
||||
bool ChatData::canEditUsername() const {
|
||||
|
@ -87,15 +87,15 @@ bool ChatData::canEditPreHistoryHidden() const {
|
|||
|
||||
bool ChatData::canDeleteMessages() const {
|
||||
return amCreator()
|
||||
|| (adminRights() & AdminRight::DeleteMessages);
|
||||
|| (adminRights() & ChatAdminRight::DeleteMessages);
|
||||
}
|
||||
|
||||
bool ChatData::canAddMembers() const {
|
||||
return amIn() && !amRestricted(Restriction::InviteUsers);
|
||||
return amIn() && !amRestricted(ChatRestriction::InviteUsers);
|
||||
}
|
||||
|
||||
bool ChatData::canSendPolls() const {
|
||||
return amIn() && !amRestricted(Restriction::SendPolls);
|
||||
return amIn() && !amRestricted(ChatRestriction::SendPolls);
|
||||
}
|
||||
|
||||
bool ChatData::canAddAdmins() const {
|
||||
|
@ -104,11 +104,11 @@ bool ChatData::canAddAdmins() const {
|
|||
|
||||
bool ChatData::canBanMembers() const {
|
||||
return amCreator()
|
||||
|| (adminRights() & AdminRight::BanUsers);
|
||||
|| (adminRights() & ChatAdminRight::BanUsers);
|
||||
}
|
||||
|
||||
bool ChatData::anyoneCanAddMembers() const {
|
||||
return !(defaultRestrictions() & Restriction::InviteUsers);
|
||||
return !(defaultRestrictions() & ChatRestriction::InviteUsers);
|
||||
}
|
||||
|
||||
void ChatData::setName(const QString &newName) {
|
||||
|
@ -142,7 +142,7 @@ void ChatData::setInviteLink(const QString &newInviteLink) {
|
|||
|
||||
bool ChatData::canHaveInviteLink() const {
|
||||
return amCreator()
|
||||
|| (adminRights() & AdminRight::InviteUsers);
|
||||
|| (adminRights() & ChatAdminRight::InviteUsers);
|
||||
}
|
||||
|
||||
void ChatData::setAdminRights(ChatAdminRights rights) {
|
||||
|
@ -414,8 +414,8 @@ void ApplyChatUpdate(
|
|||
!= ChatData::UpdateStatus::Good) {
|
||||
return;
|
||||
}
|
||||
chat->setDefaultRestrictions(Data::ChatBannedRightsFlags(
|
||||
update.vdefault_banned_rights()));
|
||||
chat->setDefaultRestrictions(ChatRestrictionsInfo(
|
||||
update.vdefault_banned_rights()).flags);
|
||||
}
|
||||
|
||||
void ApplyChatUpdate(not_null<ChatData*> chat, const MTPDchatFull &update) {
|
||||
|
|
|
@ -8,6 +8,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#pragma once
|
||||
|
||||
#include "data/data_peer.h"
|
||||
#include "data/data_chat_participant_status.h"
|
||||
|
||||
enum class ChatAdminRight;
|
||||
|
||||
enum class ChatDataFlag {
|
||||
Left = (1 << 0),
|
||||
|
@ -28,13 +31,6 @@ public:
|
|||
using Flag = ChatDataFlag;
|
||||
using Flags = Data::Flags<ChatDataFlags>;
|
||||
|
||||
using AdminRight = ChatAdminRight;
|
||||
using Restriction = ChatRestriction;
|
||||
using AdminRights = ChatAdminRights;
|
||||
using Restrictions = ChatRestrictions;
|
||||
using AdminRightFlags = Data::Flags<AdminRights>;
|
||||
using RestrictionFlags = Data::Flags<Restrictions>;
|
||||
|
||||
ChatData(not_null<Data::Session*> owner, PeerId id);
|
||||
|
||||
void setName(const QString &newName);
|
||||
|
@ -197,8 +193,8 @@ private:
|
|||
Flags _flags;
|
||||
QString _inviteLink;
|
||||
|
||||
RestrictionFlags _defaultRestrictions;
|
||||
AdminRightFlags _adminRights;
|
||||
Data::Flags<ChatRestrictions> _defaultRestrictions;
|
||||
Data::Flags<ChatAdminRights> _adminRights;
|
||||
int _version = 0;
|
||||
int _pendingRequestsCount = 0;
|
||||
std::vector<UserId> _recentRequesters;
|
||||
|
|
64
Telegram/SourceFiles/data/data_chat_participant_status.cpp
Normal file
64
Telegram/SourceFiles/data/data_chat_participant_status.cpp
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
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
|
||||
*/
|
||||
#include "data/data_chat_participant_status.h"
|
||||
|
||||
namespace {
|
||||
|
||||
[[nodiscard]] ChatAdminRights ChatAdminRightsFlags(
|
||||
const MTPChatAdminRights &rights) {
|
||||
return rights.match([](const MTPDchatAdminRights &data) {
|
||||
return ChatAdminRights::from_raw(int32(data.vflags().v));
|
||||
});
|
||||
}
|
||||
|
||||
[[nodiscard]] ChatRestrictions ChatBannedRightsFlags(
|
||||
const MTPChatBannedRights &rights) {
|
||||
return rights.match([](const MTPDchatBannedRights &data) {
|
||||
return ChatRestrictions::from_raw(int32(data.vflags().v));
|
||||
});
|
||||
}
|
||||
|
||||
[[nodiscard]] TimeId ChatBannedRightsUntilDate(
|
||||
const MTPChatBannedRights &rights) {
|
||||
return rights.match([](const MTPDchatBannedRights &data) {
|
||||
return data.vuntil_date().v;
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
ChatAdminRightsInfo::ChatAdminRightsInfo(const MTPChatAdminRights &rights)
|
||||
: flags(ChatAdminRightsFlags(rights)) {
|
||||
}
|
||||
|
||||
ChatRestrictionsInfo::ChatRestrictionsInfo(const MTPChatBannedRights &rights)
|
||||
: flags(ChatBannedRightsFlags(rights))
|
||||
, until(ChatBannedRightsUntilDate(rights)) {
|
||||
}
|
||||
|
||||
namespace Data {
|
||||
|
||||
std::vector<ChatRestrictions> ListOfRestrictions() {
|
||||
using Flag = ChatRestriction;
|
||||
|
||||
return {
|
||||
Flag::SendMessages,
|
||||
Flag::SendMedia,
|
||||
Flag::SendStickers
|
||||
| Flag::SendGifs
|
||||
| Flag::SendGames
|
||||
| Flag::SendInline,
|
||||
Flag::EmbedLinks,
|
||||
Flag::SendPolls,
|
||||
Flag::InviteUsers,
|
||||
Flag::PinMessages,
|
||||
Flag::ChangeInfo,
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace Data
|
68
Telegram/SourceFiles/data/data_chat_participant_status.h
Normal file
68
Telegram/SourceFiles/data/data_chat_participant_status.h
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
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
|
||||
|
||||
enum class ChatAdminRight {
|
||||
ChangeInfo = (1 << 0),
|
||||
PostMessages = (1 << 1),
|
||||
EditMessages = (1 << 2),
|
||||
DeleteMessages = (1 << 3),
|
||||
BanUsers = (1 << 4),
|
||||
InviteUsers = (1 << 5),
|
||||
PinMessages = (1 << 7),
|
||||
AddAdmins = (1 << 9),
|
||||
Anonymous = (1 << 10),
|
||||
ManageCall = (1 << 11),
|
||||
Other = (1 << 12),
|
||||
};
|
||||
inline constexpr bool is_flag_type(ChatAdminRight) { return true; }
|
||||
using ChatAdminRights = base::flags<ChatAdminRight>;
|
||||
|
||||
enum class ChatRestriction {
|
||||
ViewMessages = (1 << 0),
|
||||
SendMessages = (1 << 1),
|
||||
SendMedia = (1 << 2),
|
||||
SendStickers = (1 << 3),
|
||||
SendGifs = (1 << 4),
|
||||
SendGames = (1 << 5),
|
||||
SendInline = (1 << 6),
|
||||
EmbedLinks = (1 << 7),
|
||||
SendPolls = (1 << 8),
|
||||
ChangeInfo = (1 << 10),
|
||||
InviteUsers = (1 << 15),
|
||||
PinMessages = (1 << 17),
|
||||
};
|
||||
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 {
|
||||
|
||||
std::vector<ChatRestrictions> ListOfRestrictions();
|
||||
|
||||
} // namespace Data
|
|
@ -1069,24 +1069,6 @@ void PeerData::setMessagesTTL(TimeId period) {
|
|||
|
||||
namespace Data {
|
||||
|
||||
std::vector<ChatRestrictions> ListOfRestrictions() {
|
||||
using Flag = ChatRestriction;
|
||||
|
||||
return {
|
||||
Flag::SendMessages,
|
||||
Flag::SendMedia,
|
||||
Flag::SendStickers
|
||||
| Flag::SendGifs
|
||||
| Flag::SendGames
|
||||
| Flag::SendInline,
|
||||
Flag::EmbedLinks,
|
||||
Flag::SendPolls,
|
||||
Flag::InviteUsers,
|
||||
Flag::PinMessages,
|
||||
Flag::ChangeInfo,
|
||||
};
|
||||
}
|
||||
|
||||
std::optional<QString> RestrictionError(
|
||||
not_null<PeerData*> peer,
|
||||
ChatRestriction restriction) {
|
||||
|
@ -1275,22 +1257,4 @@ std::optional<int> ResolvePinnedCount(
|
|||
: std::nullopt;
|
||||
}
|
||||
|
||||
ChatAdminRights ChatAdminRightsFlags(const MTPChatAdminRights &rights) {
|
||||
return rights.match([](const MTPDchatAdminRights &data) {
|
||||
return ChatAdminRights::from_raw(int32(data.vflags().v));
|
||||
});
|
||||
}
|
||||
|
||||
ChatRestrictions ChatBannedRightsFlags(const MTPChatBannedRights &rights) {
|
||||
return rights.match([](const MTPDchatBannedRights &data) {
|
||||
return ChatRestrictions::from_raw(int32(data.vflags().v));
|
||||
});
|
||||
}
|
||||
|
||||
TimeId ChatBannedRightsUntilDate(const MTPChatBannedRights &rights) {
|
||||
return rights.match([](const MTPDchatBannedRights &data) {
|
||||
return data.vuntil_date().v;
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace Data
|
||||
|
|
|
@ -17,75 +17,7 @@ class UserData;
|
|||
class ChatData;
|
||||
class ChannelData;
|
||||
|
||||
enum class ChatAdminRight {
|
||||
ChangeInfo = (1 << 0),
|
||||
PostMessages = (1 << 1),
|
||||
EditMessages = (1 << 2),
|
||||
DeleteMessages = (1 << 3),
|
||||
BanUsers = (1 << 4),
|
||||
InviteUsers = (1 << 5),
|
||||
PinMessages = (1 << 7),
|
||||
AddAdmins = (1 << 9),
|
||||
Anonymous = (1 << 10),
|
||||
ManageCall = (1 << 11),
|
||||
Other = (1 << 12),
|
||||
};
|
||||
inline constexpr bool is_flag_type(ChatAdminRight) { return true; }
|
||||
using ChatAdminRights = base::flags<ChatAdminRight>;
|
||||
|
||||
enum class ChatRestriction {
|
||||
ViewMessages = (1 << 0),
|
||||
SendMessages = (1 << 1),
|
||||
SendMedia = (1 << 2),
|
||||
SendStickers = (1 << 3),
|
||||
SendGifs = (1 << 4),
|
||||
SendGames = (1 << 5),
|
||||
SendInline = (1 << 6),
|
||||
EmbedLinks = (1 << 7),
|
||||
SendPolls = (1 << 8),
|
||||
ChangeInfo = (1 << 10),
|
||||
InviteUsers = (1 << 15),
|
||||
PinMessages = (1 << 17),
|
||||
};
|
||||
inline constexpr bool is_flag_type(ChatRestriction) { return true; }
|
||||
using ChatRestrictions = base::flags<ChatRestriction>;
|
||||
|
||||
namespace Data {
|
||||
|
||||
[[nodiscard]] ChatAdminRights ChatAdminRightsFlags(
|
||||
const MTPChatAdminRights &rights);
|
||||
[[nodiscard]] ChatRestrictions ChatBannedRightsFlags(
|
||||
const MTPChatBannedRights &rights);
|
||||
[[nodiscard]] TimeId ChatBannedRightsUntilDate(
|
||||
const MTPChatBannedRights &rights);
|
||||
|
||||
} // namespace Data
|
||||
|
||||
struct ChatAdminRightsInfo {
|
||||
ChatAdminRightsInfo() = default;
|
||||
explicit ChatAdminRightsInfo(ChatAdminRights flags) : flags(flags) {
|
||||
}
|
||||
explicit ChatAdminRightsInfo(const MTPChatAdminRights &rights)
|
||||
: flags(Data::ChatAdminRightsFlags(rights)) {
|
||||
}
|
||||
|
||||
ChatAdminRights flags;
|
||||
};
|
||||
|
||||
struct ChatRestrictionsInfo {
|
||||
ChatRestrictionsInfo() = default;
|
||||
ChatRestrictionsInfo(ChatRestrictions flags, TimeId until)
|
||||
: flags(flags)
|
||||
, until(until) {
|
||||
}
|
||||
explicit ChatRestrictionsInfo(const MTPChatBannedRights &rights)
|
||||
: flags(Data::ChatBannedRightsFlags(rights))
|
||||
, until(Data::ChatBannedRightsUntilDate(rights)) {
|
||||
}
|
||||
|
||||
ChatRestrictions flags;
|
||||
TimeId until = 0;
|
||||
};
|
||||
enum class ChatRestriction;
|
||||
|
||||
struct BotCommand {
|
||||
QString command;
|
||||
|
@ -528,8 +460,6 @@ private:
|
|||
|
||||
namespace Data {
|
||||
|
||||
std::vector<ChatRestrictions> ListOfRestrictions();
|
||||
|
||||
std::optional<QString> RestrictionError(
|
||||
not_null<PeerData*> peer,
|
||||
ChatRestriction restriction);
|
||||
|
|
|
@ -43,6 +43,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "base/call_delayed.h"
|
||||
#include "core/file_utilities.h"
|
||||
#include "main/main_session.h"
|
||||
#include "data/data_chat_participant_status.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_scheduled_messages.h"
|
||||
#include "data/data_user.h"
|
||||
|
|
|
@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_file_origin.h"
|
||||
#include "data/data_user.h"
|
||||
#include "data/data_changes.h"
|
||||
#include "data/data_chat_participant_status.h"
|
||||
#include "inline_bots/inline_bot_result.h"
|
||||
#include "inline_bots/inline_bot_layout_item.h"
|
||||
#include "lang/lang_keys.h"
|
||||
|
|
|
@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "core/sandbox.h"
|
||||
#include "core/application.h"
|
||||
#include "core/core_settings.h"
|
||||
#include "data/data_chat_participant_status.h"
|
||||
#include "data/data_document.h"
|
||||
#include "data/data_document_media.h"
|
||||
#include "data/data_file_origin.h"
|
||||
|
|
Loading…
Add table
Reference in a new issue