[telepathy-gabble/master] Support leaving MUCs with RemoveMembers.

Will Thompson will.thompson at collabora.co.uk
Tue Jun 2 08:19:39 PDT 2009


This allows you to leave a MUC with a part message. Fixes: fd.o#16886.
---
 src/muc-channel.c             |   15 +++++++++++++--
 tests/twisted/muc/test-muc.py |    7 +++++--
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/muc-channel.c b/src/muc-channel.c
index 4272485..6e1fad9 100644
--- a/src/muc-channel.c
+++ b/src/muc-channel.c
@@ -1143,6 +1143,7 @@ gabble_muc_channel_class_init (GabbleMucChannelClass *gabble_muc_channel_class)
       gabble_muc_channel_add_member,
       gabble_muc_channel_remove_member);
   tp_group_mixin_init_dbus_properties (object_class);
+  tp_group_mixin_class_allow_self_removal (object_class);
 }
 
 static void clear_join_timer (GabbleMucChannel *chan);
@@ -2818,14 +2819,24 @@ gabble_muc_channel_remove_member (GObject *obj,
                                   const gchar *message,
                                   GError **error)
 {
-  GabbleMucChannelPrivate *priv;
+  GabbleMucChannel *chan = GABBLE_MUC_CHANNEL (obj);
+  GabbleMucChannelPrivate *priv = GABBLE_MUC_CHANNEL_GET_PRIVATE (chan);
+  TpGroupMixin *group = TP_GROUP_MIXIN (chan);
   LmMessage *msg;
   LmMessageNode *query_node, *item_node;
   const gchar *jid, *nick;
   gboolean result;
 
-  priv = GABBLE_MUC_CHANNEL_GET_PRIVATE (GABBLE_MUC_CHANNEL (obj));
+  if (handle == group->self_handle)
+    {
+      /* User wants to leave the MUC */
+
+      close_channel (chan, message, TRUE, group->self_handle,
+          TP_CHANNEL_GROUP_CHANGE_REASON_NONE);
+      return TRUE;
+    }
 
+  /* Otherwise, the user wants to kick someone. */
   msg = lm_message_new_with_sub_type (priv->jid, LM_MESSAGE_TYPE_IQ,
                                       LM_MESSAGE_SUB_TYPE_SET);
 
diff --git a/tests/twisted/muc/test-muc.py b/tests/twisted/muc/test-muc.py
index 7ae80e2..8d30857 100644
--- a/tests/twisted/muc/test-muc.py
+++ b/tests/twisted/muc/test-muc.py
@@ -8,7 +8,7 @@ import dbus
 from twisted.words.xish import domish
 
 from gabbletest import exec_test
-from servicetest import EventPattern
+from servicetest import EventPattern, assertEquals, assertLength
 import constants as cs
 
 from mucutil import join_muc_and_check
@@ -248,11 +248,14 @@ def test(q, bus, conn, stream):
     assert status.children[0] == u'hurrah'
 
     # test that leaving the channel results in an unavailable message
-    chan.Close()
+    chan.Group.RemoveMembers([chan.Group.GetSelfHandle()], 'booo')
 
     event = q.expect('stream-presence', to='chat at conf.localhost/test')
     elem = event.stanza
     assert elem['type'] == 'unavailable'
+    status = [e for e in elem.elements() if e.name == 'status']
+    assertLength(1, status)
+    assertEquals(status[0].children[0], u'booo')
 
     conn.Disconnect()
 
-- 
1.5.6.5



More information about the telepathy-commits mailing list