Don't offer hello-sticker to user you've blocked.

This commit is contained in:
John Preston 2024-09-09 16:42:02 +04:00
parent 1444009ee2
commit d01f977960
5 changed files with 38 additions and 17 deletions

View file

@ -4275,32 +4275,32 @@ auto HistoryInner::findViewForPinnedTracking(int top) const
return { nullptr, 0 }; return { nullptr, 0 };
} }
void HistoryInner::refreshAboutView() { void HistoryInner::refreshAboutView(bool force) {
if (const auto user = _peer->asUser()) { const auto refresh = [&] {
if (const auto info = user->botInfo.get()) { if (force) {
_aboutView = nullptr;
}
if (!_aboutView) { if (!_aboutView) {
_aboutView = std::make_unique<HistoryView::AboutView>( _aboutView = std::make_unique<HistoryView::AboutView>(
_history, _history,
_history->delegateMixin()->delegate()); _history->delegateMixin()->delegate());
} }
};
if (const auto user = _peer->asUser()) {
if (const auto info = user->botInfo.get()) {
refresh();
if (!info->inited) { if (!info->inited) {
session().api().requestFullPeer(user); session().api().requestFullPeer(user);
} }
} else if (user->meRequiresPremiumToWrite() } else if (user->meRequiresPremiumToWrite()
&& !user->session().premium() && !user->session().premium()
&& !historyHeight()) { && !historyHeight()) {
if (!_aboutView) { refresh();
_aboutView = std::make_unique<HistoryView::AboutView>(
_history,
_history->delegateMixin()->delegate());
}
} else if (!historyHeight()) { } else if (!historyHeight()) {
if (!user->isFullLoaded()) { if (!user->isFullLoaded()) {
session().api().requestFullPeer(user); session().api().requestFullPeer(user);
} else if (!_aboutView) { } else {
_aboutView = std::make_unique<HistoryView::AboutView>( refresh();
_history,
_history->delegateMixin()->delegate());
} }
} }
} }

View file

@ -201,7 +201,7 @@ public:
[[nodiscard]] std::pair<Element*, int> findViewForPinnedTracking( [[nodiscard]] std::pair<Element*, int> findViewForPinnedTracking(
int top) const; int top) const;
void refreshAboutView(); void refreshAboutView(bool force = false);
void notifyMigrateUpdated(); void notifyMigrateUpdated();
// Ui::AbstractTooltipShower interface. // Ui::AbstractTooltipShower interface.

View file

@ -8017,13 +8017,18 @@ void HistoryWidget::handlePeerUpdate() {
} }
} }
if (!_showAnimation) { if (!_showAnimation) {
if (_unblock->isHidden() == isBlocked() const auto blockChanged = (_unblock->isHidden() == isBlocked());
if (blockChanged
|| (!isBlocked() && _joinChannel->isHidden() == isJoinChannel())) { || (!isBlocked() && _joinChannel->isHidden() == isJoinChannel())) {
resize = true; resize = true;
} }
if (updateCanSendMessage()) { if (updateCanSendMessage()) {
resize = true; resize = true;
} }
if (blockChanged) {
_list->refreshAboutView(true);
_list->updateBotInfo();
}
updateControlsVisibility(); updateControlsVisibility();
if (resize) { if (resize) {
updateControlsGeometry(); updateControlsGeometry();

View file

@ -245,6 +245,8 @@ bool AboutView::refresh() {
} else if (user->meRequiresPremiumToWrite() } else if (user->meRequiresPremiumToWrite()
&& !user->session().premium()) { && !user->session().premium()) {
setItem(makePremiumRequired(), nullptr); setItem(makePremiumRequired(), nullptr);
} else if (user->isBlocked()) {
setItem(makeBlocked(), nullptr);
} else { } else {
makeIntro(user); makeIntro(user);
} }
@ -393,4 +395,17 @@ AdminLog::OwnedItem AboutView::makePremiumRequired() {
return result; return result;
} }
AdminLog::OwnedItem AboutView::makeBlocked() {
const auto item = _history->makeMessage({
.id = _history->nextNonHistoryEntryId(),
.flags = (MessageFlag::FakeAboutView
| MessageFlag::FakeHistoryItem
| MessageFlag::Local),
.from = _history->peer->id,
}, PreparedServiceText{
{ tr::lng_chat_intro_default_title(tr::now) }
});
return AdminLog::OwnedItem(_delegate, item);
}
} // namespace HistoryView } // namespace HistoryView

View file

@ -36,6 +36,7 @@ public:
private: private:
[[nodiscard]] AdminLog::OwnedItem makeAboutBot(not_null<BotInfo*> info); [[nodiscard]] AdminLog::OwnedItem makeAboutBot(not_null<BotInfo*> info);
[[nodiscard]] AdminLog::OwnedItem makePremiumRequired(); [[nodiscard]] AdminLog::OwnedItem makePremiumRequired();
[[nodiscard]] AdminLog::OwnedItem makeBlocked();
void makeIntro(not_null<UserData*> user); void makeIntro(not_null<UserData*> user);
void setItem(AdminLog::OwnedItem item, DocumentData *sticker); void setItem(AdminLog::OwnedItem item, DocumentData *sticker);
void setHelloChosen(not_null<DocumentData*> sticker); void setHelloChosen(not_null<DocumentData*> sticker);