diff options
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/QtUI/QtChatView.cpp | 19 | ||||
-rw-r--r-- | Swift/QtUI/QtChatView.h | 4 |
2 files changed, 8 insertions, 15 deletions
diff --git a/Swift/QtUI/QtChatView.cpp b/Swift/QtUI/QtChatView.cpp index 6b38309..3324108 100644 --- a/Swift/QtUI/QtChatView.cpp +++ b/Swift/QtUI/QtChatView.cpp @@ -68,14 +68,6 @@ void QtChatView::handleKeyPressEvent(QKeyEvent* event) { } void QtChatView::addMessage(const ChatSnippet& snippet) { - if (viewReady_) { - appendToView(snippet); - } else { - queuedSnippets_.append(snippet); - } -} - -void QtChatView::appendToView(const ChatSnippet& snippet) { //bool wasScrolledToBottom = isScrolledToBottom(); QString content = snippet.getContent(); @@ -90,7 +82,12 @@ void QtChatView::appendToView(const ChatSnippet& snippet) { else { command = "appendNextMessage(\"" + content + "\");"; } - webPage_->mainFrame()->evaluateJavaScript(command); + if (viewReady_) { + webPage_->mainFrame()->evaluateJavaScript(command); + } + else { + queuedMessages_ += command; + } //qDebug() << webPage_->mainFrame()->toHtml(); previousContinuationElementID_ = snippet.getContinuationElementID(); @@ -121,9 +118,7 @@ void QtChatView::handleLinkClicked(const QUrl& url) { void QtChatView::handleViewLoadFinished(bool ok) { Q_ASSERT(ok); viewReady_ = true; - foreach (const ChatSnippet& snippet, queuedSnippets_) { - appendToView(snippet); - } + webPage_->mainFrame()->evaluateJavaScript(queuedMessages_); queuedMessages_.clear(); } diff --git a/Swift/QtUI/QtChatView.h b/Swift/QtUI/QtChatView.h index a5b6b4a..ea64265 100644 --- a/Swift/QtUI/QtChatView.h +++ b/Swift/QtUI/QtChatView.h @@ -9,7 +9,6 @@ #include <QString> #include <QWidget> -#include <QList> #include "ChatSnippet.h" @@ -36,12 +35,11 @@ namespace Swift { void handleViewLoadFinished(bool); private: - void appendToView(const ChatSnippet& snippet); bool viewReady_; QtWebView* webView_; QWebPage* webPage_; QString previousContinuationElementID_; - QList<ChatSnippet> queuedSnippets_; + QString queuedMessages_; }; } |