diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index 41fba71ea2..41eae2dcd7 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -360,6 +360,12 @@ void ShowEditPermissions( navigation->parentController()->show(Box(std::move(createBox))); } +[[nodiscard]] int CurrentPricePerMessage(ChannelData *monoforumLink) { + return monoforumLink + ? monoforumLink->owner().commonStarsPerMessage(monoforumLink) + : -1; +} + class Controller : public base::has_weak_ptr { public: Controller( @@ -1083,8 +1089,8 @@ void Controller::fillDirectMessagesButton() { } const auto monoforumLink = _peer->asChannel()->monoforumLink(); - _starsPerDirectMessageSavedValue = rpl::variable( - monoforumLink ? monoforumLink->starsPerMessage() : -1); + const auto perMessage = CurrentPricePerMessage(monoforumLink); + _starsPerDirectMessageSavedValue = rpl::variable(perMessage); auto label = _starsPerDirectMessageSavedValue->value( ) | rpl::map([](int starsPerMessage) { @@ -2401,7 +2407,7 @@ void Controller::saveDirectMessagesPrice() { return continueSave(); } const auto monoforumLink = channel->monoforumLink(); - const auto current = monoforumLink ? monoforumLink->starsPerMessage() : -1; + const auto current = CurrentPricePerMessage(monoforumLink); const auto desired = _savingData.starsPerDirectMessage ? *_savingData.starsPerDirectMessage : current; diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 9ea1f9da3e..03528161ca 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -999,6 +999,10 @@ not_null Session::processChat(const MTPChat &data) { = data.vsend_paid_messages_stars().has_value(); if (!hasStarsPerMessage) { channel->setStarsPerMessage(0); + } else if (const auto count = data.vsend_paid_messages_stars()->v) { + _commonStarsPerMessage[channel] = count; + } else { + _commonStarsPerMessage.remove(channel); } const auto storiesState = minimal ? std::optional() @@ -5137,6 +5141,11 @@ rpl::producer Session::sentFromScheduled() const { return _sentFromScheduled.events(); } +int Session::commonStarsPerMessage(not_null channel) const { + const auto i = _commonStarsPerMessage.find(channel); + return (i != end(_commonStarsPerMessage)) ? i->second : 0; +} + void Session::clearLocalStorage() { _cache->close(); _cache->clear(); diff --git a/Telegram/SourceFiles/data/data_session.h b/Telegram/SourceFiles/data/data_session.h index 9a9e42bf09..bd0e38ee85 100644 --- a/Telegram/SourceFiles/data/data_session.h +++ b/Telegram/SourceFiles/data/data_session.h @@ -860,6 +860,9 @@ public: void sentFromScheduled(SentFromScheduled value); [[nodiscard]] rpl::producer sentFromScheduled() const; + [[nodiscard]] int commonStarsPerMessage( + not_null channel) const; + void clearLocalStorage(); private: @@ -1165,6 +1168,9 @@ private: not_null, ChannelId>> _postponedMonoforumLinkedIds; + // This one from `channel`, not `channelFull`. + base::flat_map, int> _commonStarsPerMessage; + MessageIdsList _mimeForwardIds; std::weak_ptr _creditsSubsRebuilder;