diff options
author | Catalin Badea <catalin.badea392@gmail.com> | 2012-07-24 13:26:05 (GMT) |
---|---|---|
committer | Catalin Badea <catalin.badea392@gmail.com> | 2012-07-24 13:26:05 (GMT) |
commit | 0cb7b193cd197efb28ddd14f1df2ab5e01a37609 (patch) | |
tree | 4c87ad6180d5e260872b06c553f5c8eec3a269cc /Swift | |
parent | af56b6e929a713ecbfd573ecaa5cd5d254d8ff1a (diff) | |
download | swift-contrib-0cb7b193cd197efb28ddd14f1df2ab5e01a37609.zip swift-contrib-0cb7b193cd197efb28ddd14f1df2ab5e01a37609.tar.bz2 |
Append messages to bottom.
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/QtUI/MessageSnippet.cpp | 2 | ||||
-rw-r--r-- | Swift/QtUI/QtChatView.cpp | 2 | ||||
-rw-r--r-- | Swift/QtUI/QtHistoryWindow.cpp | 18 | ||||
-rw-r--r-- | Swift/QtUI/QtHistoryWindow.h | 4 |
4 files changed, 23 insertions, 3 deletions
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("<span class='swift_time'>" + timeToEscapedString(time) + "</span>")); content_.replace("%userIconPath%", escape(iconURI)); content_ = "<div id='" + id + "'>" + content_ + "</div>"; - content_ = "<div class='date" + time.date().toString(Qt::ISODate) + "'>" + content_ + "</span>"; + content_ = "<span class='date" + time.date().toString(Qt::ISODate) + "'>" + content_ + "</span>"; } MessageSnippet::~MessageSnippet() { diff --git a/Swift/QtUI/QtChatView.cpp b/Swift/QtUI/QtChatView.cpp index 56823bf..ef39b23 100644 --- a/Swift/QtUI/QtChatView.cpp +++ b/Swift/QtUI/QtChatView.cpp @@ -106,8 +106,10 @@ void QtChatView::addMessageTop(boost::shared_ptr<ChatSnippet> 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<ChatSnippet>(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<ChatSnippet>(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<ChatSnippet>(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<QDate> dates_; int idCounter_; + bool previousTopMessageWasSelf_; + QString previousTopSenderName_; + bool previousBottomMessageWasSelf_; + QString previousBottomSenderName_; }; } |