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_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";

View file

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

View file

@ -2992,7 +2992,7 @@ void History::dialogEntryApplied() {
return;
}
if (!chatListMessage()) {
clear(ClearType::Unload);
clear(ClearType::Unload, true);
addNewerSlice(QVector<MTPMessage>());
addOlderSlice(QVector<MTPMessage>());
if (const auto channel = peer->asChannel()) {
@ -3762,7 +3762,7 @@ std::vector<MsgId> 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<not_null<HistoryItem*>>();

View file

@ -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<UserId> &changes);

View file

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

View file

@ -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<Element*> parent, Type type);
@ -421,7 +423,9 @@ int EmptyChatLockedBox::buttonSkip() {
}
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_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<ServiceBox>(
result.get(),
std::make_unique<EmptyChatLockedBox>(
result.get(),
EmptyChatLockedBox::Type::StarsCharged)));
(stars
? EmptyChatLockedBox::Type::StarsCharged
: EmptyChatLockedBox::Type::FreeDirect))));
return result;
}