From a6375f56f0df8853914955d3a4b3f6cde8f0f88b Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Tue, 11 Oct 2011 18:17:42 +0100
Subject: Fix DOM element finding for message correction


diff --git a/Swift/QtUI/QtChatView.cpp b/Swift/QtUI/QtChatView.cpp
index 97ce992..1c3dd37 100644
--- a/Swift/QtUI/QtChatView.cpp
+++ b/Swift/QtUI/QtChatView.cpp
@@ -176,6 +176,9 @@ void QtChatView::replaceMessage(const QString& newMessage, const QString& id, co
 		old = replaceTime.toOuterXml();
 		replaceTime.setInnerXml(ChatSnippet::escape(tr("%1 edited").arg(ChatSnippet::timeToEscapedString(editTime))));
 	}
+	else {
+		qWarning() << "Trying to replace element with id " << id << " but it's not there.";
+	}
 }
 
 void QtChatView::copySelectionToClipboard() {
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp
index 0635496..6b6dedf 100644
--- a/Swift/QtUI/QtChatWindow.cpp
+++ b/Swift/QtUI/QtChatWindow.cpp
@@ -51,6 +51,7 @@
 namespace Swift {
 QtChatWindow::QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventStream* eventStream) : QtTabbable(), contact_(contact), previousMessageWasSelf_(false), previousMessageWasSystem_(false), previousMessageWasPresence_(false), previousMessageWasFileTransfer_(false), eventStream_(eventStream) {
 	unreadCount_ = 0;
+	idCounter_ = 0;
 	inputEnabled_ = true;
 	completer_ = NULL;
 	affiliationEditor_ = NULL;
@@ -454,7 +455,7 @@ std::string QtChatWindow::addMessage(const std::string &message, const std::stri
 		appendToPrevious = false;
 	}
 	QString qAvatarPath =  scaledAvatarPath.isEmpty() ? "qrc:/icons/avatar.png" : QUrl::fromLocalFile(scaledAvatarPath).toEncoded();
-	std::string id = id_.generateID();
+	std::string id = "id" + boost::lexical_cast<std::string>(idCounter_++);
 	messageLog_->addMessage(boost::shared_ptr<ChatSnippet>(new MessageSnippet(htmlString, Qt::escape(P2QSTRING(senderName)), B2QDATE(time), qAvatarPath, senderIsSelf, appendToPrevious, theme_, P2QSTRING(id))));
 
 	previousMessageWasSelf_ = senderIsSelf;
@@ -500,7 +501,7 @@ std::string formatSize(const boost::uintmax_t bytes) {
 
 std::string QtChatWindow::addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes) {
 	qDebug() << "addFileTransfer";
-	std::string ft_id = id_.generateID();
+	std::string ft_id = "ft" + boost::lexical_cast<std::string>(idCounter_++);
 	
 	std::string htmlString;
 	if (senderIsSelf) {
@@ -530,7 +531,7 @@ std::string QtChatWindow::addFileTransfer(const std::string& senderName, bool se
 		appendToPrevious = false;
 	}
 	QString qAvatarPath = "qrc:/icons/avatar.png";
-	std::string id = id_.generateID();
+	std::string id = "ftmessage" + boost::lexical_cast<std::string>(idCounter_++);
 	messageLog_->addMessage(boost::shared_ptr<ChatSnippet>(new MessageSnippet(QString::fromStdString(htmlString), Qt::escape(P2QSTRING(senderName)), B2QDATE(boost::posix_time::second_clock::local_time()), qAvatarPath, senderIsSelf, appendToPrevious, theme_, P2QSTRING(id))));
 
 
@@ -613,6 +614,9 @@ void QtChatWindow::replaceMessage(const std::string& message, const std::string&
 		messageHTML.replace("\n","<br/>");
 		messageLog_->replaceMessage(messageHTML, P2QSTRING(id), B2QDATE(time));
 	}
+	else {
+		qWarning() << "Trying to replace a message with no id";
+	}
 }
 
 void QtChatWindow::addPresenceMessage(const std::string& message) {
diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h
index e546f12..0c64f02 100644
--- a/Swift/QtUI/QtChatWindow.h
+++ b/Swift/QtUI/QtChatWindow.h
@@ -14,8 +14,6 @@
 
 #include <SwifTools/LastLineTracker.h>
 
-#include <Swiften/Base/IDGenerator.h>
-
 #include <map>
 #include <QPointer>
 
@@ -150,7 +148,6 @@ namespace Swift {
 			bool inputClearing_;
 			UIEventStream* eventStream_;
 			bool inputEnabled_;
-			IDGenerator id_;
 			QSplitter *logRosterSplitter_;
 			Tristate correctionEnabled_;
 			QString alertStyleSheet_;
@@ -158,5 +155,6 @@ namespace Swift {
 			QtFileTransferJSBridge* fileTransferJS;
 			QPointer<QtMUCConfigurationWindow> mucConfigurationWindow_;
 			QPointer<QtAffiliationEditor> affiliationEditor_;
+			int idCounter_;
 	};
 }
-- 
cgit v0.10.2-6-g49f6