#include <telepathy-glib/util.h>
#include <folks/folks.h>
+#include <folks/folks-telepathy.h>
#include <extensions/extensions.h>
#include "empathy-individual-manager.h"
-#include "empathy-marshal.h"
#include "empathy-utils.h"
+#include "empathy-contact-manager.h"
#define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
#include "empathy-debug.h"
GParamSpec *pspec,
EmpathyIndividualManager *self)
{
- gboolean is_favourite = folks_favouritable_get_is_favourite (
- FOLKS_FAVOURITABLE (individual));
+ gboolean is_favourite = folks_favourite_details_get_is_favourite (
+ FOLKS_FAVOURITE_DETAILS (individual));
g_signal_emit (self, signals[FAVOURITES_CHANGED], 0, individual,
is_favourite);
}
EmpathyIndividualManagerPriv *priv = GET_PRIV (self);
g_hash_table_insert (priv->individuals,
- (gpointer) folks_individual_get_id (individual),
+ g_strdup (folks_individual_get_id (individual)),
g_object_ref (individual));
g_signal_connect (individual, "group-changed",
static void
aggregator_individuals_changed_cb (FolksIndividualAggregator *aggregator,
- GList *added,
- GList *removed,
- const char *message,
- FolksPersona *actor,
- guint reason,
+ GeeMultiMap *changes,
EmpathyIndividualManager *self)
{
EmpathyIndividualManagerPriv *priv = GET_PRIV (self);
- GList *l, *added_filtered = NULL;
+ GeeIterator *iter;
+ GeeSet *removed;
+ GeeCollection *added;
+ GList *added_set = NULL, *added_filtered = NULL, *removed_list = NULL;
+
+ /* We're not interested in the relationships between the added and removed
+ * individuals, so just extract collections of them. Note that the added
+ * collection may contain duplicates, while the removed set won't. */
+ removed = gee_multi_map_get_keys (changes);
+ added = gee_multi_map_get_values (changes);
/* Handle the removals first, as one of the added Individuals might have the
* same ID as one of the removed Individuals (due to linking). */
- for (l = removed; l; l = l->next)
+ iter = gee_iterable_iterator (GEE_ITERABLE (removed));
+ while (gee_iterator_next (iter))
{
- FolksIndividual *ind = FOLKS_INDIVIDUAL (l->data);
+ FolksIndividual *ind = gee_iterator_get (iter);
+
+ if (ind == NULL)
+ continue;
g_signal_handlers_disconnect_by_func (ind,
individual_notify_personas_cb, self);
if (g_hash_table_lookup (priv->individuals,
folks_individual_get_id (ind)) != NULL)
- remove_individual (self, ind);
+ {
+ remove_individual (self, ind);
+ removed_list = g_list_prepend (removed_list, ind);
+ }
+
+ g_clear_object (&ind);
}
+ g_clear_object (&iter);
/* Filter the individuals for ones which contain EmpathyContacts */
- for (l = added; l; l = l->next)
+ iter = gee_iterable_iterator (GEE_ITERABLE (added));
+ while (gee_iterator_next (iter))
{
- FolksIndividual *ind = FOLKS_INDIVIDUAL (l->data);
+ FolksIndividual *ind = gee_iterator_get (iter);
+
+ /* Make sure we handle each added individual only once. */
+ if (ind == NULL || g_list_find (added_set, ind) != NULL)
+ continue;
+ added_set = g_list_prepend (added_set, ind);
g_signal_connect (ind, "notify::personas",
G_CALLBACK (individual_notify_personas_cb), self);
add_individual (self, ind);
added_filtered = g_list_prepend (added_filtered, ind);
}
+
+ g_clear_object (&ind);
}
+ g_clear_object (&iter);
+
+ g_list_free (added_set);
+
+ g_object_unref (added);
+ g_object_unref (removed);
/* Bail if we have no individuals left */
if (added_filtered == NULL && removed == NULL)
added_filtered = g_list_reverse (added_filtered);
- g_signal_emit (self, signals[MEMBERS_CHANGED], 0, message,
- added_filtered, removed,
- tp_channel_group_change_reason_from_folks_groups_change_reason (reason),
+ g_signal_emit (self, signals[MEMBERS_CHANGED], 0, NULL,
+ added_filtered, removed_list,
+ TP_CHANNEL_GROUP_CHANGE_REASON_NONE,
TRUE);
g_list_free (added_filtered);
+ g_list_free (removed_list);
}
static void
EmpathyIndividualManagerPriv *priv = GET_PRIV (object);
g_hash_table_destroy (priv->individuals);
+
+ g_signal_handlers_disconnect_by_func (priv->aggregator,
+ aggregator_individuals_changed_cb, object);
tp_clear_object (&priv->aggregator);
G_OBJECT_CLASS (empathy_individual_manager_parent_class)->dispose (object);
G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
- _empathy_marshal_VOID__OBJECT_STRING_BOOLEAN,
+ g_cclosure_marshal_generic,
G_TYPE_NONE, 3, FOLKS_TYPE_INDIVIDUAL, G_TYPE_STRING, G_TYPE_BOOLEAN);
signals[FAVOURITES_CHANGED] =
G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
- _empathy_marshal_VOID__OBJECT_BOOLEAN,
+ g_cclosure_marshal_generic,
G_TYPE_NONE, 2, FOLKS_TYPE_INDIVIDUAL, G_TYPE_BOOLEAN);
signals[MEMBERS_CHANGED] =
G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
- _empathy_marshal_VOID__STRING_OBJECT_OBJECT_UINT,
+ g_cclosure_marshal_generic,
G_TYPE_NONE,
4, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_UINT);
self->priv = priv;
priv->individuals = g_hash_table_new_full (g_str_hash, g_str_equal,
- NULL, g_object_unref);
+ g_free, g_object_unref);
priv->aggregator = folks_individual_aggregator_new ();
- g_signal_connect (priv->aggregator, "individuals-changed",
+ g_signal_connect (priv->aggregator, "individuals-changed-detailed",
G_CALLBACK (aggregator_individuals_changed_cb), self);
folks_individual_aggregator_prepare (priv->aggregator, NULL, NULL);
}
EmpathyContact *contact)
{
EmpathyIndividualManagerPriv *priv;
+ FolksBackendStore *backend_store;
+ FolksBackend *backend;
+ FolksPersonaStore *persona_store;
GHashTable* details;
+ GeeMap *persona_stores;
TpAccount *account;
const gchar *store_id;
account = empathy_contact_get_account (contact);
store_id = tp_proxy_get_object_path (TP_PROXY (account));
+ /* Get the persona store to use */
+ backend_store = folks_backend_store_dup ();
+ backend =
+ folks_backend_store_dup_backend_by_name (backend_store, "telepathy");
+
+ if (backend == NULL)
+ {
+ g_warning ("Failed to add individual from contact: couldn't get "
+ "'telepathy' backend");
+ goto finish;
+ }
+
+ persona_stores = folks_backend_get_persona_stores (backend);
+ persona_store = gee_map_get (persona_stores, store_id);
+
+ if (persona_store == NULL)
+ {
+ g_warning ("Failed to add individual from contact: couldn't get persona "
+ "store '%s'", store_id);
+ goto finish;
+ }
+
details = tp_asv_new (
"contact", G_TYPE_STRING, empathy_contact_get_id (contact),
NULL);
folks_individual_aggregator_add_persona_from_details (
- priv->aggregator, NULL, "telepathy", store_id, details,
+ priv->aggregator, NULL, persona_store, details,
aggregator_add_persona_from_details_cb, contact);
g_hash_table_destroy (details);
+ g_object_unref (persona_store);
+
+finish:
+ tp_clear_object (&backend);
+ tp_clear_object (&backend_store);
}
static void
DEBUG ("removing individual %s (%s)",
folks_individual_get_id (individual),
- folks_aliasable_get_alias (FOLKS_ALIASABLE (individual)));
+ folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
folks_individual_aggregator_remove_individual (priv->aggregator, individual,
aggregator_remove_individual_cb, self);
}
+/* FIXME: The parameter @self is not required and the method can be placed in
+ * utilities. I left it as it is to stay coherent with empathy-2.34 */
+/**
+ * empathy_individual_manager_supports_blocking
+ * @self: the #EmpathyIndividualManager
+ * @individual: an individual to check
+ *
+ * Indicates whether any personas of an @individual can be blocked.
+ *
+ * Returns: %TRUE if any persona supports contact blocking
+ */
+gboolean
+empathy_individual_manager_supports_blocking (EmpathyIndividualManager *self,
+ FolksIndividual *individual)
+{
+ GeeSet *personas;
+ GeeIterator *iter;
+ gboolean retval = FALSE;
+
+ g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (self), FALSE);
+
+ personas = folks_individual_get_personas (individual);
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+ while (!retval && gee_iterator_next (iter))
+ {
+ TpfPersona *persona = gee_iterator_get (iter);
+ TpConnection *conn;
+
+ if (TPF_IS_PERSONA (persona))
+ {
+ TpContact *tp_contact;
+
+ tp_contact = tpf_persona_get_contact (persona);
+ if (tp_contact != NULL)
+ {
+ conn = tp_contact_get_connection (tp_contact);
+
+ if (tp_proxy_has_interface_by_id (conn,
+ TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING))
+ retval = TRUE;
+ }
+ }
+ g_clear_object (&persona);
+ }
+ g_clear_object (&iter);
+
+ return retval;
+}
+
+void
+empathy_individual_manager_set_blocked (EmpathyIndividualManager *self,
+ FolksIndividual *individual,
+ gboolean blocked,
+ gboolean abusive)
+{
+ GeeSet *personas;
+ GeeIterator *iter;
+
+ g_return_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (self));
+
+ personas = folks_individual_get_personas (individual);
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+ while (gee_iterator_next (iter))
+ {
+ TpfPersona *persona = gee_iterator_get (iter);
+
+ if (TPF_IS_PERSONA (persona))
+ {
+ TpContact *tp_contact;
+ TpConnection *conn;
+
+ tp_contact = tpf_persona_get_contact (persona);
+ if (tp_contact == NULL)
+ continue;
+
+ conn = tp_contact_get_connection (tp_contact);
+
+ if (!tp_proxy_has_interface_by_id (conn,
+ TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING))
+ continue;
+
+ if (blocked)
+ tp_contact_block_async (tp_contact, abusive, NULL, NULL);
+ else
+ tp_contact_unblock_async (tp_contact, NULL, NULL);
+ }
+ g_clear_object (&persona);
+ }
+ g_clear_object (&iter);
+}
+
static void
groups_change_group_cb (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
- FolksGroupable *groupable = FOLKS_GROUPABLE (source);
+ FolksGroupDetails *group_details = FOLKS_GROUP_DETAILS (source);
GError *error = NULL;
- folks_groupable_change_group_finish (groupable, result, &error);
+ folks_group_details_change_group_finish (group_details, result, &error);
if (error != NULL)
{
g_warning ("failed to change group: %s", error->message);
FolksIndividual *individual,
const gchar *group)
{
- folks_groupable_change_group (FOLKS_GROUPABLE (individual), group, FALSE,
- groups_change_group_cb, NULL);
+ folks_group_details_change_group (FOLKS_GROUP_DETAILS (individual), group,
+ FALSE, groups_change_group_cb, NULL);
}
void
void
empathy_individual_manager_link_personas (EmpathyIndividualManager *self,
- GList *personas)
+ GeeSet *personas)
{
EmpathyIndividualManagerPriv *priv;
priv = GET_PRIV (self);
- DEBUG ("Linking %u personas", g_list_length (personas));
+ DEBUG ("Linking %u personas",
+ gee_collection_get_size (GEE_COLLECTION (personas)));
folks_individual_aggregator_link_personas (priv->aggregator, personas,
(GAsyncReadyCallback) link_personas_cb, NULL);