From 844e375fac8e2aa7892a6a6b29bc5c40e7fe0256 Mon Sep 17 00:00:00 2001
From: John Preston <johnprestonmail@gmail.com>
Date: Fri, 25 Mar 2016 19:03:57 +0300
Subject: [PATCH] fixed new not important message adding

---
 Telegram/SourceFiles/history.cpp | 10 +++++-----
 Telegram/SourceFiles/history.h   |  8 +++++++-
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/Telegram/SourceFiles/history.cpp b/Telegram/SourceFiles/history.cpp
index 4110b299a..26da94f50 100644
--- a/Telegram/SourceFiles/history.cpp
+++ b/Telegram/SourceFiles/history.cpp
@@ -759,12 +759,12 @@ HistoryItem *ChannelHistory::addNewToBlocks(const MTPMessage &msg, NewMessageTyp
 
 		if (prev && prev->type() == HistoryItemGroup) {
 			static_cast<HistoryGroup*>(prev)->uniteWith(item);
-			return prev;
+		} else {
+			QDateTime date = prev ? prev->date : item->date;
+			HistoryBlock *block = prev ? prev->block() : pushBackNewBlock();
+			addItemToBlock(HistoryGroup::create(this, item, date), block);
 		}
-
-		QDateTime date = prev ? prev->date : item->date;
-		HistoryBlock *block = prev ? prev->block() : pushBackNewBlock();
-		return addItemToBlock(HistoryGroup::create(this, item, date), block);
+		return item;
 	}
 
 	// when we are receiving channel dialog rows we get one important and one not important
diff --git a/Telegram/SourceFiles/history.h b/Telegram/SourceFiles/history.h
index 07bce6754..cf4223b7b 100644
--- a/Telegram/SourceFiles/history.h
+++ b/Telegram/SourceFiles/history.h
@@ -1163,7 +1163,10 @@ public:
 		return !_block;
 	}
 	void attachToBlock(HistoryBlock *block, int index) {
-		t_assert(_block == nullptr && _indexInBlock < 0);
+		t_assert(_block == nullptr);
+		t_assert(_indexInBlock < 0);
+		t_assert(block != nullptr);
+		t_assert(index >= 0);
 
 		_block = block;
 		_indexInBlock = index;
@@ -1172,6 +1175,9 @@ public:
 		}
 	}
 	void setIndexInBlock(int index) {
+		t_assert(_block != nullptr);
+		t_assert(index >= 0);
+
 		_indexInBlock = index;
 	}
 	int indexInBlock() const {