2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-09-04 00:15:42 +00:00

Allow saving boosts to lift restrictions.

This commit is contained in:
John Preston
2024-02-06 14:54:15 +04:00
parent f6a8c1e996
commit 180b14ea36
7 changed files with 317 additions and 23 deletions

View File

@@ -772,34 +772,74 @@ void ChannelData::setMigrateFromChat(ChatData *chat) {
}
int ChannelData::slowmodeSeconds() const {
return _slowmodeSeconds;
if (const auto info = mgInfo.get()) {
return info->slowmodeSeconds;
}
return 0;
}
void ChannelData::setSlowmodeSeconds(int seconds) {
if (_slowmodeSeconds == seconds) {
if (!mgInfo || slowmodeSeconds() == seconds) {
return;
}
_slowmodeSeconds = seconds;
mgInfo->slowmodeSeconds = seconds;
session().changes().peerUpdated(this, UpdateFlag::Slowmode);
}
TimeId ChannelData::slowmodeLastMessage() const {
return (hasAdminRights() || amCreator()) ? 0 : _slowmodeLastMessage;
return (hasAdminRights() || amCreator() || !mgInfo)
? 0
: mgInfo->slowmodeLastMessage;
}
void ChannelData::growSlowmodeLastMessage(TimeId when) {
const auto info = mgInfo.get();
const auto now = base::unixtime::now();
accumulate_min(when, now);
if (_slowmodeLastMessage > now) {
_slowmodeLastMessage = when;
} else if (_slowmodeLastMessage >= when) {
if (!info) {
return;
} else if (info->slowmodeLastMessage > now) {
info->slowmodeLastMessage = when;
} else if (info->slowmodeLastMessage >= when) {
return;
} else {
_slowmodeLastMessage = when;
info->slowmodeLastMessage = when;
}
session().changes().peerUpdated(this, UpdateFlag::Slowmode);
}
int ChannelData::boostsApplied() const {
if (const auto info = mgInfo.get()) {
return info->boostsApplied;
}
return 0;
}
int ChannelData::boostsUnrestrict() const {
if (const auto info = mgInfo.get()) {
return info->boostsUnrestrict;
}
return 0;
}
void ChannelData::setBoostsUnrestrict(int applied, int unrestrict) {
if (const auto info = mgInfo.get()) {
if (info->boostsApplied == applied
&& info->boostsUnrestrict == unrestrict) {
return;
}
const auto wasUnrestricted = (info->boostsApplied > 0)
&& (info->boostsApplied >= info->boostsUnrestrict);
const auto nowUnrestricted = (applied > 0)
&& (applied >= unrestrict);
info->boostsApplied = applied;
info->boostsUnrestrict = unrestrict;
if (wasUnrestricted != nowUnrestricted) {
session().changes().peerUpdated(this, UpdateFlag::Rights);
}
}
}
void ChannelData::setInvitePeek(const QString &hash, TimeId expires) {
if (!_invitePeek) {
_invitePeek = std::make_unique<InvitePeek>();
@@ -1118,8 +1158,9 @@ void ApplyChannelUpdate(
if (stickersChanged) {
session->changes().peerUpdated(channel, UpdateFlag::StickersSet);
}
channel->mgInfo->boostsApplied = update.vboosts_applied().value_or_empty();
channel->setBoostsUnrestrict(
update.vboosts_applied().value_or_empty(),
update.vboosts_unrestrict().value_or_empty());
}
channel->setThemeEmoji(qs(update.vtheme_emoticon().value_or_empty()));
channel->setTranslationDisabled(update.is_translations_disabled());