mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
Prepare legacy group restrictions checking.
This commit is contained in:
@@ -318,21 +318,17 @@ bool ChannelData::hiddenPreHistory() const {
|
||||
}
|
||||
|
||||
bool ChannelData::canAddMembers() const {
|
||||
return (adminRights() & AdminRight::f_invite_users)
|
||||
|| amCreator()
|
||||
|| (anyoneCanAddMembers()
|
||||
&& amIn()
|
||||
&& !hasRestrictions());
|
||||
return !amRestricted(ChatRestriction::f_invite_users);
|
||||
}
|
||||
|
||||
bool ChannelData::canAddAdmins() const {
|
||||
return (adminRights() & AdminRight::f_add_admins)
|
||||
|| amCreator();
|
||||
return amCreator()
|
||||
|| (adminRights() & AdminRight::f_add_admins);
|
||||
}
|
||||
|
||||
bool ChannelData::canPublish() const {
|
||||
return (adminRights() & AdminRight::f_post_messages)
|
||||
|| amCreator();
|
||||
return amCreator()
|
||||
|| (adminRights() & AdminRight::f_post_messages);
|
||||
}
|
||||
|
||||
bool ChannelData::canWrite() const {
|
||||
@@ -340,7 +336,7 @@ bool ChannelData::canWrite() const {
|
||||
return amIn()
|
||||
&& (canPublish()
|
||||
|| (!isBroadcast()
|
||||
&& !restricted(Restriction::f_send_messages)));
|
||||
&& !amRestricted(Restriction::f_send_messages)));
|
||||
}
|
||||
|
||||
bool ChannelData::canViewMembers() const {
|
||||
@@ -357,12 +353,7 @@ bool ChannelData::canViewBanned() const {
|
||||
}
|
||||
|
||||
bool ChannelData::canEditInformation() const {
|
||||
return (adminRights() & AdminRight::f_change_info)
|
||||
|| amCreator();
|
||||
}
|
||||
|
||||
bool ChannelData::canEditInvites() const {
|
||||
return canEditInformation();
|
||||
return !amRestricted(Restriction::f_change_info);
|
||||
}
|
||||
|
||||
bool ChannelData::canEditSignatures() const {
|
||||
@@ -375,13 +366,11 @@ bool ChannelData::canEditPreHistoryHidden() const {
|
||||
|
||||
bool ChannelData::canEditUsername() const {
|
||||
return amCreator()
|
||||
&& (fullFlags()
|
||||
& MTPDchannelFull::Flag::f_can_set_username);
|
||||
&& (fullFlags() & MTPDchannelFull::Flag::f_can_set_username);
|
||||
}
|
||||
|
||||
bool ChannelData::canEditStickers() const {
|
||||
return (fullFlags()
|
||||
& MTPDchannelFull::Flag::f_can_set_stickers);
|
||||
return (fullFlags() & MTPDchannelFull::Flag::f_can_set_stickers);
|
||||
}
|
||||
|
||||
bool ChannelData::canDelete() const {
|
||||
@@ -447,15 +436,15 @@ void ChannelData::setAdminRights(const MTPChatAdminRights &rights) {
|
||||
auto amAdmin = hasAdminRights() || amCreator();
|
||||
Data::ChannelAdminChanges(this).feed(session().userId(), amAdmin);
|
||||
}
|
||||
Notify::peerUpdatedDelayed(this, UpdateFlag::ChannelRightsChanged | UpdateFlag::AdminsChanged | UpdateFlag::BannedUsersChanged);
|
||||
Notify::peerUpdatedDelayed(this, UpdateFlag::RightsChanged | UpdateFlag::AdminsChanged | UpdateFlag::BannedUsersChanged);
|
||||
}
|
||||
|
||||
void ChannelData::setRestrictedRights(const MTPChatBannedRights &rights) {
|
||||
void ChannelData::setRestrictions(const MTPChatBannedRights &rights) {
|
||||
if (rights.c_chatBannedRights().vflags.v == restrictions()
|
||||
&& rights.c_chatBannedRights().vuntil_date.v == _restrictedUntill) {
|
||||
&& rights.c_chatBannedRights().vuntil_date.v == _restrictedUntil) {
|
||||
return;
|
||||
}
|
||||
_restrictedUntill = rights.c_chatBannedRights().vuntil_date.v;
|
||||
_restrictedUntil = rights.c_chatBannedRights().vuntil_date.v;
|
||||
_restrictions.set(rights.c_chatBannedRights().vflags.v);
|
||||
if (isMegagroup()) {
|
||||
const auto self = session().user();
|
||||
@@ -470,5 +459,13 @@ void ChannelData::setRestrictedRights(const MTPChatBannedRights &rights) {
|
||||
mgInfo->lastRestricted.remove(self);
|
||||
}
|
||||
}
|
||||
Notify::peerUpdatedDelayed(this, UpdateFlag::ChannelRightsChanged | UpdateFlag::AdminsChanged | UpdateFlag::BannedUsersChanged);
|
||||
Notify::peerUpdatedDelayed(this, UpdateFlag::RightsChanged | UpdateFlag::AdminsChanged | UpdateFlag::BannedUsersChanged);
|
||||
}
|
||||
|
||||
void ChannelData::setDefaultRestrictions(const MTPChatBannedRights &rights) {
|
||||
if (rights.c_chatBannedRights().vflags.v == defaultRestrictions()) {
|
||||
return;
|
||||
}
|
||||
_defaultRestrictions.set(rights.c_chatBannedRights().vflags.v);
|
||||
Notify::peerUpdatedDelayed(this, UpdateFlag::RightsChanged);
|
||||
}
|
||||
|
@@ -22,12 +22,14 @@ struct MegagroupInfo {
|
||||
MTPChatAdminRights rights;
|
||||
bool canEdit = false;
|
||||
};
|
||||
|
||||
struct Restricted {
|
||||
explicit Restricted(MTPChatBannedRights rights)
|
||||
: rights(rights) {
|
||||
}
|
||||
MTPChatBannedRights rights;
|
||||
};
|
||||
|
||||
std::deque<not_null<UserData*>> lastParticipants;
|
||||
base::flat_map<not_null<UserData*>, Admin> lastAdmins;
|
||||
base::flat_map<not_null<UserData*>, Restricted> lastRestricted;
|
||||
@@ -76,6 +78,13 @@ public:
|
||||
MTPDchannelFull::Flags,
|
||||
kEssentialFullFlags>;
|
||||
|
||||
using AdminRight = ChatAdminRight;
|
||||
using Restriction = ChatRestriction;
|
||||
using AdminRights = ChatAdminRights;
|
||||
using Restrictions = ChatRestrictions;
|
||||
using AdminRightFlags = Data::Flags<AdminRights>;
|
||||
using RestrictionFlags = Data::Flags<Restrictions>;
|
||||
|
||||
ChannelData(not_null<Data::Session*> owner, PeerId id);
|
||||
|
||||
void setPhoto(const MTPChatPhoto &photo);
|
||||
@@ -115,12 +124,6 @@ public:
|
||||
return _fullFlags.value();
|
||||
}
|
||||
|
||||
uint64 access = 0;
|
||||
|
||||
MTPinputChannel inputChannel;
|
||||
|
||||
QString username;
|
||||
|
||||
// Returns true if about text was changed.
|
||||
bool setAbout(const QString &newAbout);
|
||||
const QString &about() const {
|
||||
@@ -179,9 +182,6 @@ public:
|
||||
|
||||
bool isGroupAdmin(not_null<UserData*> user) const;
|
||||
|
||||
int32 date = 0;
|
||||
int version = 0;
|
||||
std::unique_ptr<MegagroupInfo> mgInfo;
|
||||
bool lastParticipantsCountOutdated() const {
|
||||
if (!mgInfo
|
||||
|| !(mgInfo->lastParticipantsStatus
|
||||
@@ -208,12 +208,6 @@ public:
|
||||
return flags() & MTPDchannel::Flag::f_creator;
|
||||
}
|
||||
|
||||
using AdminRight = ChatAdminRight;
|
||||
using Restriction = ChatRestriction;
|
||||
using AdminRights = ChatAdminRights;
|
||||
using Restrictions = ChatRestrictions;
|
||||
using AdminRightFlags = Data::Flags<AdminRights>;
|
||||
using RestrictionFlags = Data::Flags<Restrictions>;
|
||||
auto adminRights() const {
|
||||
return _adminRights.current();
|
||||
}
|
||||
@@ -224,19 +218,17 @@ public:
|
||||
bool hasAdminRights() const {
|
||||
return (adminRights() != 0);
|
||||
}
|
||||
|
||||
auto restrictions() const {
|
||||
return _restrictions.current();
|
||||
}
|
||||
auto restrictionsValue() const {
|
||||
return _restrictions.value();
|
||||
}
|
||||
bool restricted(Restriction right) const {
|
||||
return restrictions() & right;
|
||||
}
|
||||
TimeId restrictedUntil() const {
|
||||
return _restrictedUntill;
|
||||
return _restrictedUntil;
|
||||
}
|
||||
void setRestrictedRights(const MTPChatBannedRights &rights);
|
||||
void setRestrictions(const MTPChatBannedRights &rights);
|
||||
bool hasRestrictions() const {
|
||||
return (restrictions() != 0);
|
||||
}
|
||||
@@ -244,20 +236,30 @@ public:
|
||||
return hasRestrictions()
|
||||
&& (restrictedUntil() > now);
|
||||
}
|
||||
|
||||
auto defaultRestrictions() const {
|
||||
return _defaultRestrictions.current();
|
||||
}
|
||||
auto defaultRestrictionsValue() const {
|
||||
return _defaultRestrictions.value();
|
||||
}
|
||||
void setDefaultRestrictions(const MTPChatBannedRights &rights);
|
||||
|
||||
// Like in ChatData.
|
||||
bool canWrite() const;
|
||||
bool canEditInformation() const;
|
||||
bool canAddMembers() const;
|
||||
|
||||
bool canBanMembers() const;
|
||||
bool canEditMessages() const;
|
||||
bool canDeleteMessages() const;
|
||||
bool anyoneCanAddMembers() const;
|
||||
bool hiddenPreHistory() const;
|
||||
bool canAddMembers() const;
|
||||
bool canAddAdmins() const;
|
||||
bool canPublish() const;
|
||||
bool canWrite() const;
|
||||
bool canViewMembers() const;
|
||||
bool canViewAdmins() const;
|
||||
bool canViewBanned() const;
|
||||
bool canEditInformation() const;
|
||||
bool canEditInvites() const;
|
||||
bool canEditSignatures() const;
|
||||
bool canEditPreHistoryHidden() const;
|
||||
bool canEditUsername() const;
|
||||
@@ -270,9 +272,6 @@ public:
|
||||
QString inviteLink() const;
|
||||
bool canHaveInviteLink() const;
|
||||
|
||||
UserId inviter = 0; // > 0 - user who invited me to channel, < 0 - not in channel
|
||||
TimeId inviteDate = 0;
|
||||
|
||||
void ptsInit(int32 pts) {
|
||||
_ptsWaiter.init(pts);
|
||||
}
|
||||
@@ -283,15 +282,15 @@ public:
|
||||
return _ptsWaiter.updateAndApply(this, pts, count);
|
||||
}
|
||||
bool ptsUpdateAndApply(
|
||||
int32 pts,
|
||||
int32 count,
|
||||
const MTPUpdate &update) {
|
||||
int32 pts,
|
||||
int32 count,
|
||||
const MTPUpdate &update) {
|
||||
return _ptsWaiter.updateAndApply(this, pts, count, update);
|
||||
}
|
||||
bool ptsUpdateAndApply(
|
||||
int32 pts,
|
||||
int32 count,
|
||||
const MTPUpdates &updates) {
|
||||
int32 pts,
|
||||
int32 count,
|
||||
const MTPUpdates &updates) {
|
||||
return _ptsWaiter.updateAndApply(this, pts, count, updates);
|
||||
}
|
||||
int32 pts() const {
|
||||
@@ -331,6 +330,20 @@ public:
|
||||
return _feed;
|
||||
}
|
||||
|
||||
// Still public data members.
|
||||
uint64 access = 0;
|
||||
|
||||
MTPinputChannel inputChannel;
|
||||
|
||||
QString username;
|
||||
|
||||
int32 date = 0;
|
||||
int version = 0;
|
||||
std::unique_ptr<MegagroupInfo> mgInfo;
|
||||
|
||||
UserId inviter = 0; // > 0 - user who invited me to channel, < 0 - not in channel
|
||||
TimeId inviteDate = 0;
|
||||
|
||||
private:
|
||||
void flagsUpdated(MTPDchannel::Flags diff);
|
||||
void fullFlagsUpdated(MTPDchannelFull::Flags diff);
|
||||
@@ -349,9 +362,10 @@ private:
|
||||
int _kickedCount = 0;
|
||||
MsgId _availableMinId = 0;
|
||||
|
||||
RestrictionFlags _defaultRestrictions;
|
||||
AdminRightFlags _adminRights;
|
||||
RestrictionFlags _restrictions;
|
||||
TimeId _restrictedUntill;
|
||||
TimeId _restrictedUntil;
|
||||
|
||||
QString _unavailableReason;
|
||||
QString _about;
|
||||
|
@@ -33,10 +33,24 @@ void ChatData::setPhoto(PhotoId photoId, const MTPChatPhoto &photo) {
|
||||
}
|
||||
}
|
||||
|
||||
bool ChatData::actionsUnavailable() const {
|
||||
return isDeactivated() || !amIn();
|
||||
}
|
||||
|
||||
bool ChatData::canWrite() const {
|
||||
// Duplicated in Data::CanWriteValue().
|
||||
return !actionsUnavailable()
|
||||
&& !amRestricted(ChatRestriction::f_send_messages);
|
||||
}
|
||||
|
||||
bool ChatData::canEditInformation() const {
|
||||
// #TODO groups
|
||||
return !isDeactivated()
|
||||
/*&& ((adminRights() & AdminRight::f_change_info) || amCreator())*/;
|
||||
return !actionsUnavailable()
|
||||
&& !amRestricted(ChatRestriction::f_change_info);
|
||||
}
|
||||
|
||||
bool ChatData::canAddMembers() const {
|
||||
return !actionsUnavailable()
|
||||
&& !amRestricted(ChatRestriction::f_invite_users);
|
||||
}
|
||||
|
||||
void ChatData::setName(const QString &newName) {
|
||||
@@ -45,16 +59,14 @@ void ChatData::setName(const QString &newName) {
|
||||
|
||||
void ChatData::invalidateParticipants() {
|
||||
// #TODO groups
|
||||
auto wasCanEdit = canEditInformation();
|
||||
participants.clear();
|
||||
admins.clear();
|
||||
//removeFlags(MTPDchat::Flag::f_admin);
|
||||
invitedByMe.clear();
|
||||
botStatus = 0;
|
||||
if (wasCanEdit != canEditInformation()) {
|
||||
Notify::peerUpdatedDelayed(this, Notify::PeerUpdate::Flag::ChatCanEdit);
|
||||
}
|
||||
Notify::peerUpdatedDelayed(this, Notify::PeerUpdate::Flag::MembersChanged | Notify::PeerUpdate::Flag::AdminsChanged);
|
||||
Notify::peerUpdatedDelayed(
|
||||
this,
|
||||
UpdateFlag::MembersChanged | UpdateFlag::AdminsChanged);
|
||||
}
|
||||
|
||||
void ChatData::setInviteLink(const QString &newInviteLink) {
|
||||
@@ -63,3 +75,23 @@ void ChatData::setInviteLink(const QString &newInviteLink) {
|
||||
Notify::peerUpdatedDelayed(this, UpdateFlag::InviteLinkChanged);
|
||||
}
|
||||
}
|
||||
|
||||
void ChatData::setAdminRights(const MTPChatAdminRights &rights) {
|
||||
if (rights.c_chatAdminRights().vflags.v == adminRights()) {
|
||||
return;
|
||||
}
|
||||
_adminRights.set(rights.c_chatAdminRights().vflags.v);
|
||||
Notify::peerUpdatedDelayed(
|
||||
this,
|
||||
(UpdateFlag::RightsChanged
|
||||
| UpdateFlag::AdminsChanged
|
||||
| UpdateFlag::BannedUsersChanged));
|
||||
}
|
||||
|
||||
void ChatData::setDefaultRestrictions(const MTPChatBannedRights &rights) {
|
||||
if (rights.c_chatBannedRights().vflags.v == defaultRestrictions()) {
|
||||
return;
|
||||
}
|
||||
_defaultRestrictions.set(rights.c_chatBannedRights().vflags.v);
|
||||
Notify::peerUpdatedDelayed(this, UpdateFlag::RightsChanged);
|
||||
}
|
||||
|
@@ -23,6 +23,13 @@ public:
|
||||
MTPDchat::Flags,
|
||||
kEssentialFlags>;
|
||||
|
||||
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 setPhoto(const MTPChatPhoto &photo);
|
||||
@@ -35,15 +42,6 @@ public:
|
||||
return (count > 0 || amIn()) && participants.empty();
|
||||
}
|
||||
|
||||
MTPint inputChat;
|
||||
|
||||
ChannelData *migrateToPtr = nullptr;
|
||||
|
||||
int count = 0;
|
||||
TimeId date = 0;
|
||||
int version = 0;
|
||||
UserId creator = 0;
|
||||
|
||||
void setFlags(MTPDchat::Flags which) {
|
||||
_flags.set(which);
|
||||
}
|
||||
@@ -60,17 +58,31 @@ public:
|
||||
return _flags.value();
|
||||
}
|
||||
|
||||
auto adminRights() const {
|
||||
return _adminRights.current();
|
||||
}
|
||||
auto adminRightsValue() const {
|
||||
return _adminRights.value();
|
||||
}
|
||||
void setAdminRights(const MTPChatAdminRights &rights);
|
||||
bool hasAdminRights() const {
|
||||
return (adminRights() != 0);
|
||||
}
|
||||
|
||||
auto defaultRestrictions() const {
|
||||
return _defaultRestrictions.current();
|
||||
}
|
||||
auto defaultRestrictionsValue() const {
|
||||
return _defaultRestrictions.value();
|
||||
}
|
||||
void setDefaultRestrictions(const MTPChatBannedRights &rights);
|
||||
|
||||
bool isForbidden() const {
|
||||
return flags() & MTPDchat_ClientFlag::f_forbidden;
|
||||
}
|
||||
bool amIn() const {
|
||||
return !isForbidden() && !haveLeft() && !wasKicked();
|
||||
}
|
||||
bool canEditInformation() const;
|
||||
bool canWrite() const {
|
||||
// Duplicated in Data::CanWriteValue().
|
||||
return !isDeactivated() && amIn();
|
||||
}
|
||||
bool haveLeft() const {
|
||||
return flags() & MTPDchat::Flag::f_left;
|
||||
}
|
||||
@@ -86,6 +98,27 @@ public:
|
||||
bool isMigrated() const {
|
||||
return flags() & MTPDchat::Flag::f_migrated_to;
|
||||
}
|
||||
|
||||
// Like in ChatData.
|
||||
bool canWrite() const;
|
||||
bool canEditInformation() const;
|
||||
bool canAddMembers() const;
|
||||
|
||||
void setInviteLink(const QString &newInviteLink);
|
||||
QString inviteLink() const {
|
||||
return _inviteLink;
|
||||
}
|
||||
|
||||
// Still public data members.
|
||||
MTPint inputChat;
|
||||
|
||||
ChannelData *migrateToPtr = nullptr;
|
||||
|
||||
int count = 0;
|
||||
TimeId date = 0;
|
||||
int version = 0;
|
||||
UserId creator = 0;
|
||||
|
||||
base::flat_map<not_null<UserData*>, int> participants;
|
||||
base::flat_set<not_null<UserData*>> invitedByMe;
|
||||
base::flat_set<not_null<UserData*>> admins;
|
||||
@@ -94,15 +127,14 @@ public:
|
||||
int botStatus = 0; // -1 - no bots, 0 - unknown, 1 - one bot, that sees all history, 2 - other
|
||||
// ImagePtr photoFull;
|
||||
|
||||
void setInviteLink(const QString &newInviteLink);
|
||||
QString inviteLink() const {
|
||||
return _inviteLink;
|
||||
}
|
||||
|
||||
private:
|
||||
[[nodiscard]] bool actionsUnavailable() const;
|
||||
void flagsUpdated(MTPDchat::Flags diff);
|
||||
|
||||
Flags _flags;
|
||||
QString _inviteLink;
|
||||
|
||||
RestrictionFlags _defaultRestrictions;
|
||||
AdminRightFlags _adminRights;
|
||||
|
||||
};
|
||||
|
@@ -222,7 +222,7 @@ bool Media::forwardedBecomesUnread() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
QString Media::errorTextForForward(not_null<ChannelData*> channel) const {
|
||||
QString Media::errorTextForForward(not_null<PeerData*> peer) const {
|
||||
return QString();
|
||||
}
|
||||
|
||||
@@ -325,9 +325,8 @@ bool MediaPhoto::allowsEditCaption() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
QString MediaPhoto::errorTextForForward(
|
||||
not_null<ChannelData*> channel) const {
|
||||
if (channel->restricted(ChatRestriction::f_send_media)) {
|
||||
QString MediaPhoto::errorTextForForward(not_null<PeerData*> peer) const {
|
||||
if (peer->amRestricted(ChatRestriction::f_send_media)) {
|
||||
return lang(lng_restricted_send_media);
|
||||
}
|
||||
return QString();
|
||||
@@ -650,23 +649,22 @@ bool MediaFile::forwardedBecomesUnread() const {
|
||||
|| _document->isVideoMessage();
|
||||
}
|
||||
|
||||
QString MediaFile::errorTextForForward(
|
||||
not_null<ChannelData*> channel) const {
|
||||
QString MediaFile::errorTextForForward(not_null<PeerData*> peer) const {
|
||||
if (const auto sticker = _document->sticker()) {
|
||||
if (channel->restricted(ChatRestriction::f_send_stickers)) {
|
||||
if (peer->amRestricted(ChatRestriction::f_send_stickers)) {
|
||||
return lang(lng_restricted_send_stickers);
|
||||
}
|
||||
} else if (_document->isAnimation()) {
|
||||
if (_document->isVideoMessage()) {
|
||||
if (channel->restricted(ChatRestriction::f_send_media)) {
|
||||
if (peer->amRestricted(ChatRestriction::f_send_media)) {
|
||||
return lang(lng_restricted_send_media);
|
||||
}
|
||||
} else {
|
||||
if (channel->restricted(ChatRestriction::f_send_gifs)) {
|
||||
if (peer->amRestricted(ChatRestriction::f_send_gifs)) {
|
||||
return lang(lng_restricted_send_gifs);
|
||||
}
|
||||
}
|
||||
} else if (channel->restricted(ChatRestriction::f_send_media)) {
|
||||
} else if (peer->amRestricted(ChatRestriction::f_send_media)) {
|
||||
return lang(lng_restricted_send_media);
|
||||
}
|
||||
return QString();
|
||||
@@ -1116,9 +1114,8 @@ TextWithEntities MediaGame::clipboardText() const {
|
||||
return TextWithEntities();
|
||||
}
|
||||
|
||||
QString MediaGame::errorTextForForward(
|
||||
not_null<ChannelData*> channel) const {
|
||||
if (channel->restricted(ChatRestriction::f_send_games)) {
|
||||
QString MediaGame::errorTextForForward(not_null<PeerData*> peer) const {
|
||||
if (peer->amRestricted(ChatRestriction::f_send_games)) {
|
||||
return lang(lng_restricted_send_inline);
|
||||
}
|
||||
return QString();
|
||||
|
@@ -95,8 +95,7 @@ public:
|
||||
virtual bool allowsEditCaption() const;
|
||||
virtual bool allowsRevoke() const;
|
||||
virtual bool forwardedBecomesUnread() const;
|
||||
virtual QString errorTextForForward(
|
||||
not_null<ChannelData*> channel) const;
|
||||
virtual QString errorTextForForward(not_null<PeerData*> peer) const;
|
||||
|
||||
[[nodiscard]] virtual bool consumeMessageText(
|
||||
const TextWithEntities &text);
|
||||
@@ -142,8 +141,7 @@ public:
|
||||
QString pinnedTextSubstring() const override;
|
||||
TextWithEntities clipboardText() const override;
|
||||
bool allowsEditCaption() const override;
|
||||
QString errorTextForForward(
|
||||
not_null<ChannelData*> channel) const override;
|
||||
QString errorTextForForward(not_null<PeerData*> peer) const override;
|
||||
|
||||
bool updateInlineResultMedia(const MTPMessageMedia &media) override;
|
||||
bool updateSentMedia(const MTPMessageMedia &media) override;
|
||||
@@ -179,8 +177,7 @@ public:
|
||||
TextWithEntities clipboardText() const override;
|
||||
bool allowsEditCaption() const override;
|
||||
bool forwardedBecomesUnread() const override;
|
||||
QString errorTextForForward(
|
||||
not_null<ChannelData*> channel) const override;
|
||||
QString errorTextForForward(not_null<PeerData*> peer) const override;
|
||||
|
||||
bool updateInlineResultMedia(const MTPMessageMedia &media) override;
|
||||
bool updateSentMedia(const MTPMessageMedia &media) override;
|
||||
@@ -331,8 +328,7 @@ public:
|
||||
QString notificationText() const override;
|
||||
QString pinnedTextSubstring() const override;
|
||||
TextWithEntities clipboardText() const override;
|
||||
QString errorTextForForward(
|
||||
not_null<ChannelData*> channel) const override;
|
||||
QString errorTextForForward(not_null<PeerData*> peer) const override;
|
||||
|
||||
bool consumeMessageText(const TextWithEntities &text) override;
|
||||
TextWithEntities consumedMessageText() const override;
|
||||
|
@@ -546,3 +546,28 @@ bool PeerData::canWrite() const {
|
||||
? asUser()->canWrite()
|
||||
: false;
|
||||
}
|
||||
|
||||
bool PeerData::amRestricted(ChatRestriction right) const {
|
||||
const auto allowByAdminRights = [](auto right, auto chat) -> bool {
|
||||
if (right == ChatRestriction::f_invite_users) {
|
||||
return chat->adminRights() & ChatAdminRight::f_invite_users;
|
||||
} else if (right == ChatRestriction::f_change_info) {
|
||||
return chat->adminRights() & ChatAdminRight::f_change_info;
|
||||
} else if (right == ChatRestriction::f_pin_messages) {
|
||||
return chat->adminRights() & ChatAdminRight::f_pin_messages;
|
||||
} else {
|
||||
return chat->hasAdminRights();
|
||||
}
|
||||
};
|
||||
if (const auto channel = asChannel()) {
|
||||
return !channel->amCreator()
|
||||
&& !allowByAdminRights(right, channel)
|
||||
&& ((channel->restrictions() & right)
|
||||
|| (channel->defaultRestrictions() & right));
|
||||
} else if (const auto chat = asChat()) {
|
||||
return !chat->amCreator()
|
||||
&& !allowByAdminRights(right, chat)
|
||||
&& (chat->defaultRestrictions() & right);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@@ -100,6 +100,8 @@ public:
|
||||
}
|
||||
|
||||
bool canWrite() const;
|
||||
bool amRestricted(ChatRestriction right) const;
|
||||
|
||||
UserData *asUser();
|
||||
const UserData *asUser() const;
|
||||
ChatData *asChat();
|
||||
|
@@ -89,6 +89,22 @@ inline auto AdminRightValue(
|
||||
return SingleFlagValue(AdminRightsValue(channel), flag);
|
||||
}
|
||||
|
||||
inline auto AdminRightsValue(not_null<ChatData*> chat) {
|
||||
return chat->adminRightsValue();
|
||||
}
|
||||
|
||||
inline auto AdminRightsValue(
|
||||
not_null<ChatData*> chat,
|
||||
MTPDchatAdminRights::Flags mask) {
|
||||
return FlagsValueWithMask(AdminRightsValue(chat), mask);
|
||||
}
|
||||
|
||||
inline auto AdminRightValue(
|
||||
not_null<ChatData*> chat,
|
||||
MTPDchatAdminRights::Flag flag) {
|
||||
return SingleFlagValue(AdminRightsValue(chat), flag);
|
||||
}
|
||||
|
||||
inline auto RestrictionsValue(not_null<ChannelData*> channel) {
|
||||
return channel->restrictionsValue();
|
||||
}
|
||||
@@ -105,6 +121,38 @@ inline auto RestrictionValue(
|
||||
return SingleFlagValue(RestrictionsValue(channel), flag);
|
||||
}
|
||||
|
||||
inline auto DefaultRestrictionsValue(not_null<ChannelData*> channel) {
|
||||
return channel->defaultRestrictionsValue();
|
||||
}
|
||||
|
||||
inline auto DefaultRestrictionsValue(
|
||||
not_null<ChannelData*> channel,
|
||||
MTPDchatBannedRights::Flags mask) {
|
||||
return FlagsValueWithMask(DefaultRestrictionsValue(channel), mask);
|
||||
}
|
||||
|
||||
inline auto DefaultRestrictionValue(
|
||||
not_null<ChannelData*> channel,
|
||||
MTPDchatBannedRights::Flag flag) {
|
||||
return SingleFlagValue(DefaultRestrictionsValue(channel), flag);
|
||||
}
|
||||
|
||||
inline auto DefaultRestrictionsValue(not_null<ChatData*> chat) {
|
||||
return chat->defaultRestrictionsValue();
|
||||
}
|
||||
|
||||
inline auto DefaultRestrictionsValue(
|
||||
not_null<ChatData*> chat,
|
||||
MTPDchatBannedRights::Flags mask) {
|
||||
return FlagsValueWithMask(DefaultRestrictionsValue(chat), mask);
|
||||
}
|
||||
|
||||
inline auto DefaultRestrictionValue(
|
||||
not_null<ChatData*> chat,
|
||||
MTPDchatBannedRights::Flag flag) {
|
||||
return SingleFlagValue(DefaultRestrictionsValue(chat), flag);
|
||||
}
|
||||
|
||||
rpl::producer<bool> PeerFlagValue(
|
||||
ChatData *chat,
|
||||
MTPDchat_ClientFlag flag) {
|
||||
@@ -125,17 +173,36 @@ rpl::producer<bool> CanWriteValue(UserData *user) {
|
||||
|
||||
rpl::producer<bool> CanWriteValue(ChatData *chat) {
|
||||
using namespace rpl::mappers;
|
||||
auto mask = 0
|
||||
const auto mask = 0
|
||||
| MTPDchat::Flag::f_deactivated
|
||||
| MTPDchat_ClientFlag::f_forbidden
|
||||
| MTPDchat::Flag::f_left
|
||||
| MTPDchat::Flag::f_creator
|
||||
| MTPDchat::Flag::f_kicked;
|
||||
return PeerFlagsValue(chat, mask)
|
||||
| rpl::map(!_1);
|
||||
return rpl::combine(
|
||||
PeerFlagsValue(chat, mask),
|
||||
AdminRightsValue(chat),
|
||||
DefaultRestrictionValue(
|
||||
chat,
|
||||
MTPDchatBannedRights::Flag::f_send_messages),
|
||||
[](
|
||||
MTPDchat::Flags flags,
|
||||
Data::Flags<ChatAdminRights>::Change adminRights,
|
||||
bool defaultSendMessagesRestriction) {
|
||||
const auto actionsUnavailableFlags = 0
|
||||
| MTPDchat::Flag::f_deactivated
|
||||
| MTPDchat_ClientFlag::f_forbidden
|
||||
| MTPDchat::Flag::f_left
|
||||
| MTPDchat::Flag::f_kicked;
|
||||
return !(flags & actionsUnavailableFlags)
|
||||
&& ((flags & MTPDchat::Flag::f_creator)
|
||||
|| (adminRights.value != MTPDchatAdminRights::Flags(0))
|
||||
|| !defaultSendMessagesRestriction);
|
||||
});
|
||||
}
|
||||
|
||||
rpl::producer<bool> CanWriteValue(ChannelData *channel) {
|
||||
auto mask = 0
|
||||
const auto mask = 0
|
||||
| MTPDchannel::Flag::f_left
|
||||
| MTPDchannel_ClientFlag::f_forbidden
|
||||
| MTPDchannel::Flag::f_creator
|
||||
@@ -148,18 +215,23 @@ rpl::producer<bool> CanWriteValue(ChannelData *channel) {
|
||||
RestrictionValue(
|
||||
channel,
|
||||
MTPDchatBannedRights::Flag::f_send_messages),
|
||||
DefaultRestrictionValue(
|
||||
channel,
|
||||
MTPDchatBannedRights::Flag::f_send_messages),
|
||||
[](
|
||||
MTPDchannel::Flags flags,
|
||||
bool postMessagesRight,
|
||||
bool sendMessagesRestriction) {
|
||||
auto notAmInFlags = 0
|
||||
bool sendMessagesRestriction,
|
||||
bool defaultSendMessagesRestriction) {
|
||||
const auto notAmInFlags = 0
|
||||
| MTPDchannel::Flag::f_left
|
||||
| MTPDchannel_ClientFlag::f_forbidden;
|
||||
return !(flags & notAmInFlags)
|
||||
&& (postMessagesRight
|
||||
|| (flags & MTPDchannel::Flag::f_creator)
|
||||
|| (!(flags & MTPDchannel::Flag::f_broadcast)
|
||||
&& !sendMessagesRestriction));
|
||||
&& !sendMessagesRestriction
|
||||
&& !defaultSendMessagesRestriction));
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -428,8 +428,8 @@ not_null<PeerData*> Session::chat(const MTPChat &data) {
|
||||
|
||||
data.match([&](const MTPDchat &data) {
|
||||
const auto chat = result->asChat();
|
||||
// #TODO groups
|
||||
const auto canEdit = chat->canEditInformation();
|
||||
|
||||
const auto canAddMembers = chat->canAddMembers();
|
||||
|
||||
if (chat->version < data.vversion.v) {
|
||||
chat->version = data.vversion.v;
|
||||
@@ -441,6 +441,13 @@ not_null<PeerData*> Session::chat(const MTPChat &data) {
|
||||
chat->setPhoto(data.vphoto);
|
||||
chat->date = data.vdate.v;
|
||||
|
||||
chat->setAdminRights(data.has_admin_rights()
|
||||
? data.vadmin_rights
|
||||
: MTPChatAdminRights(MTP_chatAdminRights(MTP_flags(0))));
|
||||
chat->setDefaultRestrictions(data.has_default_banned_rights()
|
||||
? data.vdefault_banned_rights
|
||||
: MTPChatBannedRights(MTP_chatBannedRights(MTP_flags(0), MTP_int(0))));
|
||||
|
||||
const auto &migratedTo = data.has_migrated_to()
|
||||
? data.vmigrated_to
|
||||
: MTPInputChannel(MTP_inputChannelEmpty());
|
||||
@@ -480,22 +487,16 @@ not_null<PeerData*> Session::chat(const MTPChat &data) {
|
||||
}, [](const MTPDinputChannelEmpty &) {
|
||||
});
|
||||
|
||||
// #TODO groups
|
||||
//if (!(chat->flags() & MTPDchat::Flag::f_admins_enabled)
|
||||
// && (data.vflags.v & MTPDchat::Flag::f_admins_enabled)) {
|
||||
// chat->invalidateParticipants();
|
||||
//}
|
||||
chat->setFlags(data.vflags.v);
|
||||
|
||||
chat->count = data.vparticipants_count.v;
|
||||
// #TODO groups
|
||||
if (canEdit != chat->canEditInformation()) {
|
||||
update.flags |= UpdateFlag::ChatCanEdit;
|
||||
|
||||
if (canAddMembers != chat->canAddMembers()) {
|
||||
update.flags |= UpdateFlag::RightsChanged;
|
||||
}
|
||||
}, [&](const MTPDchatForbidden &data) {
|
||||
const auto chat = result->asChat();
|
||||
// #TODO groups
|
||||
const auto canEdit = chat->canEditInformation();
|
||||
|
||||
const auto canAddMembers = chat->canAddMembers();
|
||||
|
||||
chat->input = MTP_inputPeerChat(data.vid);
|
||||
chat->setName(qs(data.vtitle));
|
||||
@@ -504,9 +505,12 @@ not_null<PeerData*> Session::chat(const MTPChat &data) {
|
||||
chat->count = -1;
|
||||
chat->invalidateParticipants();
|
||||
chat->setFlags(MTPDchat_ClientFlag::f_forbidden | 0);
|
||||
// #TODO groups
|
||||
if (canEdit != chat->canEditInformation()) {
|
||||
update.flags |= UpdateFlag::ChatCanEdit;
|
||||
chat->setAdminRights(MTP_chatAdminRights(MTP_flags(0)));
|
||||
chat->setDefaultRestrictions(
|
||||
MTP_chatBannedRights(MTP_flags(0), MTP_int(0)));
|
||||
|
||||
if (canAddMembers != chat->canAddMembers()) {
|
||||
update.flags |= UpdateFlag::RightsChanged;
|
||||
}
|
||||
}, [&](const MTPDchannel &data) {
|
||||
const auto channel = result->asChannel();
|
||||
@@ -545,9 +549,9 @@ not_null<PeerData*> Session::chat(const MTPChat &data) {
|
||||
channel->setAdminRights(MTP_chatAdminRights(MTP_flags(0)));
|
||||
}
|
||||
if (data.has_banned_rights()) {
|
||||
channel->setRestrictedRights(data.vbanned_rights);
|
||||
channel->setRestrictions(data.vbanned_rights);
|
||||
} else if (channel->hasRestrictions()) {
|
||||
channel->setRestrictedRights(MTP_chatBannedRights(MTP_flags(0), MTP_int(0)));
|
||||
channel->setRestrictions(MTP_chatBannedRights(MTP_flags(0), MTP_int(0)));
|
||||
}
|
||||
channel->inputChannel = MTP_inputChannel(data.vid, data.vaccess_hash);
|
||||
channel->access = data.vaccess_hash.v;
|
||||
@@ -577,7 +581,7 @@ not_null<PeerData*> Session::chat(const MTPChat &data) {
|
||||
if (canViewAdmins != channel->canViewAdmins()
|
||||
|| canViewMembers != channel->canViewMembers()
|
||||
|| canAddMembers != channel->canAddMembers()) {
|
||||
update.flags |= UpdateFlag::ChannelRightsChanged;
|
||||
update.flags |= UpdateFlag::RightsChanged;
|
||||
}
|
||||
}, [&](const MTPDchannelForbidden &data) {
|
||||
const auto channel = result->asChannel();
|
||||
@@ -597,7 +601,7 @@ not_null<PeerData*> Session::chat(const MTPChat &data) {
|
||||
channel->setAdminRights(MTP_chatAdminRights(MTP_flags(0)));
|
||||
}
|
||||
if (channel->hasRestrictions()) {
|
||||
channel->setRestrictedRights(MTP_chatBannedRights(MTP_flags(0), MTP_int(0)));
|
||||
channel->setRestrictions(MTP_chatBannedRights(MTP_flags(0), MTP_int(0)));
|
||||
}
|
||||
|
||||
channel->setName(qs(data.vtitle), QString());
|
||||
@@ -613,7 +617,7 @@ not_null<PeerData*> Session::chat(const MTPChat &data) {
|
||||
if (canViewAdmins != channel->canViewAdmins()
|
||||
|| canViewMembers != channel->canViewMembers()
|
||||
|| canAddMembers != channel->canAddMembers()) {
|
||||
update.flags |= UpdateFlag::ChannelRightsChanged;
|
||||
update.flags |= UpdateFlag::RightsChanged;
|
||||
}
|
||||
}, [](const MTPDchatEmpty &) {
|
||||
});
|
||||
|
Reference in New Issue
Block a user