From 20b93d969f249d850091ae020f385dd71f7524e3 Mon Sep 17 00:00:00 2001
From: John Preston <johnprestonmail@gmail.com>
Date: Sat, 2 Jan 2016 21:09:39 +0800
Subject: [PATCH] pagination added to inline bots results, preloading thumbs
 when creating layouts for results

---
 Telegram/SourceFiles/dropdown.cpp      | 15 ++++++++++++---
 Telegram/SourceFiles/gui/animation.cpp |  2 --
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/Telegram/SourceFiles/dropdown.cpp b/Telegram/SourceFiles/dropdown.cpp
index 96fb37ac8..fffad3986 100644
--- a/Telegram/SourceFiles/dropdown.cpp
+++ b/Telegram/SourceFiles/dropdown.cpp
@@ -1672,6 +1672,7 @@ void StickerPanInner::inlineRowsAddItem(DocumentData *savedGif, InlineResult *re
 	}
 	if (!layout) return;
 
+	layout->preload();
 	if (inlineRowFinalize(row, sumWidth, layout->fullLine())) {
 		layout->setPosition(_inlineRows.size() * MatrixRowShift);
 	}
@@ -3458,6 +3459,9 @@ void EmojiPan::onScroll() {
 	if (_stickersShown) {
 		updatePanelsPositions(s_panels, st);
 		validateSelectedIcon(true);
+		if (st + s_scroll.height() > s_scroll.scrollTopMax()) {
+			onInlineRequest();
+		}
 	}
 	s_inner.setScrollTop(st);
 }
@@ -3633,9 +3637,9 @@ void EmojiPan::inlineResultsDone(const MTPmessages_BotResults &result) {
 		if (!adding) {
 			it = _inlineCache.insert(_inlineQuery, new InlineCacheEntry());
 		}
-		it.value()->nextOffset = v.isEmpty() ? QString() : qs(d.vnext_offset);
+		it.value()->nextOffset = qs(d.vnext_offset);
 
-		int32 count = v.size();
+		int32 count = v.size(), added = 0;
 		if (count) {
 			it.value()->results.reserve(it.value()->results.size() + count);
 		}
@@ -3704,14 +3708,19 @@ void EmojiPan::inlineResultsDone(const MTPmessages_BotResults &result) {
 			if (result->type.isEmpty() || badAttachment || !canSend) {
 				delete result;
 			} else {
+				++added;
 				it.value()->results.push_back(result);
 			}
 		}
+
+		if (!added) {
+			it.value()->nextOffset = QString();
+		}
 	} else if (adding) {
-		it.value()->clearResults();
 		it.value()->nextOffset = QString();
 	}
 	showInlineRows(!adding);
+	onScroll();
 }
 
 bool EmojiPan::inlineResultsFail(const RPCError &error) {
diff --git a/Telegram/SourceFiles/gui/animation.cpp b/Telegram/SourceFiles/gui/animation.cpp
index 243930df4..e373f58a4 100644
--- a/Telegram/SourceFiles/gui/animation.cpp
+++ b/Telegram/SourceFiles/gui/animation.cpp
@@ -880,7 +880,6 @@ public:
 			return error();
 		}
 		if (ms >= _nextUpdateMs) {
-			LOG(("Slow frame, keeping up.."));
 			if (!prepareNextFrame()) {
 				return error();
 			}
@@ -1075,7 +1074,6 @@ bool ClipReadManager::handleProcessResult(ClipReaderPrivate *reader, ClipProcess
 		ClipReader::Frame *other = it.key()->frameToWriteNext(false);
 		t_assert(other != 0);
 		if (other->when && other->when + WaitBeforeGifPause < qMax(reader->_previousMs, ms)) {
-			LOG(("Pausing reader.."));
 			reader->_paused = true;
 			it.key()->_paused.storeRelease(1);
 			result = ClipProcessPaused;