]> git.0d.be Git - empathy.git/blob - libempathy/empathy-tp-group.c
Completely reworked ContactList API. Fixes bug #471611, bug #467280, bug #459540...
[empathy.git] / libempathy / empathy-tp-group.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2006 Xavier Claessens <xclaesse@gmail.com>
4  * Copyright (C) 2007 Collabora Ltd.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of the
9  * License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public
17  * License along with this program; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21  * Authors: Xavier Claessens <xclaesse@gmail.com>
22  */
23
24 #include <config.h>
25
26 #include <dbus/dbus-glib.h>
27 #include <libtelepathy/tp-chan.h>
28 #include <libtelepathy/tp-chan-gen.h>
29 #include <libtelepathy/tp-chan-iface-group-gen.h>
30 #include <libtelepathy/tp-constants.h>
31 #include <libtelepathy/tp-conn.h>
32
33 #include "empathy-tp-group.h"
34 #include "empathy-contact-factory.h"
35 #include "empathy-debug.h"
36 #include "empathy-utils.h"
37 #include "empathy-marshal.h"
38
39 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
40                        EMPATHY_TYPE_TP_GROUP, EmpathyTpGroupPriv))
41
42 #define DEBUG_DOMAIN "TpGroup"
43
44 struct _EmpathyTpGroupPriv {
45         EmpathyContactFactory *factory;
46         McAccount             *account;
47         DBusGProxy            *group_iface;
48         TpChan                *tp_chan;
49         gchar                 *group_name;
50         guint                  self_handle;
51
52         GList                 *members;
53         GList                 *local_pendings;
54         GList                 *remote_pendings;
55 };
56
57 static void empathy_tp_group_class_init (EmpathyTpGroupClass *klass);
58 static void empathy_tp_group_init       (EmpathyTpGroup      *group);
59
60 enum {
61         MEMBER_ADDED,
62         MEMBER_REMOVED,
63         LOCAL_PENDING,
64         REMOTE_PENDING,
65         DESTROY,
66         LAST_SIGNAL
67 };
68
69 static guint signals[LAST_SIGNAL];
70
71 G_DEFINE_TYPE (EmpathyTpGroup, empathy_tp_group, G_TYPE_OBJECT);
72
73 static EmpathyContact *
74 tp_group_get_contact (EmpathyTpGroup *group,
75                       guint           handle)
76 {
77         EmpathyTpGroupPriv *priv = GET_PRIV (group);
78         EmpathyContact     *contact = NULL;
79         
80         if (handle != 0) {
81                 contact = empathy_contact_factory_get_from_handle (priv->factory,
82                                                                    priv->account,
83                                                                    handle);
84         }
85
86         if (contact && empathy_contact_get_handle (contact) == priv->self_handle) {
87                 empathy_contact_set_is_user (contact, TRUE);
88         }
89
90         return contact;
91 }
92
93 static GList *
94 tp_group_get_contacts (EmpathyTpGroup *group,
95                        GArray         *handles)
96 {
97         EmpathyTpGroupPriv *priv = GET_PRIV (group);
98         GList              *contacts,  *l;
99
100         if (!handles) {
101                 return NULL;
102         }
103
104         contacts = empathy_contact_factory_get_from_handles (priv->factory,
105                                                              priv->account,
106                                                              handles);
107
108         /* FIXME: Only useful if the group has a different self handle than
109          * the connection, otherwise the contact factory already set that
110          * property. That can be known using group flags. */
111         for (l = contacts; l; l = l->next) {
112                 if (empathy_contact_get_handle (l->data) == priv->self_handle) {
113                         empathy_contact_set_is_user (l->data, TRUE);
114                 }
115         }
116
117         return contacts;
118 }
119
120 EmpathyPendingInfo *
121 empathy_pending_info_new (EmpathyContact *member,
122                           EmpathyContact *actor,
123                           const gchar    *message)
124 {
125         EmpathyPendingInfo *info;
126
127         info = g_slice_new0 (EmpathyPendingInfo);
128
129         if (member) {
130                 info->member = g_object_ref (member);
131         }
132         if (actor) {
133                 info->actor = g_object_ref (actor);
134         }
135         if (message) {
136                 info->message = g_strdup (message);
137         }
138
139         return info;
140 }
141
142 void
143 empathy_pending_info_free (EmpathyPendingInfo *info)
144 {
145         if (!info) {
146                 return;
147         }
148
149         if (info->member) {
150                 g_object_unref (info->member);
151         }
152         if (info->actor) {
153                 g_object_unref (info->actor);
154         }
155         g_free (info->message);
156
157         g_slice_free (EmpathyPendingInfo, info);
158 }
159
160 static gint
161 tp_group_local_pending_find (gconstpointer a,
162                              gconstpointer b)
163 {
164         const EmpathyPendingInfo *info = a;
165
166         return (info->member != b);
167 }
168
169 static void
170 tp_group_remove_from_pendings (EmpathyTpGroup *group,
171                                EmpathyContact *contact)
172 {
173         EmpathyTpGroupPriv *priv = GET_PRIV (group);
174         GList              *l;
175
176         /* local pending */
177         l = g_list_find_custom (priv->local_pendings,
178                                 contact,
179                                 tp_group_local_pending_find);
180         if (l) {
181                 empathy_pending_info_free (l->data);
182                 priv->local_pendings = g_list_delete_link (priv->local_pendings, l);
183         }
184
185         /* remote pending */
186         l = g_list_find (priv->remote_pendings, contact);
187         if (l) {
188                 g_object_unref (l->data);
189                 priv->remote_pendings = g_list_delete_link (priv->remote_pendings, l);
190         }
191 }
192
193 static void
194 tp_group_members_changed_cb (DBusGProxy     *group_iface,
195                              const gchar    *message,
196                              GArray         *added,
197                              GArray         *removed,
198                              GArray         *local_pending,
199                              GArray         *remote_pending,
200                              guint           actor,
201                              guint           reason,
202                              EmpathyTpGroup *group)
203 {
204         EmpathyTpGroupPriv *priv = GET_PRIV (group);
205         EmpathyContact     *actor_contact = NULL;
206         GList              *contacts, *l, *ll;
207
208         actor_contact = tp_group_get_contact (group, actor);
209
210         empathy_debug (DEBUG_DOMAIN, "Members changed for list %s:\n"
211                                      "  added-len=%d, current-len=%d\n"
212                                      "  removed-len=%d\n"
213                                      "  local-pending-len=%d, current-len=%d\n"
214                                      "  remote-pending-len=%d, current-len=%d",
215                        empathy_tp_group_get_name (group),
216                        added ? added->len : 0, g_list_length (priv->members),
217                        removed ? removed->len : 0,
218                        local_pending ? local_pending->len : 0,
219                        g_list_length (priv->local_pendings),
220                        remote_pending ? remote_pending->len : 0,
221                        g_list_length (priv->remote_pendings));
222
223         /* Contacts added */
224         contacts = tp_group_get_contacts (group, added);
225         for (l = contacts; l; l = l->next) {
226                 tp_group_remove_from_pendings (group, l->data);
227
228                 /* If the contact is not yet member, add it and emit signal */
229                 if (!g_list_find (priv->members, l->data)) {
230                         priv->members = g_list_prepend (priv->members,
231                                                         g_object_ref (l->data));
232                         g_signal_emit (group, signals[MEMBER_ADDED], 0,
233                                        l->data, actor_contact, reason, message);
234                 }
235                 g_object_unref (l->data);
236         }
237         g_list_free (contacts);
238
239         /* Contacts removed */
240         contacts = tp_group_get_contacts (group, removed);
241         for (l = contacts; l; l = l->next) {
242                 tp_group_remove_from_pendings (group, l->data);
243
244                 /* If the contact is member, remove it and emit signal */
245                 if ((ll = g_list_find (priv->members, l->data))) {
246                         g_object_unref (ll->data);
247                         priv->members = g_list_delete_link (priv->members, ll);
248                         g_signal_emit (group, signals[MEMBER_REMOVED], 0,
249                                        l->data, actor_contact, reason, message);
250                 }
251                 g_object_unref (l->data);
252         }
253         g_list_free (contacts);
254
255         /* Contacts local pending */
256         contacts = tp_group_get_contacts (group, local_pending);
257         for (l = contacts; l; l = l->next) {
258                 /* If the contact is not yet local-pending, add it and emit signal */
259                 if (!g_list_find_custom (priv->members, l->data,
260                                          tp_group_local_pending_find)) {
261                         EmpathyPendingInfo *info;
262
263                         info = empathy_pending_info_new (l->data,
264                                                          actor_contact,
265                                                          message);
266
267                         priv->local_pendings = g_list_prepend (priv->local_pendings, info);
268                         g_signal_emit (group, signals[LOCAL_PENDING], 0,
269                                        l->data, actor_contact, reason, message);
270                 }
271                 g_object_unref (l->data);
272         }
273         g_list_free (contacts);
274
275         /* Contacts remote pending */
276         contacts = tp_group_get_contacts (group, remote_pending);
277         for (l = contacts; l; l = l->next) {
278                 /* If the contact is not yet remote-pending, add it and emit signal */
279                 if (!g_list_find (priv->remote_pendings, l->data)) {
280                         priv->remote_pendings = g_list_prepend (priv->remote_pendings,
281                                                                 g_object_ref (l->data));
282                         g_signal_emit (group, signals[REMOTE_PENDING], 0,
283                                        l->data, actor_contact, reason, message);
284                 }
285                 g_object_unref (l->data);
286         }
287         g_list_free (contacts);
288
289         if (actor_contact) {
290                 g_object_unref (actor_contact);
291         }
292
293         empathy_debug (DEBUG_DOMAIN, "Members changed done for list %s:\n"
294                                      "  members-len=%d\n"
295                                      "  local-pendings-len=%d\n"
296                                      "  remote-pendings-len=%d",
297                        empathy_tp_group_get_name (group),
298                        g_list_length (priv->members),
299                        g_list_length (priv->local_pendings),
300                        g_list_length (priv->remote_pendings));
301 }
302
303 static void
304 tp_group_destroy_cb (TpChan         *tp_chan,
305                      EmpathyTpGroup *group)
306 {
307         EmpathyTpGroupPriv *priv = GET_PRIV (group);
308
309         empathy_debug (DEBUG_DOMAIN, "Account disconnected or CM crashed");
310
311         g_object_unref (priv->tp_chan);
312         priv->group_iface = NULL;
313         priv->tp_chan = NULL;
314
315         g_signal_emit (group, signals[DESTROY], 0);
316 }
317
318 static void tp_group_closed_cb (DBusGProxy     *proxy,
319                                 EmpathyTpGroup *group);
320
321 static void
322 tp_group_disconnect (EmpathyTpGroup *group)
323 {
324         EmpathyTpGroupPriv *priv = GET_PRIV (group);
325
326         if (priv->group_iface) {
327                 dbus_g_proxy_disconnect_signal (priv->group_iface, "MembersChanged",
328                                                 G_CALLBACK (tp_group_members_changed_cb),
329                                                 group);
330         }
331         if (priv->tp_chan) {
332                 g_signal_handlers_disconnect_by_func (priv->tp_chan,
333                                                       tp_group_destroy_cb,
334                                                       group);
335                 dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (priv->tp_chan), "Closed",
336                                                 G_CALLBACK (tp_group_closed_cb),
337                                                 group);
338         }
339 }
340
341 static void
342 tp_group_closed_cb (DBusGProxy     *proxy,
343                     EmpathyTpGroup *group)
344 {
345         tp_group_disconnect (group);
346         tp_group_destroy_cb (TELEPATHY_CHAN (proxy), group);
347 }
348
349 static void
350 tp_group_get_members_cb (DBusGProxy *proxy,
351                          GArray     *handles,
352                          GError     *error,
353                          gpointer    user_data)
354 {
355         EmpathyTpGroup     *group = user_data;
356         EmpathyTpGroupPriv *priv = GET_PRIV (group);
357
358         if (error) {
359                 empathy_debug (DEBUG_DOMAIN, "Failed to get members: %s",
360                                error->message);
361                 return;
362         }
363
364         tp_group_members_changed_cb (priv->group_iface,
365                                      NULL,    /* message */
366                                      handles, /* added */
367                                      NULL,    /* removed */
368                                      NULL,    /* local_pending */
369                                      NULL,    /* remote_pending */
370                                      0,       /* actor */
371                                      0,       /* reason */
372                                      group);
373 }
374
375 static void
376 tp_group_get_local_pending_cb (DBusGProxy *proxy,
377                                GPtrArray  *array,
378                                GError     *error,
379                                gpointer    user_data)
380 {
381         EmpathyTpGroup     *group = user_data;
382         EmpathyTpGroupPriv *priv = GET_PRIV (group);
383         GArray             *handles;
384         guint               i;
385         
386         if (error) {
387                 empathy_debug (DEBUG_DOMAIN, "Failed to get local pendings: %s",
388                                error->message);
389                 return;
390         }
391
392         handles = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1);
393         for (i = 0; array->len > i; i++) {
394                 GValueArray        *pending_struct;
395                 const gchar        *message;
396                 guint               member_handle;
397                 guint               actor_handle;
398                 guint               reason;
399
400                 pending_struct = g_ptr_array_index (array, i);
401                 member_handle = g_value_get_uint (g_value_array_get_nth (pending_struct, 0));
402                 actor_handle = g_value_get_uint (g_value_array_get_nth (pending_struct, 1));
403                 reason = g_value_get_uint (g_value_array_get_nth (pending_struct, 2));
404                 message = g_value_get_string (g_value_array_get_nth (pending_struct, 3));
405
406                 g_array_insert_val (handles, 0, member_handle);
407                 tp_group_members_changed_cb (priv->group_iface,
408                                              message,      /* message */
409                                              NULL,         /* added */
410                                              NULL,         /* removed */
411                                              handles,      /* local_pending */
412                                              NULL,         /* remote_pending */
413                                              actor_handle, /* actor */
414                                              reason,       /* reason */
415                                              group);
416         }
417         g_array_free (handles, TRUE);
418 }
419
420 static void
421 tp_group_get_remote_pending_cb (DBusGProxy *proxy,
422                                 GArray     *handles,
423                                 GError     *error,
424                                 gpointer    user_data)
425 {
426         EmpathyTpGroup     *group = user_data;
427         EmpathyTpGroupPriv *priv = GET_PRIV (group);
428         
429         if (error) {
430                 empathy_debug (DEBUG_DOMAIN, "Failed to get remote pendings: %s",
431                                error->message);
432                 return;
433         }
434
435         tp_group_members_changed_cb (priv->group_iface,
436                                      NULL,    /* message */
437                                      NULL,    /* added */
438                                      NULL,    /* removed */
439                                      NULL,    /* local_pending */
440                                      handles, /* remote_pending */
441                                      0,       /* actor */
442                                      0,       /* reason */
443                                      group);
444 }
445
446 static void
447 tp_group_finalize (GObject *object)
448 {
449         EmpathyTpGroupPriv *priv = GET_PRIV (object);
450
451         tp_group_disconnect (EMPATHY_TP_GROUP (object));
452
453         if (priv->tp_chan) {
454                 g_object_unref (priv->tp_chan);
455         }
456         if (priv->account) {
457                 g_object_unref (priv->account);
458         }
459         if (priv->factory) {
460                 g_object_unref (priv->factory);
461         }
462         g_free (priv->group_name);
463
464         g_list_foreach (priv->members, (GFunc) g_object_unref, NULL);
465         g_list_free (priv->members);
466
467         g_list_foreach (priv->local_pendings, (GFunc) empathy_pending_info_free, NULL);
468         g_list_free (priv->local_pendings);
469
470         g_list_foreach (priv->remote_pendings, (GFunc) g_object_unref, NULL);
471         g_list_free (priv->remote_pendings);
472
473         G_OBJECT_CLASS (empathy_tp_group_parent_class)->finalize (object);
474 }
475
476 static void
477 empathy_tp_group_class_init (EmpathyTpGroupClass *klass)
478 {
479         GObjectClass *object_class = G_OBJECT_CLASS (klass);
480
481         object_class->finalize = tp_group_finalize;
482
483         signals[MEMBER_ADDED] =
484                 g_signal_new ("member-added",
485                               G_TYPE_FROM_CLASS (klass),
486                               G_SIGNAL_RUN_LAST,
487                               0,
488                               NULL, NULL,
489                               empathy_marshal_VOID__OBJECT_OBJECT_UINT_STRING,
490                               G_TYPE_NONE,
491                               4, EMPATHY_TYPE_CONTACT, EMPATHY_TYPE_CONTACT, G_TYPE_UINT, G_TYPE_STRING);
492
493         signals[MEMBER_REMOVED] =
494                 g_signal_new ("member-removed",
495                               G_TYPE_FROM_CLASS (klass),
496                               G_SIGNAL_RUN_LAST,
497                               0,
498                               NULL, NULL,
499                               empathy_marshal_VOID__OBJECT_OBJECT_UINT_STRING,
500                               G_TYPE_NONE,
501                               4, EMPATHY_TYPE_CONTACT, EMPATHY_TYPE_CONTACT, G_TYPE_UINT, G_TYPE_STRING);
502
503         signals[LOCAL_PENDING] =
504                 g_signal_new ("local-pending",
505                               G_TYPE_FROM_CLASS (klass),
506                               G_SIGNAL_RUN_LAST,
507                               0,
508                               NULL, NULL,
509                               empathy_marshal_VOID__OBJECT_OBJECT_UINT_STRING,
510                               G_TYPE_NONE,
511                               4, EMPATHY_TYPE_CONTACT, EMPATHY_TYPE_CONTACT, G_TYPE_UINT, G_TYPE_STRING);
512
513         signals[REMOTE_PENDING] =
514                 g_signal_new ("remote-pending",
515                               G_TYPE_FROM_CLASS (klass),
516                               G_SIGNAL_RUN_LAST,
517                               0,
518                               NULL, NULL,
519                               empathy_marshal_VOID__OBJECT_OBJECT_UINT_STRING,
520                               G_TYPE_NONE,
521                               4, EMPATHY_TYPE_CONTACT, EMPATHY_TYPE_CONTACT, G_TYPE_UINT, G_TYPE_STRING);
522
523         signals[DESTROY] =
524                 g_signal_new ("destroy",
525                               G_TYPE_FROM_CLASS (klass),
526                               G_SIGNAL_RUN_LAST,
527                               0,
528                               NULL, NULL,
529                               g_cclosure_marshal_VOID__VOID,
530                               G_TYPE_NONE,
531                               0);
532
533         g_type_class_add_private (object_class, sizeof (EmpathyTpGroupPriv));
534 }
535
536 static void
537 empathy_tp_group_init (EmpathyTpGroup *group)
538 {
539 }
540
541 EmpathyTpGroup *
542 empathy_tp_group_new (McAccount *account,
543                       TpChan    *tp_chan)
544 {
545         EmpathyTpGroup     *group;
546         EmpathyTpGroupPriv *priv;
547         DBusGProxy         *group_iface;
548         GError             *error;
549
550         g_return_val_if_fail (TELEPATHY_IS_CHAN (tp_chan), NULL);
551         g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
552
553         group_iface = tp_chan_get_interface (tp_chan,
554                                              TELEPATHY_CHAN_IFACE_GROUP_QUARK);
555         g_return_val_if_fail (group_iface != NULL, NULL);
556
557         group = g_object_new (EMPATHY_TYPE_TP_GROUP, NULL);
558         priv = GET_PRIV (group);
559
560         priv->account = g_object_ref (account);
561         priv->tp_chan = g_object_ref (tp_chan);
562         priv->group_iface = group_iface;
563         priv->factory = empathy_contact_factory_new ();
564
565         if (!tp_chan_iface_group_get_self_handle (priv->group_iface,
566                                                   &priv->self_handle,
567                                                   &error)) {
568                 empathy_debug (DEBUG_DOMAIN, 
569                               "Failed to get self handle: %s",
570                               error ? error->message : "No error given");
571                 g_clear_error (&error);
572         }
573
574         dbus_g_proxy_connect_signal (priv->group_iface, "MembersChanged",
575                                      G_CALLBACK (tp_group_members_changed_cb),
576                                      group, NULL);
577         dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->tp_chan), "Closed",
578                                      G_CALLBACK (tp_group_closed_cb),
579                                      group, NULL);
580         g_signal_connect (priv->tp_chan, "destroy",
581                           G_CALLBACK (tp_group_destroy_cb),
582                           group);
583
584         tp_chan_iface_group_get_members_async (priv->group_iface,
585                                                tp_group_get_members_cb,
586                                                group);
587         tp_chan_iface_group_get_local_pending_members_with_info_async (priv->group_iface,
588                                                                        tp_group_get_local_pending_cb,
589                                                                        group);
590         tp_chan_iface_group_get_remote_pending_members_async (priv->group_iface,
591                                                               tp_group_get_remote_pending_cb,
592                                                               group);
593
594         return group;
595 }
596
597 static void
598 tp_group_async_cb (DBusGProxy *proxy, GError *error, gpointer user_data)
599 {
600         const gchar *msg = user_data;
601
602         if (error) {
603                 empathy_debug (DEBUG_DOMAIN, "%s: %s", msg, error->message);
604         }
605 }
606
607 void
608 empathy_tp_group_close  (EmpathyTpGroup *group)
609 {
610         EmpathyTpGroupPriv *priv = GET_PRIV (group);
611
612         tp_chan_close_async (DBUS_G_PROXY (priv->tp_chan),
613                              tp_group_async_cb,
614                              "Failed to close");
615 }
616
617 static GArray *
618 tp_group_get_handles (GList *contacts)
619 {
620         GArray *handles;
621         guint   length;
622         GList  *l;
623
624         length = g_list_length (contacts);
625         handles = g_array_sized_new (FALSE, FALSE, sizeof (guint), length);
626
627         for (l = contacts; l; l = l->next) {
628                 guint handle;
629
630                 handle = empathy_contact_get_handle (l->data);
631                 g_array_append_val (handles, handle);
632         }
633
634         return handles;
635 }
636
637 void
638 empathy_tp_group_add_members (EmpathyTpGroup *group,
639                               GList          *contacts,
640                               const gchar    *message)
641 {
642         EmpathyTpGroupPriv *priv = GET_PRIV (group);
643         GArray             *handles;
644
645         g_return_if_fail (EMPATHY_IS_TP_GROUP (group));
646         g_return_if_fail (contacts != NULL);
647
648         handles = tp_group_get_handles (contacts);
649         tp_chan_iface_group_add_members_async (priv->group_iface,
650                                                handles,
651                                                message,
652                                                tp_group_async_cb,
653                                                "Failed to add members");
654
655         g_array_free (handles, TRUE);
656 }
657
658 void
659 empathy_tp_group_add_member (EmpathyTpGroup *group,
660                              EmpathyContact *contact,
661                              const gchar    *message)
662 {
663         EmpathyTpGroupPriv *priv = GET_PRIV (group);
664         GArray             *handles;
665         guint               handle;
666
667         handle = empathy_contact_get_handle (contact);
668         handles = g_array_new (FALSE, FALSE, sizeof (guint));
669         g_array_append_val (handles, handle);
670
671         tp_chan_iface_group_add_members_async (priv->group_iface,
672                                                handles,
673                                                message,
674                                                tp_group_async_cb,
675                                                "Failed to add member");
676
677         g_array_free (handles, TRUE);
678 }
679
680 void
681 empathy_tp_group_remove_members (EmpathyTpGroup *group,
682                                  GList          *contacts,
683                                  const gchar    *message)
684 {
685         EmpathyTpGroupPriv *priv = GET_PRIV (group);
686         GArray             *handles;
687
688         g_return_if_fail (EMPATHY_IS_TP_GROUP (group));
689         g_return_if_fail (contacts != NULL);
690
691         handles = tp_group_get_handles (contacts);
692         tp_chan_iface_group_remove_members_async (priv->group_iface,
693                                                   handles,
694                                                   message,
695                                                   tp_group_async_cb,
696                                                   "Failed to remove members");
697
698         g_array_free (handles, TRUE);
699 }
700
701 void
702 empathy_tp_group_remove_member (EmpathyTpGroup *group,
703                                 EmpathyContact *contact,
704                                 const gchar    *message)
705 {
706         EmpathyTpGroupPriv *priv = GET_PRIV (group);
707         GArray             *handles;
708         guint               handle;
709
710         handle = empathy_contact_get_handle (contact);
711         handles = g_array_new (FALSE, FALSE, sizeof (guint));
712         g_array_append_val (handles, handle);
713
714         tp_chan_iface_group_remove_members_async (priv->group_iface,
715                                                   handles,
716                                                   message,
717                                                   tp_group_async_cb,
718                                                   "Failed to remove member");
719
720         g_array_free (handles, TRUE);
721 }
722
723 GList *
724 empathy_tp_group_get_members (EmpathyTpGroup *group)
725 {
726         EmpathyTpGroupPriv *priv = GET_PRIV (group);
727
728         g_list_foreach (priv->members, (GFunc) g_object_ref, NULL);
729
730         return g_list_copy (priv->members);
731 }
732
733 GList *
734 empathy_tp_group_get_local_pendings (EmpathyTpGroup *group)
735 {
736         EmpathyTpGroupPriv *priv = GET_PRIV (group);
737         GList              *pendings = NULL, *l;
738
739         for (l = priv->local_pendings; l; l = l->next) {
740                 EmpathyPendingInfo *info;
741                 EmpathyPendingInfo *new_info;
742
743                 info = l->data;
744                 new_info = empathy_pending_info_new (info->member,
745                                                      info->actor,
746                                                      info->message);
747                 pendings = g_list_prepend (pendings, new_info);
748         }
749
750         return pendings;
751 }
752
753 GList *
754 empathy_tp_group_get_remote_pendings (EmpathyTpGroup *group)
755 {
756         EmpathyTpGroupPriv *priv = GET_PRIV (group);
757
758         g_list_foreach (priv->remote_pendings, (GFunc) g_object_ref, NULL);
759
760         return g_list_copy (priv->remote_pendings);
761 }
762
763 const gchar *
764 empathy_tp_group_get_name (EmpathyTpGroup *group)
765 {
766         EmpathyTpGroupPriv *priv;
767
768         g_return_val_if_fail (EMPATHY_IS_TP_GROUP (group), NULL);
769
770         priv = GET_PRIV (group);
771
772         /* Lazy initialisation */
773         if (!priv->group_name) {
774                 priv->group_name = empathy_inspect_channel (priv->account, priv->tp_chan);
775         }
776
777         return priv->group_name;
778 }
779
780 EmpathyContact *
781 empathy_tp_group_get_self_contact (EmpathyTpGroup *group)
782 {
783         EmpathyTpGroupPriv *priv = GET_PRIV (group);
784
785         g_return_val_if_fail (EMPATHY_IS_TP_GROUP (group), NULL);
786
787         return tp_group_get_contact (group, priv->self_handle);
788 }
789
790 const gchar *
791 empathy_tp_group_get_object_path (EmpathyTpGroup *group)
792 {
793         EmpathyTpGroupPriv *priv;
794
795         g_return_val_if_fail (EMPATHY_IS_TP_GROUP (group), NULL);
796
797         priv = GET_PRIV (group);
798
799         return dbus_g_proxy_get_path (DBUS_G_PROXY (priv->tp_chan));
800 }
801
802 gboolean
803 empathy_tp_group_is_member (EmpathyTpGroup *group,
804                             EmpathyContact *contact)
805 {
806         EmpathyTpGroupPriv *priv = GET_PRIV (group);
807
808         return g_list_find (priv->members, contact) != NULL;
809 }
810