mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-30 22:25:12 +00:00
Don't use MTP* for ChatAdminRight / ChatRestriction.
This commit is contained in:
@@ -44,32 +44,32 @@ void ChatData::setPhoto(const MTPChatPhoto &photo) {
|
||||
});
|
||||
}
|
||||
|
||||
auto ChatData::defaultAdminRights(not_null<UserData*> user) -> AdminRights {
|
||||
ChatAdminRightsInfo ChatData::defaultAdminRights(not_null<UserData*> user) {
|
||||
const auto isCreator = (creator == peerToUser(user->id))
|
||||
|| (user->isSelf() && amCreator());
|
||||
using Flag = AdminRight;
|
||||
return Flag::f_other
|
||||
| Flag::f_change_info
|
||||
| Flag::f_delete_messages
|
||||
| Flag::f_ban_users
|
||||
| Flag::f_invite_users
|
||||
| Flag::f_pin_messages
|
||||
| Flag::f_manage_call
|
||||
| (isCreator ? Flag::f_add_admins : Flag(0));
|
||||
return ChatAdminRightsInfo(Flag::Other
|
||||
| Flag::ChangeInfo
|
||||
| Flag::DeleteMessages
|
||||
| Flag::BanUsers
|
||||
| Flag::InviteUsers
|
||||
| Flag::PinMessages
|
||||
| Flag::ManageCall
|
||||
| (isCreator ? Flag::AddAdmins : Flag(0)));
|
||||
}
|
||||
|
||||
bool ChatData::canWrite() const {
|
||||
// Duplicated in Data::CanWriteValue().
|
||||
return amIn() && !amRestricted(Restriction::f_send_messages);
|
||||
return amIn() && !amRestricted(Restriction::SendMessages);
|
||||
}
|
||||
|
||||
bool ChatData::canEditInformation() const {
|
||||
return amIn() && !amRestricted(Restriction::f_change_info);
|
||||
return amIn() && !amRestricted(Restriction::ChangeInfo);
|
||||
}
|
||||
|
||||
bool ChatData::canEditPermissions() const {
|
||||
return amIn()
|
||||
&& (amCreator() || (adminRights() & AdminRight::f_ban_users));
|
||||
&& (amCreator() || (adminRights() & AdminRight::BanUsers));
|
||||
}
|
||||
|
||||
bool ChatData::canEditUsername() const {
|
||||
@@ -83,15 +83,15 @@ bool ChatData::canEditPreHistoryHidden() const {
|
||||
|
||||
bool ChatData::canDeleteMessages() const {
|
||||
return amCreator()
|
||||
|| (adminRights() & AdminRight::f_delete_messages);
|
||||
|| (adminRights() & AdminRight::DeleteMessages);
|
||||
}
|
||||
|
||||
bool ChatData::canAddMembers() const {
|
||||
return amIn() && !amRestricted(Restriction::f_invite_users);
|
||||
return amIn() && !amRestricted(Restriction::InviteUsers);
|
||||
}
|
||||
|
||||
bool ChatData::canSendPolls() const {
|
||||
return amIn() && !amRestricted(Restriction::f_send_polls);
|
||||
return amIn() && !amRestricted(Restriction::SendPolls);
|
||||
}
|
||||
|
||||
bool ChatData::canAddAdmins() const {
|
||||
@@ -100,11 +100,11 @@ bool ChatData::canAddAdmins() const {
|
||||
|
||||
bool ChatData::canBanMembers() const {
|
||||
return amCreator()
|
||||
|| (adminRights() & AdminRight::f_ban_users);
|
||||
|| (adminRights() & AdminRight::BanUsers);
|
||||
}
|
||||
|
||||
bool ChatData::anyoneCanAddMembers() const {
|
||||
return !(defaultRestrictions() & Restriction::f_invite_users);
|
||||
return !(defaultRestrictions() & Restriction::InviteUsers);
|
||||
}
|
||||
|
||||
void ChatData::setName(const QString &newName) {
|
||||
@@ -123,8 +123,8 @@ void ChatData::applyEditAdmin(not_null<UserData*> user, bool isAdmin) {
|
||||
void ChatData::invalidateParticipants() {
|
||||
participants.clear();
|
||||
admins.clear();
|
||||
setAdminRights(MTP_chatAdminRights(MTP_flags(0)));
|
||||
//setDefaultRestrictions(MTP_chatBannedRights(MTP_flags(0), MTP_int(0)));
|
||||
setAdminRights(ChatAdminRights());
|
||||
//setDefaultRestrictions(ChatRestrictions());
|
||||
invitedByMe.clear();
|
||||
botStatus = 0;
|
||||
session().changes().peerUpdated(
|
||||
@@ -138,25 +138,24 @@ void ChatData::setInviteLink(const QString &newInviteLink) {
|
||||
|
||||
bool ChatData::canHaveInviteLink() const {
|
||||
return amCreator()
|
||||
|| (adminRights() & AdminRight::f_invite_users);
|
||||
|| (adminRights() & AdminRight::InviteUsers);
|
||||
}
|
||||
|
||||
void ChatData::setAdminRights(const MTPChatAdminRights &rights) {
|
||||
if (rights.c_chatAdminRights().vflags().v == adminRights()) {
|
||||
void ChatData::setAdminRights(ChatAdminRights rights) {
|
||||
if (rights == adminRights()) {
|
||||
return;
|
||||
}
|
||||
_adminRights.set(rights.c_chatAdminRights().vflags().v);
|
||||
_adminRights.set(rights);
|
||||
session().changes().peerUpdated(
|
||||
this,
|
||||
UpdateFlag::Rights | UpdateFlag::Admins | UpdateFlag::BannedUsers);
|
||||
}
|
||||
|
||||
void ChatData::setDefaultRestrictions(const MTPChatBannedRights &rights) {
|
||||
const auto restrictionFlags = Data::ChatBannedRightsFlags(rights);
|
||||
if (restrictionFlags == defaultRestrictions()) {
|
||||
void ChatData::setDefaultRestrictions(ChatRestrictions rights) {
|
||||
if (rights == defaultRestrictions()) {
|
||||
return;
|
||||
}
|
||||
_defaultRestrictions.set(restrictionFlags);
|
||||
_defaultRestrictions.set(rights);
|
||||
session().changes().peerUpdated(this, UpdateFlag::Rights);
|
||||
}
|
||||
|
||||
@@ -329,7 +328,7 @@ void ApplyChatUpdate(
|
||||
chat->invitedByMe.remove(user);
|
||||
chat->admins.remove(user);
|
||||
if (user->isSelf()) {
|
||||
chat->setAdminRights(MTP_chatAdminRights(MTP_flags(0)));
|
||||
chat->setAdminRights(ChatAdminRights());
|
||||
}
|
||||
if (const auto history = chat->owner().historyLoaded(chat)) {
|
||||
if (history->lastKeyboardFrom == user->id) {
|
||||
@@ -357,9 +356,9 @@ void ApplyChatUpdate(
|
||||
return;
|
||||
}
|
||||
if (user->isSelf()) {
|
||||
chat->setAdminRights(MTP_chatAdminRights(mtpIsTrue(update.vis_admin())
|
||||
? MTP_flags(chat->defaultAdminRights(user))
|
||||
: MTP_flags(0)));
|
||||
chat->setAdminRights(mtpIsTrue(update.vis_admin())
|
||||
? chat->defaultAdminRights(user).flags
|
||||
: ChatAdminRights());
|
||||
}
|
||||
if (mtpIsTrue(update.vis_admin())) {
|
||||
if (chat->noParticipantInfo()) {
|
||||
@@ -380,7 +379,8 @@ void ApplyChatUpdate(
|
||||
!= ChatData::UpdateStatus::Good) {
|
||||
return;
|
||||
}
|
||||
chat->setDefaultRestrictions(update.vdefault_banned_rights());
|
||||
chat->setDefaultRestrictions(Data::ChatBannedRightsFlags(
|
||||
update.vdefault_banned_rights()));
|
||||
}
|
||||
|
||||
void ApplyChatUpdate(not_null<ChatData*> chat, const MTPDchatFull &update) {
|
||||
@@ -450,7 +450,7 @@ void ApplyChatUpdate(
|
||||
chat->participants.clear();
|
||||
chat->invitedByMe.clear();
|
||||
chat->admins.clear();
|
||||
chat->setAdminRights(MTP_chatAdminRights(MTP_flags(0)));
|
||||
chat->setAdminRights(ChatAdminRights());
|
||||
const auto selfUserId = session->userId();
|
||||
for (const auto &participant : list) {
|
||||
const auto userId = participant.match([&](const auto &data) {
|
||||
@@ -479,8 +479,8 @@ void ApplyChatUpdate(
|
||||
}, [&](const MTPDchatParticipantAdmin &data) {
|
||||
chat->admins.emplace(user);
|
||||
if (user->isSelf()) {
|
||||
chat->setAdminRights(MTP_chatAdminRights(
|
||||
MTP_flags(chat->defaultAdminRights(user))));
|
||||
chat->setAdminRights(
|
||||
chat->defaultAdminRights(user).flags);
|
||||
}
|
||||
}, [](const MTPDchatParticipant &) {
|
||||
});
|
||||
|
Reference in New Issue
Block a user