[Telepathy-commits] [telepathy-gabble/master] Pass invitations into MUC channels as a construct-time property instead of calling a function afterwards

Simon McVittie simon.mcvittie at collabora.co.uk
Tue Aug 19 10:53:46 PDT 2008


20080721175846-53eee-1d4713876b7bdb30f981e11b774f0df262339c59.gz
---
 src/muc-channel.c |   48 ++++++++++++++++++++++++++++++++++++++++++++----
 src/muc-channel.h |    2 --
 src/muc-factory.c |   20 ++++++++++++++++----
 3 files changed, 60 insertions(+), 10 deletions(-)

diff --git a/src/muc-channel.c b/src/muc-channel.c
index 2eaac26..884968c 100644
--- a/src/muc-channel.c
+++ b/src/muc-channel.c
@@ -106,6 +106,7 @@ enum
   PROP_CONNECTION,
   PROP_STATE,
   PROP_INVITE_SELF,
+  PROP_INVITATION_MESSAGE,
   PROP_INTERFACES,
   PROP_INITIATOR_HANDLE,
   PROP_INITIATOR_ID,
@@ -242,6 +243,7 @@ struct _GabbleMucChannelPrivate
   gboolean dispose_has_run;
 
   gboolean invite_self;
+  gchar *invitation_message;
 
   /* Aggregate all presences when joining the chatroom */
   InitialStateAggregator *initial_state_aggregator;
@@ -272,14 +274,20 @@ gabble_muc_channel_init (GabbleMucChannel *obj)
       g_direct_equal);
 }
 
+
 static void contact_handle_to_room_identity (GabbleMucChannel *, TpHandle,
     TpHandle *, GString **);
 
+static void _gabble_muc_channel_handle_invited (GabbleMucChannel *chan,
+    TpHandle inviter, const gchar *message);
+
+
 static GObject *
 gabble_muc_channel_constructor (GType type, guint n_props,
                                 GObjectConstructParam *props)
 {
   GObject *obj;
+  GabbleMucChannel *self;
   GabbleMucChannelPrivate *priv;
   TpBaseConnection *conn;
   DBusGConnection *bus;
@@ -288,8 +296,9 @@ gabble_muc_channel_constructor (GType type, guint n_props,
 
   obj = G_OBJECT_CLASS (gabble_muc_channel_parent_class)->
            constructor (type, n_props, props);
+  self = GABBLE_MUC_CHANNEL (obj);
 
-  priv = GABBLE_MUC_CHANNEL_GET_PRIVATE (obj);
+  priv = GABBLE_MUC_CHANNEL_GET_PRIVATE (self);
   conn = (TpBaseConnection *) priv->conn;
 
   room_handles = tp_base_connection_get_handles (conn, TP_HANDLE_TYPE_ROOM);
@@ -302,8 +311,8 @@ gabble_muc_channel_constructor (GType type, guint n_props,
   /* get the room's jid */
   priv->jid = tp_handle_inspect (room_handles, priv->handle);
 
-  if (priv->initiator != 0)
-    tp_handle_ref (contact_handles, priv->initiator);
+  g_assert (priv->initiator != 0);
+  tp_handle_ref (contact_handles, priv->initiator);
 
   /* get our own identity in the room */
   contact_handle_to_room_identity (GABBLE_MUC_CHANNEL (obj),
@@ -355,6 +364,10 @@ gabble_muc_channel_constructor (GType type, guint n_props,
     {
       GError *error = NULL;
       GArray *members = g_array_sized_new (FALSE, FALSE, sizeof (TpHandle), 1);
+
+      g_assert (priv->initiator == conn->self_handle);
+      g_assert (priv->invitation_message == NULL);
+
       g_array_append_val (members, self_handle);
       tp_group_mixin_add_handle_owner (obj, self_handle, conn->self_handle);
       tp_group_mixin_add_members (obj, members,
@@ -362,6 +375,19 @@ gabble_muc_channel_constructor (GType type, guint n_props,
       g_assert (error == NULL);
       g_array_free (members, TRUE);
     }
+  else
+    {
+      g_assert (priv->initiator != 0);
+      g_assert (priv->invitation_message != NULL);
+
+      _gabble_muc_channel_handle_invited (self, priv->initiator,
+          priv->invitation_message);
+
+      /* we've dealt with it (and copied it elsewhere), so there's no point
+       * in keeping it */
+      g_free (priv->invitation_message);
+      priv->invitation_message = NULL;
+    }
 
   tp_handle_unref (contact_handles, self_handle);
 
@@ -844,6 +870,10 @@ gabble_muc_channel_set_property (GObject     *object,
     case PROP_INITIATOR_HANDLE:
       priv->initiator = g_value_get_uint (value);
       break;
+    case PROP_INVITATION_MESSAGE:
+      g_assert (priv->invitation_message == NULL);
+      priv->invitation_message = g_value_dup_string (value);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -966,6 +996,16 @@ gabble_muc_channel_class_init (GabbleMucChannelClass *gabble_muc_channel_class)
   g_object_class_install_property (object_class, PROP_INITIATOR_ID,
       param_spec);
 
+  param_spec = g_param_spec_string ("invitation-message",
+      "Invitation message",
+      "The message we were sent when invited; NULL if not invited or if "
+      "already processed",
+      NULL,
+      G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
+      G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME);
+  g_object_class_install_property (object_class, PROP_INVITATION_MESSAGE,
+      param_spec);
+
   signals[READY] =
     g_signal_new ("ready",
                   G_OBJECT_CLASS_TYPE (gabble_muc_channel_class),
@@ -2179,7 +2219,7 @@ _gabble_muc_channel_receive (GabbleMucChannel *chan,
       timestamp, text);
 }
 
-void
+static void
 _gabble_muc_channel_handle_invited (GabbleMucChannel *chan,
                                     TpHandle inviter,
                                     const gchar *message)
diff --git a/src/muc-channel.h b/src/muc-channel.h
index 9b71760..e05c390 100644
--- a/src/muc-channel.h
+++ b/src/muc-channel.h
@@ -94,8 +94,6 @@ void _gabble_muc_channel_receive (GabbleMucChannel *chan,
     TpChannelTextMessageType msg_type, TpHandleType handle_type,
     TpHandle sender, time_t timestamp, const gchar *text, LmMessage *msg);
 
-void _gabble_muc_channel_handle_invited (GabbleMucChannel *chan,
-    TpHandle inviter, const gchar *message);
 void _gabble_muc_channel_state_receive (GabbleMucChannel *chan,
     guint state, guint from_handle);
 
diff --git a/src/muc-factory.c b/src/muc-factory.c
index 0258044..7791c33 100644
--- a/src/muc-factory.c
+++ b/src/muc-factory.c
@@ -363,6 +363,7 @@ new_muc_channel (GabbleMucFactory *fac,
        "handle", handle,
        "invite-self", invite_self,
        "initiator-handle", inviter,
+       "invitation-message", message,
        NULL);
 
   g_signal_connect (chan, "closed", (GCallback) muc_channel_closed_cb, fac);
@@ -371,13 +372,24 @@ new_muc_channel (GabbleMucFactory *fac,
 
   g_free (object_path);
 
-  g_signal_connect (chan, "ready", G_CALLBACK (muc_ready_cb), fac);
+  if (invite_self)
+    {
+      g_assert (!_gabble_muc_channel_is_ready (chan));
+
+      g_signal_connect (chan, "ready", G_CALLBACK (muc_ready_cb), fac);
+    }
+  else
+    {
+      /* if we've been invited by someone else, then it's considered to be
+       * ready immediately - but we're too late to get the signal since
+       * g_object_new emitted it */
+      g_assert (_gabble_muc_channel_is_ready (chan));
+      muc_ready_cb (chan, fac);
+    }
+
   g_signal_connect (chan, "join-error", G_CALLBACK (muc_join_error_cb),
                     fac);
 
-  if (!invite_self)
-    _gabble_muc_channel_handle_invited (chan, inviter, message);
-
   return chan;
 }
 
-- 
1.5.6.3




More information about the Telepathy-commits mailing list