[telepathy-gabble/master] support setting presence before going online

Dafydd Harries dafydd.harries at collabora.co.uk
Wed Sep 2 12:21:14 PDT 2009


---
 src/conn-presence.c |   20 ++++++++++++++------
 src/connection.c    |   30 +++++++++++++++++++++++-------
 2 files changed, 37 insertions(+), 13 deletions(-)

diff --git a/src/conn-presence.c b/src/conn-presence.c
index 35ad86a..bc2b315 100644
--- a/src/conn-presence.c
+++ b/src/conn-presence.c
@@ -249,12 +249,18 @@ set_own_status_cb (GObject *obj,
   if (gabble_presence_update (conn->self_presence, resource, i,
         message_str, prio))
     {
-      emit_one_presence_update (conn, base->self_handle);
-      retval = _gabble_connection_signal_own_presence (conn, error);
+      if (base->status == TP_CONNECTION_STATUS_CONNECTED)
+        {
+          emit_one_presence_update (conn, base->self_handle);
+          retval = _gabble_connection_signal_own_presence (conn, error);
+        }
+      else
+        {
+          retval = TRUE;
+        }
     }
 
 OUT:
-
   g_free (resource);
 
   return retval;
@@ -293,10 +299,12 @@ status_available_cb (GObject *obj, guint status)
   GabbleConnection *conn = GABBLE_CONNECTION (obj);
   TpBaseConnection *base = (TpBaseConnection *) conn;
 
-  if (base->status != TP_CONNECTION_STATUS_CONNECTED)
-    return FALSE;
+  /* If we've gone online and found that the server doesn't support invisible,
+   * reject it.
+   */
 
-  if (gabble_statuses[status].presence_type == TP_CONNECTION_PRESENCE_TYPE_HIDDEN &&
+  if (base->status == TP_CONNECTION_STATUS_CONNECTED &&
+      gabble_statuses[status].presence_type == TP_CONNECTION_PRESENCE_TYPE_HIDDEN &&
       (conn->features & GABBLE_CONNECTION_FEATURES_PRESENCE_INVISIBLE) == 0)
     return FALSE;
   else
diff --git a/src/connection.c b/src/connection.c
index 43e62e8..d421af6 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -336,6 +336,12 @@ gabble_connection_constructed (GObject *object)
           g_random_int ());
       DEBUG ("defaulted resource to %s", priv->resource);
     }
+
+  /* set initial presence */
+  self->self_presence = gabble_presence_new ();
+  g_assert (priv->resource);
+  gabble_presence_update (self->self_presence, priv->resource,
+      GABBLE_PRESENCE_AVAILABLE, NULL, priv->priority);
 }
 
 static void
@@ -480,8 +486,23 @@ gabble_connection_set_property (GObject      *object,
       priv->password = g_value_dup_string (value);
       break;
     case PROP_RESOURCE:
-      g_free (priv->resource);
-      priv->resource = g_value_dup_string (value);
+      if (tp_strdiff (priv->resource, g_value_get_string (value)))
+        {
+          gchar *old_resource = g_strdup (priv->resource);
+          gchar *new_resource = g_value_dup_string (value);
+
+          priv->resource = new_resource;
+
+          /* Add self presence for new resource... */
+          gabble_presence_update (self->self_presence, new_resource,
+              self->self_presence->status, self->self_presence->status_message,
+              priv->priority);
+          /* ...and remove it for the old one. */
+          gabble_presence_update (self->self_presence, old_resource,
+              GABBLE_PRESENCE_OFFLINE, NULL, 0);
+
+          g_free (old_resource);
+        }
       break;
     case PROP_PRIORITY:
       priv->priority = g_value_get_char (value);
@@ -2121,11 +2142,6 @@ connection_auth_cb (LmConnection *lmconn,
 
   DEBUG ("Created self handle %d, our JID is %s", base->self_handle, jid);
 
-  /* set initial presence */
-  conn->self_presence = gabble_presence_new ();
-  gabble_presence_update (conn->self_presence, priv->resource,
-      GABBLE_PRESENCE_AVAILABLE, NULL, priv->priority);
-
   /* set initial capabilities */
   gabble_presence_set_capabilities (conn->self_presence, priv->resource,
       capabilities_get_initial_caps (), NULL, priv->caps_serial++);
-- 
1.5.6.5




More information about the telepathy-commits mailing list