2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Support legacy groups in participant boxes.

This commit is contained in:
John Preston
2019-01-10 10:26:08 +04:00
parent 18c6be0d3b
commit a605c110a8
39 changed files with 3064 additions and 2649 deletions

View File

@@ -105,12 +105,23 @@ void ChannelData::setKickedCount(int newKickedCount) {
MTPChatBannedRights ChannelData::KickedRestrictedRights() {
using Flag = MTPDchatBannedRights::Flag;
auto flags = Flag::f_view_messages | Flag::f_send_messages | Flag::f_send_media | Flag::f_embed_links | Flag::f_send_stickers | Flag::f_send_gifs | Flag::f_send_games | Flag::f_send_inline;
return MTP_chatBannedRights(MTP_flags(flags), MTP_int(std::numeric_limits<int32>::max()));
const auto flags = Flag::f_view_messages
| Flag::f_send_messages
| Flag::f_send_media
| Flag::f_embed_links
| Flag::f_send_stickers
| Flag::f_send_gifs
| Flag::f_send_games
| Flag::f_send_inline;
return MTP_chatBannedRights(
MTP_flags(flags),
MTP_int(std::numeric_limits<int32>::max()));
}
void ChannelData::applyEditAdmin(not_null<UserData*> user, const MTPChatAdminRights &oldRights, const MTPChatAdminRights &newRights) {
auto flags = Notify::PeerUpdate::Flag::AdminsChanged | Notify::PeerUpdate::Flag::None;
void ChannelData::applyEditAdmin(
not_null<UserData*> user,
const MTPChatAdminRights &oldRights,
const MTPChatAdminRights &newRights) {
if (mgInfo) {
// If rights are empty - still add participant? TODO check
if (!base::contains(mgInfo->lastParticipants, user)) {
@@ -167,7 +178,9 @@ void ChannelData::applyEditAdmin(not_null<UserData*> user, const MTPChatAdminRig
setAdminsCount(adminsCount() + 1);
updateFullForced();
}
Notify::peerUpdatedDelayed(this, flags);
Notify::peerUpdatedDelayed(
this,
Notify::PeerUpdate::Flag::AdminsChanged);
}
void ChannelData::applyEditBanned(not_null<UserData*> user, const MTPChatBannedRights &oldRights, const MTPChatBannedRights &newRights) {
@@ -285,23 +298,22 @@ void ChannelData::setFeedPointer(Data::Feed *feed) {
}
bool ChannelData::canBanMembers() const {
return (adminRights() & AdminRight::f_ban_users)
|| amCreator();
return amCreator()
|| (adminRights() & AdminRight::f_ban_users);
}
bool ChannelData::canEditMessages() const {
return (adminRights() & AdminRight::f_edit_messages)
|| amCreator();
return amCreator()
|| (adminRights() & AdminRight::f_edit_messages);
}
bool ChannelData::canDeleteMessages() const {
return (adminRights() & AdminRight::f_delete_messages)
|| amCreator();
return amCreator()
|| (adminRights() & AdminRight::f_delete_messages);
}
bool ChannelData::anyoneCanAddMembers() const {
// #TODO groups
return false;// (flags() & MTPDchannel::Flag::f_democracy);
return !(defaultRestrictions() & Restriction::f_invite_users);
}
bool ChannelData::hiddenPreHistory() const {
@@ -312,6 +324,10 @@ bool ChannelData::canAddMembers() const {
return !amRestricted(ChatRestriction::f_invite_users);
}
bool ChannelData::canSendPolls() const {
return canWrite() && !amRestricted(ChatRestriction::f_send_polls);
}
bool ChannelData::canAddAdmins() const {
return amCreator()
|| (adminRights() & AdminRight::f_add_admins);

View File

@@ -246,13 +246,14 @@ public:
bool canEditUsername() const;
bool canEditPreHistoryHidden() const;
bool canAddMembers() const;
bool canAddAdmins() const;
bool canBanMembers() const;
bool canSendPolls() const;
bool anyoneCanAddMembers() const;
bool canEditMessages() const;
bool canDeleteMessages() const;
bool anyoneCanAddMembers() const;
bool hiddenPreHistory() const;
bool canAddAdmins() const;
bool canPublish() const;
bool canViewMembers() const;
bool canViewAdmins() const;

View File

@@ -37,15 +37,24 @@ bool ChatData::actionsUnavailable() const {
return isDeactivated() || !amIn();
}
auto ChatData::DefaultAdminRights() -> AdminRights {
using Flag = AdminRight;
return Flag::f_change_info
| Flag::f_delete_messages
| Flag::f_ban_users
| Flag::f_invite_users
| Flag::f_pin_messages;
}
bool ChatData::canWrite() const {
// Duplicated in Data::CanWriteValue().
return !actionsUnavailable()
&& !amRestricted(ChatRestriction::f_send_messages);
&& !amRestricted(Restriction::f_send_messages);
}
bool ChatData::canEditInformation() const {
return !actionsUnavailable()
&& !amRestricted(ChatRestriction::f_change_info);
&& !amRestricted(Restriction::f_change_info);
}
bool ChatData::canEditPermissions() const {
@@ -64,13 +73,45 @@ bool ChatData::canEditPreHistoryHidden() const {
bool ChatData::canAddMembers() const {
return !actionsUnavailable()
&& !amRestricted(ChatRestriction::f_invite_users);
&& !amRestricted(Restriction::f_invite_users);
}
bool ChatData::canSendPolls() const {
return !actionsUnavailable()
&& !amRestricted(Restriction::f_send_polls);
}
bool ChatData::canAddAdmins() const {
return !actionsUnavailable()
&& amCreator();
}
bool ChatData::canBanMembers() const {
return amCreator()
|| (adminRights() & AdminRight::f_ban_users);
}
bool ChatData::anyoneCanAddMembers() const {
return !(defaultRestrictions() & Restriction::f_invite_users);
}
void ChatData::setName(const QString &newName) {
updateNameDelayed(newName.isEmpty() ? name : newName, QString(), QString());
}
void ChatData::applyEditAdmin(not_null<UserData*> user, bool isAdmin) {
auto flags = Notify::PeerUpdate::Flag::AdminsChanged
| Notify::PeerUpdate::Flag::None;
if (isAdmin) {
admins.emplace(user);
} else {
admins.remove(user);
}
Notify::peerUpdatedDelayed(
this,
Notify::PeerUpdate::Flag::AdminsChanged);
}
void ChatData::invalidateParticipants() {
// #TODO groups
participants.clear();

View File

@@ -121,13 +121,21 @@ public:
return flags() & MTPDchat::Flag::f_migrated_to;
}
// Like in ChatData.
static AdminRights DefaultAdminRights();
// Like in ChannelData.
bool canWrite() const;
bool canEditInformation() const;
bool canEditPermissions() const;
bool canEditUsername() const;
bool canEditPreHistoryHidden() const;
bool canAddMembers() const;
bool canAddAdmins() const;
bool canBanMembers() const;
bool canSendPolls() const;
bool anyoneCanAddMembers() const;
void applyEditAdmin(not_null<UserData*> user, bool isAdmin);
void setInviteLink(const QString &newInviteLink);
QString inviteLink() const {

View File

@@ -1253,6 +1253,13 @@ TextWithEntities MediaPoll::clipboardText() const {
return { text, EntitiesInText() };
}
QString MediaPoll::errorTextForForward(not_null<PeerData*> peer) const {
if (peer->amRestricted(ChatRestriction::f_send_polls)) {
return lang(lng_restricted_send_polls);
}
return QString();
}
bool MediaPoll::updateInlineResultMedia(const MTPMessageMedia &media) {
return false;
}

View File

@@ -389,6 +389,7 @@ public:
QString notificationText() const override;
QString pinnedTextSubstring() const override;
TextWithEntities clipboardText() const override;
QString errorTextForForward(not_null<PeerData*> peer) const override;
bool updateInlineResultMedia(const MTPMessageMedia &media) override;
bool updateSentMedia(const MTPMessageMedia &media) override;

View File

@@ -435,14 +435,15 @@ void PeerData::fillNames() {
PeerData::~PeerData() = default;
void PeerData::updateFull() {
if (!_lastFullUpdate || getms(true) > _lastFullUpdate + kUpdateFullPeerTimeout) {
if (!_lastFullUpdate
|| getms(true) > _lastFullUpdate + kUpdateFullPeerTimeout) {
updateFullForced();
}
}
void PeerData::updateFullForced() {
session().api().requestFullPeer(this);
if (auto channel = asChannel()) {
if (const auto channel = asChannel()) {
if (!channel->amCreator() && !channel->inviter) {
session().api().requestSelfParticipant(channel);
}