Nicer empty monoforum for non-admins.

This commit is contained in:
John Preston 2025-06-04 15:44:45 +04:00
parent 8f7195d3b2
commit a330a3f2eb
6 changed files with 54 additions and 20 deletions

View file

@ -5297,6 +5297,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_send_non_premium_message_toast" = "**{user}** only accepts messages from contacts and {link} subscribers."; "lng_send_non_premium_message_toast" = "**{user}** only accepts messages from contacts and {link} subscribers.";
"lng_send_non_premium_message_toast_link" = "Telegram Premium"; "lng_send_non_premium_message_toast_link" = "Telegram Premium";
"lng_send_charges_stars_channel" = "{channel} charges {amount} per message to its admin.";
"lng_send_free_channel" = "Send a direct message to the administrator of {channel}.";
"lng_send_charges_stars_text" = "{user} charges {amount} for each message."; "lng_send_charges_stars_text" = "{user} charges {amount} for each message.";
"lng_send_charges_stars_go" = "Buy Stars"; "lng_send_charges_stars_go" = "Buy Stars";

View file

@ -947,11 +947,6 @@ void ChannelData::growSlowmodeLastMessage(TimeId when) {
} }
int ChannelData::starsPerMessage() const { int ChannelData::starsPerMessage() const {
if (const auto broadcast = monoforumBroadcast()) {
if (!amMonoforumAdmin()) {
return broadcast->starsPerMessage();
}
}
return _starsPerMessage; return _starsPerMessage;
} }

View file

@ -2992,7 +2992,7 @@ void History::dialogEntryApplied() {
return; return;
} }
if (!chatListMessage()) { if (!chatListMessage()) {
clear(ClearType::Unload); clear(ClearType::Unload, true);
addNewerSlice(QVector<MTPMessage>()); addNewerSlice(QVector<MTPMessage>());
addOlderSlice(QVector<MTPMessage>()); addOlderSlice(QVector<MTPMessage>());
if (const auto channel = peer->asChannel()) { if (const auto channel = peer->asChannel()) {
@ -3762,7 +3762,7 @@ std::vector<MsgId> History::collectMessagesFromParticipantToDelete(
return result; return result;
} }
void History::clear(ClearType type) { void History::clear(ClearType type, bool markEmpty) {
_unreadBarView = nullptr; _unreadBarView = nullptr;
_firstUnreadView = nullptr; _firstUnreadView = nullptr;
removeJoinedMessage(); removeJoinedMessage();
@ -3772,7 +3772,7 @@ void History::clear(ClearType type) {
owner().notifyHistoryUnloaded(this); owner().notifyHistoryUnloaded(this);
lastKeyboardInited = false; lastKeyboardInited = false;
if (type == ClearType::Unload) { if (type == ClearType::Unload) {
_loadedAtTop = _loadedAtBottom = false; _loadedAtTop = _loadedAtBottom = markEmpty;
} else { } else {
// Leave the 'sending' messages in local messages. // Leave the 'sending' messages in local messages.
auto local = base::flat_set<not_null<HistoryItem*>>(); auto local = base::flat_set<not_null<HistoryItem*>>();

View file

@ -110,7 +110,7 @@ public:
DeleteChat, DeleteChat,
ClearHistory, ClearHistory,
}; };
void clear(ClearType type); void clear(ClearType type, bool markEmpty = false);
void clearUpTill(MsgId availableMinId); void clearUpTill(MsgId availableMinId);
void applyGroupAdminChanges(const base::flat_set<UserId> &changes); void applyGroupAdminChanges(const base::flat_set<UserId> &changes);

View file

@ -4542,6 +4542,10 @@ void HistoryInner::refreshAboutView(bool force) {
session().api().requestFullPeer(user); session().api().requestFullPeer(user);
} }
} }
} else if (const auto monoforum = _peer->asChannel()) {
if (monoforum->isMonoforum() && !monoforum->amMonoforumAdmin()) {
refresh();
}
} }
} }

View file

@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "countries/countries_instance.h" #include "countries/countries_instance.h"
#include "data/business/data_business_common.h" #include "data/business/data_business_common.h"
#include "data/stickers/data_custom_emoji.h" #include "data/stickers/data_custom_emoji.h"
#include "data/data_channel.h"
#include "data/data_document.h" #include "data/data_document.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_user.h" #include "data/data_user.h"
@ -61,6 +62,7 @@ public:
enum class Type { enum class Type {
PremiumRequired, PremiumRequired,
StarsCharged, StarsCharged,
FreeDirect,
}; };
EmptyChatLockedBox(not_null<Element*> parent, Type type); EmptyChatLockedBox(not_null<Element*> parent, Type type);
@ -421,7 +423,9 @@ int EmptyChatLockedBox::buttonSkip() {
} }
rpl::producer<QString> EmptyChatLockedBox::button() { rpl::producer<QString> EmptyChatLockedBox::button() {
return (_type == Type::PremiumRequired) return (_type == Type::FreeDirect)
? nullptr
: (_type == Type::PremiumRequired)
? tr::lng_send_non_premium_go() ? tr::lng_send_non_premium_go()
: tr::lng_send_charges_stars_go(); : tr::lng_send_charges_stars_go();
} }
@ -512,6 +516,9 @@ bool AboutView::refresh() {
return true; return true;
} }
const auto user = _history->peer->asUser(); const auto user = _history->peer->asUser();
const auto monoforum = _history->peer->isMonoforum()
? _history->peer->asChannel()
: nullptr;
const auto info = user ? user->botInfo.get() : nullptr; const auto info = user ? user->botInfo.get() : nullptr;
if (!info) { if (!info) {
if (user if (user
@ -539,6 +546,14 @@ bool AboutView::refresh() {
makeIntro(user); makeIntro(user);
} }
return true; return true;
} else if (monoforum && _history->isDisplayedEmpty()) {
if (_item) {
return false;
}
setItem(
makeStarsPerMessage(monoforum->starsPerMessageChecked()),
nullptr);
return true;
} }
if (_item) { if (_item) {
setItem({}, nullptr); setItem({}, nullptr);
@ -813,20 +828,36 @@ AdminLog::OwnedItem AboutView::makePremiumRequired() {
} }
AdminLog::OwnedItem AboutView::makeStarsPerMessage(int stars) { AdminLog::OwnedItem AboutView::makeStarsPerMessage(int stars) {
auto name = Ui::Text::Bold(_history->peer->shortName());
auto cost = Ui::Text::IconEmoji(
&st::starIconEmoji
).append(Ui::Text::Bold(Lang::FormatCountDecimal(stars)));
const auto item = _history->makeMessage({ const auto item = _history->makeMessage({
.id = _history->nextNonHistoryEntryId(), .id = _history->nextNonHistoryEntryId(),
.flags = (MessageFlag::FakeAboutView .flags = (MessageFlag::FakeAboutView
| MessageFlag::FakeHistoryItem | MessageFlag::FakeHistoryItem
| MessageFlag::Local), | MessageFlag::Local),
.from = _history->peer->id, .from = _history->peer->id,
}, PreparedServiceText{ tr::lng_send_charges_stars_text( }, PreparedServiceText{ !_history->peer->isMonoforum()
? tr::lng_send_charges_stars_text(
tr::now, tr::now,
lt_user, lt_user,
Ui::Text::Bold(_history->peer->shortName()), std::move(name),
lt_amount, lt_amount,
Ui::Text::IconEmoji( std::move(cost),
&st::starIconEmoji Ui::Text::RichLangValue)
).append(Ui::Text::Bold(Lang::FormatCountDecimal(stars))), : stars
? tr::lng_send_charges_stars_channel(
tr::now,
lt_channel,
std::move(name),
lt_amount,
std::move(cost),
Ui::Text::RichLangValue)
: tr::lng_send_free_channel(
tr::now,
lt_channel,
std::move(name),
Ui::Text::RichLangValue), Ui::Text::RichLangValue),
}); });
auto result = AdminLog::OwnedItem(_delegate, item); auto result = AdminLog::OwnedItem(_delegate, item);
@ -834,7 +865,9 @@ AdminLog::OwnedItem AboutView::makeStarsPerMessage(int stars) {
result.get(), result.get(),
std::make_unique<EmptyChatLockedBox>( std::make_unique<EmptyChatLockedBox>(
result.get(), result.get(),
EmptyChatLockedBox::Type::StarsCharged))); (stars
? EmptyChatLockedBox::Type::StarsCharged
: EmptyChatLockedBox::Type::FreeDirect))));
return result; return result;
} }