From 2980154e30885cd9c828b3f6fa8feee59f28c7ae Mon Sep 17 00:00:00 2001
From: Tristan Matthews <tristan.matthews@savoirfairelinux.com>
Date: Tue, 3 Jan 2012 17:14:08 -0500
Subject: [PATCH] * #7593: don't add calls to history that haven't been dialed.

---
 daemon/src/history/historyitem.cpp    |  5 +++++
 daemon/src/history/historyitem.h      |  3 ++-
 daemon/src/history/historymanager.cpp |  3 +--
 gnome/src/contacts/calllist.c         | 10 +++++++---
 4 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/daemon/src/history/historyitem.cpp b/daemon/src/history/historyitem.cpp
index 75707ff2a7..a0edd4b34d 100644
--- a/daemon/src/history/historyitem.cpp
+++ b/daemon/src/history/historyitem.cpp
@@ -92,6 +92,11 @@ bool HistoryItem::youngerThan(int otherTime) const
     return atol(getTimestampStart().c_str()) >= otherTime;
 }
 
+bool HistoryItem::hasPeerNumber() const
+{
+    return entryMap_.find(PEER_NUMBER_KEY) != entryMap_.end();
+}
+
 std::string HistoryItem::getTimestampStart() const {
     using std::map;
     using std::string;
diff --git a/daemon/src/history/historyitem.h b/daemon/src/history/historyitem.h
index 2ad0b0d245..c134e46f18 100644
--- a/daemon/src/history/historyitem.h
+++ b/daemon/src/history/historyitem.h
@@ -58,7 +58,7 @@ class HistoryItem {
         HistoryItem(const std::map<std::string, std::string> &args);
         HistoryItem(const std::string &item, Conf::ConfigTree &list);
 
-        std::string getTimestampStart() const;
+        bool hasPeerNumber() const;
 
         bool youngerThan(int otherTime) const;
 
@@ -67,6 +67,7 @@ class HistoryItem {
         std::map<std::string, std::string> toMap() const;
 
     private:
+        std::string getTimestampStart() const;
         std::map<std::string, std::string> entryMap_;
 };
 
diff --git a/daemon/src/history/historymanager.cpp b/daemon/src/history/historymanager.cpp
index 03c3146908..46966cc504 100644
--- a/daemon/src/history/historymanager.cpp
+++ b/daemon/src/history/historymanager.cpp
@@ -171,9 +171,8 @@ int HistoryManager::setHistorySerialized(const std::vector<std::map<std::string,
     int items_added = 0;
     for (vector<map<string, string> >::const_iterator iter = history.begin(); iter != history.end(); ++iter) {
         HistoryItem new_item(*iter);
-        int item_timestamp = atol(new_item.getTimestampStart().c_str());
 
-        if (item_timestamp >= ((int) current_timestamp - history_limit)) {
+        if (new_item.hasPeerNumber() and new_item.youngerThan((int) current_timestamp - history_limit)) {
             addNewHistoryEntry(new_item);
             ++items_added;
         }
diff --git a/gnome/src/contacts/calllist.c b/gnome/src/contacts/calllist.c
index 4f0dfd0e9e..4cc64dbf38 100644
--- a/gnome/src/contacts/calllist.c
+++ b/gnome/src/contacts/calllist.c
@@ -29,6 +29,7 @@
  */
 
 #include "calllist.h"
+#include <string.h>
 #include "calltab.h"
 #include "calltree.h"
 #include "unused.h"
@@ -159,7 +160,7 @@ calllist_remove_call(calltab_t* tab, const gchar * callID)
     if (c == NULL)
         return;
 
-    QueueElement *element = (QueueElement *)c->data;
+    QueueElement *element = (QueueElement *) c->data;
 
     if (element->type != HIST_CALL) {
         ERROR("CallList: Error: Element %s is not a call", callID);
@@ -168,8 +169,11 @@ calllist_remove_call(calltab_t* tab, const gchar * callID)
 
     g_queue_remove(tab->callQueue, element);
 
-    calllist_add_call(history_tab, element->elem.call);
-    calltree_add_history_entry(element->elem.call);
+    /* Don't save empty (i.e. started dialing, then deleted) calls */
+    if (element->elem.call->_peer_number && strlen(element->elem.call->_peer_number) > 0) {
+        calllist_add_call(history_tab, element->elem.call);
+        calltree_add_history_entry(element->elem.call);
+    }
 }
 
 
-- 
GitLab