From cd495654573953fa356e1f9e142e20ef4971d18c Mon Sep 17 00:00:00 2001
From: John Preston <johnprestonmail@gmail.com>
Date: Tue, 29 Mar 2016 21:03:53 +0300
Subject: [PATCH] Skipping message date height when scrolling to the unread
 bar.

---
 Telegram/SourceFiles/history.cpp       | 12 +++++++-----
 Telegram/SourceFiles/historywidget.cpp |  6 ++++++
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/Telegram/SourceFiles/history.cpp b/Telegram/SourceFiles/history.cpp
index 1478fe97c..7ea40b30d 100644
--- a/Telegram/SourceFiles/history.cpp
+++ b/Telegram/SourceFiles/history.cpp
@@ -377,11 +377,13 @@ bool History::updateTyping(uint64 ms, bool force) {
 	return changed;
 }
 
-ChannelHistory::ChannelHistory(const PeerId &peer) : History(peer),
-unreadCountAll(0),
-_onlyImportant(!isMegagroup()),
-_otherOldLoaded(false), _otherNewLoaded(true),
-_collapseMessage(0), _joinedMessage(0) {
+ChannelHistory::ChannelHistory(const PeerId &peer) : History(peer)
+, unreadCountAll(0)
+, _onlyImportant(!isMegagroup())
+, _otherOldLoaded(false)
+, _otherNewLoaded(true)
+, _collapseMessage(nullptr)
+, _joinedMessage(nullptr) {
 }
 
 bool ChannelHistory::isSwitchReadyFor(MsgId switchId, MsgId &fixInScrollMsgId, int32 &fixInScrollMsgTop) {
diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp
index 0f4017583..c8f665649 100644
--- a/Telegram/SourceFiles/historywidget.cpp
+++ b/Telegram/SourceFiles/historywidget.cpp
@@ -6557,8 +6557,14 @@ void HistoryWidget::updateListSize(bool initial, bool loadedDown, const ScrollCh
 		}
 	} else if (initial && _migrated && _migrated->unreadBar) {
 		toY = _list->itemTop(_migrated->unreadBar);
+		if (_migrated->unreadBar->Has<HistoryMessageDate>()) {
+			toY += _migrated->unreadBar->Get<HistoryMessageDate>()->height();
+		}
 	} else if (initial && _history->unreadBar) {
 		toY = _list->itemTop(_history->unreadBar);
+		if (_history->unreadBar->Has<HistoryMessageDate>()) {
+			toY += _history->unreadBar->Get<HistoryMessageDate>()->height();
+		}
 	} else if (_migrated && _migrated->showFrom) {
 		toY = _list->itemTop(_migrated->showFrom);
 		if (toY < _scroll.scrollTopMax() + st::unreadBarHeight) {