mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 06:35:14 +00:00
Update API scheme to layer 126.
This commit is contained in:
@@ -267,11 +267,17 @@ void ChannelData::applyEditAdmin(
|
||||
session().changes().peerUpdated(this, UpdateFlag::Admins);
|
||||
}
|
||||
|
||||
void ChannelData::applyEditBanned(not_null<UserData*> user, const MTPChatBannedRights &oldRights, const MTPChatBannedRights &newRights) {
|
||||
void ChannelData::applyEditBanned(
|
||||
not_null<PeerData*> participant,
|
||||
const MTPChatBannedRights &oldRights,
|
||||
const MTPChatBannedRights &newRights) {
|
||||
auto flags = UpdateFlag::BannedUsers | UpdateFlag::None;
|
||||
auto isKicked = (newRights.c_chatBannedRights().vflags().v & MTPDchatBannedRights::Flag::f_view_messages);
|
||||
auto isRestricted = !isKicked && (newRights.c_chatBannedRights().vflags().v != 0);
|
||||
if (mgInfo) {
|
||||
auto isKicked = Data::ChatBannedRightsFlags(newRights)
|
||||
& ChatRestriction::f_view_messages;
|
||||
auto isRestricted = !isKicked
|
||||
&& (Data::ChatBannedRightsFlags(newRights) != 0);
|
||||
const auto user = participant->asUser();
|
||||
if (mgInfo && user) {
|
||||
// If rights are empty - still remove admin? TODO check
|
||||
if (mgInfo->lastAdmins.contains(user)) {
|
||||
mgInfo->lastAdmins.remove(user);
|
||||
@@ -284,7 +290,9 @@ void ChannelData::applyEditBanned(not_null<UserData*> user, const MTPChatBannedR
|
||||
auto it = mgInfo->lastRestricted.find(user);
|
||||
if (isRestricted) {
|
||||
if (it == mgInfo->lastRestricted.cend()) {
|
||||
mgInfo->lastRestricted.emplace(user, MegagroupInfo::Restricted { newRights });
|
||||
mgInfo->lastRestricted.emplace(
|
||||
user,
|
||||
MegagroupInfo::Restricted { newRights });
|
||||
setRestrictedCount(restrictedCount() + 1);
|
||||
} else {
|
||||
it->second.rights = newRights;
|
||||
@@ -297,7 +305,9 @@ void ChannelData::applyEditBanned(not_null<UserData*> user, const MTPChatBannedR
|
||||
}
|
||||
}
|
||||
if (isKicked) {
|
||||
auto i = ranges::find(mgInfo->lastParticipants, user);
|
||||
auto i = ranges::find(
|
||||
mgInfo->lastParticipants,
|
||||
not_null{ user });
|
||||
if (i != mgInfo->lastParticipants.end()) {
|
||||
mgInfo->lastParticipants.erase(i);
|
||||
}
|
||||
@@ -319,9 +329,9 @@ void ChannelData::applyEditBanned(not_null<UserData*> user, const MTPChatBannedR
|
||||
}
|
||||
}
|
||||
Data::ChannelAdminChanges(this).remove(peerToUser(user->id));
|
||||
} else {
|
||||
} else if (!mgInfo) {
|
||||
if (isKicked) {
|
||||
if (membersCount() > 1) {
|
||||
if (user && membersCount() > 1) {
|
||||
setMembersCount(membersCount() - 1);
|
||||
flags |= UpdateFlag::Members;
|
||||
}
|
||||
@@ -543,12 +553,14 @@ void ChannelData::setAdminRights(const MTPChatAdminRights &rights) {
|
||||
}
|
||||
|
||||
void ChannelData::setRestrictions(const MTPChatBannedRights &rights) {
|
||||
if (rights.c_chatBannedRights().vflags().v == restrictions()
|
||||
&& rights.c_chatBannedRights().vuntil_date().v == _restrictedUntil) {
|
||||
const auto restrictedFlags = Data::ChatBannedRightsFlags(rights);
|
||||
const auto restrictedUntilDate = Data::ChatBannedRightsUntilDate(rights);
|
||||
if (restrictedFlags == restrictions()
|
||||
&& restrictedUntilDate == _restrictedUntil) {
|
||||
return;
|
||||
}
|
||||
_restrictedUntil = rights.c_chatBannedRights().vuntil_date().v;
|
||||
_restrictions.set(rights.c_chatBannedRights().vflags().v);
|
||||
_restrictedUntil = restrictedUntilDate;
|
||||
_restrictions.set(restrictedFlags);
|
||||
if (isMegagroup()) {
|
||||
const auto self = session().user();
|
||||
if (hasRestrictions()) {
|
||||
@@ -568,10 +580,11 @@ void ChannelData::setRestrictions(const MTPChatBannedRights &rights) {
|
||||
}
|
||||
|
||||
void ChannelData::setDefaultRestrictions(const MTPChatBannedRights &rights) {
|
||||
if (rights.c_chatBannedRights().vflags().v == defaultRestrictions()) {
|
||||
const auto restrictionFlags = Data::ChatBannedRightsFlags(rights);
|
||||
if (restrictionFlags == defaultRestrictions()) {
|
||||
return;
|
||||
}
|
||||
_defaultRestrictions.set(rights.c_chatBannedRights().vflags().v);
|
||||
_defaultRestrictions.set(restrictionFlags);
|
||||
session().changes().peerUpdated(this, UpdateFlag::Rights);
|
||||
}
|
||||
|
||||
@@ -903,8 +916,11 @@ void ApplyMegagroupAdmins(
|
||||
auto admins = ranges::make_subrange(
|
||||
list.begin(), list.end()
|
||||
) | ranges::views::transform([](const MTPChannelParticipant &p) {
|
||||
const auto userId = p.match([](const auto &data) {
|
||||
return data.vuser_id().v;
|
||||
const auto participantId = p.match([](
|
||||
const MTPDchannelParticipantBanned &data) {
|
||||
return peerFromMTP(data.vpeer());
|
||||
}, [](const auto &data) {
|
||||
return peerFromUser(data.vuser_id());
|
||||
});
|
||||
const auto rank = p.match([](const MTPDchannelParticipantAdmin &data) {
|
||||
return qs(data.vrank().value_or_empty());
|
||||
@@ -913,10 +929,13 @@ void ApplyMegagroupAdmins(
|
||||
}, [](const auto &data) {
|
||||
return QString();
|
||||
});
|
||||
return std::make_pair(userId, rank);
|
||||
return std::make_pair(participantId, rank);
|
||||
}) | ranges::views::filter([](const auto &pair) {
|
||||
return peerIsUser(pair.first);
|
||||
});
|
||||
for (const auto &[userId, rank] : admins) {
|
||||
adding.emplace(userId, rank);
|
||||
for (const auto &[participantId, rank] : admins) {
|
||||
Assert(peerIsUser(participantId));
|
||||
adding.emplace(peerToUser(participantId), rank);
|
||||
}
|
||||
if (channel->mgInfo->creator) {
|
||||
adding.emplace(
|
||||
|
Reference in New Issue
Block a user