From 97643bb9103a7b4a61cd267648f36cc7ffb36e6d Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Mon, 30 Aug 2010 19:45:55 +0100
Subject: Start scrolling on new messages.

Resolves: #551

diff --git a/Swift/QtUI/QtChatView.cpp b/Swift/QtUI/QtChatView.cpp
index 52b399b..32f2394 100644
--- a/Swift/QtUI/QtChatView.cpp
+++ b/Swift/QtUI/QtChatView.cpp
@@ -13,6 +13,7 @@
 #include <QWebFrame>
 #include <QKeyEvent>
 #include <QStackedWidget>
+#include <QTimer>
 
 #include "QtWebView.h"
 #include "QtChatTheme.h"
@@ -88,6 +89,8 @@ QWebElement QtChatView::snippetToDOM(boost::shared_ptr<ChatSnippet> snippet) {
 }
 
 void QtChatView::addToDOM(boost::shared_ptr<ChatSnippet> snippet) {
+	bool bottom = isScrolledToBottom();
+	qDebug() << "Appending to the dom - scrolled to bottom? " << bottom;
 	QWebElement newElement = snippetToDOM(snippet);
 	QWebElement continuationElement = lastElement_.findFirst("#insert");
 	if (snippet->getAppendToPrevious()) {
@@ -98,6 +101,10 @@ void QtChatView::addToDOM(boost::shared_ptr<ChatSnippet> snippet) {
 		newInsertPoint_.prependOutside(newElement);
 	}
 	lastElement_ = newElement;
+	if (bottom /* Or was me? */) {
+		QTimer::singleShot(0, this, SLOT(scrollToBottom()));
+	}
+	qDebug() << "Appended, now at bottom? " << isScrolledToBottom();
 }
 
 void QtChatView::correctLastMessage(const QString& newMessage) {
-- 
cgit v0.10.2-6-g49f6