void roster_update(const char * const barejid, const char * const name, GSList *groups, const char * const subscription, gboolean pending_out) { PContact contact = g_hash_table_lookup(contacts, barejid); assert(contact != NULL); p_contact_set_subscription(contact, subscription); p_contact_set_pending_out(contact, pending_out); const char * const new_name = name; const char * current_name = NULL; if (p_contact_name(contact) != NULL) { current_name = strdup(p_contact_name(contact)); } p_contact_set_name(contact, new_name); p_contact_set_groups(contact, groups); _replace_name(current_name, new_name, barejid); // add groups while (groups != NULL) { autocomplete_add(groups_ac, groups->data); groups = g_slist_next(groups); } }
void roster_change_name(PContact contact, const char * const new_name) { assert(contact != NULL); const char *current_name = NULL; const char *barejid = p_contact_barejid(contact); if (p_contact_name(contact) != NULL) { current_name = strdup(p_contact_name(contact)); } p_contact_set_name(contact, new_name); _replace_name(current_name, new_name, barejid); }
void roster_update(const char *const barejid, const char *const name, GSList *groups, const char *const subscription, gboolean pending_out) { assert(roster != NULL); PContact contact = roster_get_contact(barejid); assert(contact != NULL); p_contact_set_subscription(contact, subscription); p_contact_set_pending_out(contact, pending_out); const char * const new_name = name; const char * current_name = NULL; if (p_contact_name(contact)) { current_name = strdup(p_contact_name(contact)); } p_contact_set_name(contact, new_name); _replace_name(current_name, new_name, barejid); GSList *curr_new_group = groups; while (curr_new_group) { char *new_group = curr_new_group->data; // contact added to group if (!p_contact_in_group(contact, new_group)) { // group doesn't yet exist if (!g_hash_table_contains(roster->group_count, new_group)) { g_hash_table_insert(roster->group_count, strdup(new_group), GINT_TO_POINTER(1)); autocomplete_add(roster->groups_ac, curr_new_group->data); // increment count } else { int count = GPOINTER_TO_INT(g_hash_table_lookup(roster->group_count, new_group)); g_hash_table_insert(roster->group_count, strdup(new_group), GINT_TO_POINTER(count + 1)); } } curr_new_group = g_slist_next(curr_new_group); } GSList *old_groups = p_contact_groups(contact); GSList *curr_old_group = old_groups; while (curr_old_group) { char *old_group = curr_old_group->data; // removed from group if (!g_slist_find_custom(groups, old_group, (GCompareFunc)g_strcmp0)) { if (g_hash_table_contains(roster->group_count, old_group)) { int count = GPOINTER_TO_INT(g_hash_table_lookup(roster->group_count, old_group)); count--; if (count < 1) { g_hash_table_remove(roster->group_count, old_group); autocomplete_remove(roster->groups_ac, old_group); } else { g_hash_table_insert(roster->group_count, strdup(old_group), GINT_TO_POINTER(count)); } } } curr_old_group = g_slist_next(curr_old_group); } p_contact_set_groups(contact, groups); }