From 413eafb240ed47dbb68a5453f55ff8d2f61d73c6 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 30 Apr 2017 16:58:45 +0300 Subject: [PATCH] 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. --- Telegram/SourceFiles/history/history_item.cpp | 43 ++++++++++++++++--- Telegram/SourceFiles/history/history_item.h | 19 +------- 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index e74301f4a1..2f6d19f0ca 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -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 { diff --git a/Telegram/SourceFiles/history/history_item.h b/Telegram/SourceFiles/history/history_item.h index 5b9f129f88..fc36358eaf 100644 --- a/Telegram/SourceFiles/history/history_item.h +++ b/Telegram/SourceFiles/history/history_item.h @@ -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 {