1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007-2010 Collabora Ltd.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Authors: Xavier Claessens <xclaesse@gmail.com>
20 * Travis Reitter <travis.reitter@collabora.co.uk>
24 #include "empathy-individual-manager.h"
26 #include <tp-account-widgets/tpaw-utils.h>
27 #include <telepathy-glib/telepathy-glib-dbus.h>
29 #include "empathy-utils.h"
31 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
32 #include "empathy-debug.h"
34 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIndividualManager)
36 /* We just expose the $TOP_INDIVIDUALS_LEN more popular individuals as that's
37 * what the view actually care about. We just want to notify it when this list
38 * changes, not when the position of every single individual is updated. */
39 #define TOP_INDIVIDUALS_LEN 5
41 /* The constant INDIVIDUALS_COUNT_COMPRESS_FACTOR represents the number of
42 * interactions needed to be considered as 1 interaction */
43 #define INTERACTION_COUNT_COMPRESS_FACTOR 50
45 /* The constant DAY_IN_SECONDS represents the seconds in a day */
46 #define DAY_IN_SECONDS 86400
48 /* This class only stores and refs Individuals who contain an EmpathyContact.
50 * This class merely forwards along signals from the aggregator and individuals
51 * and wraps aggregator functions for other client code. */
54 FolksIndividualAggregator *aggregator;
55 GHashTable *individuals; /* Individual.id -> Individual */
56 gboolean contacts_loaded;
58 /* reffed FolksIndividual sorted by popularity (most popular first) */
59 GSequence *individuals_pop;
60 /* The TOP_INDIVIDUALS_LEN first FolksIndividual (borrowed) from
62 GList *top_individuals;
63 guint global_interaction_counter;
64 } EmpathyIndividualManagerPriv;
68 PROP_TOP_INDIVIDUALS = 1,
81 static guint signals[LAST_SIGNAL] = { 0 };
83 G_DEFINE_TYPE (EmpathyIndividualManager, empathy_individual_manager,
86 static EmpathyIndividualManager *manager_singleton = NULL;
89 individual_manager_get_property (GObject *object,
94 EmpathyIndividualManager *self = EMPATHY_INDIVIDUAL_MANAGER (object);
95 EmpathyIndividualManagerPriv *priv = GET_PRIV (self);
99 case PROP_TOP_INDIVIDUALS:
100 g_value_set_pointer (value, priv->top_individuals);
102 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
108 individual_group_changed_cb (FolksIndividual *individual,
111 EmpathyIndividualManager *self)
113 g_signal_emit (self, signals[GROUPS_CHANGED], 0, individual, group,
118 individual_notify_is_favourite_cb (FolksIndividual *individual,
120 EmpathyIndividualManager *self)
122 gboolean is_favourite = folks_favourite_details_get_is_favourite (
123 FOLKS_FAVOURITE_DETAILS (individual));
124 g_signal_emit (self, signals[FAVOURITES_CHANGED], 0, individual,
129 /* Contacts that have been interacted with within the last 30 days and have
130 * have an interaction count > INTERACTION_COUNT_COMPRESS_FACTOR have a
131 * popularity value of the count/INTERACTION_COUNT_COMPRESS_FACTOR */
133 compute_popularity (FolksIndividual *individual)
135 FolksInteractionDetails *details = FOLKS_INTERACTION_DETAILS (individual);
137 guint current_timestamp, count;
140 last = folks_interaction_details_get_last_im_interaction_datetime (details);
144 /* Convert g_get_real_time () fro microseconds to seconds */
145 current_timestamp = g_get_real_time () / 1000000;
146 timediff = current_timestamp - g_date_time_to_unix (last);
148 if (timediff / DAY_IN_SECONDS > 30)
151 count = folks_interaction_details_get_im_interaction_count (details);
152 count = count / INTERACTION_COUNT_COMPRESS_FACTOR;
160 check_top_individuals (EmpathyIndividualManager *self)
162 EmpathyIndividualManagerPriv *priv = GET_PRIV (self);
164 GList *l, *new_list = NULL;
165 gboolean modified = FALSE;
168 iter = g_sequence_get_begin_iter (priv->individuals_pop);
169 l = priv->top_individuals;
171 /* Check if the TOP_INDIVIDUALS_LEN first individuals in individuals_pop are
172 * still the same as the ones in top_individuals */
173 for (i = 0; i < TOP_INDIVIDUALS_LEN && !g_sequence_iter_is_end (iter); i++)
175 FolksIndividual *individual = g_sequence_get (iter);
178 /* Don't include individual having 0 as pop */
179 pop = compute_popularity (individual);
187 /* Old list is shorter than the new one */
192 modified = (individual != l->data);
198 new_list = g_list_prepend (new_list, individual);
200 iter = g_sequence_iter_next (iter);
203 g_list_free (priv->top_individuals);
204 priv->top_individuals = g_list_reverse (new_list);
208 DEBUG ("Top individuals changed:");
210 for (l = priv->top_individuals; l != NULL; l = g_list_next (l))
212 FolksIndividual *individual = l->data;
215 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
216 compute_popularity (individual));
219 g_object_notify (G_OBJECT (self), "top-individuals");
224 compare_individual_by_pop (gconstpointer a,
230 pop_a = compute_popularity (FOLKS_INDIVIDUAL (a));
231 pop_b = compute_popularity (FOLKS_INDIVIDUAL (b));
233 return pop_b - pop_a;
237 individual_notify_im_interaction_count (FolksIndividual *individual,
239 EmpathyIndividualManager *self)
241 EmpathyIndividualManagerPriv *priv = GET_PRIV (self);
243 /* We don't use g_sequence_sort_changed() because we'll first have to find
244 * the iter of @individual using g_sequence_lookup() but the lookup function
245 * won't work as it assumes that the sequence is sorted which is no longer
246 * the case at this point as @individual's popularity just changed. */
247 g_sequence_sort (priv->individuals_pop, compare_individual_by_pop, NULL);
249 /* Only check for top individuals after 10 interaction events happen */
250 if (priv->global_interaction_counter % 10 == 0)
251 check_top_individuals (self);
252 priv->global_interaction_counter++;
256 add_individual (EmpathyIndividualManager *self, FolksIndividual *individual)
258 EmpathyIndividualManagerPriv *priv = GET_PRIV (self);
260 g_hash_table_insert (priv->individuals,
261 g_strdup (folks_individual_get_id (individual)),
262 g_object_ref (individual));
264 g_sequence_insert_sorted (priv->individuals_pop, g_object_ref (individual),
265 compare_individual_by_pop, NULL);
266 check_top_individuals (self);
268 g_signal_connect (individual, "group-changed",
269 G_CALLBACK (individual_group_changed_cb), self);
270 g_signal_connect (individual, "notify::is-favourite",
271 G_CALLBACK (individual_notify_is_favourite_cb), self);
272 g_signal_connect (individual, "notify::im-interaction-count",
273 G_CALLBACK (individual_notify_im_interaction_count), self);
277 remove_individual (EmpathyIndividualManager *self, FolksIndividual *individual)
279 EmpathyIndividualManagerPriv *priv = GET_PRIV (self);
282 iter = g_sequence_lookup (priv->individuals_pop, individual,
283 compare_individual_by_pop, NULL);
286 /* priv->top_individuals borrows its reference from
287 * priv->individuals_pop so we take a reference on the individual while
288 * removing it to make sure it stays alive while calling
289 * check_top_individuals(). */
290 g_object_ref (individual);
291 g_sequence_remove (iter);
292 check_top_individuals (self);
293 g_object_unref (individual);
296 g_signal_handlers_disconnect_by_func (individual,
297 individual_group_changed_cb, self);
298 g_signal_handlers_disconnect_by_func (individual,
299 individual_notify_is_favourite_cb, self);
300 g_signal_handlers_disconnect_by_func (individual,
301 individual_notify_im_interaction_count, self);
303 g_hash_table_remove (priv->individuals, folks_individual_get_id (individual));
306 /* This is emitted for *all* individuals in the individual aggregator (not
307 * just the ones we keep a reference to), to allow for the case where a new
308 * individual doesn't contain an EmpathyContact, but later has a persona added
311 individual_notify_personas_cb (FolksIndividual *individual,
313 EmpathyIndividualManager *self)
315 EmpathyIndividualManagerPriv *priv = GET_PRIV (self);
317 const gchar *id = folks_individual_get_id (individual);
318 gboolean has_contact = empathy_folks_individual_contains_contact (individual);
319 gboolean had_contact = (g_hash_table_lookup (priv->individuals,
320 id) != NULL) ? TRUE : FALSE;
322 if (had_contact == TRUE && has_contact == FALSE)
324 GList *removed = NULL;
326 /* The Individual has lost its EmpathyContact */
327 removed = g_list_prepend (removed, individual);
328 g_signal_emit (self, signals[MEMBERS_CHANGED], 0, NULL, NULL, removed,
329 TP_CHANNEL_GROUP_CHANGE_REASON_NONE /* FIXME */);
330 g_list_free (removed);
332 remove_individual (self, individual);
334 else if (had_contact == FALSE && has_contact == TRUE)
338 /* The Individual has gained its first EmpathyContact */
339 add_individual (self, individual);
341 added = g_list_prepend (added, individual);
342 g_signal_emit (self, signals[MEMBERS_CHANGED], 0, NULL, added, NULL,
343 TP_CHANNEL_GROUP_CHANGE_REASON_NONE /* FIXME */);
349 aggregator_individuals_changed_cb (FolksIndividualAggregator *aggregator,
350 GeeMultiMap *changes,
351 EmpathyIndividualManager *self)
353 EmpathyIndividualManagerPriv *priv = GET_PRIV (self);
356 GeeCollection *added;
357 GList *added_set = NULL, *added_filtered = NULL, *removed_list = NULL;
359 /* We're not interested in the relationships between the added and removed
360 * individuals, so just extract collections of them. Note that the added
361 * collection may contain duplicates, while the removed set won't. */
362 removed = gee_multi_map_get_keys (changes);
363 added = gee_multi_map_get_values (changes);
365 /* Handle the removals first, as one of the added Individuals might have the
366 * same ID as one of the removed Individuals (due to linking). */
367 iter = gee_iterable_iterator (GEE_ITERABLE (removed));
368 while (gee_iterator_next (iter))
370 FolksIndividual *ind = gee_iterator_get (iter);
375 g_signal_handlers_disconnect_by_func (ind,
376 individual_notify_personas_cb, self);
378 if (g_hash_table_lookup (priv->individuals,
379 folks_individual_get_id (ind)) != NULL)
381 remove_individual (self, ind);
382 removed_list = g_list_prepend (removed_list, ind);
385 g_clear_object (&ind);
387 g_clear_object (&iter);
389 /* Filter the individuals for ones which contain EmpathyContacts */
390 iter = gee_iterable_iterator (GEE_ITERABLE (added));
391 while (gee_iterator_next (iter))
393 FolksIndividual *ind = gee_iterator_get (iter);
395 /* Make sure we handle each added individual only once. */
396 if (ind == NULL || g_list_find (added_set, ind) != NULL)
398 added_set = g_list_prepend (added_set, ind);
400 g_signal_connect (ind, "notify::personas",
401 G_CALLBACK (individual_notify_personas_cb), self);
403 if (empathy_folks_individual_contains_contact (ind) == TRUE)
405 add_individual (self, ind);
406 added_filtered = g_list_prepend (added_filtered, ind);
410 g_clear_object (&ind);
412 g_clear_object (&iter);
414 g_list_free (added_set);
416 g_object_unref (added);
417 g_object_unref (removed);
419 /* Bail if we have no individuals left */
420 if (added_filtered == NULL && removed == NULL)
423 added_filtered = g_list_reverse (added_filtered);
425 g_signal_emit (self, signals[MEMBERS_CHANGED], 0, NULL,
426 added_filtered, removed_list,
427 TP_CHANNEL_GROUP_CHANGE_REASON_NONE,
430 g_list_free (added_filtered);
431 g_list_free (removed_list);
435 individual_manager_dispose (GObject *object)
437 EmpathyIndividualManagerPriv *priv = GET_PRIV (object);
439 g_hash_table_unref (priv->individuals);
441 tp_clear_object (&priv->aggregator);
443 G_OBJECT_CLASS (empathy_individual_manager_parent_class)->dispose (object);
447 individual_manager_finalize (GObject *object)
449 EmpathyIndividualManagerPriv *priv = GET_PRIV (object);
451 g_sequence_free (priv->individuals_pop);
453 G_OBJECT_CLASS (empathy_individual_manager_parent_class)->finalize (object);
457 individual_manager_constructor (GType type,
459 GObjectConstructParam *props)
463 if (manager_singleton)
465 retval = g_object_ref (manager_singleton);
470 G_OBJECT_CLASS (empathy_individual_manager_parent_class)->
471 constructor (type, n_props, props);
473 manager_singleton = EMPATHY_INDIVIDUAL_MANAGER (retval);
474 g_object_add_weak_pointer (retval, (gpointer) & manager_singleton);
481 * empathy_individual_manager_initialized:
483 * Reports whether or not the singleton has already been created.
485 * There can be instances where you want to access the #EmpathyIndividualManager
486 * only if it has been set up for this process.
488 * Returns: %TRUE if the #EmpathyIndividualManager singleton has previously
492 empathy_individual_manager_initialized (void)
494 return (manager_singleton != NULL);
498 empathy_individual_manager_class_init (EmpathyIndividualManagerClass *klass)
500 GObjectClass *object_class = G_OBJECT_CLASS (klass);
503 object_class->get_property = individual_manager_get_property;
504 object_class->dispose = individual_manager_dispose;
505 object_class->finalize = individual_manager_finalize;
506 object_class->constructor = individual_manager_constructor;
508 spec = g_param_spec_pointer ("top-individuals", "top individuals",
510 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
511 g_object_class_install_property (object_class, PROP_TOP_INDIVIDUALS, spec);
513 signals[GROUPS_CHANGED] =
514 g_signal_new ("groups-changed",
515 G_TYPE_FROM_CLASS (klass),
519 g_cclosure_marshal_generic,
520 G_TYPE_NONE, 3, FOLKS_TYPE_INDIVIDUAL, G_TYPE_STRING, G_TYPE_BOOLEAN);
522 signals[FAVOURITES_CHANGED] =
523 g_signal_new ("favourites-changed",
524 G_TYPE_FROM_CLASS (klass),
528 g_cclosure_marshal_generic,
529 G_TYPE_NONE, 2, FOLKS_TYPE_INDIVIDUAL, G_TYPE_BOOLEAN);
531 signals[MEMBERS_CHANGED] =
532 g_signal_new ("members-changed",
533 G_TYPE_FROM_CLASS (klass),
537 g_cclosure_marshal_generic,
539 4, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_UINT);
541 signals[CONTACTS_LOADED] =
542 g_signal_new ("contacts-loaded",
543 G_TYPE_FROM_CLASS (klass),
547 g_cclosure_marshal_generic,
551 g_type_class_add_private (object_class,
552 sizeof (EmpathyIndividualManagerPriv));
556 aggregator_is_quiescent_notify_cb (FolksIndividualAggregator *aggregator,
558 EmpathyIndividualManager *self)
560 EmpathyIndividualManagerPriv *priv = GET_PRIV (self);
561 gboolean is_quiescent;
563 if (priv->contacts_loaded)
566 g_object_get (aggregator, "is-quiescent", &is_quiescent, NULL);
571 priv->contacts_loaded = TRUE;
573 g_signal_emit (self, signals[CONTACTS_LOADED], 0);
577 empathy_individual_manager_init (EmpathyIndividualManager *self)
579 EmpathyIndividualManagerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
580 EMPATHY_TYPE_INDIVIDUAL_MANAGER, EmpathyIndividualManagerPriv);
583 priv->individuals = g_hash_table_new_full (g_str_hash, g_str_equal,
584 g_free, g_object_unref);
586 priv->individuals_pop = g_sequence_new (g_object_unref);
588 priv->aggregator = folks_individual_aggregator_dup ();
589 tp_g_signal_connect_object (priv->aggregator, "individuals-changed-detailed",
590 G_CALLBACK (aggregator_individuals_changed_cb), self, 0);
591 tp_g_signal_connect_object (priv->aggregator, "notify::is-quiescent",
592 G_CALLBACK (aggregator_is_quiescent_notify_cb), self, 0);
593 folks_individual_aggregator_prepare (priv->aggregator, NULL, NULL);
596 EmpathyIndividualManager *
597 empathy_individual_manager_dup_singleton (void)
599 return g_object_new (EMPATHY_TYPE_INDIVIDUAL_MANAGER, NULL);
603 empathy_individual_manager_get_members (EmpathyIndividualManager *self)
605 EmpathyIndividualManagerPriv *priv = GET_PRIV (self);
607 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (self), NULL);
609 return g_hash_table_get_values (priv->individuals);
613 empathy_individual_manager_lookup_member (EmpathyIndividualManager *self,
616 EmpathyIndividualManagerPriv *priv = GET_PRIV (self);
618 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (self), NULL);
620 return g_hash_table_lookup (priv->individuals, id);
624 aggregator_add_persona_from_details_cb (GObject *source,
625 GAsyncResult *result,
628 FolksIndividualAggregator *aggregator = FOLKS_INDIVIDUAL_AGGREGATOR (source);
629 EmpathyContact *contact = EMPATHY_CONTACT (user_data);
630 FolksPersona *persona;
631 GError *error = NULL;
633 persona = folks_individual_aggregator_add_persona_from_details_finish (
634 aggregator, result, &error);
637 g_warning ("failed to add individual from contact: %s", error->message);
638 g_clear_error (&error);
641 /* The persona can be NULL even if there wasn't an error, if the persona was
642 * already in the contact list */
645 /* Set the contact's persona */
646 empathy_contact_set_persona (contact, persona);
647 g_object_unref (persona);
650 g_object_unref (contact);
654 empathy_individual_manager_add_from_contact (EmpathyIndividualManager *self,
655 EmpathyContact *contact)
657 EmpathyIndividualManagerPriv *priv;
658 FolksBackendStore *backend_store;
659 FolksBackend *backend;
660 FolksPersonaStore *persona_store;
662 GeeMap *persona_stores;
664 const gchar *store_id;
666 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (self));
667 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
669 priv = GET_PRIV (self);
671 /* We need to ref the contact since otherwise its linked TpHandle will be
673 g_object_ref (contact);
675 DEBUG ("adding individual from contact %s (%s)",
676 empathy_contact_get_id (contact), empathy_contact_get_alias (contact));
678 account = empathy_contact_get_account (contact);
679 store_id = tp_proxy_get_object_path (TP_PROXY (account));
681 /* Get the persona store to use */
682 backend_store = folks_backend_store_dup ();
684 folks_backend_store_dup_backend_by_name (backend_store, "telepathy");
688 g_warning ("Failed to add individual from contact: couldn't get "
689 "'telepathy' backend");
693 persona_stores = folks_backend_get_persona_stores (backend);
694 persona_store = gee_map_get (persona_stores, store_id);
696 if (persona_store == NULL)
698 g_warning ("Failed to add individual from contact: couldn't get persona "
699 "store '%s'", store_id);
703 details = tp_asv_new (
704 "contact", G_TYPE_STRING, empathy_contact_get_id (contact),
707 folks_individual_aggregator_add_persona_from_details (
708 priv->aggregator, NULL, persona_store, details,
709 aggregator_add_persona_from_details_cb, contact);
711 g_hash_table_unref (details);
712 g_object_unref (persona_store);
715 tp_clear_object (&backend);
716 tp_clear_object (&backend_store);
720 aggregator_remove_individual_cb (GObject *source,
721 GAsyncResult *result,
724 FolksIndividualAggregator *aggregator = FOLKS_INDIVIDUAL_AGGREGATOR (source);
725 GError *error = NULL;
727 folks_individual_aggregator_remove_individual_finish (
728 aggregator, result, &error);
731 g_warning ("failed to remove individual: %s", error->message);
732 g_clear_error (&error);
737 * Removes the inner contact from the server (and thus the Individual). Not
738 * meant for de-shelling inner personas from an Individual.
741 empathy_individual_manager_remove (EmpathyIndividualManager *self,
742 FolksIndividual *individual,
743 const gchar *message)
745 EmpathyIndividualManagerPriv *priv;
747 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (self));
748 g_return_if_fail (FOLKS_IS_INDIVIDUAL (individual));
750 priv = GET_PRIV (self);
752 DEBUG ("removing individual %s (%s)",
753 folks_individual_get_id (individual),
754 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
756 folks_individual_aggregator_remove_individual (priv->aggregator, individual,
757 aggregator_remove_individual_cb, self);
760 /* FIXME: The parameter @self is not required and the method can be placed in
761 * utilities. I left it as it is to stay coherent with empathy-2.34 */
763 * empathy_individual_manager_supports_blocking
764 * @self: the #EmpathyIndividualManager
765 * @individual: an individual to check
767 * Indicates whether any personas of an @individual can be blocked.
769 * Returns: %TRUE if any persona supports contact blocking
772 empathy_individual_manager_supports_blocking (EmpathyIndividualManager *self,
773 FolksIndividual *individual)
777 gboolean retval = FALSE;
779 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (self), FALSE);
781 personas = folks_individual_get_personas (individual);
782 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
783 while (!retval && gee_iterator_next (iter))
785 TpfPersona *persona = gee_iterator_get (iter);
788 if (TPF_IS_PERSONA (persona))
790 TpContact *tp_contact;
792 tp_contact = tpf_persona_get_contact (persona);
793 if (tp_contact != NULL)
795 conn = tp_contact_get_connection (tp_contact);
797 if (tp_proxy_has_interface_by_id (conn,
798 TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING))
802 g_clear_object (&persona);
804 g_clear_object (&iter);
810 empathy_individual_manager_set_blocked (EmpathyIndividualManager *self,
811 FolksIndividual *individual,
818 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (self));
820 personas = folks_individual_get_personas (individual);
821 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
822 while (gee_iterator_next (iter))
824 TpfPersona *persona = gee_iterator_get (iter);
826 if (TPF_IS_PERSONA (persona))
828 TpContact *tp_contact;
831 tp_contact = tpf_persona_get_contact (persona);
832 if (tp_contact == NULL)
835 conn = tp_contact_get_connection (tp_contact);
837 if (!tp_proxy_has_interface_by_id (conn,
838 TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING))
842 tp_contact_block_async (tp_contact, abusive, NULL, NULL);
844 tp_contact_unblock_async (tp_contact, NULL, NULL);
848 g_clear_object (&persona);
850 g_clear_object (&iter);
854 groups_change_group_cb (GObject *source,
855 GAsyncResult *result,
858 FolksGroupDetails *group_details = FOLKS_GROUP_DETAILS (source);
859 GError *error = NULL;
861 folks_group_details_change_group_finish (group_details, result, &error);
864 g_warning ("failed to change group: %s", error->message);
865 g_clear_error (&error);
870 remove_group_cb (const gchar *id,
871 FolksIndividual *individual,
874 folks_group_details_change_group (FOLKS_GROUP_DETAILS (individual), group,
875 FALSE, groups_change_group_cb, NULL);
879 empathy_individual_manager_remove_group (EmpathyIndividualManager *manager,
882 EmpathyIndividualManagerPriv *priv;
884 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (manager));
885 g_return_if_fail (group != NULL);
887 priv = GET_PRIV (manager);
889 DEBUG ("removing group %s", group);
891 /* Remove every individual from the group */
892 g_hash_table_foreach (priv->individuals, (GHFunc) remove_group_cb,
897 empathy_individual_manager_get_contacts_loaded (EmpathyIndividualManager *self)
899 EmpathyIndividualManagerPriv *priv = GET_PRIV (self);
901 return priv->contacts_loaded;
905 empathy_individual_manager_get_top_individuals (EmpathyIndividualManager *self)
907 EmpathyIndividualManagerPriv *priv = GET_PRIV (self);
909 return priv->top_individuals;
913 unprepare_cb (GObject *source,
914 GAsyncResult *result,
917 GError *error = NULL;
918 GSimpleAsyncResult *my_result = user_data;
920 folks_individual_aggregator_unprepare_finish (
921 FOLKS_INDIVIDUAL_AGGREGATOR (source), result, &error);
925 DEBUG ("Failed to unprepare the aggregator: %s", error->message);
926 g_simple_async_result_take_error (my_result, error);
929 g_simple_async_result_complete (my_result);
930 g_object_unref (my_result);
934 empathy_individual_manager_unprepare_async (
935 EmpathyIndividualManager *self,
936 GAsyncReadyCallback callback,
939 EmpathyIndividualManagerPriv *priv = GET_PRIV (self);
940 GSimpleAsyncResult *result;
942 result = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
943 empathy_individual_manager_unprepare_async);
945 folks_individual_aggregator_unprepare (priv->aggregator, unprepare_cb,
950 empathy_individual_manager_unprepare_finish (
951 EmpathyIndividualManager *self,
952 GAsyncResult *result,
955 tpaw_implement_finish_void (self,
956 empathy_individual_manager_unprepare_async)