[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdenetwork/kopete/plugins/history
From:       Roman Jarosz <kedgedev () gmail ! com>
Date:       2010-07-06 16:14:52
Message-ID: 20100706161452.67550AC85D () svn ! kde ! org
[Download RAW message or body]

SVN commit 1146770 by rjarosz:

Fix bug ICQ-Chat History is displayed in wrong order, if the computer-date is \
incorrect.

BUG: 186016
BUG: 212392



 M  +23 -1     historylogger.cpp  


--- trunk/KDE/kdenetwork/kopete/plugins/history/historylogger.cpp #1146769:1146770
@@ -41,6 +41,12 @@
 
 bool messageTimestampLessThan(const Kopete::Message &m1, const Kopete::Message &m2)
 {
+	const Kopete::Contact* c1 = (m1.direction() == Kopete::Message::Outbound) ? \
m1.to().value(0) : m1.from(); +	const Kopete::Contact* c2 = (m2.direction() == \
Kopete::Message::Outbound) ? m2.to().value(0) : m2.from(); +
+	if (c1 == c2) // Messages from the same account, keep order as it was saved.
+		return false;
+
 	return m1.timestamp() < m2.timestamp();
 }
 
@@ -406,7 +412,23 @@
 
 	}
 
-	qSort(messages.begin(), messages.end(), messageTimestampLessThan);
+	//Bubble Sort, can't use qStableSort because we have to compare surrounding items \
only, mostly +	//it will be only O(n) sort, because we will only have one contact in \
metacontact for a day. +	const int size = messages.size();
+	for (int i = 0; i < size; i++)
+	{
+		bool swap = false;
+		for (int j = 0; j < size - 1; j++)
+		{
+			if (messageTimestampLessThan(messages.at(j + 1), messages.at(j))) {
+				messages.swap(j, j + 1);
+				swap = true;
+			}
+		}
+
+		if (!swap)
+			break;
+	}
 	return messages;
 }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic