mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-19 23:57:16 +02:00
Fix opening Replies section on unread bar.
This commit is contained in:
parent
8d70a62ee8
commit
4b6d74dd9b
7 changed files with 45 additions and 10 deletions
|
@ -479,9 +479,15 @@ void MessagesSliceBuilder::requestMessagesCount() {
|
|||
MessagesSlice MessagesSliceBuilder::snapshot() const {
|
||||
auto result = MessagesSlice();
|
||||
result.ids.reserve(_ids.size());
|
||||
auto nearestToAround = std::optional<FullMsgId>();
|
||||
for (const auto &position : _ids) {
|
||||
result.ids.push_back(position.fullId);
|
||||
if (!nearestToAround && position >= _key) {
|
||||
nearestToAround = position.fullId;
|
||||
}
|
||||
}
|
||||
result.nearestToAround = nearestToAround.value_or(
|
||||
_ids.empty() ? FullMsgId() : _ids.back().fullId);
|
||||
result.skippedBefore = _skippedBefore;
|
||||
result.skippedAfter = _skippedAfter;
|
||||
result.fullCount = _fullCount;
|
||||
|
|
|
@ -93,10 +93,10 @@ constexpr auto UnreadMessagePosition = MessagePosition(
|
|||
|
||||
struct MessagesSlice {
|
||||
std::vector<FullMsgId> ids;
|
||||
FullMsgId nearestToAround;
|
||||
std::optional<int> skippedBefore;
|
||||
std::optional<int> skippedAfter;
|
||||
std::optional<int> fullCount;
|
||||
|
||||
};
|
||||
|
||||
struct MessagesQuery {
|
||||
|
@ -112,7 +112,6 @@ struct MessagesQuery {
|
|||
MessagePosition aroundId;
|
||||
int limitBefore = 0;
|
||||
int limitAfter = 0;
|
||||
|
||||
};
|
||||
|
||||
struct MessagesResult {
|
||||
|
|
|
@ -227,6 +227,7 @@ void RepliesList::injectRootDivider(
|
|||
bool RepliesList::buildFromData(not_null<Viewer*> viewer) {
|
||||
if (_list.empty() && _skippedBefore == 0 && _skippedAfter == 0) {
|
||||
viewer->slice.ids.clear();
|
||||
viewer->slice.nearestToAround = FullMsgId();
|
||||
viewer->slice.fullCount
|
||||
= viewer->slice.skippedBefore
|
||||
= viewer->slice.skippedAfter
|
||||
|
@ -268,10 +269,20 @@ bool RepliesList::buildFromData(not_null<Viewer*> viewer) {
|
|||
|
||||
const auto channelId = _history->channelId();
|
||||
slice->ids.clear();
|
||||
auto nearestToAround = std::optional<MsgId>();
|
||||
slice->ids.reserve(useAfter + useBefore);
|
||||
for (auto j = i - useAfter, e = i + useBefore; j != e; ++j) {
|
||||
if (!nearestToAround && *j < around) {
|
||||
nearestToAround = (j == i - useAfter)
|
||||
? *j
|
||||
: *(j - 1);
|
||||
}
|
||||
slice->ids.emplace_back(channelId, *j);
|
||||
}
|
||||
slice->nearestToAround = FullMsgId(
|
||||
channelId,
|
||||
nearestToAround.value_or(
|
||||
slice->ids.empty() ? 0 : slice->ids.back().msg));
|
||||
slice->fullCount = _fullCount.current();
|
||||
|
||||
injectRootMessageAndReverse(slice);
|
||||
|
|
|
@ -336,12 +336,16 @@ void ListWidget::refreshRows() {
|
|||
|
||||
_items.clear();
|
||||
_items.reserve(_slice.ids.size());
|
||||
auto nearestIndex = -1;
|
||||
for (const auto &fullId : _slice.ids) {
|
||||
if (const auto item = session().data().message(fullId)) {
|
||||
if (_slice.nearestToAround == fullId) {
|
||||
nearestIndex = int(_items.size());
|
||||
}
|
||||
_items.push_back(enforceViewForItem(item));
|
||||
}
|
||||
}
|
||||
updateAroundPositionFromRows();
|
||||
updateAroundPositionFromNearest(nearestIndex);
|
||||
|
||||
updateItemsGeometry();
|
||||
checkUnreadBarCreation();
|
||||
|
@ -573,8 +577,7 @@ not_null<Element*> ListWidget::enforceViewForItem(
|
|||
return i->second.get();
|
||||
}
|
||||
|
||||
void ListWidget::updateAroundPositionFromRows() {
|
||||
const auto nearestIndex = findNearestItem(_aroundPosition);
|
||||
void ListWidget::updateAroundPositionFromNearest(int nearestIndex) {
|
||||
if (nearestIndex < 0) {
|
||||
_aroundIndex = -1;
|
||||
return;
|
||||
|
|
|
@ -305,7 +305,7 @@ private:
|
|||
using CursorState = HistoryView::CursorState;
|
||||
|
||||
void refreshViewer();
|
||||
void updateAroundPositionFromRows();
|
||||
void updateAroundPositionFromNearest(int nearestIndex);
|
||||
void refreshRows();
|
||||
ScrollTopState countScrollState() const;
|
||||
void saveScrollState();
|
||||
|
|
|
@ -1519,7 +1519,7 @@ void RepliesWidget::updateControlsGeometry() {
|
|||
|
||||
const auto bottom = height();
|
||||
const auto controlsHeight = _composeControls->heightCurrent();
|
||||
const auto scrollY = _topBar->height() + _rootView->height();
|
||||
const auto scrollY = _topBar->height() + _rootViewHeight;
|
||||
const auto scrollHeight = bottom - scrollY - controlsHeight;
|
||||
const auto scrollSize = QSize(contentWidth, scrollHeight);
|
||||
if (_scroll->size() != scrollSize) {
|
||||
|
@ -1585,13 +1585,28 @@ void RepliesWidget::updatePinnedVisibility() {
|
|||
return _root;
|
||||
}();
|
||||
const auto view = _inner->viewByPosition(item->position());
|
||||
setPinnedVisibility(!view
|
||||
|| (view->y() + view->height() <= _scroll->scrollTop()));
|
||||
const auto visible = !view
|
||||
|| (view->y() + view->height() <= _scroll->scrollTop());
|
||||
setPinnedVisibility(visible);
|
||||
}
|
||||
|
||||
void RepliesWidget::setPinnedVisibility(bool shown) {
|
||||
if (!animating()) {
|
||||
_rootView->toggle(shown, anim::type::normal);
|
||||
if (!_rootViewInited) {
|
||||
const auto height = shown ? st::historyReplyHeight : 0;
|
||||
if (const auto delta = height - _rootViewHeight) {
|
||||
_rootViewHeight = height;
|
||||
if (_scroll->scrollTop() == _scroll->scrollTopMax()) {
|
||||
setGeometryWithTopMoved(geometry(), delta);
|
||||
} else {
|
||||
updateControlsGeometry();
|
||||
}
|
||||
}
|
||||
_rootView->toggle(shown, anim::type::instant);
|
||||
_rootViewInited = true;
|
||||
} else {
|
||||
_rootView->toggle(shown, anim::type::normal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -255,6 +255,7 @@ private:
|
|||
object_ptr<Ui::SlideWrap<Ui::RpWidget>> _rootView;
|
||||
int _rootViewHeight = 0;
|
||||
object_ptr<Ui::PlainShadow> _rootShadow;
|
||||
bool _rootViewInited = false;
|
||||
|
||||
std::unique_ptr<Ui::ScrollArea> _scroll;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue