Allow chat creator/admins to delete for everyone.

Chat creator and admins (if admins are enabled) now can delete
any message for everyone, not only outgoing ones.
This commit is contained in:
John Preston 2017-04-30 16:58:45 +03:00
parent 4c2a0fa630
commit 413eafb240
2 changed files with 40 additions and 22 deletions

View File

@ -753,6 +753,10 @@ void HistoryItem::setId(MsgId newId) {
}
}
bool HistoryItem::canPin() const {
return id > 0 && _history->peer->isMegagroup() && (_history->peer->asChannel()->amEditor() || _history->peer->asChannel()->amCreator()) && toHistoryMessage();
}
bool HistoryItem::canEdit(const QDateTime &cur) const {
auto messageToMyself = (_history->peer->id == AuthSession::CurrentUserPeerId());
auto messageTooOld = messageToMyself ? false : (date.secsTo(cur) >= Global::EditTimeLimit());
@ -779,20 +783,49 @@ bool HistoryItem::canEdit(const QDateTime &cur) const {
return false;
}
bool HistoryItem::canDelete() const {
auto channel = _history->peer->asChannel();
if (!channel) {
return !(_flags & MTPDmessage_ClientFlag::f_is_group_migrate);
}
if (id == 1) {
return false;
}
if (channel->amCreator()) {
return true;
}
if (isPost()) {
if (channel->amEditor() && out()) {
return true;
}
return false;
}
return (channel->amEditor() || channel->amModerator() || out());
}
bool HistoryItem::canDeleteForEveryone(const QDateTime &cur) const {
auto messageToMyself = (_history->peer->id == AuthSession::CurrentUserPeerId());
auto messageTooOld = messageToMyself ? false : (date.secsTo(cur) >= Global::EditTimeLimit());
if (id < 0 || messageToMyself || messageTooOld) {
if (id < 0 || messageToMyself || messageTooOld || isPost()) {
return false;
}
if (history()->peer->isChannel()) {
return false;
}
if (auto msg = toHistoryMessage()) {
return !isPost() && out();
if (!toHistoryMessage()) {
return false;
}
return false;
if (!out()) {
if (auto chat = history()->peer->asChat()) {
if (!chat->amCreator() && (!chat->amAdmin() || !chat->adminsEnabled())) {
return false;
}
} else {
return false;
}
}
return true;
}
QString HistoryItem::directLink() const {

View File

@ -684,24 +684,9 @@ public:
return _text.isEmpty();
}
bool canDelete() const {
auto channel = _history->peer->asChannel();
if (!channel) return !(_flags & MTPDmessage_ClientFlag::f_is_group_migrate);
if (id == 1) return false;
if (channel->amCreator()) return true;
if (isPost()) {
if (channel->amEditor() && out()) return true;
return false;
}
return (channel->amEditor() || channel->amModerator() || out());
}
bool canPin() const {
return id > 0 && _history->peer->isMegagroup() && (_history->peer->asChannel()->amEditor() || _history->peer->asChannel()->amCreator()) && toHistoryMessage();
}
bool canPin() const;
bool canEdit(const QDateTime &cur) const;
bool canDelete() const;
bool canDeleteForEveryone(const QDateTime &cur) const;
bool suggestBanReportDeleteAll() const {