[folks] telepathy: Move Zeitgeist code entirely into Tpf.PersonaStore



commit 6afd8a4f4d2a8f799aee98ba72d3b5e4ea4d3bb4
Author: Philip Withnall <philip tecnocode co uk>
Date:   Fri Jul 5 11:09:51 2013 +0100

    telepathy: Move Zeitgeist code entirely into Tpf.PersonaStore
    
    Ready to split it out into a shim library.
    
    Helps: https://bugzilla.gnome.org/show_bug.cgi?id=701099

 backends/telepathy/lib/tpf-persona-store.vala |   20 +++++++-
 backends/telepathy/lib/tpf-persona.vala       |   66 +++++++++++--------------
 2 files changed, 48 insertions(+), 38 deletions(-)
---
diff --git a/backends/telepathy/lib/tpf-persona-store.vala b/backends/telepathy/lib/tpf-persona-store.vala
index 59ba3a7..f08ad89 100644
--- a/backends/telepathy/lib/tpf-persona-store.vala
+++ b/backends/telepathy/lib/tpf-persona-store.vala
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2010 Collabora Ltd.
+ * Copyright (C) 2013 Philip Withnall
  *
  * This library is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -1735,7 +1736,24 @@ public class Tpf.PersonaStore : Folks.PersonaStore
       if (id != null && this._personas.has_key (id) && interaction_type != null)
         {
           var persona = this._personas.get (id);
-          persona._increase_counter (id, interaction_type, event);
+          var timestamp = (uint) (event.timestamp / 1000);
+          var converted_datetime = new DateTime.from_unix_utc (timestamp);
+          var interpretation = event.interpretation;
+
+          /* Only count send/receive for IM interactions */
+          if (interaction_type == Zeitgeist.NMO.IMMESSAGE &&
+              (interpretation == Zeitgeist.ZG.SEND_EVENT ||
+               interpretation == Zeitgeist.ZG.RECEIVE_EVENT))
+            {
+              persona._increase_im_interaction_counter (id, converted_datetime);
+            }
+          /* Only count successful call for call interactions */
+          else if (interaction_type == Zeitgeist.NFO.AUDIO &&
+                    interpretation == Zeitgeist.ZG.LEAVE_EVENT)
+            {
+              persona._increase_last_call_interaction_counter (id,
+                  converted_datetime);
+            }
         }
     }
 
diff --git a/backends/telepathy/lib/tpf-persona.vala b/backends/telepathy/lib/tpf-persona.vala
index b891436..249aa89 100644
--- a/backends/telepathy/lib/tpf-persona.vala
+++ b/backends/telepathy/lib/tpf-persona.vala
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2010 Collabora Ltd.
+ * Copyright (C) 2013 Philip Withnall
  *
  * This library is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -16,15 +17,13 @@
  *
  * Authors:
  *       Travis Reitter <travis reitter collabora co uk>
+ *       Philip Withnall <philip tecnocode co uk>
  */
 
 using Gee;
 using GLib;
 using TelepathyGLib;
 using Folks;
-#if HAVE_ZEITGEIST
-using Zeitgeist;
-#endif
 
 /**
  * A persona subclass which represents a single instant messaging contact from
@@ -1399,44 +1398,38 @@ public class Tpf.Persona : Folks.Persona,
       return store._ensure_persona_for_contact (contact);
     }
 
-#if HAVE_ZEITGEIST
-  internal void _increase_counter (string id, string interaction_type, Event event)
+  internal void _increase_im_interaction_counter (string id,
+      DateTime converted_datetime)
     {
-      var timestamp = (uint) (event.timestamp / 1000);
-      var converted_datetime = new DateTime.from_unix_utc (timestamp);
-      var interpretation = event.interpretation;
-
-      /* Only count send/receive for IM interactions */
-      if (interaction_type == Zeitgeist.NMO.IMMESSAGE &&
-          (interpretation == Zeitgeist.ZG.SEND_EVENT ||
-           interpretation == Zeitgeist.ZG.RECEIVE_EVENT))
+      this._im_interaction_count++;
+      this.notify_property ("im-interaction-count");
+      if (this._last_im_interaction_datetime == null ||
+          this._last_im_interaction_datetime.compare (converted_datetime) == -1)
         {
-          this._im_interaction_count++;
-          this.notify_property ("im-interaction-count");
-          if (this._last_im_interaction_datetime == null ||
-              this._last_im_interaction_datetime.compare (converted_datetime) == -1)
-            {
-              this._last_im_interaction_datetime = converted_datetime;
-              this.notify_property ("last-im-interaction-datetime");
-            }
-          debug ("Persona %s IM interaction details changed:\n - count: %u \n - timestamp: %lld\n",
-              id, this._im_interaction_count, this._last_im_interaction_datetime.format ("%H %M %S - %d %m 
%y"));
+          this._last_im_interaction_datetime = converted_datetime;
+          this.notify_property ("last-im-interaction-datetime");
         }
-      /* Only count successful call for call interactions */
-      else if (interaction_type == Zeitgeist.NFO.AUDIO &&
-                interpretation == Zeitgeist.ZG.LEAVE_EVENT)
+      debug ("Persona %s IM interaction details changed:\n" +
+          " - count: %u \n - timestamp: %lld",
+          id, this._im_interaction_count,
+          this._last_im_interaction_datetime.format ("%H %M %S - %d %m %y"));
+    }
+
+  internal void _increase_last_call_interaction_counter (string id,
+      DateTime converted_datetime)
+    {
+      this._call_interaction_count++;
+      this.notify_property ("call-interaction-count");
+      if (this._last_call_interaction_datetime == null ||
+          this._last_call_interaction_datetime.compare (converted_datetime) == -1)
         {
-          this._call_interaction_count++;
-          this.notify_property ("call-interaction-count");
-          if (this._last_call_interaction_datetime == null ||
-              this._last_call_interaction_datetime.compare (converted_datetime) == -1)
-            {
-              this._last_call_interaction_datetime = converted_datetime;
-              this.notify_property ("last-call-interaction-datetime");
-            }
-          debug ("Persona %s Call interaction details changed:\n - count: %u \n - timestamp: %lld\n",
-             id, this._call_interaction_count, this._last_call_interaction_datetime.format ("%H %M %S - %d 
%m %y"));
+          this._last_call_interaction_datetime = converted_datetime;
+          this.notify_property ("last-call-interaction-datetime");
         }
+      debug ("Persona %s Call interaction details changed:\n" +
+          " - count: %u \n - timestamp: %lld",
+          id, this._call_interaction_count,
+          this._last_call_interaction_datetime.format ("%H %M %S - %d %m %y"));
     }
 
   internal void _reset_interaction ()
@@ -1446,5 +1439,4 @@ public class Tpf.Persona : Folks.Persona,
       this._last_call_interaction_datetime = null;
       this._last_im_interaction_datetime = null;
     }
-#endif
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]