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:
@@ -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());
|
||||
|
Reference in New Issue
Block a user