Hide pinned bar in topics for a single pin.

This commit is contained in:
John Preston 2022-11-09 10:44:35 +04:00
parent 7e2a49c1f9
commit 3fad69d3c8
2 changed files with 21 additions and 13 deletions

View file

@ -837,9 +837,12 @@ void ListWidget::updateAroundPositionFromNearest(int nearestIndex) {
Element *ListWidget::viewByPosition(Data::MessagePosition position) const { Element *ListWidget::viewByPosition(Data::MessagePosition position) const {
const auto index = findNearestItem(position); const auto index = findNearestItem(position);
return (index < 0 || _items[index]->data()->position() != position) const auto result = (index < 0) ? nullptr : _items[index].get();
? nullptr return (position == Data::MinMessagePosition
: _items[index].get(); || position == Data::MaxMessagePosition
|| result->data()->position() == position)
? result
: nullptr;
} }
int ListWidget::findNearestItem(Data::MessagePosition position) const { int ListWidget::findNearestItem(Data::MessagePosition position) const {

View file

@ -1620,9 +1620,12 @@ void RepliesWidget::checkPinnedBarState() {
_pinnedTracker->shownMessageId(), _pinnedTracker->shownMessageId(),
[bar = _pinnedBar.get()] { bar->customEmojiRepaint(); }), [bar = _pinnedBar.get()] { bar->customEmojiRepaint(); }),
std::move(pinnedRefreshed), std::move(pinnedRefreshed),
std::move(markupRefreshed) std::move(markupRefreshed),
) | rpl::map([](Ui::MessageBarContent &&content, bool, HistoryItem*) { _rootVisible.value()
return std::move(content); ) | rpl::map([](Ui::MessageBarContent &&content, auto, auto, bool show) {
return (show || content.count > 1)
? std::move(content)
: Ui::MessageBarContent();
})); }));
controller()->adaptive().oneColumnValue( controller()->adaptive().oneColumnValue(
@ -2223,26 +2226,28 @@ void RepliesWidget::updateInnerVisibleArea() {
void RepliesWidget::updatePinnedVisibility() { void RepliesWidget::updatePinnedVisibility() {
if (!_loaded) { if (!_loaded) {
return; return;
} else if (!_root || _root->isEmpty()) { } else if (!_topic && (!_root || _root->isEmpty())) {
setPinnedVisibility(!_root); setPinnedVisibility(!_root);
return; return;
} }
const auto item = [&] { const auto rootItem = [&] {
if (const auto group = _history->owner().groups().find(_root)) { if (const auto group = _history->owner().groups().find(_root)) {
return group->items.front().get(); return group->items.front().get();
} }
return _root; return _root;
}(); };
const auto view = _inner->viewByPosition(item->position()); const auto view = _inner->viewByPosition(_topic
? Data::MinMessagePosition
: rootItem()->position());
const auto visible = !view const auto visible = !view
|| (view->y() + view->height() <= _scroll->scrollTop()); || (view->y() + view->height() <= _scroll->scrollTop());
setPinnedVisibility(visible); setPinnedVisibility(visible || (_topic && !view->data()->isPinned()));
} }
void RepliesWidget::setPinnedVisibility(bool shown) { void RepliesWidget::setPinnedVisibility(bool shown) {
if (animatingShow() || _topic) { if (animatingShow()) {
return; return;
} else if (!_rootViewInited) { } else if (!_topic && !_rootViewInited) {
const auto height = shown ? st::historyReplyHeight : 0; const auto height = shown ? st::historyReplyHeight : 0;
if (const auto delta = height - _rootViewHeight) { if (const auto delta = height - _rootViewHeight) {
_rootViewHeight = height; _rootViewHeight = height;