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 {
const auto index = findNearestItem(position);
return (index < 0 || _items[index]->data()->position() != position)
? nullptr
: _items[index].get();
const auto result = (index < 0) ? nullptr : _items[index].get();
return (position == Data::MinMessagePosition
|| position == Data::MaxMessagePosition
|| result->data()->position() == position)
? result
: nullptr;
}
int ListWidget::findNearestItem(Data::MessagePosition position) const {

View file

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