From a330a3f2ebfae08107bc09e2e7fb4c19e7ef6835 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 4 Jun 2025 15:44:45 +0400 Subject: [PATCH] Nicer empty monoforum for non-admins. --- Telegram/Resources/langs/lang.strings | 2 + Telegram/SourceFiles/data/data_channel.cpp | 5 -- Telegram/SourceFiles/history/history.cpp | 6 +- Telegram/SourceFiles/history/history.h | 2 +- .../history/history_inner_widget.cpp | 4 ++ .../history/view/history_view_about_view.cpp | 55 +++++++++++++++---- 6 files changed, 54 insertions(+), 20 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 37b72d4b3b..77a065e20f 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -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_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_go" = "Buy Stars"; diff --git a/Telegram/SourceFiles/data/data_channel.cpp b/Telegram/SourceFiles/data/data_channel.cpp index 8365be635b..bb41dd4b4e 100644 --- a/Telegram/SourceFiles/data/data_channel.cpp +++ b/Telegram/SourceFiles/data/data_channel.cpp @@ -947,11 +947,6 @@ void ChannelData::growSlowmodeLastMessage(TimeId when) { } int ChannelData::starsPerMessage() const { - if (const auto broadcast = monoforumBroadcast()) { - if (!amMonoforumAdmin()) { - return broadcast->starsPerMessage(); - } - } return _starsPerMessage; } diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index 77000409e0..1bb9b4fb23 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -2992,7 +2992,7 @@ void History::dialogEntryApplied() { return; } if (!chatListMessage()) { - clear(ClearType::Unload); + clear(ClearType::Unload, true); addNewerSlice(QVector()); addOlderSlice(QVector()); if (const auto channel = peer->asChannel()) { @@ -3762,7 +3762,7 @@ std::vector History::collectMessagesFromParticipantToDelete( return result; } -void History::clear(ClearType type) { +void History::clear(ClearType type, bool markEmpty) { _unreadBarView = nullptr; _firstUnreadView = nullptr; removeJoinedMessage(); @@ -3772,7 +3772,7 @@ void History::clear(ClearType type) { owner().notifyHistoryUnloaded(this); lastKeyboardInited = false; if (type == ClearType::Unload) { - _loadedAtTop = _loadedAtBottom = false; + _loadedAtTop = _loadedAtBottom = markEmpty; } else { // Leave the 'sending' messages in local messages. auto local = base::flat_set>(); diff --git a/Telegram/SourceFiles/history/history.h b/Telegram/SourceFiles/history/history.h index 7ebacdfc82..86c14ccc37 100644 --- a/Telegram/SourceFiles/history/history.h +++ b/Telegram/SourceFiles/history/history.h @@ -110,7 +110,7 @@ public: DeleteChat, ClearHistory, }; - void clear(ClearType type); + void clear(ClearType type, bool markEmpty = false); void clearUpTill(MsgId availableMinId); void applyGroupAdminChanges(const base::flat_set &changes); diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index ede9c81b08..0d2c3e520b 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -4542,6 +4542,10 @@ void HistoryInner::refreshAboutView(bool force) { session().api().requestFullPeer(user); } } + } else if (const auto monoforum = _peer->asChannel()) { + if (monoforum->isMonoforum() && !monoforum->amMonoforumAdmin()) { + refresh(); + } } } diff --git a/Telegram/SourceFiles/history/view/history_view_about_view.cpp b/Telegram/SourceFiles/history/view/history_view_about_view.cpp index 486bcd984f..3ad2dcf1ee 100644 --- a/Telegram/SourceFiles/history/view/history_view_about_view.cpp +++ b/Telegram/SourceFiles/history/view/history_view_about_view.cpp @@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "countries/countries_instance.h" #include "data/business/data_business_common.h" #include "data/stickers/data_custom_emoji.h" +#include "data/data_channel.h" #include "data/data_document.h" #include "data/data_session.h" #include "data/data_user.h" @@ -61,6 +62,7 @@ public: enum class Type { PremiumRequired, StarsCharged, + FreeDirect, }; EmptyChatLockedBox(not_null parent, Type type); @@ -421,7 +423,9 @@ int EmptyChatLockedBox::buttonSkip() { } rpl::producer EmptyChatLockedBox::button() { - return (_type == Type::PremiumRequired) + return (_type == Type::FreeDirect) + ? nullptr + : (_type == Type::PremiumRequired) ? tr::lng_send_non_premium_go() : tr::lng_send_charges_stars_go(); } @@ -512,6 +516,9 @@ bool AboutView::refresh() { return true; } const auto user = _history->peer->asUser(); + const auto monoforum = _history->peer->isMonoforum() + ? _history->peer->asChannel() + : nullptr; const auto info = user ? user->botInfo.get() : nullptr; if (!info) { if (user @@ -539,6 +546,14 @@ bool AboutView::refresh() { makeIntro(user); } return true; + } else if (monoforum && _history->isDisplayedEmpty()) { + if (_item) { + return false; + } + setItem( + makeStarsPerMessage(monoforum->starsPerMessageChecked()), + nullptr); + return true; } if (_item) { setItem({}, nullptr); @@ -813,28 +828,46 @@ AdminLog::OwnedItem AboutView::makePremiumRequired() { } 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({ .id = _history->nextNonHistoryEntryId(), .flags = (MessageFlag::FakeAboutView | MessageFlag::FakeHistoryItem | MessageFlag::Local), .from = _history->peer->id, - }, PreparedServiceText{ tr::lng_send_charges_stars_text( - tr::now, - lt_user, - Ui::Text::Bold(_history->peer->shortName()), - lt_amount, - Ui::Text::IconEmoji( - &st::starIconEmoji - ).append(Ui::Text::Bold(Lang::FormatCountDecimal(stars))), - Ui::Text::RichLangValue), + }, PreparedServiceText{ !_history->peer->isMonoforum() + ? tr::lng_send_charges_stars_text( + tr::now, + lt_user, + std::move(name), + lt_amount, + std::move(cost), + Ui::Text::RichLangValue) + : 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), }); auto result = AdminLog::OwnedItem(_delegate, item); result->overrideMedia(std::make_unique( result.get(), std::make_unique( result.get(), - EmptyChatLockedBox::Type::StarsCharged))); + (stars + ? EmptyChatLockedBox::Type::StarsCharged + : EmptyChatLockedBox::Type::FreeDirect)))); return result; }