From 22d4e0bfe7d78beba9fb24ef71513702340993b5 Mon Sep 17 00:00:00 2001 From: Catalin Badea Date: Tue, 24 Jul 2012 16:26:05 +0300 Subject: Append messages to bottom. diff --git a/Swift/QtUI/MessageSnippet.cpp b/Swift/QtUI/MessageSnippet.cpp index 51c9c78..a10ee2c 100644 --- a/Swift/QtUI/MessageSnippet.cpp +++ b/Swift/QtUI/MessageSnippet.cpp @@ -37,7 +37,7 @@ MessageSnippet::MessageSnippet(const QString& message, const QString& sender, co content_.replace("%time%", wrapResizable("" + timeToEscapedString(time) + "")); content_.replace("%userIconPath%", escape(iconURI)); content_ = "
" + content_ + "
"; - content_ = "
" + content_ + ""; + content_ = "" + content_ + ""; } MessageSnippet::~MessageSnippet() { diff --git a/Swift/QtUI/QtChatView.cpp b/Swift/QtUI/QtChatView.cpp index b2a1754..0af1262 100644 --- a/Swift/QtUI/QtChatView.cpp +++ b/Swift/QtUI/QtChatView.cpp @@ -106,8 +106,10 @@ void QtChatView::addMessageTop(boost::shared_ptr snippet) { topMessageAdded_ = true; QWebElement newElement = snippetToDOM(snippet); + firstElement_.prependOutside(newElement); firstElement_ = newElement; + if (lastElement_.isNull()) { lastElement_ = firstElement_; } diff --git a/Swift/QtUI/QtHistoryWindow.cpp b/Swift/QtUI/QtHistoryWindow.cpp index b3603a8..0a7c5b5 100644 --- a/Swift/QtUI/QtHistoryWindow.cpp +++ b/Swift/QtUI/QtHistoryWindow.cpp @@ -27,7 +27,9 @@ namespace Swift { -QtHistoryWindow::QtHistoryWindow(SettingsProvider* settings, UIEventStream* eventStream) { +QtHistoryWindow::QtHistoryWindow(SettingsProvider* settings, UIEventStream* eventStream) : + previousTopMessageWasSelf_(false), + previousBottomMessageWasSelf_(false) { ui_.setupUi(this); theme_ = new QtChatTheme(""); @@ -112,10 +114,17 @@ void QtHistoryWindow::addMessage(const std::string &message, const std::string & QString qAvatarPath = scaledAvatarPath.isEmpty() ? "qrc:/icons/avatar.png" : QUrl::fromLocalFile(scaledAvatarPath).toEncoded(); if (addAtTheTop) { + // bool appendToPrevious = ((senderIsSelf && previousTopMessageWasSelf_) || (!senderIsSelf && !previousTopMessageWasSelf_&& previousTopSenderName_ == P2QSTRING(senderName))); conversation_->addMessageTop(boost::shared_ptr(new MessageSnippet(messageHTML, Qt::escape(P2QSTRING(senderName)), qTime, qAvatarPath, senderIsSelf, false, theme_, P2QSTRING(id)))); + + previousTopMessageWasSelf_ = senderIsSelf; + previousTopSenderName_ = P2QSTRING(senderName); } else { - conversation_->addMessageBottom(boost::shared_ptr(new MessageSnippet(messageHTML, Qt::escape(P2QSTRING(senderName)), qTime, qAvatarPath, senderIsSelf, false, theme_, P2QSTRING(id)))); + bool appendToPrevious = ((senderIsSelf && previousBottomMessageWasSelf_) || (!senderIsSelf && !previousBottomMessageWasSelf_&& previousBottomSenderName_ == P2QSTRING(senderName))); + conversation_->addMessageBottom(boost::shared_ptr(new MessageSnippet(messageHTML, Qt::escape(P2QSTRING(senderName)), qTime, qAvatarPath, senderIsSelf, appendToPrevious, theme_, P2QSTRING(id)))); + previousBottomMessageWasSelf_ = senderIsSelf; + previousBottomSenderName_ = P2QSTRING(senderName); } // keep track of the days viewable in the chatView @@ -129,6 +138,11 @@ void QtHistoryWindow::handleSomethingSelectedChanged(RosterItem* item) { } void QtHistoryWindow::resetConversationView() { + previousTopMessageWasSelf_ = false; + previousBottomMessageWasSelf_ = false; + previousTopSenderName_.clear(); + previousBottomSenderName_.clear(); + dates_.clear(); conversation_->resetView(); } diff --git a/Swift/QtUI/QtHistoryWindow.h b/Swift/QtUI/QtHistoryWindow.h index cdffe69..c813b82 100644 --- a/Swift/QtUI/QtHistoryWindow.h +++ b/Swift/QtUI/QtHistoryWindow.h @@ -54,5 +54,9 @@ namespace Swift { QtTreeWidget* conversationRoster_; std::set dates_; int idCounter_; + bool previousTopMessageWasSelf_; + QString previousTopSenderName_; + bool previousBottomMessageWasSelf_; + QString previousBottomSenderName_; }; } -- cgit v0.10.2-6-g49f6