summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCatalin Badea <catalin.badea392@gmail.com>2012-07-29 13:42:06 (GMT)
committerCătălin Badea <catalin.badea392@gmail.com>2012-08-11 15:59:13 (GMT)
commit94ff6ec9e699a2db97775063eb7fa2f6d24b281a (patch)
tree80d093df35ea27b258957130c53b859faad5e177
parentc0f0ab471345fe3f3a3517bb302c7da1549c8f25 (diff)
downloadswift-contrib-94ff6ec9e699a2db97775063eb7fa2f6d24b281a.zip
swift-contrib-94ff6ec9e699a2db97775063eb7fa2f6d24b281a.tar.bz2
Fix adding messages at the top.
-rw-r--r--Swift/Controllers/HistoryViewController.cpp3
-rw-r--r--Swift/Controllers/UIInterfaces/HistoryWindow.h1
-rw-r--r--Swift/QtUI/QtChatView.cpp28
-rw-r--r--Swift/QtUI/QtChatView.h2
-rw-r--r--Swift/QtUI/QtHistoryWindow.cpp10
-rw-r--r--Swift/QtUI/QtHistoryWindow.h3
6 files changed, 37 insertions, 10 deletions
diff --git a/Swift/Controllers/HistoryViewController.cpp b/Swift/Controllers/HistoryViewController.cpp
index e5e2acc..c6e663b 100644
--- a/Swift/Controllers/HistoryViewController.cpp
+++ b/Swift/Controllers/HistoryViewController.cpp
@@ -158,9 +158,10 @@ void HistoryViewController::handleReturnPressed(const std::string& keyword) {
void HistoryViewController::handleScrollReachedTop(const boost::gregorian::date& date) {
std::vector<HistoryMessage> messages = historyController_->getMessagesFromPreviousDate(selfJID_, selectedItem_->getJID(), selectedItemType_, date);
- reverse_foreach (const HistoryMessage& message, messages) {
+ foreach (const HistoryMessage& message, messages) {
addNewMessage(message, true);
}
+ historyWindow_->resetConversationViewTopInsertPoint();
}
void HistoryViewController::handleScrollReachedBottom(const boost::gregorian::date& date) {
diff --git a/Swift/Controllers/UIInterfaces/HistoryWindow.h b/Swift/Controllers/UIInterfaces/HistoryWindow.h
index aa1a495..edc4af3 100644
--- a/Swift/Controllers/UIInterfaces/HistoryWindow.h
+++ b/Swift/Controllers/UIInterfaces/HistoryWindow.h
@@ -17,6 +17,7 @@ namespace Swift {
virtual void setRosterModel(Roster*) = 0;
virtual void addMessage(const std::string &message, const std::string &senderName, bool senderIsSelf, const std::string& avatarPath, const boost::posix_time::ptime& time, bool addAtTheTop) = 0;
virtual void resetConversationView() = 0;
+ virtual void resetConversationViewTopInsertPoint() = 0; // this is a temporary fix used in adding messages at the top
virtual void setDate(const boost::gregorian::date& date) = 0;
boost::signal<void (RosterItem*)> onSelectedContactChanged;
diff --git a/Swift/QtUI/QtChatView.cpp b/Swift/QtUI/QtChatView.cpp
index 0af1262..3ad957c 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();
+}
+
}
diff --git a/Swift/QtUI/QtChatView.h b/Swift/QtUI/QtChatView.h
index d778f6f..dada46a 100644
--- a/Swift/QtUI/QtChatView.h
+++ b/Swift/QtUI/QtChatView.h
@@ -61,6 +61,7 @@ namespace Swift {
void handleLinkClicked(const QUrl&);
void handleKeyPressEvent(QKeyEvent* event);
void resetView();
+ void resetTopInsertPoint();
void increaseFontSize(int numSteps = 1);
void decreaseFontSize();
void resizeFont(int fontSizeSteps);
@@ -86,6 +87,7 @@ namespace Swift {
int fontSizeSteps_;
QtChatTheme* theme_;
QWebElement newInsertPoint_;
+ QWebElement topInsertPoint_;
QWebElement lineSeparator_;
QWebElement lastElement_;
QWebElement firstElement_;
diff --git a/Swift/QtUI/QtHistoryWindow.cpp b/Swift/QtUI/QtHistoryWindow.cpp
index a0ccbf9..d9b587f 100644
--- a/Swift/QtUI/QtHistoryWindow.cpp
+++ b/Swift/QtUI/QtHistoryWindow.cpp
@@ -117,8 +117,8 @@ 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))));
+ 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, appendToPrevious, theme_, P2QSTRING(id))));
previousTopMessageWasSelf_ = senderIsSelf;
previousTopSenderName_ = P2QSTRING(senderName);
@@ -206,4 +206,10 @@ void QtHistoryWindow::handleFontResized(int fontSizeSteps) {
emit fontResized(fontSizeSteps);
}
+void QtHistoryWindow::resetConversationViewTopInsertPoint() {
+ previousTopMessageWasSelf_ = false;
+ previousTopSenderName_ = QString();
+ conversation_->resetTopInsertPoint();
+}
+
}
diff --git a/Swift/QtUI/QtHistoryWindow.h b/Swift/QtUI/QtHistoryWindow.h
index c813b82..13d3f14 100644
--- a/Swift/QtUI/QtHistoryWindow.h
+++ b/Swift/QtUI/QtHistoryWindow.h
@@ -23,8 +23,9 @@ namespace Swift {
~QtHistoryWindow();
void activate();
void setRosterModel(Roster*);
- void addMessage(const std::string &message, const std::string &senderName, bool senderIsSelf, const std::string& avatarPath, const boost::posix_time::ptime& time, bool addAtTheTop);
+ void addMessage(const std::string& message, const std::string& senderName, bool senderIsSelf, const std::string& avatarPath, const boost::posix_time::ptime& time, bool addAtTheTop);
void resetConversationView();
+ void resetConversationViewTopInsertPoint();
void setDate(const boost::gregorian::date& date);
void closeEvent(QCloseEvent* event);