diff options
Diffstat (limited to 'Swift/QtUI/QtChatView.cpp')
-rw-r--r-- | Swift/QtUI/QtChatView.cpp | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/Swift/QtUI/QtChatView.cpp b/Swift/QtUI/QtChatView.cpp index ef39b23..4ae613a 100644 --- a/Swift/QtUI/QtChatView.cpp +++ b/Swift/QtUI/QtChatView.cpp @@ -93,11 +93,8 @@ void QtChatView::addMessageBottom(boost::shared_ptr<ChatSnippet> snippet) { /* If this asserts, the previous queuing code was necessary and should be reinstated */ assert(false); } - - if (firstElement_.isNull()) { - firstElement_ = lastElement_; - } } + void QtChatView::addMessageTop(boost::shared_ptr<ChatSnippet> snippet) { // save scrollbar maximum value if (!topMessageAdded_) { @@ -105,9 +102,22 @@ void QtChatView::addMessageTop(boost::shared_ptr<ChatSnippet> snippet) { } topMessageAdded_ = true; - QWebElement newElement = snippetToDOM(snippet); + QWebElement continuationElement = firstElement_.findFirst("#insert"); + + bool insert = snippet->getAppendToPrevious(); + bool fallback = continuationElement.isNull(); + + boost::shared_ptr<ChatSnippet> newSnippet = (insert && fallback) ? snippet->getContinuationFallbackSnippet() : snippet; + QWebElement newElement = snippetToDOM(newSnippet); + + if (insert && !fallback) { + Q_ASSERT(!continuationElement.isNull()); + continuationElement.replace(newElement); + } else { + continuationElement.removeFromDocument(); + topInsertPoint_.appendOutside(newElement); + } - firstElement_.prependOutside(newElement); firstElement_ = newElement; if (lastElement_.isNull()) { @@ -345,6 +355,8 @@ void QtChatView::resetView() { QWebElement chatElement = document_.findFirst("#Chat"); newInsertPoint_ = chatElement.clone(); newInsertPoint_.setOuterXml("<div id='swift_insert'/>"); + topInsertPoint_ = newInsertPoint_.clone(); + chatElement.appendInside(topInsertPoint_); chatElement.appendInside(newInsertPoint_); Q_ASSERT(!newInsertPoint_.isNull()); @@ -444,4 +456,8 @@ int QtChatView::getSnippetPositionByDate(const QDate& date) { return message.geometry().top(); } +void QtChatView::resetTopInsertPoint() { + firstElement_ = QWebElement(); +} + } |