[folks] Add new properties to Individual and Persona:



commit f08ec1f0490c601c1a576428b55fb36dd1a93e93
Author: Seif Lotfy <seif lotfy com>
Date:   Thu Apr 19 02:24:05 2012 +0200

    Add new properties to Individual and Persona:
    
    Added new im_interaction_count and last_im_interaction_timestamp to Persona and Individual
    Added new call_interaction_count and last_call_interaction_timestamp to Persona and Individual
    
    Signed-off-by: Seif Lotfy <seif lotfy collabora co uk>
    Signed-off-by: Seif Lotfy <seif lotfy com>

 folks/Makefile.am              |    1 +
 folks/individual.vala          |  162 ++++++++++++++++++++++++++++++++++++++++
 folks/interaction-details.vala |   72 ++++++++++++++++++
 folks/persona-store.vala       |   36 ++++++++-
 4 files changed, 269 insertions(+), 2 deletions(-)
---
diff --git a/folks/Makefile.am b/folks/Makefile.am
index a9262a2..336efd9 100644
--- a/folks/Makefile.am
+++ b/folks/Makefile.am
@@ -66,6 +66,7 @@ libfolks_la_SOURCES = \
 	group-details.vala \
 	web-service-details.vala \
 	im-details.vala \
+	interaction-details.vala \
 	local-id-details.vala \
 	name-details.vala \
 	note-details.vala \
diff --git a/folks/individual.vala b/folks/individual.vala
index 2f9050d..e163836 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -89,6 +89,7 @@ public class Folks.Individual : Object,
     GenderDetails,
     GroupDetails,
     ImDetails,
+    InteractionDetails,
     LocalIdDetails,
     NameDetails,
     NoteDetails,
@@ -776,6 +777,110 @@ public class Folks.Individual : Object,
     }
 
   /**
+   * { inheritDoc}
+   */
+  public uint im_interaction_count
+    {
+      get
+        {
+          uint counter = 0;
+          /* Iterate over all personas and sum up their IM interaction counts*/
+          foreach (var persona in this._persona_set)
+            {
+              var my_interaction_details = persona as InteractionDetails;
+              if (my_interaction_details != null)
+                {
+                  counter = counter + my_interaction_details.im_interaction_count;
+                }
+            }
+          return counter;
+        }
+    }
+
+  /**
+   * { inheritDoc}
+   */
+  private DateTime? _last_im_interaction_datetime = null;
+
+  public DateTime? last_im_interaction_datetime
+    {
+      get 
+        {
+          if (this._last_im_interaction_datetime == null)
+            {
+              /* Iterate over all personas and get the latest IM interaction datetime */
+              foreach (var persona in this._persona_set)
+                {
+                  var my_interaction_details = persona as InteractionDetails;
+                  if (my_interaction_details != null &&
+                      my_interaction_details.last_im_interaction_datetime != null)
+                    {
+                      DateTime interaction_datetime = my_interaction_details.last_im_interaction_datetime;
+                      if (this._last_im_interaction_datetime == null ||
+                          interaction_datetime.compare (this._last_im_interaction_datetime) == 1)
+                        {
+                          this._last_im_interaction_datetime = my_interaction_details.last_im_interaction_datetime;
+                        }
+                    }
+                }
+            }
+          return this._last_im_interaction_datetime;
+        }
+    }
+
+  /**
+   * { inheritDoc}
+   */
+  public uint call_interaction_count
+    {
+      get 
+        {
+          uint counter = 0;
+          /* Iterate over all personas and sum up their call interaction counts*/
+          foreach (var persona in this._persona_set)
+            {
+              var my_interaction_details = persona as InteractionDetails;
+              if (my_interaction_details != null)
+                {
+                  counter = counter + my_interaction_details.call_interaction_count;
+                }
+            }
+          return counter;
+        }
+    }
+
+  /**
+   * { inheritDoc}
+   */
+  private DateTime? _last_call_interaction_datetime = null;
+
+  public DateTime? last_call_interaction_datetime
+    {
+      get
+        {
+          if (this._last_call_interaction_datetime == null)
+            {
+              /* Iterate over all personas and get the latest IM interaction datetime */
+              foreach (var persona in this._persona_set)
+                {
+                  var my_interaction_details = persona as InteractionDetails;
+                  if (my_interaction_details != null &&
+                      my_interaction_details.last_call_interaction_datetime != null)
+                    {
+                      var interaction_datetime = my_interaction_details.last_call_interaction_datetime;
+                      if (this._last_call_interaction_datetime == null ||
+                          interaction_datetime.compare (this._last_call_interaction_datetime) > 1)
+                        {
+                          this._last_call_interaction_datetime = my_interaction_details.last_call_interaction_datetime;
+                        }
+                    }
+                }
+            }
+          return this._last_call_interaction_datetime;
+        }
+    }
+
+  /**
    * The set of { link Persona}s encapsulated by this Individual.
    *
    * No order is specified over the set of personas, as such an order may be
@@ -932,6 +1037,44 @@ public class Folks.Individual : Object,
       this._update_is_favourite ();
     }
 
+  private void _notify_im_interaction_count_cb (Object obj, ParamSpec ps)
+    {
+      /**
+       * The property is pull rather than push. This function is called in
+       * response to personas emitting a similar notification.
+       */
+      this.notify_property ("im-interaction-count");
+    }
+
+  private void _notify_call_interaction_count_cb (Object obj, ParamSpec ps)
+    {
+      /**
+       * The property is pull rather than push. This function is called in
+       * response to personas emitting a similar notification.
+       */
+      this.notify_property ("call-interaction-count");
+    }
+
+  private void _notify_last_im_interaction_datetime_cb (Object obj, ParamSpec ps)
+    {
+      /**
+       * The property is pull rather than push. This function is called in
+       * response to personas emitting a similar notification.
+       */
+      this._last_im_interaction_datetime = null;
+      this.notify_property ("last-im-interaction-datetime");
+    }
+
+  private void _notify_last_call_interaction_datetime_cb (Object obj, ParamSpec ps)
+    {
+      /**
+       * The property is pull rather than push. This function is called in
+       * response to personas emitting a similar notification.
+       */
+      this._last_call_interaction_datetime = null;
+      this.notify_property ("last-call-interaction-datetime");
+    }
+
   /**
    * Create a new Individual.
    *
@@ -1476,6 +1619,15 @@ public class Folks.Individual : Object,
           ((GroupDetails) persona).group_changed.connect (
               this._persona_group_changed_cb);
         }
+      /* Subscribe to the interactions signal for the persona */
+      var p_interaction_details = persona as InteractionDetails;
+      if (p_interaction_details != null) 
+        {
+          persona.notify["im-interaction-count"].connect (this._notify_im_interaction_count_cb);
+          persona.notify["call-interaction-count"].connect (this._notify_call_interaction_count_cb);
+          persona.notify["last-im-interaction-datetime"].connect (this._notify_last_im_interaction_datetime_cb);
+          persona.notify["last-call-interaction-datetime"].connect (this._notify_last_call_interaction_datetime_cb);
+        }
     }
 
   private void _update_structured_name ()
@@ -1608,6 +1760,16 @@ public class Folks.Individual : Object,
               this._persona_group_changed_cb);
         }
 
+      /* Unsubscribe from the interactions signal for the persona */
+      var p_interaction_details = persona as InteractionDetails;
+      if (p_interaction_details != null) 
+        {
+          persona.notify["im-interaction-count"].disconnect (this._notify_im_interaction_count_cb);
+          persona.notify["call-interaction-count"].disconnect (this._notify_call_interaction_count_cb);
+          persona.notify["last-im-interaction-datetime"].disconnect (this._notify_last_im_interaction_datetime_cb);
+          persona.notify["last-call-interaction-datetime"].disconnect (this._notify_last_call_interaction_datetime_cb);
+        }
+
       /* Don't update the individual if the persona's been added to the new one
        * already (and thus the new individual has already changed
        * persona.individual).
diff --git a/folks/interaction-details.vala b/folks/interaction-details.vala
new file mode 100644
index 0000000..0bf710a
--- /dev/null
+++ b/folks/interaction-details.vala
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2012 Collabora Ltd.
+ *
+ * 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
+ * the Free Software Foundation, either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *       Seif Lotfy <seif lotfy collabora co uk>
+ */
+
+using GLib;
+
+/**
+ * Object representing interaction details for an Individual or Persona.
+ * Interaction details are the number of call or IM interactions with the a
+ * a { link Persona} or an { link Individual} as well as the the datetime of
+ * the last call and im interaction.
+ *
+ * @since UNRELEASED
+ */
+public interface Folks.InteractionDetails : Object
+{
+  /**
+   * The IM interaction associated with a Persona
+   *
+   * @since UNRELEASED
+   */
+  public abstract uint im_interaction_count
+    {
+      get;
+    }
+
+  /**
+   * The latest IM interaction timestamp associated with a Persona
+   *
+   * @since UNRELEASED
+   */
+  public abstract DateTime? last_im_interaction_datetime
+    {
+      get;
+    }
+
+  /**
+   * The call interaction associated with a Persona
+   *
+   * @since UNRELEASED
+   */
+  public abstract uint call_interaction_count
+    {
+      get;
+    }
+
+  /**
+   * The latest call interaction timestamp associated with a Persona
+   *
+   * @since UNRELEASED
+   */
+  public abstract DateTime? last_call_interaction_datetime
+    {
+      get;
+    }
+}
diff --git a/folks/persona-store.vala b/folks/persona-store.vala
index b5758d6..5609cd8 100644
--- a/folks/persona-store.vala
+++ b/folks/persona-store.vala
@@ -266,7 +266,35 @@ public enum Folks.PersonaDetail
    *
    * @since 0.6.2
    */
-  GROUPS
+  GROUPS,
+
+  /**
+   * Field for { link InteractionDetails.im_interaction_count}.
+   *
+   * @since UNRELEASED
+   */
+  IM_INTERACTION_COUNT,
+
+  /**
+   * Field for { link InteractionDetails.last_im_interaction_datetime}.
+   *
+   * @since UNRELEASED
+   */
+  LAST_IM_INTERACTION_DATETIME,
+
+  /**
+   * Field for { link InteractionDetails.call_interaction_count}.
+   *
+   * @since UNRELEASED
+   */
+  CALL_INTERACTION_COUNT,
+
+  /**
+   * Field for { link InteractionDetails.last_call_interaction_datetime}.
+   *
+   * @since UNRELEASED
+   */
+  LAST_CALL_INTERACTION_DATETIME
 }
 
 /**
@@ -321,7 +349,11 @@ public abstract class Folks.PersonaStore : Object
     "structured-name",
     "urls",
     "web-service-addresses",
-    "groups"
+    "groups",
+    "im-interaction-count",
+    "last-im-interaction-datetime",
+    "call-interaction-count",
+    "last-call-interaction-datetime"
   };
 
   /**



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