Fix editing price per message.

This commit is contained in:
John Preston 2025-07-02 12:36:07 +04:00
parent 33671e7737
commit fd24f7045e
6 changed files with 29 additions and 7 deletions

View file

@ -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;
}

View file

@ -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<Ui::SettingsButton>(
inner,

View file

@ -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;

View file

@ -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);

View file

@ -999,6 +999,7 @@ not_null<PeerData*> 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<SentFromScheduled> Session::sentFromScheduled() const {
return _sentFromScheduled.events();
}
int Session::commonStarsPerMessage(not_null<ChannelData*> channel) const {
void Session::editStarsPerMessage(
not_null<ChannelData*> 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<const ChannelData*> channel) const {
const auto i = _commonStarsPerMessage.find(channel);
return (i != end(_commonStarsPerMessage)) ? i->second : 0;
}

View file

@ -860,8 +860,9 @@ public:
void sentFromScheduled(SentFromScheduled value);
[[nodiscard]] rpl::producer<SentFromScheduled> sentFromScheduled() const;
void editStarsPerMessage(not_null<ChannelData*> channel, int count);
[[nodiscard]] int commonStarsPerMessage(
not_null<ChannelData*> channel) const;
not_null<const ChannelData*> channel) const;
void clearLocalStorage();
@ -1169,7 +1170,7 @@ private:
ChannelId>> _postponedMonoforumLinkedIds;
// This one from `channel`, not `channelFull`.
base::flat_map<not_null<ChannelData*>, int> _commonStarsPerMessage;
base::flat_map<not_null<const ChannelData*>, int> _commonStarsPerMessage;
MessageIdsList _mimeForwardIds;