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>
27 #include <telepathy-glib/telepathy-glib.h>
29 #include <folks/folks.h>
30 #include <folks/folks-telepathy.h>
32 #include <extensions/extensions.h>
34 #include "empathy-individual-manager.h"
35 #include "empathy-utils.h"
37 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
38 #include "empathy-debug.h"
40 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIndividualManager)
42 /* We just expose the $TOP_INDIVIDUALS_LEN more popular individuals as that's
43 * what the view actually care about. We just want to notify it when this list
44 * changes, not when the position of every single individual is updated. */
45 #define TOP_INDIVIDUALS_LEN 5
47 /* The constant INDIVIDUALS_COUNT_COMPRESS_FACTOR represents the number of
48 * interactions needed to be considered as 1 interaction */
49 #define INTERACTION_COUNT_COMPRESS_FACTOR 50
51 /* The constant DAY_IN_SECONDS represents the seconds in a day */
52 #define DAY_IN_SECONDS 86400
54 /* This class only stores and refs Individuals who contain an EmpathyContact.
56 * This class merely forwards along signals from the aggregator and individuals
57 * and wraps aggregator functions for other client code. */
60 FolksIndividualAggregator *aggregator;
61 GHashTable *individuals; /* Individual.id -> Individual */
62 gboolean contacts_loaded;
64 /* reffed FolksIndividual sorted by popularity (most popular first) */
65 GSequence *individuals_pop;
66 /* The TOP_INDIVIDUALS_LEN first FolksIndividual (borrowed) from
68 GList *top_individuals;
69 guint global_interaction_counter;
70 } EmpathyIndividualManagerPriv;
74 PROP_TOP_INDIVIDUALS = 1,
87 static guint signals[LAST_SIGNAL] = { 0 };
89 G_DEFINE_TYPE (EmpathyIndividualManager, empathy_individual_manager,
92 static EmpathyIndividualManager *manager_singleton = NULL;
95 individual_manager_get_property (GObject *object,
100 EmpathyIndividualManager *self = EMPATHY_INDIVIDUAL_MANAGER (object);
101 EmpathyIndividualManagerPriv *priv = GET_PRIV (self);
105 case PROP_TOP_INDIVIDUALS:
106 g_value_set_pointer (value, priv->top_individuals);
108 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
114 individual_group_changed_cb (FolksIndividual *individual,
117 EmpathyIndividualManager *self)
119 g_signal_emit (self, signals[GROUPS_CHANGED], 0, individual, group,
124 individual_notify_is_favourite_cb (FolksIndividual *individual,
126 EmpathyIndividualManager *self)
128 gboolean is_favourite = folks_favourite_details_get_is_favourite (
129 FOLKS_FAVOURITE_DETAILS (individual));
130 g_signal_emit (self, signals[FAVOURITES_CHANGED], 0, individual,
135 /* Contacts that have been interacted with within the last 30 days and have
136 * have an interaction count > INTERACTION_COUNT_COMPRESS_FACTOR have a
137 * popularity value of the count/INTERACTION_COUNT_COMPRESS_FACTOR */
139 compute_popularity (FolksIndividual *individual)
141 FolksInteractionDetails *details = FOLKS_INTERACTION_DETAILS (individual);
143 guint current_timestamp, count;
146 last = folks_interaction_details_get_last_im_interaction_datetime (details);
150 /* Convert g_get_real_time () fro microseconds to seconds */
151 current_timestamp = g_get_real_time () / 1000000;
152 timediff = current_timestamp - g_date_time_to_unix (last);
154 if (timediff / DAY_IN_SECONDS > 30)
157 count = folks_interaction_details_get_im_interaction_count (details);
158 count = count / INTERACTION_COUNT_COMPRESS_FACTOR;
166 check_top_individuals (EmpathyIndividualManager *self)
168 EmpathyIndividualManagerPriv *priv = GET_PRIV (self);
170 GList *l, *new_list = NULL;
171 gboolean modified = FALSE;
174 iter = g_sequence_get_begin_iter (priv->individuals_pop);
175 l = priv->top_individuals;
177 /* Check if the TOP_INDIVIDUALS_LEN first individuals in individuals_pop are
178 * still the same as the ones in top_individuals */
179 for (i = 0; i < TOP_INDIVIDUALS_LEN && !g_sequence_iter_is_end (iter); i++)
181 FolksIndividual *individual = g_sequence_get (iter);
184 /* Don't include individual having 0 as pop */
185 pop = compute_popularity (individual);
193 /* Old list is shorter than the new one */
198 modified = (individual != l->data);
204 new_list = g_list_prepend (new_list, individual);
206 iter = g_sequence_iter_next (iter);
209 g_list_free (priv->top_individuals);
210 priv->top_individuals = g_list_reverse (new_list);
214 DEBUG ("Top individuals changed:");
216 for (l = priv->top_individuals; l != NULL; l = g_list_next (l))
218 FolksIndividual *individual = l->data;
221 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
222 compute_popularity (individual));
225 g_object_notify (G_OBJECT (self), "top-individuals");
230 compare_individual_by_pop (gconstpointer a,
236 pop_a = compute_popularity (FOLKS_INDIVIDUAL (a));
237 pop_b = compute_popularity (FOLKS_INDIVIDUAL (b));
239 return pop_b - pop_a;
243 individual_notify_im_interaction_count (FolksIndividual *individual,
245 EmpathyIndividualManager *self)
247 EmpathyIndividualManagerPriv *priv = GET_PRIV (self);
249 /* We don't use g_sequence_sort_changed() because we'll first have to find
250 * the iter of @individual using g_sequence_lookup() but the lookup function
251 * won't work as it assumes that the sequence is sorted which is no longer
252 * the case at this point as @individual's popularity just changed. */
253 g_sequence_sort (priv->individuals_pop, compare_individual_by_pop, NULL);
255 /* Only check for top individuals after 10 interaction events happen */
256 if (priv->global_interaction_counter % 10 == 0)
257 check_top_individuals (self);
258 priv->global_interaction_counter++;
262 add_individual (EmpathyIndividualManager *self, FolksIndividual *individual)
264 EmpathyIndividualManagerPriv *priv = GET_PRIV (self);
266 g_hash_table_insert (priv->individuals,
267 g_strdup (folks_individual_get_id (individual)),
268 g_object_ref (individual));
270 g_sequence_insert_sorted (priv->individuals_pop, g_object_ref (individual),
271 compare_individual_by_pop, NULL);
272 check_top_individuals (self);
274 g_signal_connect (individual, "group-changed",
275 G_CALLBACK (individual_group_changed_cb), self);
276 g_signal_connect (individual, "notify::is-favourite",
277 G_CALLBACK (individual_notify_is_favourite_cb), self);
278 g_signal_connect (individual, "notify::im-interaction-count",
279 G_CALLBACK (individual_notify_im_interaction_count), self);
283 remove_individual (EmpathyIndividualManager *self, FolksIndividual *individual)
285 EmpathyIndividualManagerPriv *priv = GET_PRIV (self);
288 iter = g_sequence_lookup (priv->individuals_pop, individual,
289 compare_individual_by_pop, NULL);
292 /* priv->top_individuals borrows its reference from
293 * priv->individuals_pop so we take a reference on the individual while
294 * removing it to make sure it stays alive while calling
295 * check_top_individuals(). */
296 g_object_ref (individual);
297 g_sequence_remove (iter);
298 check_top_individuals (self);
299 g_object_unref (individual);
302 g_signal_handlers_disconnect_by_func (individual,
303 individual_group_changed_cb, self);
304 g_signal_handlers_disconnect_by_func (individual,
305 individual_notify_is_favourite_cb, self);
306 g_signal_handlers_disconnect_by_func (individual,
307 individual_notify_im_interaction_count, self);
309 g_hash_table_remove (priv->individuals, folks_individual_get_id (individual));
312 /* This is emitted for *all* individuals in the individual aggregator (not
313 * just the ones we keep a reference to), to allow for the case where a new
314 * individual doesn't contain an EmpathyContact, but later has a persona added
317 individual_notify_personas_cb (FolksIndividual *individual,
319 EmpathyIndividualManager *self)
321 EmpathyIndividualManagerPriv *priv = GET_PRIV (self);
323 const gchar *id = folks_individual_get_id (individual);
324 gboolean has_contact = empathy_folks_individual_contains_contact (individual);
325 gboolean had_contact = (g_hash_table_lookup (priv->individuals,
326 id) != NULL) ? TRUE : FALSE;
328 if (had_contact == TRUE && has_contact == FALSE)
330 GList *removed = NULL;
332 /* The Individual has lost its EmpathyContact */
333 removed = g_list_prepend (removed, individual);
334 g_signal_emit (self, signals[MEMBERS_CHANGED], 0, NULL, NULL, removed,
335 TP_CHANNEL_GROUP_CHANGE_REASON_NONE /* FIXME */);
336 g_list_free (removed);
338 remove_individual (self, individual);
340 else if (had_contact == FALSE && has_contact == TRUE)
344 /* The Individual has gained its first EmpathyContact */
345 add_individual (self, individual);
347 added = g_list_prepend (added, individual);
348 g_signal_emit (self, signals[MEMBERS_CHANGED], 0, NULL, added, NULL,
349 TP_CHANNEL_GROUP_CHANGE_REASON_NONE /* FIXME */);
355 aggregator_individuals_changed_cb (FolksIndividualAggregator *aggregator,
356 GeeMultiMap *changes,
357 EmpathyIndividualManager *self)
359 EmpathyIndividualManagerPriv *priv = GET_PRIV (self);
362 GeeCollection *added;
363 GList *added_set = NULL, *added_filtered = NULL, *removed_list = NULL;
365 /* We're not interested in the relationships between the added and removed
366 * individuals, so just extract collections of them. Note that the added
367 * collection may contain duplicates, while the removed set won't. */
368 removed = gee_multi_map_get_keys (changes);
369 added = gee_multi_map_get_values (changes);
371 /* Handle the removals first, as one of the added Individuals might have the
372 * same ID as one of the removed Individuals (due to linking). */
373 iter = gee_iterable_iterator (GEE_ITERABLE (removed));
374 while (gee_iterator_next (iter))
376 FolksIndividual *ind = gee_iterator_get (iter);
381 g_signal_handlers_disconnect_by_func (ind,
382 individual_notify_personas_cb, self);
384 if (g_hash_table_lookup (priv->individuals,
385 folks_individual_get_id (ind)) != NULL)
387 remove_individual (self, ind);
388 removed_list = g_list_prepend (removed_list, ind);
391 g_clear_object (&ind);
393 g_clear_object (&iter);
395 /* Filter the individuals for ones which contain EmpathyContacts */
396 iter = gee_iterable_iterator (GEE_ITERABLE (added));
397 while (gee_iterator_next (iter))
399 FolksIndividual *ind = gee_iterator_get (iter);
401 /* Make sure we handle each added individual only once. */
402 if (ind == NULL || g_list_find (added_set, ind) != NULL)
404 added_set = g_list_prepend (added_set, ind);
406 g_signal_connect (ind, "notify::personas",
407 G_CALLBACK (individual_notify_personas_cb), self);
409 if (empathy_folks_individual_contains_contact (ind) == TRUE)
411 add_individual (self, ind);
412 added_filtered = g_list_prepend (added_filtered, ind);
415 g_clear_object (&ind);
417 g_clear_object (&iter);
419 g_list_free (added_set);
421 g_object_unref (added);
422 g_object_unref (removed);
424 /* Bail if we have no individuals left */
425 if (added_filtered == NULL && removed == NULL)
428 added_filtered = g_list_reverse (added_filtered);
430 g_signal_emit (self, signals[MEMBERS_CHANGED], 0, NULL,
431 added_filtered, removed_list,
432 TP_CHANNEL_GROUP_CHANGE_REASON_NONE,
435 g_list_free (added_filtered);
436 g_list_free (removed_list);
440 individual_manager_dispose (GObject *object)
442 EmpathyIndividualManagerPriv *priv = GET_PRIV (object);
444 g_hash_table_unref (priv->individuals);
446 tp_clear_object (&priv->aggregator);
448 G_OBJECT_CLASS (empathy_individual_manager_parent_class)->dispose (object);
452 individual_manager_finalize (GObject *object)
454 EmpathyIndividualManagerPriv *priv = GET_PRIV (object);
456 g_sequence_free (priv->individuals_pop);
458 G_OBJECT_CLASS (empathy_individual_manager_parent_class)->finalize (object);
462 individual_manager_constructor (GType type,
464 GObjectConstructParam *props)
468 if (manager_singleton)
470 retval = g_object_ref (manager_singleton);
475 G_OBJECT_CLASS (empathy_individual_manager_parent_class)->
476 constructor (type, n_props, props);
478 manager_singleton = EMPATHY_INDIVIDUAL_MANAGER (retval);
479 g_object_add_weak_pointer (retval, (gpointer) & manager_singleton);
486 * empathy_individual_manager_initialized:
488 * Reports whether or not the singleton has already been created.
490 * There can be instances where you want to access the #EmpathyIndividualManager
491 * only if it has been set up for this process.
493 * Returns: %TRUE if the #EmpathyIndividualManager singleton has previously
497 empathy_individual_manager_initialized (void)
499 return (manager_singleton != NULL);
503 empathy_individual_manager_class_init (EmpathyIndividualManagerClass *klass)
505 GObjectClass *object_class = G_OBJECT_CLASS (klass);
508 object_class->get_property = individual_manager_get_property;
509 object_class->dispose = individual_manager_dispose;
510 object_class->finalize = individual_manager_finalize;
511 object_class->constructor = individual_manager_constructor;
513 spec = g_param_spec_pointer ("top-individuals", "top individuals",
515 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
516 g_object_class_install_property (object_class, PROP_TOP_INDIVIDUALS, spec);
518 signals[GROUPS_CHANGED] =
519 g_signal_new ("groups-changed",
520 G_TYPE_FROM_CLASS (klass),
524 g_cclosure_marshal_generic,
525 G_TYPE_NONE, 3, FOLKS_TYPE_INDIVIDUAL, G_TYPE_STRING, G_TYPE_BOOLEAN);
527 signals[FAVOURITES_CHANGED] =
528 g_signal_new ("favourites-changed",
529 G_TYPE_FROM_CLASS (klass),
533 g_cclosure_marshal_generic,
534 G_TYPE_NONE, 2, FOLKS_TYPE_INDIVIDUAL, G_TYPE_BOOLEAN);
536 signals[MEMBERS_CHANGED] =
537 g_signal_new ("members-changed",
538 G_TYPE_FROM_CLASS (klass),
542 g_cclosure_marshal_generic,
544 4, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_UINT);
546 signals[CONTACTS_LOADED] =
547 g_signal_new ("contacts-loaded",
548 G_TYPE_FROM_CLASS (klass),
552 g_cclosure_marshal_generic,
556 g_type_class_add_private (object_class,
557 sizeof (EmpathyIndividualManagerPriv));
561 aggregator_is_quiescent_notify_cb (FolksIndividualAggregator *aggregator,
563 EmpathyIndividualManager *self)
565 EmpathyIndividualManagerPriv *priv = GET_PRIV (self);
566 gboolean is_quiescent;
568 if (priv->contacts_loaded)
571 g_object_get (aggregator, "is-quiescent", &is_quiescent, NULL);
576 priv->contacts_loaded = TRUE;
578 g_signal_emit (self, signals[CONTACTS_LOADED], 0);
582 empathy_individual_manager_init (EmpathyIndividualManager *self)
584 EmpathyIndividualManagerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
585 EMPATHY_TYPE_INDIVIDUAL_MANAGER, EmpathyIndividualManagerPriv);
588 priv->individuals = g_hash_table_new_full (g_str_hash, g_str_equal,
589 g_free, g_object_unref);
591 priv->individuals_pop = g_sequence_new (g_object_unref);
593 priv->aggregator = folks_individual_aggregator_new ();
594 tp_g_signal_connect_object (priv->aggregator, "individuals-changed-detailed",
595 G_CALLBACK (aggregator_individuals_changed_cb), self, 0);
596 tp_g_signal_connect_object (priv->aggregator, "notify::is-quiescent",
597 G_CALLBACK (aggregator_is_quiescent_notify_cb), self, 0);
598 folks_individual_aggregator_prepare (priv->aggregator, NULL, NULL);
601 EmpathyIndividualManager *
602 empathy_individual_manager_dup_singleton (void)
604 return g_object_new (EMPATHY_TYPE_INDIVIDUAL_MANAGER, NULL);
608 empathy_individual_manager_get_members (EmpathyIndividualManager *self)
610 EmpathyIndividualManagerPriv *priv = GET_PRIV (self);
612 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (self), NULL);
614 return g_hash_table_get_values (priv->individuals);
618 empathy_individual_manager_lookup_member (EmpathyIndividualManager *self,
621 EmpathyIndividualManagerPriv *priv = GET_PRIV (self);
623 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (self), NULL);
625 return g_hash_table_lookup (priv->individuals, id);
629 aggregator_add_persona_from_details_cb (GObject *source,
630 GAsyncResult *result,
633 FolksIndividualAggregator *aggregator = FOLKS_INDIVIDUAL_AGGREGATOR (source);
634 EmpathyContact *contact = EMPATHY_CONTACT (user_data);
635 FolksPersona *persona;
636 GError *error = NULL;
638 persona = folks_individual_aggregator_add_persona_from_details_finish (
639 aggregator, result, &error);
642 g_warning ("failed to add individual from contact: %s", error->message);
643 g_clear_error (&error);
646 /* The persona can be NULL even if there wasn't an error, if the persona was
647 * already in the contact list */
650 /* Set the contact's persona */
651 empathy_contact_set_persona (contact, persona);
652 g_object_unref (persona);
655 g_object_unref (contact);
659 empathy_individual_manager_add_from_contact (EmpathyIndividualManager *self,
660 EmpathyContact *contact)
662 EmpathyIndividualManagerPriv *priv;
663 FolksBackendStore *backend_store;
664 FolksBackend *backend;
665 FolksPersonaStore *persona_store;
667 GeeMap *persona_stores;
669 const gchar *store_id;
671 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (self));
672 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
674 priv = GET_PRIV (self);
676 /* We need to ref the contact since otherwise its linked TpHandle will be
678 g_object_ref (contact);
680 DEBUG ("adding individual from contact %s (%s)",
681 empathy_contact_get_id (contact), empathy_contact_get_alias (contact));
683 account = empathy_contact_get_account (contact);
684 store_id = tp_proxy_get_object_path (TP_PROXY (account));
686 /* Get the persona store to use */
687 backend_store = folks_backend_store_dup ();
689 folks_backend_store_dup_backend_by_name (backend_store, "telepathy");
693 g_warning ("Failed to add individual from contact: couldn't get "
694 "'telepathy' backend");
698 persona_stores = folks_backend_get_persona_stores (backend);
699 persona_store = gee_map_get (persona_stores, store_id);
701 if (persona_store == NULL)
703 g_warning ("Failed to add individual from contact: couldn't get persona "
704 "store '%s'", store_id);
708 details = tp_asv_new (
709 "contact", G_TYPE_STRING, empathy_contact_get_id (contact),
712 folks_individual_aggregator_add_persona_from_details (
713 priv->aggregator, NULL, persona_store, details,
714 aggregator_add_persona_from_details_cb, contact);
716 g_hash_table_unref (details);
717 g_object_unref (persona_store);
720 tp_clear_object (&backend);
721 tp_clear_object (&backend_store);
725 aggregator_remove_individual_cb (GObject *source,
726 GAsyncResult *result,
729 FolksIndividualAggregator *aggregator = FOLKS_INDIVIDUAL_AGGREGATOR (source);
730 GError *error = NULL;
732 folks_individual_aggregator_remove_individual_finish (
733 aggregator, result, &error);
736 g_warning ("failed to remove individual: %s", error->message);
737 g_clear_error (&error);
742 * Removes the inner contact from the server (and thus the Individual). Not
743 * meant for de-shelling inner personas from an Individual.
746 empathy_individual_manager_remove (EmpathyIndividualManager *self,
747 FolksIndividual *individual,
748 const gchar *message)
750 EmpathyIndividualManagerPriv *priv;
752 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (self));
753 g_return_if_fail (FOLKS_IS_INDIVIDUAL (individual));
755 priv = GET_PRIV (self);
757 DEBUG ("removing individual %s (%s)",
758 folks_individual_get_id (individual),
759 folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
761 folks_individual_aggregator_remove_individual (priv->aggregator, individual,
762 aggregator_remove_individual_cb, self);
765 /* FIXME: The parameter @self is not required and the method can be placed in
766 * utilities. I left it as it is to stay coherent with empathy-2.34 */
768 * empathy_individual_manager_supports_blocking
769 * @self: the #EmpathyIndividualManager
770 * @individual: an individual to check
772 * Indicates whether any personas of an @individual can be blocked.
774 * Returns: %TRUE if any persona supports contact blocking
777 empathy_individual_manager_supports_blocking (EmpathyIndividualManager *self,
778 FolksIndividual *individual)
782 gboolean retval = FALSE;
784 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (self), FALSE);
786 personas = folks_individual_get_personas (individual);
787 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
788 while (!retval && gee_iterator_next (iter))
790 TpfPersona *persona = gee_iterator_get (iter);
793 if (TPF_IS_PERSONA (persona))
795 TpContact *tp_contact;
797 tp_contact = tpf_persona_get_contact (persona);
798 if (tp_contact != NULL)
800 conn = tp_contact_get_connection (tp_contact);
802 if (tp_proxy_has_interface_by_id (conn,
803 TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING))
807 g_clear_object (&persona);
809 g_clear_object (&iter);
815 empathy_individual_manager_set_blocked (EmpathyIndividualManager *self,
816 FolksIndividual *individual,
823 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (self));
825 personas = folks_individual_get_personas (individual);
826 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
827 while (gee_iterator_next (iter))
829 TpfPersona *persona = gee_iterator_get (iter);
831 if (TPF_IS_PERSONA (persona))
833 TpContact *tp_contact;
836 tp_contact = tpf_persona_get_contact (persona);
837 if (tp_contact == NULL)
840 conn = tp_contact_get_connection (tp_contact);
842 if (!tp_proxy_has_interface_by_id (conn,
843 TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING))
847 tp_contact_block_async (tp_contact, abusive, NULL, NULL);
849 tp_contact_unblock_async (tp_contact, NULL, NULL);
851 g_clear_object (&persona);
853 g_clear_object (&iter);
857 groups_change_group_cb (GObject *source,
858 GAsyncResult *result,
861 FolksGroupDetails *group_details = FOLKS_GROUP_DETAILS (source);
862 GError *error = NULL;
864 folks_group_details_change_group_finish (group_details, result, &error);
867 g_warning ("failed to change group: %s", error->message);
868 g_clear_error (&error);
873 remove_group_cb (const gchar *id,
874 FolksIndividual *individual,
877 folks_group_details_change_group (FOLKS_GROUP_DETAILS (individual), group,
878 FALSE, groups_change_group_cb, NULL);
882 empathy_individual_manager_remove_group (EmpathyIndividualManager *manager,
885 EmpathyIndividualManagerPriv *priv;
887 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (manager));
888 g_return_if_fail (group != NULL);
890 priv = GET_PRIV (manager);
892 DEBUG ("removing group %s", group);
894 /* Remove every individual from the group */
895 g_hash_table_foreach (priv->individuals, (GHFunc) remove_group_cb,
900 empathy_individual_manager_get_contacts_loaded (EmpathyIndividualManager *self)
902 EmpathyIndividualManagerPriv *priv = GET_PRIV (self);
904 return priv->contacts_loaded;
908 empathy_individual_manager_get_top_individuals (EmpathyIndividualManager *self)
910 EmpathyIndividualManagerPriv *priv = GET_PRIV (self);
912 return priv->top_individuals;
916 unprepare_cb (GObject *source,
917 GAsyncResult *result,
920 GError *error = NULL;
921 GSimpleAsyncResult *my_result = user_data;
923 folks_individual_aggregator_unprepare_finish (
924 FOLKS_INDIVIDUAL_AGGREGATOR (source), result, &error);
928 DEBUG ("Failed to unprepare the aggregator: %s", error->message);
929 g_simple_async_result_take_error (my_result, error);
932 g_simple_async_result_complete (my_result);
933 g_object_unref (my_result);
937 empathy_individual_manager_unprepare_async (
938 EmpathyIndividualManager *self,
939 GAsyncReadyCallback callback,
942 EmpathyIndividualManagerPriv *priv = GET_PRIV (self);
943 GSimpleAsyncResult *result;
945 result = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
946 empathy_individual_manager_unprepare_async);
948 folks_individual_aggregator_unprepare (priv->aggregator, unprepare_cb,
953 empathy_individual_manager_unprepare_finish (
954 EmpathyIndividualManager *self,
955 GAsyncResult *result,
958 empathy_implement_finish_void (self,
959 empathy_individual_manager_unprepare_async)