Implement new choosing of shown pinned message.
This commit is contained in:
		
							parent
							
								
									77fa29f8ce
								
							
						
					
					
						commit
						08f7069370
					
				
					 2 changed files with 44 additions and 10 deletions
				
			
		| 
						 | 
					@ -1608,6 +1608,8 @@ void HistoryWidget::showHistory(
 | 
				
			||||||
		const PeerId &peerId,
 | 
							const PeerId &peerId,
 | 
				
			||||||
		MsgId showAtMsgId,
 | 
							MsgId showAtMsgId,
 | 
				
			||||||
		bool reload) {
 | 
							bool reload) {
 | 
				
			||||||
 | 
						_pinnedClickedId = FullMsgId();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	MsgId wasMsgId = _showAtMsgId;
 | 
						MsgId wasMsgId = _showAtMsgId;
 | 
				
			||||||
	History *wasHistory = _history;
 | 
						History *wasHistory = _history;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2747,6 +2749,14 @@ void HistoryWidget::onScroll() {
 | 
				
			||||||
	if (!_synteticScrollEvent) {
 | 
						if (!_synteticScrollEvent) {
 | 
				
			||||||
		_lastUserScrolled = crl::now();
 | 
							_lastUserScrolled = crl::now();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						const auto scrollTop = _scroll->scrollTop();
 | 
				
			||||||
 | 
						if (scrollTop != _lastScrollTop) {
 | 
				
			||||||
 | 
							if (!_synteticScrollEvent) {
 | 
				
			||||||
 | 
								checkLastPinnedClickedIdReset(_lastScrollTop, scrollTop);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							_lastScrolled = crl::now();
 | 
				
			||||||
 | 
							_lastScrollTop = scrollTop;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool HistoryWidget::isItemCompletelyHidden(HistoryItem *item) const {
 | 
					bool HistoryWidget::isItemCompletelyHidden(HistoryItem *item) const {
 | 
				
			||||||
| 
						 | 
					@ -2789,12 +2799,6 @@ void HistoryWidget::preloadHistoryIfNeeded() {
 | 
				
			||||||
		preloadHistoryByScroll();
 | 
							preloadHistoryByScroll();
 | 
				
			||||||
		checkReplyReturns();
 | 
							checkReplyReturns();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	auto scrollTop = _scroll->scrollTop();
 | 
					 | 
				
			||||||
	if (scrollTop != _lastScrollTop) {
 | 
					 | 
				
			||||||
		_lastScrolled = crl::now();
 | 
					 | 
				
			||||||
		_lastScrollTop = scrollTop;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void HistoryWidget::preloadHistoryByScroll() {
 | 
					void HistoryWidget::preloadHistoryByScroll() {
 | 
				
			||||||
| 
						 | 
					@ -5176,15 +5180,39 @@ void HistoryWidget::updatePinnedViewer() {
 | 
				
			||||||
		|| !_historyInited) {
 | 
							|| !_historyInited) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	const auto visibleTop = _scroll->scrollTop();
 | 
						const auto visibleBottom = _scroll->scrollTop() + _scroll->height();
 | 
				
			||||||
	const auto add = (st::historyReplyHeight - _pinnedBarHeight);
 | 
						auto [view, offset] = _list->findViewForPinnedTracking(visibleBottom);
 | 
				
			||||||
	auto [view, offset] = _list->findViewForPinnedTracking(visibleTop + add);
 | 
					 | 
				
			||||||
	const auto lessThanId = !view
 | 
						const auto lessThanId = !view
 | 
				
			||||||
		? (ServerMaxMsgId - 1)
 | 
							? (ServerMaxMsgId - 1)
 | 
				
			||||||
		: (view->data()->history() != _history)
 | 
							: (view->data()->history() != _history)
 | 
				
			||||||
		? (view->data()->id + (offset > 0 ? 1 : 0) - ServerMaxMsgId)
 | 
							? (view->data()->id + (offset > 0 ? 1 : 0) - ServerMaxMsgId)
 | 
				
			||||||
		: (view->data()->id + (offset > 0 ? 1 : 0));
 | 
							: (view->data()->id + (offset > 0 ? 1 : 0));
 | 
				
			||||||
	_pinnedTracker->trackAround(lessThanId);
 | 
						const auto lastClickedId = !_pinnedClickedId
 | 
				
			||||||
 | 
							? (ServerMaxMsgId - 1)
 | 
				
			||||||
 | 
							: (!_migrated || _pinnedClickedId.channel)
 | 
				
			||||||
 | 
							? _pinnedClickedId.msg
 | 
				
			||||||
 | 
							: (_pinnedClickedId.msg - ServerMaxMsgId);
 | 
				
			||||||
 | 
						if (_pinnedClickedId && lessThanId <= lastClickedId) {
 | 
				
			||||||
 | 
							_pinnedClickedId = FullMsgId();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						_pinnedTracker->trackAround(std::min(lessThanId, lastClickedId));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void HistoryWidget::checkLastPinnedClickedIdReset(
 | 
				
			||||||
 | 
							int wasScrollTop,
 | 
				
			||||||
 | 
							int nowScrollTop) {
 | 
				
			||||||
 | 
						if (_firstLoadRequest
 | 
				
			||||||
 | 
							|| _delayedShowAtRequest
 | 
				
			||||||
 | 
							|| _scroll->isHidden()
 | 
				
			||||||
 | 
							|| !_history
 | 
				
			||||||
 | 
							|| !_historyInited) {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if (wasScrollTop < nowScrollTop && _pinnedClickedId) {
 | 
				
			||||||
 | 
							// User scrolled down.
 | 
				
			||||||
 | 
							_pinnedClickedId = FullMsgId();
 | 
				
			||||||
 | 
							updatePinnedViewer();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void HistoryWidget::setupPinnedTracker() {
 | 
					void HistoryWidget::setupPinnedTracker() {
 | 
				
			||||||
| 
						 | 
					@ -5268,6 +5296,8 @@ void HistoryWidget::checkPinnedBarState() {
 | 
				
			||||||
		const auto id = _pinnedTracker->currentMessageId();
 | 
							const auto id = _pinnedTracker->currentMessageId();
 | 
				
			||||||
		if (const auto item = session().data().message(id.message)) {
 | 
							if (const auto item = session().data().message(id.message)) {
 | 
				
			||||||
			Ui::showPeerHistory(item->history()->peer, item->id);
 | 
								Ui::showPeerHistory(item->history()->peer, item->id);
 | 
				
			||||||
 | 
								_pinnedClickedId = id.message;
 | 
				
			||||||
 | 
								updatePinnedViewer();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}, _pinnedBar->lifetime());
 | 
						}, _pinnedBar->lifetime());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -480,6 +480,9 @@ private:
 | 
				
			||||||
	void setupPinnedTracker();
 | 
						void setupPinnedTracker();
 | 
				
			||||||
	void checkPinnedBarState();
 | 
						void checkPinnedBarState();
 | 
				
			||||||
	void refreshPinnedBarButton(bool many);
 | 
						void refreshPinnedBarButton(bool many);
 | 
				
			||||||
 | 
						void checkLastPinnedClickedIdReset(
 | 
				
			||||||
 | 
							int wasScrollTop,
 | 
				
			||||||
 | 
							int nowScrollTop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void sendInlineResult(
 | 
						void sendInlineResult(
 | 
				
			||||||
		not_null<InlineBots::Result*> result,
 | 
							not_null<InlineBots::Result*> result,
 | 
				
			||||||
| 
						 | 
					@ -596,6 +599,7 @@ private:
 | 
				
			||||||
	std::unique_ptr<HistoryView::PinnedTracker> _pinnedTracker;
 | 
						std::unique_ptr<HistoryView::PinnedTracker> _pinnedTracker;
 | 
				
			||||||
	std::unique_ptr<Ui::PinnedBar> _pinnedBar;
 | 
						std::unique_ptr<Ui::PinnedBar> _pinnedBar;
 | 
				
			||||||
	int _pinnedBarHeight = 0;
 | 
						int _pinnedBarHeight = 0;
 | 
				
			||||||
 | 
						FullMsgId _pinnedClickedId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mtpRequestId _saveEditMsgRequestId = 0;
 | 
						mtpRequestId _saveEditMsgRequestId = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue