[next] telepathy-salut: presence mixin: switch to singular API

Simon McVittie smcv at kemper.freedesktop.org
Mon Jan 13 05:10:38 PST 2014


Module: telepathy-salut
Branch: next
Commit: 60f16c664d45295a7127ce6e3d483123158ba864
URL:    http://cgit.freedesktop.org/telepathy/telepathy-salut/commit/?id=60f16c664d45295a7127ce6e3d483123158ba864

Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date:   Wed Jan  8 13:04:41 2014 +0000

presence mixin: switch to singular API

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=50093
Reviewed-by: Guillaume Desmottes <guillaume.desmottes at collabora.co.uk>

---

 src/connection.c |   57 +++++++++++++++++++++++++-----------------------------
 1 file changed, 26 insertions(+), 31 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 9152c71..59fdc67 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -571,51 +571,46 @@ make_presence_opt_args (SalutPresenceId presence, const gchar *message)
   return ret;
 }
 
-static GHashTable *
-get_contact_statuses (GObject *obj,
-                      const GArray *handles)
+static TpPresenceStatus *
+get_contact_status (GObject *obj,
+    TpHandle handle)
 {
   SalutConnection *self = SALUT_CONNECTION (obj);
   SalutConnectionPrivate *priv = self->priv;
   TpBaseConnection *base = (TpBaseConnection *) self;
   TpHandle self_handle = tp_base_connection_get_self_handle (base);
-  GHashTable *ret;
-  guint i;
-
-  ret = g_hash_table_new_full (g_direct_hash, g_direct_equal,
-      NULL, (GDestroyNotify) tp_presence_status_free);
+  TpPresenceStatus *ps;
+  SalutPresenceId presence;
+  const gchar *message = NULL;
+  GHashTable *optional_arguments;
 
-  for (i = 0; i < handles->len; i++)
+  if (handle == self_handle)
     {
-      TpHandle handle = g_array_index (handles, TpHandle, i);
-      TpPresenceStatus *ps = tp_presence_status_new
-          (SALUT_PRESENCE_OFFLINE, NULL);
-      const gchar *message = NULL;
+      presence = priv->self->status;
+      message = priv->self->status_message;
+    }
+  else
+    {
+      SalutContact *contact = salut_contact_manager_get_contact
+          (priv->contact_manager, handle);
 
-      if (handle == self_handle)
+      if (contact == NULL)
         {
-          ps->index = priv->self->status;
-          message = priv->self->status_message;
+          presence = SALUT_PRESENCE_OFFLINE;
+          message = "";
         }
       else
         {
-          SalutContact *contact = salut_contact_manager_get_contact
-              (priv->contact_manager, handle);
-
-          if (contact != NULL)
-            {
-              ps->index = contact->status;
-              message = contact->status_message;
-              g_object_unref (contact);
-            }
+          presence = contact->status;
+          message = contact->status_message;
+          g_object_unref (contact);
         }
-
-      ps->optional_arguments = make_presence_opt_args (ps->index, message);
-
-      g_hash_table_insert (ret, GUINT_TO_POINTER (handle), ps);
     }
 
-  return ret;
+  optional_arguments = make_presence_opt_args (presence, message);
+  ps = tp_presence_status_new (presence, optional_arguments);
+  g_hash_table_unref (optional_arguments);
+  return ps;
 }
 
 static void
@@ -787,7 +782,7 @@ salut_connection_class_init (SalutConnectionClass *salut_connection_class)
 
   tp_presence_mixin_class_init (object_class,
       G_STRUCT_OFFSET (SalutConnectionClass, presence_mixin),
-      is_presence_status_available, get_contact_statuses, set_own_status,
+      is_presence_status_available, get_contact_status, set_own_status,
       presence_statuses);
 
   tp_presence_mixin_init_dbus_properties (object_class);



More information about the telepathy-commits mailing list