Hide community chat bars while searching

This commit is contained in:
John Preston
2026-07-10 00:47:21 +04:00
parent 69208ae951
commit 64b8f75b8e
5 changed files with 60 additions and 25 deletions
@@ -134,16 +134,13 @@ CommunityRequestableList::CommunityRequestableList(
chatsController->setDelegate(delegate);
_count = chatsController->countValue();
_count.value(
) | rpl::on_next([=](int count) {
setVisible(count > 0);
resizeToWidth(width());
}, lifetime());
_content->heightValue(
) | rpl::on_next([=] {
resizeToWidth(width());
}, lifetime());
hide();
}
CommunityRequestableList::~CommunityRequestableList() = default;
@@ -809,7 +809,7 @@ int InnerWidget::communityRequestableTop() const {
int InnerWidget::communitySectionsBottom() const {
auto result = communityRequestableTop();
if (_communityRequestableList && !_communityRequestableList->isHidden()) {
if (_communityRequestableList && (_communityRequestableCount > 0)) {
result += st::searchedBarHeight + _communityRequestableList->height();
}
return result;
@@ -928,13 +928,15 @@ void InnerWidget::changeOpenedCommunity(Data::CommunityInfo *community) {
refreshShownList();
_openedCommunityLifetime.destroy();
_communityRequestableList.destroy();
_communityRequestableCount = 0;
if (community) {
_communityRequestableList = object_ptr<CommunityRequestableList>(
this,
_controller,
community);
_communityRequestableList->countValue(
) | rpl::on_next([=] {
) | rpl::on_next([=](int count) {
_communityRequestableCount = count;
refresh();
}, _openedCommunityLifetime);
@@ -1365,7 +1367,7 @@ void InnerWidget::paintEvent(QPaintEvent *e) {
tr::lng_community_chats_viewable(tr::now),
0);
if (_communityRequestableList
&& !_communityRequestableList->isHidden()) {
&& (_communityRequestableCount > 0)) {
p.save();
p.translate(0, communityRequestableTop());
paintBar(tr::lng_community_chats_requestable(tr::now));
@@ -4757,7 +4759,7 @@ void InnerWidget::refresh(bool toTop) {
if (_state == WidgetState::Default) {
if (_openedCommunity) {
const auto requestableShown = _communityRequestableList
&& !_communityRequestableList->isHidden();
&& (_communityRequestableCount > 0);
if (_shownList->empty()
&& _communityViewable.empty()
&& !requestableShown) {
@@ -4842,9 +4844,7 @@ void InnerWidget::refreshEmpty() {
? EmptyState::EmptyForum
: EmptyState::Loading)
: _openedCommunity
? ((_communityViewable.empty()
&& (!_communityRequestableList
|| _communityRequestableList->isHidden()))
? ((_communityViewable.empty() && !_communityRequestableCount)
? EmptyState::Loading
: EmptyState::None)
: (!_filterId && data->contactsLoaded().current())
@@ -4994,7 +4994,14 @@ void InnerWidget::resizeEmpty() {
}
void InnerWidget::updateCommunityRequestableGeometry() {
if (_communityRequestableList && !_communityRequestableList->isHidden()) {
if (!_communityRequestableList) {
return;
}
const auto shown = _openedCommunity
&& (_state == WidgetState::Default)
&& (_communityRequestableCount > 0);
_communityRequestableList->setVisible(shown);
if (shown) {
_communityRequestableList->resizeToWidth(width());
_communityRequestableList->moveToLeft(
0,
@@ -5196,6 +5203,7 @@ void InnerWidget::clearFilter() {
void InnerWidget::setState(WidgetState state) {
_state = state;
updateCommunityRequestableGeometry();
}
void InnerWidget::selectSkip(int32 direction) {
@@ -733,6 +733,7 @@ private:
= { nullptr };
int _communitySelected = -1;
int _communityPressed = -1;
int _communityRequestableCount = 0;
rpl::lifetime _openedCommunityLifetime;
WidgetState _state = WidgetState::Default;
+37 -12
View File
@@ -1283,10 +1283,27 @@ void Widget::updateTopBarSuggestions() {
}
}
bool Widget::communityOverlaysShown() const {
return _openedCommunity
&& (_inner->state() == WidgetState::Default);
}
void Widget::updateCommunityOverlaysVisibility() {
if (_communityRequests) {
_communityRequests->toggle(
communityOverlaysShown() && (_communityRequestsCount > 0),
anim::type::instant);
}
if (_communityAddChat) {
_communityAddChatRefresh.fire({});
}
}
void Widget::updateCommunityRequestsBubble() {
_communityRequestsLifetime.destroy();
_communityRequestsPlaceholder = nullptr;
_communityRequests = nullptr;
_communityRequestsCount = 0;
const auto channel = _openedCommunity
? _openedCommunity->channel().get()
@@ -1340,7 +1357,8 @@ void Widget::updateCommunityRequestsBubble() {
});
std::move(count) | rpl::on_next([=](int c) {
_communityRequests->toggle(c > 0, anim::type::instant);
_communityRequestsCount = c;
updateCommunityOverlaysVisibility();
}, _communityRequestsLifetime);
}
@@ -1406,6 +1424,7 @@ void Widget::updateCommunityAddChatButton() {
narrowButton->hide();
const auto pinToBottom = [=] {
const auto shown = communityOverlaysShown();
const auto narrow
= (_scroll->width() < st::columnMinimalWidthLeft / 2);
const auto buttonHeight = st::communityAddChatButton.height;
@@ -1414,7 +1433,11 @@ void Widget::updateCommunityAddChatButton() {
const auto stripHeight = buttonHeight
+ st::defaultDialogRow.padding.top()
+ st::defaultDialogRow.padding.bottom();
if (narrow) {
if (!shown) {
raw->toggle(false, anim::type::instant);
narrowButton->hide();
placeholder->resize(placeholder->width(), 0);
} else if (narrow) {
placeholder->resize(placeholder->width(), stripHeight);
const auto bottom = std::max(0, _scroll->height() - stripHeight);
raw->toggle(false, anim::type::instant);
@@ -1431,18 +1454,18 @@ void Widget::updateCommunityAddChatButton() {
const auto bottom = std::max(0, _scroll->height() - height);
raw->moveToLeft(0, bottom);
}
_scroll->setBarBottomInset(shown
? (st::communityAddChatButtonMargin.top()
+ buttonHeight
+ st::communityAddChatButtonMargin.bottom())
: 0);
};
_scroll->sizeValue(
) | rpl::to_empty | rpl::on_next(pinToBottom, _communityAddChatLifetime);
raw->heightValue(
) | rpl::to_empty | rpl::on_next(pinToBottom, _communityAddChatLifetime);
rpl::merge(
_scroll->sizeValue() | rpl::to_empty,
raw->heightValue() | rpl::to_empty,
_communityAddChatRefresh.events()
) | rpl::on_next(pinToBottom, _communityAddChatLifetime);
pinToBottom();
_scroll->setBarBottomInset(st::communityAddChatButtonMargin.top()
+ st::communityAddChatButton.height
+ st::communityAddChatButtonMargin.bottom());
raw->toggle(true, anim::type::instant);
}
void Widget::setupMoreChatsBar() {
@@ -1894,6 +1917,7 @@ void Widget::updateControlsVisibility(bool fast) {
if (_chatFilters) {
_chatFilters->setVisible(!_openedForum && !_openedCommunity);
}
updateCommunityOverlaysVisibility();
if (_openedFolder || _openedForum || _openedCommunity) {
_subsectionTopBar->show();
if (_forumTopShadow) {
@@ -4098,6 +4122,7 @@ bool Widget::applySearchState(SearchState state) {
setSearchQuery(_searchState.query);
}
_inner->applySearchState(_searchState);
updateCommunityOverlaysVisibility();
if (!_postponeProcessSearchFocusChange) {
// Suggestions depend on _inner->state(), not on _searchState.
@@ -238,6 +238,8 @@ private:
void updateTopBarSuggestions();
void updateCommunityRequestsBubble();
void updateCommunityAddChatButton();
void updateCommunityOverlaysVisibility();
[[nodiscard]] bool communityOverlaysShown() const;
void updateFrozenAccountBar();
void updateControlsVisibility(bool fast = false);
void updateLockUnlockVisibility(
@@ -351,10 +353,12 @@ private:
base::unique_qptr<Ui::SlideWrap<Ui::RpWidget>> _communityRequests;
base::unique_qptr<Ui::RpWidget> _communityRequestsPlaceholder;
rpl::lifetime _communityRequestsLifetime;
int _communityRequestsCount = 0;
base::unique_qptr<Ui::SlideWrap<Ui::VerticalLayout>> _communityAddChat;
base::unique_qptr<Ui::RpWidget> _communityAddChatPlaceholder;
rpl::lifetime _communityAddChatLifetime;
base::unique_qptr<Ui::RpWidget> _communityAddChatNarrow;
rpl::event_stream<> _communityAddChatRefresh;
rpl::event_stream<bool> _searchStateForTopBarSuggestion;
rpl::event_stream<> _prepareTopBarSnapshot;
rpl::event_stream<bool> _openedFolderOrForumChanges;