[telepathy-gabble/telepathy-gabble-0.8] presence-cache.c: move code in the new function self_avatar_resolve_conflict() to avoid quadrubly-nested "if" blocks

Alban Crequy alban.crequy at collabora.co.uk
Thu Oct 1 07:36:29 PDT 2009


---
 src/presence-cache.c |   60 +++++++++++++++++++++++++++++--------------------
 1 files changed, 35 insertions(+), 25 deletions(-)

diff --git a/src/presence-cache.c b/src/presence-cache.c
index e419379..ea93350 100644
--- a/src/presence-cache.c
+++ b/src/presence-cache.c
@@ -657,6 +657,40 @@ self_vcard_request_cb (GabbleVCardManager *self,
 }
 
 static void
+self_avatar_resolve_conflict (GabblePresenceCache *cache)
+{
+  GabblePresenceCachePrivate *priv = GABBLE_PRESENCE_CACHE_PRIV (cache);
+  TpBaseConnection *base_conn = (TpBaseConnection *) priv->conn;
+  GabblePresence *presence = priv->conn->self_presence;
+
+  /* We don't want recursive image resetting */
+  if (!priv->avatar_reset_pending)
+    {
+      /* according to XEP-0153 section 4.3-2. 3rd bullet:
+       * if we receive a photo from another resource, then we MUST
+       * immediately send a presence update with an empty update child
+       * element (no photo node), then re-download our own vCard;
+       * when that arrives, we may start setting the photo node in our
+       * presence again.
+       */
+      GError *error = NULL;
+      priv->avatar_reset_pending = TRUE;
+      presence->avatar_sha1 = NULL;
+      if (!_gabble_connection_signal_own_presence (priv->conn, &error))
+        {
+          DEBUG ("failed to send own presence: %s", error->message);
+          g_error_free (error);
+        }
+
+      gabble_vcard_manager_invalidate_cache (priv->conn->vcard_manager,
+          base_conn->self_handle);
+      gabble_vcard_manager_request (priv->conn->vcard_manager,
+          base_conn->self_handle, 0, self_vcard_request_cb, cache,
+          NULL);
+    }
+}
+
+static void
 _grab_avatar_sha1 (GabblePresenceCache *cache,
                    TpHandle handle,
                    const gchar *from,
@@ -712,31 +746,7 @@ _grab_avatar_sha1 (GabblePresenceCache *cache,
       g_free (presence->avatar_sha1);
       if (handle == base_conn->self_handle)
         {
-          /* We don't want recursive image resetting */
-          if (!priv->avatar_reset_pending)
-            {
-              /* according to XEP-0153 section 4.3-2. 3rd bullet:
-               * if we receive a photo from another resource, then we MUST
-               * immediately send a presence update with an empty update child
-               * element (no photo node), then re-download our own vCard;
-               * when that arrives, we may start setting the photo node in our
-               * presence again.
-               */
-              GError *error = NULL;
-              priv->avatar_reset_pending = TRUE;
-              presence->avatar_sha1 = NULL;
-              if (!_gabble_connection_signal_own_presence (priv->conn, &error))
-                {
-                  DEBUG ("failed to send own presence: %s", error->message);
-                  g_error_free (error);
-                }
-
-              gabble_vcard_manager_invalidate_cache (priv->conn->vcard_manager,
-                  base_conn->self_handle);
-              gabble_vcard_manager_request (priv->conn->vcard_manager,
-                  base_conn->self_handle, 0, self_vcard_request_cb, cache,
-                  NULL);
-            }
+          self_avatar_resolve_conflict(cache);
         }
       else
         {
-- 
1.5.6.5




More information about the telepathy-commits mailing list