diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index 41eae2dcd7..f122beffc0 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -255,7 +255,7 @@ void SaveStarsPerMessage( api->clearModifyRequest(key); api->applyUpdates(result); if (!broadcast) { - channel->setStarsPerMessage(starsPerMessage); + channel->owner().editStarsPerMessage(channel, starsPerMessage); } done(true); }).fail([=](const MTP::Error &error) { @@ -265,7 +265,9 @@ void SaveStarsPerMessage( done(false); } else { if (!broadcast) { - channel->setStarsPerMessage(starsPerMessage); + channel->owner().editStarsPerMessage( + channel, + starsPerMessage); } done(true); } @@ -362,7 +364,7 @@ void ShowEditPermissions( [[nodiscard]] int CurrentPricePerMessage(ChannelData *monoforumLink) { return monoforumLink - ? monoforumLink->owner().commonStarsPerMessage(monoforumLink) + ? monoforumLink->commonStarsPerMessage() : -1; } diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp index 0b762a6cf5..f13430e82b 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp @@ -1179,7 +1179,7 @@ void ShowEditPeerPermissionsBox( if (available) { Ui::AddSkip(inner); const auto starsPerMessage = peer->isChannel() - ? peer->asChannel()->starsPerMessage() + ? peer->asChannel()->commonStarsPerMessage() : 0; charging = inner->add(object_ptr( inner, diff --git a/Telegram/SourceFiles/data/data_channel.cpp b/Telegram/SourceFiles/data/data_channel.cpp index dc67580df9..708ada2682 100644 --- a/Telegram/SourceFiles/data/data_channel.cpp +++ b/Telegram/SourceFiles/data/data_channel.cpp @@ -957,6 +957,10 @@ int ChannelData::starsPerMessage() const { return _starsPerMessage; } +int ChannelData::commonStarsPerMessage() const { + return owner().commonStarsPerMessage(this); +} + void ChannelData::setStarsPerMessage(int stars) { if (_starsPerMessage != stars) { _starsPerMessage = stars; diff --git a/Telegram/SourceFiles/data/data_channel.h b/Telegram/SourceFiles/data/data_channel.h index 11f74847f7..4bf99d75f3 100644 --- a/Telegram/SourceFiles/data/data_channel.h +++ b/Telegram/SourceFiles/data/data_channel.h @@ -502,6 +502,7 @@ public: void setStarsPerMessage(int stars); [[nodiscard]] int starsPerMessage() const; + [[nodiscard]] int commonStarsPerMessage() const; [[nodiscard]] int peerGiftsCount() const; void setPeerGiftsCount(int count); diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 03528161ca..6ce89d88c3 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -999,6 +999,7 @@ not_null Session::processChat(const MTPChat &data) { = data.vsend_paid_messages_stars().has_value(); if (!hasStarsPerMessage) { channel->setStarsPerMessage(0); + _commonStarsPerMessage.remove(channel); } else if (const auto count = data.vsend_paid_messages_stars()->v) { _commonStarsPerMessage[channel] = count; } else { @@ -5141,7 +5142,20 @@ rpl::producer Session::sentFromScheduled() const { return _sentFromScheduled.events(); } -int Session::commonStarsPerMessage(not_null channel) const { +void Session::editStarsPerMessage( + not_null channel, + int count) { + // For admin it's zero, we're admin if we can edit it. + channel->setStarsPerMessage(0); + if (count) { + _commonStarsPerMessage[channel] = count; + } else { + _commonStarsPerMessage.remove(channel); + } +} + +int Session::commonStarsPerMessage( + not_null channel) const { const auto i = _commonStarsPerMessage.find(channel); return (i != end(_commonStarsPerMessage)) ? i->second : 0; } diff --git a/Telegram/SourceFiles/data/data_session.h b/Telegram/SourceFiles/data/data_session.h index bd0e38ee85..701eaf08db 100644 --- a/Telegram/SourceFiles/data/data_session.h +++ b/Telegram/SourceFiles/data/data_session.h @@ -860,8 +860,9 @@ public: void sentFromScheduled(SentFromScheduled value); [[nodiscard]] rpl::producer sentFromScheduled() const; + void editStarsPerMessage(not_null channel, int count); [[nodiscard]] int commonStarsPerMessage( - not_null channel) const; + not_null channel) const; void clearLocalStorage(); @@ -1169,7 +1170,7 @@ private: ChannelId>> _postponedMonoforumLinkedIds; // This one from `channel`, not `channelFull`. - base::flat_map, int> _commonStarsPerMessage; + base::flat_map, int> _commonStarsPerMessage; MessageIdsList _mimeForwardIds;