diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp index 1044fcc3c..d087ab850 100644 --- a/Telegram/SourceFiles/data/data_peer.cpp +++ b/Telegram/SourceFiles/data/data_peer.cpp @@ -406,7 +406,8 @@ bool PeerData::canPinMessages() const { if (const auto user = asUser()) { return user->fullFlags() & MTPDuserFull::Flag::f_can_pin_message; } else if (const auto chat = asChat()) { - return chat->amIn() && !chat->amRestricted(ChatRestriction::f_pin_messages); + return chat->amIn() + && !chat->amRestricted(ChatRestriction::f_pin_messages); } else if (const auto channel = asChannel()) { return channel->isMegagroup() ? !channel->amRestricted(ChatRestriction::f_pin_messages) @@ -416,6 +417,19 @@ bool PeerData::canPinMessages() const { Unexpected("Peer type in PeerData::canPinMessages."); } +bool PeerData::canEditMessagesIndefinitely() const { + if (const auto user = asUser()) { + return user->isSelf(); + } else if (const auto chat = asChat()) { + return false; + } else if (const auto channel = asChannel()) { + return channel->isMegagroup() + ? channel->canPinMessages() + : channel->canEditMessages(); + } + Unexpected("Peer type in PeerData::canEditMessagesIndefinitely."); +} + void PeerData::setPinnedMessageId(MsgId messageId) { const auto min = [&] { if (const auto channel = asChannel()) { diff --git a/Telegram/SourceFiles/data/data_peer.h b/Telegram/SourceFiles/data/data_peer.h index 94328faaf..c861e856c 100644 --- a/Telegram/SourceFiles/data/data_peer.h +++ b/Telegram/SourceFiles/data/data_peer.h @@ -297,6 +297,7 @@ public: [[nodiscard]] ImagePtr currentUserpic() const; [[nodiscard]] bool canPinMessages() const; + [[nodiscard]] bool canEditMessagesIndefinitely() const; [[nodiscard]] MsgId pinnedMessageId() const { return _pinnedMessageId; } diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 69e0258ca..207f520c6 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -768,15 +768,8 @@ bool HistoryMessage::allowsSendNow() const { } bool HistoryMessage::isTooOldForEdit(TimeId now) const { - const auto peer = _history->peer; - if (peer->isSelf()) { - return false; - } else if (const auto megagroup = peer->asMegagroup()) { - if (megagroup->canPinMessages()) { - return false; - } - } - return (now - date() >= Global::EditTimeLimit()); + return !_history->peer->canEditMessagesIndefinitely() + && (now - date() >= Global::EditTimeLimit()); } bool HistoryMessage::allowsEdit(TimeId now) const { diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 3836e6e9a..93dd89b2d 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -6831,12 +6831,9 @@ void HistoryWidget::paintEditHeader(Painter &p, const QRect &rect, int left, int p.setFont(st::msgServiceNameFont); p.drawTextLeft(left, top + st::msgReplyPadding.top(), width(), tr::lng_edit_message(tr::now)); - if (!_replyEditMsg || _replyEditMsg->history()->peer->isSelf()) return; - - if (const auto megagroup = _replyEditMsg->history()->peer->asMegagroup()) { - if (megagroup->amCreator() || megagroup->hasAdminRights()) { - return; - } + if (!_replyEditMsg + || _replyEditMsg->history()->peer->canEditMessagesIndefinitely()) { + return; } QString editTimeLeftText;