Prepare legacy group restrictions checking.

This commit is contained in:
John Preston 2019-01-05 14:50:04 +04:00
parent 441989a8e1
commit 61419b57c8
25 changed files with 415 additions and 403 deletions

View File

@ -665,7 +665,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_profile_manage_admins" = "Manage administrators"; "lng_profile_manage_admins" = "Manage administrators";
"lng_profile_manage_blocklist" = "Manage banned users"; "lng_profile_manage_blocklist" = "Manage banned users";
"lng_profile_manage_restrictedlist" = "Manage restricted users"; "lng_profile_manage_restrictedlist" = "Manage restricted users";
"lng_profile_recent_actions" = "Recent actions";
"lng_profile_common_groups#one" = "{count} group in common"; "lng_profile_common_groups#one" = "{count} group in common";
"lng_profile_common_groups#other" = "{count} groups in common"; "lng_profile_common_groups#other" = "{count} groups in common";
"lng_profile_participants_section" = "Members"; "lng_profile_participants_section" = "Members";
@ -1297,9 +1296,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_edit_contact_title" = "Edit contact name"; "lng_edit_contact_title" = "Edit contact name";
"lng_edit_channel_title" = "Edit channel"; "lng_edit_channel_title" = "Edit channel";
"lng_edit_sign_messages" = "Sign messages"; "lng_edit_sign_messages" = "Sign messages";
"lng_edit_group_who_invites" = "Who can add members";
"lng_edit_group_invites_everybody" = "All members";
"lng_edit_group_invites_only_admins" = "Only admins";
"lng_edit_group" = "Edit group"; "lng_edit_group" = "Edit group";
"lng_edit_self_title" = "Edit your name"; "lng_edit_self_title" = "Edit your name";
"lng_confirm_contact_data" = "New Contact"; "lng_confirm_contact_data" = "New Contact";

View File

@ -1061,7 +1061,7 @@ void ApiWrap::gotChatFull(PeerData *peer, const MTPmessages_ChatFull &result, mt
if (canViewAdmins != channel->canViewAdmins() if (canViewAdmins != channel->canViewAdmins()
|| canViewMembers != channel->canViewMembers()) { || canViewMembers != channel->canViewMembers()) {
Notify::peerUpdatedDelayed(channel, UpdateFlag::ChannelRightsChanged); Notify::peerUpdatedDelayed(channel, UpdateFlag::RightsChanged);
} }
notifySettingReceived(MTP_inputNotifyPeer(peer->input), f.vnotify_settings); notifySettingReceived(MTP_inputNotifyPeer(peer->input), f.vnotify_settings);

View File

@ -159,8 +159,6 @@ namespace App {
case mtpc_chatParticipants: { case mtpc_chatParticipants: {
const auto &d(p.c_chatParticipants()); const auto &d(p.c_chatParticipants());
chat = App::chat(d.vchat_id.v); chat = App::chat(d.vchat_id.v);
// #TODO groups
auto canEdit = chat->canEditInformation();
if (!requestBotInfos || chat->version <= d.vversion.v) { // !requestBotInfos is true on getFullChat result if (!requestBotInfos || chat->version <= d.vversion.v) { // !requestBotInfos is true on getFullChat result
chat->version = d.vversion.v; chat->version = d.vversion.v;
auto &v = d.vparticipants.v; auto &v = d.vparticipants.v;
@ -238,10 +236,6 @@ namespace App {
} }
} }
} }
// #TODO groups
if (canEdit != chat->canEditInformation()) {
Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::ChatCanEdit);
}
} break; } break;
} }
Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::MembersChanged | Notify::PeerUpdate::Flag::AdminsChanged); Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::MembersChanged | Notify::PeerUpdate::Flag::AdminsChanged);
@ -291,8 +285,6 @@ namespace App {
Auth().api().requestPeer(chat); Auth().api().requestPeer(chat);
} else if (chat->version <= d.vversion.v && chat->count > 0) { } else if (chat->version <= d.vversion.v && chat->count > 0) {
chat->version = d.vversion.v; chat->version = d.vversion.v;
// #TODO groups
auto canEdit = chat->canEditInformation();
const auto user = App::userLoaded(d.vuser_id.v); const auto user = App::userLoaded(d.vuser_id.v);
if (user) { if (user) {
if (chat->participants.empty()) { if (chat->participants.empty()) {
@ -334,25 +326,19 @@ namespace App {
chat->invalidateParticipants(); chat->invalidateParticipants();
chat->count--; chat->count--;
} }
// #TODO groups
if (canEdit != chat->canEditInformation()) {
Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::ChatCanEdit);
}
Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::MembersChanged); Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::MembersChanged);
} }
} }
void feedParticipantAdmin(const MTPDupdateChatParticipantAdmin &d) { void feedParticipantAdmin(const MTPDupdateChatParticipantAdmin &d) {
ChatData *chat = App::chat(d.vchat_id.v); const auto chat = App::chat(d.vchat_id.v);
if (chat->version + 1 < d.vversion.v) { if (chat->version + 1 < d.vversion.v) {
chat->version = d.vversion.v; chat->version = d.vversion.v;
chat->invalidateParticipants(); chat->invalidateParticipants();
Auth().api().requestPeer(chat); Auth().api().requestPeer(chat);
} else if (chat->version <= d.vversion.v && chat->count > 0) { } else if (chat->version <= d.vversion.v && chat->count > 0) {
chat->version = d.vversion.v; chat->version = d.vversion.v;
// #TODO groups const auto user = App::userLoaded(d.vuser_id.v);
auto canEdit = chat->canEditInformation();
UserData *user = App::userLoaded(d.vuser_id.v);
if (user) { if (user) {
if (mtpIsTrue(d.vis_admin)) { if (mtpIsTrue(d.vis_admin)) {
if (user->isSelf()) { if (user->isSelf()) {
@ -374,9 +360,6 @@ namespace App {
} else { } else {
chat->invalidateParticipants(); chat->invalidateParticipants();
} }
if (canEdit != chat->canEditInformation()) {
Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::ChatCanEdit);
}
Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::AdminsChanged); Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::AdminsChanged);
} }
} }

View File

@ -100,7 +100,6 @@ private:
void descriptionResized(); void descriptionResized();
void updateMaxHeight(); void updateMaxHeight();
void updateSelected(const QPoint &cursorGlobalPosition);
CreatingGroupType _creating; CreatingGroupType _creating;
bool _fromTypeChoose = false; bool _fromTypeChoose = false;
@ -138,7 +137,6 @@ private:
}; };
void privacyChanged(Privacy value); void privacyChanged(Privacy value);
void updateSelected(const QPoint &cursorGlobalPosition); void updateSelected(const QPoint &cursorGlobalPosition);
void showAddContactsToChannelBox() const;
void handleChange(); void handleChange();
void check(); void check();
void save(); void save();

View File

@ -844,22 +844,15 @@ std::unique_ptr<ChatsListBoxController::Row> AddBotToGroupBoxController::createR
bool AddBotToGroupBoxController::needToCreateRow(not_null<PeerData*> peer) const { bool AddBotToGroupBoxController::needToCreateRow(not_null<PeerData*> peer) const {
if (sharingBotGame()) { if (sharingBotGame()) {
if (!peer->canWrite()) { if (!peer->canWrite()
|| peer->amRestricted(ChatRestriction::f_send_games)) {
return false; return false;
} }
if (auto group = peer->asMegagroup()) {
if (group->restricted(ChatRestriction::f_send_games)) {
return false;
}
}
return true; return true;
} }
if (auto chat = peer->asChat()) { if (const auto chat = peer->asChat()) {
// #TODO groups return chat->canAddMembers();
if (chat->canEditInformation()) { } else if (const auto group = peer->asMegagroup()) {
return true;
}
} else if (auto group = peer->asMegagroup()) {
return group->canAddMembers(); return group->canAddMembers();
} }
return false; return false;

View File

@ -61,10 +61,6 @@ private:
Public, Public,
Private, Private,
}; };
enum class Invites {
Everyone,
OnlyAdmins,
};
enum class HistoryVisibility { enum class HistoryVisibility {
Visible, Visible,
Hidden, Hidden,
@ -93,7 +89,6 @@ private:
std::shared_ptr<Ui::RadioenumGroup<HistoryVisibility>> historyVisibility; std::shared_ptr<Ui::RadioenumGroup<HistoryVisibility>> historyVisibility;
Ui::SlideWrap<Ui::RpWidget> *historyVisibilityWrap = nullptr; Ui::SlideWrap<Ui::RpWidget> *historyVisibilityWrap = nullptr;
std::shared_ptr<Ui::RadioenumGroup<Invites>> invites;
Ui::Checkbox *signatures = nullptr; Ui::Checkbox *signatures = nullptr;
}; };
struct Saving { struct Saving {
@ -102,7 +97,6 @@ private:
std::optional<QString> description; std::optional<QString> description;
std::optional<bool> hiddenPreHistory; std::optional<bool> hiddenPreHistory;
std::optional<bool> signatures; std::optional<bool> signatures;
std::optional<bool> everyoneInvites;
}; };
Fn<QString()> computeTitle() const; Fn<QString()> computeTitle() const;
@ -116,7 +110,6 @@ private:
object_ptr<Ui::RpWidget> createInviteLinkEdit(); object_ptr<Ui::RpWidget> createInviteLinkEdit();
object_ptr<Ui::RpWidget> createHistoryVisibilityEdit(); object_ptr<Ui::RpWidget> createHistoryVisibilityEdit();
object_ptr<Ui::RpWidget> createSignaturesEdit(); object_ptr<Ui::RpWidget> createSignaturesEdit();
object_ptr<Ui::RpWidget> createInvitesEdit();
object_ptr<Ui::RpWidget> createStickersEdit(); object_ptr<Ui::RpWidget> createStickersEdit();
object_ptr<Ui::RpWidget> createManageAdminsButton(); object_ptr<Ui::RpWidget> createManageAdminsButton();
object_ptr<Ui::RpWidget> createUpgradeButton(); object_ptr<Ui::RpWidget> createUpgradeButton();
@ -153,7 +146,6 @@ private:
bool validateTitle(Saving &to) const; bool validateTitle(Saving &to) const;
bool validateDescription(Saving &to) const; bool validateDescription(Saving &to) const;
bool validateHistoryVisibility(Saving &to) const; bool validateHistoryVisibility(Saving &to) const;
bool validateInvites(Saving &to) const;
bool validateSignatures(Saving &to) const; bool validateSignatures(Saving &to) const;
void save(); void save();
@ -161,7 +153,6 @@ private:
void saveTitle(); void saveTitle();
void saveDescription(); void saveDescription();
void saveHistoryVisibility(); void saveHistoryVisibility();
void saveInvites();
void saveSignatures(); void saveSignatures();
void savePhoto(); void savePhoto();
void pushSaveStage(FnMut<void()> &&lambda); void pushSaveStage(FnMut<void()> &&lambda);
@ -218,7 +209,6 @@ object_ptr<Ui::VerticalLayout> Controller::createContent() {
_wrap->add(createInviteLinkEdit()); _wrap->add(createInviteLinkEdit());
_wrap->add(createHistoryVisibilityEdit()); _wrap->add(createHistoryVisibilityEdit());
_wrap->add(createSignaturesEdit()); _wrap->add(createSignaturesEdit());
_wrap->add(createInvitesEdit());
_wrap->add(createStickersEdit()); _wrap->add(createStickersEdit());
_wrap->add(createManageAdminsButton()); _wrap->add(createManageAdminsButton());
_wrap->add(createUpgradeButton()); _wrap->add(createUpgradeButton());
@ -917,57 +907,6 @@ object_ptr<Ui::RpWidget> Controller::createSignaturesEdit() {
return std::move(result); return std::move(result);
} }
object_ptr<Ui::RpWidget> Controller::createInvitesEdit() {
Expects(_wrap != nullptr);
auto channel = _peer->asChannel();
if (!channel
|| !channel->canEditInvites()
|| !channel->isMegagroup()) {
return nullptr;
}
auto result = object_ptr<Ui::PaddingWrap<Ui::VerticalLayout>>(
_wrap,
object_ptr<Ui::VerticalLayout>(_wrap),
st::editPeerInvitesMargins);
auto container = result->entity();
container->add(object_ptr<Ui::FlatLabel>(
container,
Lang::Viewer(lng_edit_group_who_invites),
st::editPeerSectionLabel));
_controls.invites = std::make_shared<Ui::RadioenumGroup<Invites>>(
channel->anyoneCanAddMembers()
? Invites::Everyone
: Invites::OnlyAdmins);
auto addButton = [&](
Invites value,
LangKey textKey) {
container->add(object_ptr<Ui::FixedHeightWidget>(
container,
st::editPeerInvitesTopSkip + st::editPeerInvitesSkip));
container->add(object_ptr<Ui::Radioenum<Invites>>(
container,
_controls.invites,
value,
lang(textKey),
st::defaultBoxCheckbox));
};
addButton(
Invites::Everyone,
lng_edit_group_invites_everybody);
addButton(
Invites::OnlyAdmins,
lng_edit_group_invites_only_admins);
container->add(object_ptr<Ui::FixedHeightWidget>(
container,
st::editPeerInvitesSkip));
return std::move(result);
}
object_ptr<Ui::RpWidget> Controller::createStickersEdit() { object_ptr<Ui::RpWidget> Controller::createStickersEdit() {
Expects(_wrap != nullptr); Expects(_wrap != nullptr);
@ -1102,7 +1041,6 @@ std::optional<Controller::Saving> Controller::validate() const {
&& validateTitle(result) && validateTitle(result)
&& validateDescription(result) && validateDescription(result)
&& validateHistoryVisibility(result) && validateHistoryVisibility(result)
&& validateInvites(result)
&& validateSignatures(result)) { && validateSignatures(result)) {
return result; return result;
} }
@ -1158,15 +1096,6 @@ bool Controller::validateHistoryVisibility(Saving &to) const {
return true; return true;
} }
bool Controller::validateInvites(Saving &to) const {
if (!_controls.invites) {
return true;
}
to.everyoneInvites
= (_controls.invites->value() == Invites::Everyone);
return true;
}
bool Controller::validateSignatures(Saving &to) const { bool Controller::validateSignatures(Saving &to) const {
if (!_controls.signatures) { if (!_controls.signatures) {
return true; return true;
@ -1187,7 +1116,6 @@ void Controller::save() {
pushSaveStage([this] { saveTitle(); }); pushSaveStage([this] { saveTitle(); });
pushSaveStage([this] { saveDescription(); }); pushSaveStage([this] { saveDescription(); });
pushSaveStage([this] { saveHistoryVisibility(); }); pushSaveStage([this] { saveHistoryVisibility(); });
pushSaveStage([this] { saveInvites(); });
pushSaveStage([this] { saveSignatures(); }); pushSaveStage([this] { saveSignatures(); });
pushSaveStage([this] { savePhoto(); }); pushSaveStage([this] { savePhoto(); });
continueSave(); continueSave();
@ -1351,29 +1279,6 @@ void Controller::saveHistoryVisibility() {
}).send(); }).send();
} }
void Controller::saveInvites() {
auto channel = _peer->asChannel();
if (!_savingData.everyoneInvites
|| !channel
|| *_savingData.everyoneInvites == channel->anyoneCanAddMembers()) {
return continueSave();
}
// #TODO groups
//request(MTPchannels_ToggleInvites(
// channel->inputChannel,
// MTP_bool(*_savingData.everyoneInvites)
//)).done([this](const MTPUpdates &result) {
// Auth().api().applyUpdates(result);
// continueSave();
//}).fail([this](const RPCError &error) {
// if (error.type() == qstr("CHAT_NOT_MODIFIED")) {
// continueSave();
// } else {
// cancelSave();
// }
//}).send();
}
void Controller::saveSignatures() { void Controller::saveSignatures() {
auto channel = _peer->asChannel(); auto channel = _peer->asChannel();
if (!_savingData.signatures if (!_savingData.signatures

View File

@ -352,7 +352,7 @@ TabbedSelector::TabbedSelector(
subscribe( subscribe(
Notify::PeerUpdated(), Notify::PeerUpdated(),
Notify::PeerUpdatedHandler( Notify::PeerUpdatedHandler(
Notify::PeerUpdate::Flag::ChannelRightsChanged, Notify::PeerUpdate::Flag::RightsChanged,
handleUpdate)); handleUpdate));
Auth().api().stickerSetInstalled( Auth().api().stickerSetInstalled(
@ -672,9 +672,12 @@ void TabbedSelector::setCurrentPeer(PeerData *peer) {
} }
void TabbedSelector::checkRestrictedPeer() { void TabbedSelector::checkRestrictedPeer() {
if (auto megagroup = _currentPeer ? _currentPeer->asMegagroup() : nullptr) { if (_currentPeer) {
auto restricted = (_currentTabType == SelectorTab::Stickers) ? megagroup->restricted(ChatRestriction::f_send_stickers) : const auto restricted = (_currentTabType == SelectorTab::Stickers)
(_currentTabType == SelectorTab::Gifs) ? megagroup->restricted(ChatRestriction::f_send_gifs) : false; ? _currentPeer->amRestricted(ChatRestriction::f_send_stickers)
: (_currentTabType == SelectorTab::Gifs)
? _currentPeer->amRestricted(ChatRestriction::f_send_gifs)
: false;
if (restricted) { if (restricted) {
if (!_restrictedLabel) { if (!_restrictedLabel) {
auto text = (_currentTabType == SelectorTab::Stickers) auto text = (_currentTabType == SelectorTab::Stickers)

View File

@ -318,21 +318,17 @@ bool ChannelData::hiddenPreHistory() const {
} }
bool ChannelData::canAddMembers() const { bool ChannelData::canAddMembers() const {
return (adminRights() & AdminRight::f_invite_users) return !amRestricted(ChatRestriction::f_invite_users);
|| amCreator()
|| (anyoneCanAddMembers()
&& amIn()
&& !hasRestrictions());
} }
bool ChannelData::canAddAdmins() const { bool ChannelData::canAddAdmins() const {
return (adminRights() & AdminRight::f_add_admins) return amCreator()
|| amCreator(); || (adminRights() & AdminRight::f_add_admins);
} }
bool ChannelData::canPublish() const { bool ChannelData::canPublish() const {
return (adminRights() & AdminRight::f_post_messages) return amCreator()
|| amCreator(); || (adminRights() & AdminRight::f_post_messages);
} }
bool ChannelData::canWrite() const { bool ChannelData::canWrite() const {
@ -340,7 +336,7 @@ bool ChannelData::canWrite() const {
return amIn() return amIn()
&& (canPublish() && (canPublish()
|| (!isBroadcast() || (!isBroadcast()
&& !restricted(Restriction::f_send_messages))); && !amRestricted(Restriction::f_send_messages)));
} }
bool ChannelData::canViewMembers() const { bool ChannelData::canViewMembers() const {
@ -357,12 +353,7 @@ bool ChannelData::canViewBanned() const {
} }
bool ChannelData::canEditInformation() const { bool ChannelData::canEditInformation() const {
return (adminRights() & AdminRight::f_change_info) return !amRestricted(Restriction::f_change_info);
|| amCreator();
}
bool ChannelData::canEditInvites() const {
return canEditInformation();
} }
bool ChannelData::canEditSignatures() const { bool ChannelData::canEditSignatures() const {
@ -375,13 +366,11 @@ bool ChannelData::canEditPreHistoryHidden() const {
bool ChannelData::canEditUsername() const { bool ChannelData::canEditUsername() const {
return amCreator() return amCreator()
&& (fullFlags() && (fullFlags() & MTPDchannelFull::Flag::f_can_set_username);
& MTPDchannelFull::Flag::f_can_set_username);
} }
bool ChannelData::canEditStickers() const { bool ChannelData::canEditStickers() const {
return (fullFlags() return (fullFlags() & MTPDchannelFull::Flag::f_can_set_stickers);
& MTPDchannelFull::Flag::f_can_set_stickers);
} }
bool ChannelData::canDelete() const { bool ChannelData::canDelete() const {
@ -447,15 +436,15 @@ void ChannelData::setAdminRights(const MTPChatAdminRights &rights) {
auto amAdmin = hasAdminRights() || amCreator(); auto amAdmin = hasAdminRights() || amCreator();
Data::ChannelAdminChanges(this).feed(session().userId(), amAdmin); 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() if (rights.c_chatBannedRights().vflags.v == restrictions()
&& rights.c_chatBannedRights().vuntil_date.v == _restrictedUntill) { && rights.c_chatBannedRights().vuntil_date.v == _restrictedUntil) {
return; return;
} }
_restrictedUntill = rights.c_chatBannedRights().vuntil_date.v; _restrictedUntil = rights.c_chatBannedRights().vuntil_date.v;
_restrictions.set(rights.c_chatBannedRights().vflags.v); _restrictions.set(rights.c_chatBannedRights().vflags.v);
if (isMegagroup()) { if (isMegagroup()) {
const auto self = session().user(); const auto self = session().user();
@ -470,5 +459,13 @@ void ChannelData::setRestrictedRights(const MTPChatBannedRights &rights) {
mgInfo->lastRestricted.remove(self); 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);
} }

View File

@ -22,12 +22,14 @@ struct MegagroupInfo {
MTPChatAdminRights rights; MTPChatAdminRights rights;
bool canEdit = false; bool canEdit = false;
}; };
struct Restricted { struct Restricted {
explicit Restricted(MTPChatBannedRights rights) explicit Restricted(MTPChatBannedRights rights)
: rights(rights) { : rights(rights) {
} }
MTPChatBannedRights rights; MTPChatBannedRights rights;
}; };
std::deque<not_null<UserData*>> lastParticipants; std::deque<not_null<UserData*>> lastParticipants;
base::flat_map<not_null<UserData*>, Admin> lastAdmins; base::flat_map<not_null<UserData*>, Admin> lastAdmins;
base::flat_map<not_null<UserData*>, Restricted> lastRestricted; base::flat_map<not_null<UserData*>, Restricted> lastRestricted;
@ -76,6 +78,13 @@ public:
MTPDchannelFull::Flags, MTPDchannelFull::Flags,
kEssentialFullFlags>; 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); ChannelData(not_null<Data::Session*> owner, PeerId id);
void setPhoto(const MTPChatPhoto &photo); void setPhoto(const MTPChatPhoto &photo);
@ -115,12 +124,6 @@ public:
return _fullFlags.value(); return _fullFlags.value();
} }
uint64 access = 0;
MTPinputChannel inputChannel;
QString username;
// Returns true if about text was changed. // Returns true if about text was changed.
bool setAbout(const QString &newAbout); bool setAbout(const QString &newAbout);
const QString &about() const { const QString &about() const {
@ -179,9 +182,6 @@ public:
bool isGroupAdmin(not_null<UserData*> user) const; bool isGroupAdmin(not_null<UserData*> user) const;
int32 date = 0;
int version = 0;
std::unique_ptr<MegagroupInfo> mgInfo;
bool lastParticipantsCountOutdated() const { bool lastParticipantsCountOutdated() const {
if (!mgInfo if (!mgInfo
|| !(mgInfo->lastParticipantsStatus || !(mgInfo->lastParticipantsStatus
@ -208,12 +208,6 @@ public:
return flags() & MTPDchannel::Flag::f_creator; 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 { auto adminRights() const {
return _adminRights.current(); return _adminRights.current();
} }
@ -224,19 +218,17 @@ public:
bool hasAdminRights() const { bool hasAdminRights() const {
return (adminRights() != 0); return (adminRights() != 0);
} }
auto restrictions() const { auto restrictions() const {
return _restrictions.current(); return _restrictions.current();
} }
auto restrictionsValue() const { auto restrictionsValue() const {
return _restrictions.value(); return _restrictions.value();
} }
bool restricted(Restriction right) const {
return restrictions() & right;
}
TimeId restrictedUntil() const { TimeId restrictedUntil() const {
return _restrictedUntill; return _restrictedUntil;
} }
void setRestrictedRights(const MTPChatBannedRights &rights); void setRestrictions(const MTPChatBannedRights &rights);
bool hasRestrictions() const { bool hasRestrictions() const {
return (restrictions() != 0); return (restrictions() != 0);
} }
@ -244,20 +236,30 @@ public:
return hasRestrictions() return hasRestrictions()
&& (restrictedUntil() > now); && (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 canBanMembers() const;
bool canEditMessages() const; bool canEditMessages() const;
bool canDeleteMessages() const; bool canDeleteMessages() const;
bool anyoneCanAddMembers() const; bool anyoneCanAddMembers() const;
bool hiddenPreHistory() const; bool hiddenPreHistory() const;
bool canAddMembers() const;
bool canAddAdmins() const; bool canAddAdmins() const;
bool canPublish() const; bool canPublish() const;
bool canWrite() const;
bool canViewMembers() const; bool canViewMembers() const;
bool canViewAdmins() const; bool canViewAdmins() const;
bool canViewBanned() const; bool canViewBanned() const;
bool canEditInformation() const;
bool canEditInvites() const;
bool canEditSignatures() const; bool canEditSignatures() const;
bool canEditPreHistoryHidden() const; bool canEditPreHistoryHidden() const;
bool canEditUsername() const; bool canEditUsername() const;
@ -270,9 +272,6 @@ public:
QString inviteLink() const; QString inviteLink() const;
bool canHaveInviteLink() 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) { void ptsInit(int32 pts) {
_ptsWaiter.init(pts); _ptsWaiter.init(pts);
} }
@ -283,15 +282,15 @@ public:
return _ptsWaiter.updateAndApply(this, pts, count); return _ptsWaiter.updateAndApply(this, pts, count);
} }
bool ptsUpdateAndApply( bool ptsUpdateAndApply(
int32 pts, int32 pts,
int32 count, int32 count,
const MTPUpdate &update) { const MTPUpdate &update) {
return _ptsWaiter.updateAndApply(this, pts, count, update); return _ptsWaiter.updateAndApply(this, pts, count, update);
} }
bool ptsUpdateAndApply( bool ptsUpdateAndApply(
int32 pts, int32 pts,
int32 count, int32 count,
const MTPUpdates &updates) { const MTPUpdates &updates) {
return _ptsWaiter.updateAndApply(this, pts, count, updates); return _ptsWaiter.updateAndApply(this, pts, count, updates);
} }
int32 pts() const { int32 pts() const {
@ -331,6 +330,20 @@ public:
return _feed; 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: private:
void flagsUpdated(MTPDchannel::Flags diff); void flagsUpdated(MTPDchannel::Flags diff);
void fullFlagsUpdated(MTPDchannelFull::Flags diff); void fullFlagsUpdated(MTPDchannelFull::Flags diff);
@ -349,9 +362,10 @@ private:
int _kickedCount = 0; int _kickedCount = 0;
MsgId _availableMinId = 0; MsgId _availableMinId = 0;
RestrictionFlags _defaultRestrictions;
AdminRightFlags _adminRights; AdminRightFlags _adminRights;
RestrictionFlags _restrictions; RestrictionFlags _restrictions;
TimeId _restrictedUntill; TimeId _restrictedUntil;
QString _unavailableReason; QString _unavailableReason;
QString _about; QString _about;

View File

@ -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 { bool ChatData::canEditInformation() const {
// #TODO groups return !actionsUnavailable()
return !isDeactivated() && !amRestricted(ChatRestriction::f_change_info);
/*&& ((adminRights() & AdminRight::f_change_info) || amCreator())*/; }
bool ChatData::canAddMembers() const {
return !actionsUnavailable()
&& !amRestricted(ChatRestriction::f_invite_users);
} }
void ChatData::setName(const QString &newName) { void ChatData::setName(const QString &newName) {
@ -45,16 +59,14 @@ void ChatData::setName(const QString &newName) {
void ChatData::invalidateParticipants() { void ChatData::invalidateParticipants() {
// #TODO groups // #TODO groups
auto wasCanEdit = canEditInformation();
participants.clear(); participants.clear();
admins.clear(); admins.clear();
//removeFlags(MTPDchat::Flag::f_admin); //removeFlags(MTPDchat::Flag::f_admin);
invitedByMe.clear(); invitedByMe.clear();
botStatus = 0; botStatus = 0;
if (wasCanEdit != canEditInformation()) { Notify::peerUpdatedDelayed(
Notify::peerUpdatedDelayed(this, Notify::PeerUpdate::Flag::ChatCanEdit); this,
} UpdateFlag::MembersChanged | UpdateFlag::AdminsChanged);
Notify::peerUpdatedDelayed(this, Notify::PeerUpdate::Flag::MembersChanged | Notify::PeerUpdate::Flag::AdminsChanged);
} }
void ChatData::setInviteLink(const QString &newInviteLink) { void ChatData::setInviteLink(const QString &newInviteLink) {
@ -63,3 +75,23 @@ void ChatData::setInviteLink(const QString &newInviteLink) {
Notify::peerUpdatedDelayed(this, UpdateFlag::InviteLinkChanged); 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);
}

View File

@ -23,6 +23,13 @@ public:
MTPDchat::Flags, MTPDchat::Flags,
kEssentialFlags>; 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); ChatData(not_null<Data::Session*> owner, PeerId id);
void setPhoto(const MTPChatPhoto &photo); void setPhoto(const MTPChatPhoto &photo);
@ -35,15 +42,6 @@ public:
return (count > 0 || amIn()) && participants.empty(); 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) { void setFlags(MTPDchat::Flags which) {
_flags.set(which); _flags.set(which);
} }
@ -60,17 +58,31 @@ public:
return _flags.value(); 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 { bool isForbidden() const {
return flags() & MTPDchat_ClientFlag::f_forbidden; return flags() & MTPDchat_ClientFlag::f_forbidden;
} }
bool amIn() const { bool amIn() const {
return !isForbidden() && !haveLeft() && !wasKicked(); return !isForbidden() && !haveLeft() && !wasKicked();
} }
bool canEditInformation() const;
bool canWrite() const {
// Duplicated in Data::CanWriteValue().
return !isDeactivated() && amIn();
}
bool haveLeft() const { bool haveLeft() const {
return flags() & MTPDchat::Flag::f_left; return flags() & MTPDchat::Flag::f_left;
} }
@ -86,6 +98,27 @@ public:
bool isMigrated() const { bool isMigrated() const {
return flags() & MTPDchat::Flag::f_migrated_to; 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_map<not_null<UserData*>, int> participants;
base::flat_set<not_null<UserData*>> invitedByMe; base::flat_set<not_null<UserData*>> invitedByMe;
base::flat_set<not_null<UserData*>> admins; 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 int botStatus = 0; // -1 - no bots, 0 - unknown, 1 - one bot, that sees all history, 2 - other
// ImagePtr photoFull; // ImagePtr photoFull;
void setInviteLink(const QString &newInviteLink);
QString inviteLink() const {
return _inviteLink;
}
private: private:
[[nodiscard]] bool actionsUnavailable() const;
void flagsUpdated(MTPDchat::Flags diff); void flagsUpdated(MTPDchat::Flags diff);
Flags _flags; Flags _flags;
QString _inviteLink; QString _inviteLink;
RestrictionFlags _defaultRestrictions;
AdminRightFlags _adminRights;
}; };

View File

@ -222,7 +222,7 @@ bool Media::forwardedBecomesUnread() const {
return false; return false;
} }
QString Media::errorTextForForward(not_null<ChannelData*> channel) const { QString Media::errorTextForForward(not_null<PeerData*> peer) const {
return QString(); return QString();
} }
@ -325,9 +325,8 @@ bool MediaPhoto::allowsEditCaption() const {
return true; return true;
} }
QString MediaPhoto::errorTextForForward( QString MediaPhoto::errorTextForForward(not_null<PeerData*> peer) const {
not_null<ChannelData*> channel) const { if (peer->amRestricted(ChatRestriction::f_send_media)) {
if (channel->restricted(ChatRestriction::f_send_media)) {
return lang(lng_restricted_send_media); return lang(lng_restricted_send_media);
} }
return QString(); return QString();
@ -650,23 +649,22 @@ bool MediaFile::forwardedBecomesUnread() const {
|| _document->isVideoMessage(); || _document->isVideoMessage();
} }
QString MediaFile::errorTextForForward( QString MediaFile::errorTextForForward(not_null<PeerData*> peer) const {
not_null<ChannelData*> channel) const {
if (const auto sticker = _document->sticker()) { 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); return lang(lng_restricted_send_stickers);
} }
} else if (_document->isAnimation()) { } else if (_document->isAnimation()) {
if (_document->isVideoMessage()) { if (_document->isVideoMessage()) {
if (channel->restricted(ChatRestriction::f_send_media)) { if (peer->amRestricted(ChatRestriction::f_send_media)) {
return lang(lng_restricted_send_media); return lang(lng_restricted_send_media);
} }
} else { } else {
if (channel->restricted(ChatRestriction::f_send_gifs)) { if (peer->amRestricted(ChatRestriction::f_send_gifs)) {
return lang(lng_restricted_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 lang(lng_restricted_send_media);
} }
return QString(); return QString();
@ -1116,9 +1114,8 @@ TextWithEntities MediaGame::clipboardText() const {
return TextWithEntities(); return TextWithEntities();
} }
QString MediaGame::errorTextForForward( QString MediaGame::errorTextForForward(not_null<PeerData*> peer) const {
not_null<ChannelData*> channel) const { if (peer->amRestricted(ChatRestriction::f_send_games)) {
if (channel->restricted(ChatRestriction::f_send_games)) {
return lang(lng_restricted_send_inline); return lang(lng_restricted_send_inline);
} }
return QString(); return QString();

View File

@ -95,8 +95,7 @@ public:
virtual bool allowsEditCaption() const; virtual bool allowsEditCaption() const;
virtual bool allowsRevoke() const; virtual bool allowsRevoke() const;
virtual bool forwardedBecomesUnread() const; virtual bool forwardedBecomesUnread() const;
virtual QString errorTextForForward( virtual QString errorTextForForward(not_null<PeerData*> peer) const;
not_null<ChannelData*> channel) const;
[[nodiscard]] virtual bool consumeMessageText( [[nodiscard]] virtual bool consumeMessageText(
const TextWithEntities &text); const TextWithEntities &text);
@ -142,8 +141,7 @@ public:
QString pinnedTextSubstring() const override; QString pinnedTextSubstring() const override;
TextWithEntities clipboardText() const override; TextWithEntities clipboardText() const override;
bool allowsEditCaption() const override; bool allowsEditCaption() const override;
QString errorTextForForward( QString errorTextForForward(not_null<PeerData*> peer) const override;
not_null<ChannelData*> channel) const override;
bool updateInlineResultMedia(const MTPMessageMedia &media) override; bool updateInlineResultMedia(const MTPMessageMedia &media) override;
bool updateSentMedia(const MTPMessageMedia &media) override; bool updateSentMedia(const MTPMessageMedia &media) override;
@ -179,8 +177,7 @@ public:
TextWithEntities clipboardText() const override; TextWithEntities clipboardText() const override;
bool allowsEditCaption() const override; bool allowsEditCaption() const override;
bool forwardedBecomesUnread() const override; bool forwardedBecomesUnread() const override;
QString errorTextForForward( QString errorTextForForward(not_null<PeerData*> peer) const override;
not_null<ChannelData*> channel) const override;
bool updateInlineResultMedia(const MTPMessageMedia &media) override; bool updateInlineResultMedia(const MTPMessageMedia &media) override;
bool updateSentMedia(const MTPMessageMedia &media) override; bool updateSentMedia(const MTPMessageMedia &media) override;
@ -331,8 +328,7 @@ public:
QString notificationText() const override; QString notificationText() const override;
QString pinnedTextSubstring() const override; QString pinnedTextSubstring() const override;
TextWithEntities clipboardText() const override; TextWithEntities clipboardText() const override;
QString errorTextForForward( QString errorTextForForward(not_null<PeerData*> peer) const override;
not_null<ChannelData*> channel) const override;
bool consumeMessageText(const TextWithEntities &text) override; bool consumeMessageText(const TextWithEntities &text) override;
TextWithEntities consumedMessageText() const override; TextWithEntities consumedMessageText() const override;

View File

@ -546,3 +546,28 @@ bool PeerData::canWrite() const {
? asUser()->canWrite() ? asUser()->canWrite()
: false; : 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;
}

View File

@ -100,6 +100,8 @@ public:
} }
bool canWrite() const; bool canWrite() const;
bool amRestricted(ChatRestriction right) const;
UserData *asUser(); UserData *asUser();
const UserData *asUser() const; const UserData *asUser() const;
ChatData *asChat(); ChatData *asChat();

View File

@ -89,6 +89,22 @@ inline auto AdminRightValue(
return SingleFlagValue(AdminRightsValue(channel), flag); 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) { inline auto RestrictionsValue(not_null<ChannelData*> channel) {
return channel->restrictionsValue(); return channel->restrictionsValue();
} }
@ -105,6 +121,38 @@ inline auto RestrictionValue(
return SingleFlagValue(RestrictionsValue(channel), flag); 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( rpl::producer<bool> PeerFlagValue(
ChatData *chat, ChatData *chat,
MTPDchat_ClientFlag flag) { MTPDchat_ClientFlag flag) {
@ -125,17 +173,36 @@ rpl::producer<bool> CanWriteValue(UserData *user) {
rpl::producer<bool> CanWriteValue(ChatData *chat) { rpl::producer<bool> CanWriteValue(ChatData *chat) {
using namespace rpl::mappers; using namespace rpl::mappers;
auto mask = 0 const auto mask = 0
| MTPDchat::Flag::f_deactivated | MTPDchat::Flag::f_deactivated
| MTPDchat_ClientFlag::f_forbidden | MTPDchat_ClientFlag::f_forbidden
| MTPDchat::Flag::f_left | MTPDchat::Flag::f_left
| MTPDchat::Flag::f_creator
| MTPDchat::Flag::f_kicked; | MTPDchat::Flag::f_kicked;
return PeerFlagsValue(chat, mask) return rpl::combine(
| rpl::map(!_1); 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) { rpl::producer<bool> CanWriteValue(ChannelData *channel) {
auto mask = 0 const auto mask = 0
| MTPDchannel::Flag::f_left | MTPDchannel::Flag::f_left
| MTPDchannel_ClientFlag::f_forbidden | MTPDchannel_ClientFlag::f_forbidden
| MTPDchannel::Flag::f_creator | MTPDchannel::Flag::f_creator
@ -148,18 +215,23 @@ rpl::producer<bool> CanWriteValue(ChannelData *channel) {
RestrictionValue( RestrictionValue(
channel, channel,
MTPDchatBannedRights::Flag::f_send_messages), MTPDchatBannedRights::Flag::f_send_messages),
DefaultRestrictionValue(
channel,
MTPDchatBannedRights::Flag::f_send_messages),
[]( [](
MTPDchannel::Flags flags, MTPDchannel::Flags flags,
bool postMessagesRight, bool postMessagesRight,
bool sendMessagesRestriction) { bool sendMessagesRestriction,
auto notAmInFlags = 0 bool defaultSendMessagesRestriction) {
const auto notAmInFlags = 0
| MTPDchannel::Flag::f_left | MTPDchannel::Flag::f_left
| MTPDchannel_ClientFlag::f_forbidden; | MTPDchannel_ClientFlag::f_forbidden;
return !(flags & notAmInFlags) return !(flags & notAmInFlags)
&& (postMessagesRight && (postMessagesRight
|| (flags & MTPDchannel::Flag::f_creator) || (flags & MTPDchannel::Flag::f_creator)
|| (!(flags & MTPDchannel::Flag::f_broadcast) || (!(flags & MTPDchannel::Flag::f_broadcast)
&& !sendMessagesRestriction)); && !sendMessagesRestriction
&& !defaultSendMessagesRestriction));
}); });
} }

View File

@ -428,8 +428,8 @@ not_null<PeerData*> Session::chat(const MTPChat &data) {
data.match([&](const MTPDchat &data) { data.match([&](const MTPDchat &data) {
const auto chat = result->asChat(); const auto chat = result->asChat();
// #TODO groups
const auto canEdit = chat->canEditInformation(); const auto canAddMembers = chat->canAddMembers();
if (chat->version < data.vversion.v) { if (chat->version < data.vversion.v) {
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->setPhoto(data.vphoto);
chat->date = data.vdate.v; 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() const auto &migratedTo = data.has_migrated_to()
? data.vmigrated_to ? data.vmigrated_to
: MTPInputChannel(MTP_inputChannelEmpty()); : MTPInputChannel(MTP_inputChannelEmpty());
@ -480,22 +487,16 @@ not_null<PeerData*> Session::chat(const MTPChat &data) {
}, [](const MTPDinputChannelEmpty &) { }, [](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->setFlags(data.vflags.v);
chat->count = data.vparticipants_count.v; chat->count = data.vparticipants_count.v;
// #TODO groups
if (canEdit != chat->canEditInformation()) { if (canAddMembers != chat->canAddMembers()) {
update.flags |= UpdateFlag::ChatCanEdit; update.flags |= UpdateFlag::RightsChanged;
} }
}, [&](const MTPDchatForbidden &data) { }, [&](const MTPDchatForbidden &data) {
const auto chat = result->asChat(); const auto chat = result->asChat();
// #TODO groups
const auto canEdit = chat->canEditInformation(); const auto canAddMembers = chat->canAddMembers();
chat->input = MTP_inputPeerChat(data.vid); chat->input = MTP_inputPeerChat(data.vid);
chat->setName(qs(data.vtitle)); chat->setName(qs(data.vtitle));
@ -504,9 +505,12 @@ not_null<PeerData*> Session::chat(const MTPChat &data) {
chat->count = -1; chat->count = -1;
chat->invalidateParticipants(); chat->invalidateParticipants();
chat->setFlags(MTPDchat_ClientFlag::f_forbidden | 0); chat->setFlags(MTPDchat_ClientFlag::f_forbidden | 0);
// #TODO groups chat->setAdminRights(MTP_chatAdminRights(MTP_flags(0)));
if (canEdit != chat->canEditInformation()) { chat->setDefaultRestrictions(
update.flags |= UpdateFlag::ChatCanEdit; MTP_chatBannedRights(MTP_flags(0), MTP_int(0)));
if (canAddMembers != chat->canAddMembers()) {
update.flags |= UpdateFlag::RightsChanged;
} }
}, [&](const MTPDchannel &data) { }, [&](const MTPDchannel &data) {
const auto channel = result->asChannel(); const auto channel = result->asChannel();
@ -545,9 +549,9 @@ not_null<PeerData*> Session::chat(const MTPChat &data) {
channel->setAdminRights(MTP_chatAdminRights(MTP_flags(0))); channel->setAdminRights(MTP_chatAdminRights(MTP_flags(0)));
} }
if (data.has_banned_rights()) { if (data.has_banned_rights()) {
channel->setRestrictedRights(data.vbanned_rights); channel->setRestrictions(data.vbanned_rights);
} else if (channel->hasRestrictions()) { } 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->inputChannel = MTP_inputChannel(data.vid, data.vaccess_hash);
channel->access = data.vaccess_hash.v; channel->access = data.vaccess_hash.v;
@ -577,7 +581,7 @@ not_null<PeerData*> Session::chat(const MTPChat &data) {
if (canViewAdmins != channel->canViewAdmins() if (canViewAdmins != channel->canViewAdmins()
|| canViewMembers != channel->canViewMembers() || canViewMembers != channel->canViewMembers()
|| canAddMembers != channel->canAddMembers()) { || canAddMembers != channel->canAddMembers()) {
update.flags |= UpdateFlag::ChannelRightsChanged; update.flags |= UpdateFlag::RightsChanged;
} }
}, [&](const MTPDchannelForbidden &data) { }, [&](const MTPDchannelForbidden &data) {
const auto channel = result->asChannel(); const auto channel = result->asChannel();
@ -597,7 +601,7 @@ not_null<PeerData*> Session::chat(const MTPChat &data) {
channel->setAdminRights(MTP_chatAdminRights(MTP_flags(0))); channel->setAdminRights(MTP_chatAdminRights(MTP_flags(0)));
} }
if (channel->hasRestrictions()) { 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()); channel->setName(qs(data.vtitle), QString());
@ -613,7 +617,7 @@ not_null<PeerData*> Session::chat(const MTPChat &data) {
if (canViewAdmins != channel->canViewAdmins() if (canViewAdmins != channel->canViewAdmins()
|| canViewMembers != channel->canViewMembers() || canViewMembers != channel->canViewMembers()
|| canAddMembers != channel->canAddMembers()) { || canAddMembers != channel->canAddMembers()) {
update.flags |= UpdateFlag::ChannelRightsChanged; update.flags |= UpdateFlag::RightsChanged;
} }
}, [](const MTPDchatEmpty &) { }, [](const MTPDchatEmpty &) {
}); });

View File

@ -52,16 +52,14 @@ MTPDmessage::Flags NewForwardedFlags(
if (fwd->Has<HistoryMessageVia>()) { if (fwd->Has<HistoryMessageVia>()) {
result |= MTPDmessage::Flag::f_via_bot_id; result |= MTPDmessage::Flag::f_via_bot_id;
} }
if (const auto channel = peer->asChannel()) { if (const auto media = fwd->media()) {
if (dynamic_cast<Data::MediaWebPage*>(fwd->media())) { if (dynamic_cast<Data::MediaWebPage*>(media)) {
// Drop web page if we're not allowed to send it. // Drop web page if we're not allowed to send it.
if (channel->restricted( if (peer->amRestricted(ChatRestriction::f_embed_links)) {
ChatRestriction::f_embed_links)) {
result &= ~MTPDmessage::Flag::f_media; result &= ~MTPDmessage::Flag::f_media;
} }
} }
} else if (const auto media = fwd->media()) { if (!peer->isChannel() && media->forwardedBecomesUnread()) {
if (media->forwardedBecomesUnread()) {
result |= MTPDmessage::Flag::f_media_unread; result |= MTPDmessage::Flag::f_media_unread;
} }
} }
@ -256,19 +254,17 @@ QString GetErrorTextForForward(
return lang(lng_forward_cant); return lang(lng_forward_cant);
} }
if (auto megagroup = peer->asMegagroup()) { for (const auto item : items) {
for (const auto item : items) { if (const auto media = item->media()) {
if (const auto media = item->media()) { const auto error = media->errorTextForForward(peer);
const auto error = media->errorTextForForward(megagroup); if (!error.isEmpty() && error != qstr("skip")) {
if (!error.isEmpty() && error != qstr("skip")) { return error;
return error;
}
} }
} }
if (megagroup->restricted(ChatRestriction::f_send_inline) }
&& HasInlineItems(items)) { if (peer->amRestricted(ChatRestriction::f_send_inline)
return lang(lng_restricted_send_inline); && HasInlineItems(items)) {
} return lang(lng_restricted_send_inline);
} }
return QString(); return QString();
} }
@ -385,6 +381,8 @@ HistoryMessage::HistoryMessage(
NewForwardedFlags(history->peer, from, original) | flags, NewForwardedFlags(history->peer, from, original) | flags,
date, date,
from) { from) {
const auto peer = history->peer;
CreateConfig config; CreateConfig config;
if (original->Has<HistoryMessageForwarded>() || !original->history()->peer->isSelf()) { if (original->Has<HistoryMessageForwarded>() || !original->history()->peer->isSelf()) {
@ -397,7 +395,7 @@ HistoryMessage::HistoryMessage(
config.originalId = original->idOriginal(); config.originalId = original->idOriginal();
} }
} }
if (history->peer->isSelf()) { if (peer->isSelf()) {
// //
// iOS app sends you to the original post if we forward a forward from channel. // iOS app sends you to the original post if we forward a forward from channel.
// But server returns not the original post but the forward in saved_from_... // But server returns not the original post but the forward in saved_from_...
@ -430,12 +428,10 @@ HistoryMessage::HistoryMessage(
createComponents(config); createComponents(config);
auto ignoreMedia = [&] { const auto ignoreMedia = [&] {
if (mediaOriginal && mediaOriginal->webpage()) { if (mediaOriginal && mediaOriginal->webpage()) {
if (const auto channel = history->peer->asChannel()) { if (peer->amRestricted(ChatRestriction::f_embed_links)) {
if (channel->restricted(ChatRestriction::f_embed_links)) { return true;
return true;
}
} }
} }
return false; return false;

View File

@ -405,7 +405,7 @@ HistoryWidget::HistoryWidget(
} }
}); });
using UpdateFlag = Notify::PeerUpdate::Flag; using UpdateFlag = Notify::PeerUpdate::Flag;
auto changes = UpdateFlag::ChannelRightsChanged auto changes = UpdateFlag::RightsChanged
| UpdateFlag::UnreadMentionsChanged | UpdateFlag::UnreadMentionsChanged
| UpdateFlag::UnreadViewChanged | UpdateFlag::UnreadViewChanged
| UpdateFlag::MigrationChanged | UpdateFlag::MigrationChanged
@ -420,7 +420,7 @@ HistoryWidget::HistoryWidget(
| UpdateFlag::ChannelPromotedChanged; | UpdateFlag::ChannelPromotedChanged;
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(changes, [this](const Notify::PeerUpdate &update) { subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(changes, [this](const Notify::PeerUpdate &update) {
if (update.peer == _peer) { if (update.peer == _peer) {
if (update.flags & UpdateFlag::ChannelRightsChanged) { if (update.flags & UpdateFlag::RightsChanged) {
checkPreview(); checkPreview();
} }
if (update.flags & UpdateFlag::UnreadMentionsChanged) { if (update.flags & UpdateFlag::UnreadMentionsChanged) {
@ -1934,11 +1934,7 @@ bool HistoryWidget::canWriteMessage() const {
} }
bool HistoryWidget::isRestrictedWrite() const { bool HistoryWidget::isRestrictedWrite() const {
if (auto megagroup = _peer ? _peer->asMegagroup() : nullptr) { return _peer && _peer->amRestricted(ChatRestriction::f_send_messages);
return megagroup->restricted(
ChatRestriction::f_send_messages);
}
return false;
} }
void HistoryWidget::updateControlsVisibility() { void HistoryWidget::updateControlsVisibility() {
@ -3034,12 +3030,11 @@ void HistoryWidget::step_recording(float64 ms, bool timer) {
} }
void HistoryWidget::chooseAttach() { void HistoryWidget::chooseAttach() {
if (!_peer || !_peer->canWrite()) return; if (!_peer || !_peer->canWrite()) {
if (auto megagroup = _peer->asMegagroup()) { return;
if (megagroup->restricted(ChatRestriction::f_send_media)) { } else if (_peer->amRestricted(ChatRestriction::f_send_media)) {
Ui::show(Box<InformBox>(lang(lng_restricted_send_media))); Ui::show(Box<InformBox>(lang(lng_restricted_send_media)));
return; return;
}
} }
auto filter = FileDialog::AllFilesFilter() + qsl(";;Image files (*") + cImgExtensions().join(qsl(" *")) + qsl(")"); auto filter = FileDialog::AllFilesFilter() + qsl(";;Image files (*") + cImgExtensions().join(qsl(" *")) + qsl(")");
@ -3142,14 +3137,11 @@ void HistoryWidget::leaveToChildEvent(QEvent *e, QWidget *child) { // e -- from
} }
void HistoryWidget::recordStartCallback() { void HistoryWidget::recordStartCallback() {
if (!Media::Capture::instance()->available()) { if (_peer && _peer->amRestricted(ChatRestriction::f_send_media)) {
Ui::show(Box<InformBox>(lang(lng_restricted_send_media)));
return;
} else if (!Media::Capture::instance()->available()) {
return; return;
}
if (auto megagroup = _peer ? _peer->asMegagroup() : nullptr) {
if (megagroup->restricted(ChatRestriction::f_send_media)) {
Ui::show(Box<InformBox>(lang(lng_restricted_send_media)));
return;
}
} }
emit Media::Capture::instance()->start(); emit Media::Capture::instance()->start();
@ -3940,12 +3932,9 @@ void HistoryWidget::updateFieldPlaceholder() {
bool HistoryWidget::showSendingFilesError( bool HistoryWidget::showSendingFilesError(
const Storage::PreparedList &list) const { const Storage::PreparedList &list) const {
const auto text = [&] { const auto text = [&] {
if (const auto megagroup = _peer ? _peer->asMegagroup() : nullptr) { if (_peer && _peer->amRestricted(ChatRestriction::f_send_media)) {
if (megagroup->restricted(ChatRestriction::f_send_media)) { return lang(lng_restricted_send_media);
return lang(lng_restricted_send_media); } else if (!canWriteMessage()) {
}
}
if (!canWriteMessage()) {
return lang(lng_forward_send_files_cant); return lang(lng_forward_send_files_cant);
} }
using Error = Storage::PreparedList::Error; using Error = Storage::PreparedList::Error;
@ -5379,13 +5368,11 @@ void HistoryWidget::destroyPinnedBar() {
bool HistoryWidget::sendExistingDocument( bool HistoryWidget::sendExistingDocument(
not_null<DocumentData*> document, not_null<DocumentData*> document,
TextWithEntities caption) { TextWithEntities caption) {
if (const auto megagroup = _peer ? _peer->asMegagroup() : nullptr) { if (_peer && _peer->amRestricted(ChatRestriction::f_send_stickers)) {
if (megagroup->restricted(ChatRestriction::f_send_stickers)) { Ui::show(
Ui::show( Box<InformBox>(lang(lng_restricted_send_stickers)),
Box<InformBox>(lang(lng_restricted_send_stickers)), LayerOption::KeepOther);
LayerOption::KeepOther); return false;
return false;
}
} else if (!_peer || !_peer->canWrite()) { } else if (!_peer || !_peer->canWrite()) {
return false; return false;
} }
@ -5415,13 +5402,11 @@ bool HistoryWidget::sendExistingDocument(
bool HistoryWidget::sendExistingPhoto( bool HistoryWidget::sendExistingPhoto(
not_null<PhotoData*> photo, not_null<PhotoData*> photo,
TextWithEntities caption) { TextWithEntities caption) {
if (const auto megagroup = _peer ? _peer->asMegagroup() : nullptr) { if (_peer && _peer->amRestricted(ChatRestriction::f_send_media)) {
if (megagroup->restricted(ChatRestriction::f_send_media)) { Ui::show(
Ui::show( Box<InformBox>(lang(lng_restricted_send_media)),
Box<InformBox>(lang(lng_restricted_send_media)), LayerOption::KeepOther);
LayerOption::KeepOther); return false;
return false;
}
} else if (!_peer || !_peer->canWrite()) { } else if (!_peer || !_peer->canWrite()) {
return false; return false;
} }
@ -5862,12 +5847,7 @@ void HistoryWidget::previewCancel() {
void HistoryWidget::checkPreview() { void HistoryWidget::checkPreview() {
auto previewRestricted = [this] { auto previewRestricted = [this] {
if (auto megagroup = _peer ? _peer->asMegagroup() : nullptr) { return _peer && _peer->amRestricted(ChatRestriction::f_embed_links);
if (megagroup->restricted(ChatRestriction::f_embed_links)) {
return true;
}
}
return false;
}; };
if (_previewCancelled || previewRestricted()) { if (_previewCancelled || previewRestricted()) {
previewCancel(); previewCancel();

View File

@ -285,14 +285,14 @@ void Cover::initViewers() {
_peer, _peer,
Flag::UserOnlineChanged | Flag::MembersChanged Flag::UserOnlineChanged | Flag::MembersChanged
) | rpl::start_with_next( ) | rpl::start_with_next(
[this] { refreshStatusText(); }, [=] { refreshStatusText(); },
lifetime()); lifetime());
if (!_peer->isUser()) { if (!_peer->isUser()) {
Notify::PeerUpdateValue( Notify::PeerUpdateValue(
_peer, _peer,
Flag::ChannelRightsChanged | Flag::ChatCanEdit Flag::RightsChanged
) | rpl::start_with_next( ) | rpl::start_with_next(
[this] { refreshUploadPhotoOverlay(); }, [=] { refreshUploadPhotoOverlay(); },
lifetime()); lifetime());
} else if (_peer->isSelf()) { } else if (_peer->isSelf()) {
refreshUploadPhotoOverlay(); refreshUploadPhotoOverlay();
@ -300,7 +300,7 @@ void Cover::initViewers() {
VerifiedValue( VerifiedValue(
_peer _peer
) | rpl::start_with_next( ) | rpl::start_with_next(
[this](bool verified) { setVerified(verified); }, [=](bool verified) { setVerified(verified); },
lifetime()); lifetime());
} }

View File

@ -214,8 +214,8 @@ rpl::producer<int> AdminsCountValue(
using Flag = Notify::PeerUpdate::Flag; using Flag = Notify::PeerUpdate::Flag;
return Notify::PeerUpdateValue( return Notify::PeerUpdateValue(
channel, channel,
Flag::AdminsChanged | Flag::ChannelRightsChanged Flag::AdminsChanged | Flag::RightsChanged
) | rpl::map([channel] { ) | rpl::map([=] {
return channel->canViewAdmins() return channel->canViewAdmins()
? channel->adminsCount() ? channel->adminsCount()
: 0; : 0;
@ -227,8 +227,8 @@ rpl::producer<int> RestrictedCountValue(
using Flag = Notify::PeerUpdate::Flag; using Flag = Notify::PeerUpdate::Flag;
return Notify::PeerUpdateValue( return Notify::PeerUpdateValue(
channel, channel,
Flag::BannedUsersChanged | Flag::ChannelRightsChanged Flag::BannedUsersChanged | Flag::RightsChanged
) | rpl::map([channel] { ) | rpl::map([=] {
return channel->canViewBanned() return channel->canViewBanned()
? channel->restrictedCount() ? channel->restrictedCount()
: 0; : 0;
@ -240,8 +240,8 @@ rpl::producer<int> KickedCountValue(
using Flag = Notify::PeerUpdate::Flag; using Flag = Notify::PeerUpdate::Flag;
return Notify::PeerUpdateValue( return Notify::PeerUpdateValue(
channel, channel,
Flag::BannedUsersChanged | Flag::ChannelRightsChanged Flag::BannedUsersChanged | Flag::RightsChanged
) | rpl::map([channel] { ) | rpl::map([=] {
return channel->canViewBanned() return channel->canViewBanned()
? channel->kickedCount() ? channel->kickedCount()
: 0; : 0;
@ -284,15 +284,15 @@ rpl::producer<bool> CanAddMemberValue(
if (auto chat = peer->asChat()) { if (auto chat = peer->asChat()) {
return Notify::PeerUpdateValue( return Notify::PeerUpdateValue(
chat, chat,
Notify::PeerUpdate::Flag::ChatCanEdit Notify::PeerUpdate::Flag::RightsChanged
) | rpl::map([chat] { ) | rpl::map([=] {
return chat->canEditInformation(); // #TODO groups return chat->canAddMembers();
}); });
} else if (auto channel = peer->asChannel()) { } else if (auto channel = peer->asChannel()) {
return Notify::PeerUpdateValue( return Notify::PeerUpdateValue(
channel, channel,
Notify::PeerUpdate::Flag::ChannelRightsChanged Notify::PeerUpdate::Flag::RightsChanged
) | rpl::map([channel] { ) | rpl::map([=] {
return channel->canAddMembers(); return channel->canAddMembers();
}); });
} }

View File

@ -64,10 +64,8 @@ void SendDataCommon::addToHistory(
QString SendDataCommon::getErrorOnSend( QString SendDataCommon::getErrorOnSend(
const Result *owner, const Result *owner,
not_null<History*> history) const { not_null<History*> history) const {
if (const auto megagroup = history->peer->asMegagroup()) { if (history->peer->amRestricted(ChatRestriction::f_send_messages)) {
if (megagroup->restricted(ChatRestriction::f_send_messages)) { return lang(lng_restricted_send_message);
return lang(lng_restricted_send_message);
}
} }
return QString(); return QString();
} }
@ -146,10 +144,8 @@ void SendPhoto::addToHistory(
QString SendPhoto::getErrorOnSend( QString SendPhoto::getErrorOnSend(
const Result *owner, const Result *owner,
not_null<History*> history) const { not_null<History*> history) const {
if (const auto megagroup = history->peer->asMegagroup()) { if (history->peer->amRestricted(ChatRestriction::f_send_media)) {
if (megagroup->restricted(ChatRestriction::f_send_media)) { return lang(lng_restricted_send_media);
return lang(lng_restricted_send_media);
}
} }
return QString(); return QString();
} }
@ -181,17 +177,15 @@ void SendFile::addToHistory(
QString SendFile::getErrorOnSend( QString SendFile::getErrorOnSend(
const Result *owner, const Result *owner,
not_null<History*> history) const { not_null<History*> history) const {
if (const auto megagroup = history->peer->asMegagroup()) { if (history->peer->amRestricted(ChatRestriction::f_send_media)) {
if (megagroup->restricted(ChatRestriction::f_send_media)) { return lang(lng_restricted_send_media);
return lang(lng_restricted_send_media); } else if (history->peer->amRestricted(ChatRestriction::f_send_stickers)
} else if (megagroup->restricted(ChatRestriction::f_send_stickers) && (_document->sticker() != nullptr)) {
&& (_document->sticker() != nullptr)) { return lang(lng_restricted_send_stickers);
return lang(lng_restricted_send_stickers); } else if (history->peer->amRestricted(ChatRestriction::f_send_gifs)
} else if (megagroup->restricted(ChatRestriction::f_send_gifs) && _document->isAnimation()
&& _document->isAnimation() && !_document->isVideoMessage()) {
&& !_document->isVideoMessage()) { return lang(lng_restricted_send_gifs);
return lang(lng_restricted_send_gifs);
}
} }
return QString(); return QString();
} }
@ -222,10 +216,8 @@ void SendGame::addToHistory(
QString SendGame::getErrorOnSend( QString SendGame::getErrorOnSend(
const Result *owner, const Result *owner,
not_null<History*> history) const { not_null<History*> history) const {
if (auto megagroup = history->peer->asMegagroup()) { if (history->peer->amRestricted(ChatRestriction::f_send_games)) {
if (megagroup->restricted(ChatRestriction::f_send_games)) { return lang(lng_restricted_send_inline);
return lang(lng_restricted_send_inline);
}
} }
return QString(); return QString();
} }

View File

@ -58,7 +58,7 @@ Inner::Inner(QWidget *parent, not_null<Window::Controller*> controller) : TWidge
update(); update();
} }
}); });
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(Notify::PeerUpdate::Flag::ChannelRightsChanged, [this](const Notify::PeerUpdate &update) { subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(Notify::PeerUpdate::Flag::RightsChanged, [this](const Notify::PeerUpdate &update) {
if (update.peer == _inlineQueryPeer) { if (update.peer == _inlineQueryPeer) {
auto isRestricted = (_restrictedLabel != nullptr); auto isRestricted = (_restrictedLabel != nullptr);
if (isRestricted != isRestrictedView()) { if (isRestricted != isRestrictedView()) {
@ -80,8 +80,8 @@ void Inner::visibleTopBottomUpdated(
} }
void Inner::checkRestrictedPeer() { void Inner::checkRestrictedPeer() {
if (auto megagroup = _inlineQueryPeer ? _inlineQueryPeer->asMegagroup() : nullptr) { if (_inlineQueryPeer) {
if (megagroup->restricted(ChatRestriction::f_send_inline)) { if (_inlineQueryPeer->amRestricted(ChatRestriction::f_send_inline)) {
if (!_restrictedLabel) { if (!_restrictedLabel) {
_restrictedLabel.create(this, lang(lng_restricted_send_inline), Ui::FlatLabel::InitType::Simple, st::stickersRestrictedLabel); _restrictedLabel.create(this, lang(lng_restricted_send_inline), Ui::FlatLabel::InitType::Simple, st::stickersRestrictedLabel);
_restrictedLabel->show(); _restrictedLabel->show();

View File

@ -565,11 +565,9 @@ bool MainWidget::sendPaths(PeerId peerId) {
if (!peer->canWrite()) { if (!peer->canWrite()) {
Ui::show(Box<InformBox>(lang(lng_forward_send_files_cant))); Ui::show(Box<InformBox>(lang(lng_forward_send_files_cant)));
return false; return false;
} else if (auto megagroup = peer->asMegagroup()) { } else if (peer->amRestricted(ChatRestriction::f_send_media)) {
if (megagroup->restricted(ChatRestriction::f_send_media)) { Ui::show(Box<InformBox>(lang(lng_restricted_send_media)));
Ui::show(Box<InformBox>(lang(lng_restricted_send_media))); return false;
return false;
}
} }
Ui::showPeerHistory(peer, ShowAtTheEndMsgId); Ui::showPeerHistory(peer, ShowAtTheEndMsgId);
return _history->confirmSendingFiles(cSendPaths()); return _history->confirmSendingFiles(cSendPaths());

View File

@ -46,26 +46,23 @@ struct PeerUpdate {
AdminsChanged = (1 << 13), AdminsChanged = (1 << 13),
BannedUsersChanged = (1 << 14), BannedUsersChanged = (1 << 14),
UnreadMentionsChanged = (1 << 15), UnreadMentionsChanged = (1 << 15),
RightsChanged = (1 << 16),
// For users // For users
UserCanShareContact = (1 << 16), UserCanShareContact = (1 << 17),
UserIsContact = (1 << 17), UserIsContact = (1 << 18),
UserPhoneChanged = (1 << 18), UserPhoneChanged = (1 << 19),
UserIsBlocked = (1 << 19), UserIsBlocked = (1 << 20),
BotCommandsChanged = (1 << 20), BotCommandsChanged = (1 << 21),
UserOnlineChanged = (1 << 21), UserOnlineChanged = (1 << 22),
BotCanAddToGroups = (1 << 22), BotCanAddToGroups = (1 << 23),
UserCommonChatsChanged = (1 << 23), UserCommonChatsChanged = (1 << 24),
UserHasCalls = (1 << 24), UserHasCalls = (1 << 25),
UserOccupiedChanged = (1 << 25), UserOccupiedChanged = (1 << 26),
UserSupportInfoChanged = (1 << 26), UserSupportInfoChanged = (1 << 27),
// For chats
ChatCanEdit = (1 << 16),
// For channels // For channels
ChannelAmIn = (1 << 16), ChannelAmIn = (1 << 17),
ChannelRightsChanged = (1 << 17),
ChannelStickersChanged = (1 << 18), ChannelStickersChanged = (1 << 18),
ChannelPromotedChanged = (1 << 19), ChannelPromotedChanged = (1 << 19),
}; };