mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Roster handle changes handled correctly
This commit is contained in:
parent
6c4b81d093
commit
4a8db64d7a
@ -82,6 +82,8 @@ p_contact_set_name(const PContact contact, const char * const name)
|
|||||||
|
|
||||||
if (name != NULL) {
|
if (name != NULL) {
|
||||||
contact->name = strdup(name);
|
contact->name = strdup(name);
|
||||||
|
} else {
|
||||||
|
FREE_SET_NULL(contact->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,35 +259,46 @@ roster_contact_offline(const char * const barejid,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
roster_change_handle(const char * const barejid, const char * const handle)
|
roster_change_handle(const char * const barejid, const char * const new_handle)
|
||||||
{
|
{
|
||||||
PContact contact = g_hash_table_lookup(contacts, barejid);
|
PContact contact = g_hash_table_lookup(contacts, barejid);
|
||||||
|
const char * current_handle = NULL;
|
||||||
if (p_contact_name(contact) != NULL) {
|
if (p_contact_name(contact) != NULL) {
|
||||||
autocomplete_remove(handle_ac, p_contact_name(contact));
|
current_handle = strdup(p_contact_name(contact));
|
||||||
g_hash_table_remove(handle_to_jid, p_contact_name(contact));
|
|
||||||
} else {
|
|
||||||
autocomplete_remove(handle_ac, barejid);
|
|
||||||
g_hash_table_remove(handle_to_jid, barejid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handle != NULL) {
|
if (contact != NULL) {
|
||||||
autocomplete_add(handle_ac, strdup(handle));
|
p_contact_set_name(contact, new_handle);
|
||||||
g_hash_table_insert(handle_to_jid, strdup(handle), strdup(barejid));
|
|
||||||
|
// current handle exists already
|
||||||
|
if (current_handle != NULL) {
|
||||||
|
autocomplete_remove(handle_ac, current_handle);
|
||||||
|
g_hash_table_remove(handle_to_jid, current_handle);
|
||||||
|
|
||||||
|
if (new_handle != NULL) {
|
||||||
|
autocomplete_add(handle_ac, strdup(new_handle));
|
||||||
|
g_hash_table_insert(handle_to_jid, strdup(new_handle), strdup(barejid));
|
||||||
} else {
|
} else {
|
||||||
autocomplete_add(handle_ac, strdup(barejid));
|
autocomplete_add(handle_ac, strdup(barejid));
|
||||||
g_hash_table_insert(handle_to_jid, strdup(barejid), strdup(barejid));
|
g_hash_table_insert(handle_to_jid, strdup(barejid), strdup(barejid));
|
||||||
}
|
}
|
||||||
|
// no current handle
|
||||||
|
} else {
|
||||||
|
if (new_handle != NULL) {
|
||||||
|
autocomplete_remove(handle_ac, barejid);
|
||||||
|
g_hash_table_remove(handle_to_jid, barejid);
|
||||||
|
|
||||||
if (contact != NULL) {
|
autocomplete_add(handle_ac, strdup(new_handle));
|
||||||
p_contact_set_name(contact, handle);
|
g_hash_table_insert(handle_to_jid, strdup(new_handle), strdup(barejid));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
xmpp_conn_t * const conn = connection_get_conn();
|
xmpp_conn_t * const conn = connection_get_conn();
|
||||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||||
xmpp_stanza_t *iq = stanza_create_roster_set(ctx, barejid, handle);
|
xmpp_stanza_t *iq = stanza_create_roster_set(ctx, barejid, new_handle);
|
||||||
xmpp_send(conn, iq);
|
xmpp_send(conn, iq);
|
||||||
xmpp_stanza_release(iq);
|
xmpp_stanza_release(iq);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -298,32 +309,48 @@ roster_update(const char * const barejid, const char * const name,
|
|||||||
|
|
||||||
if (contact == NULL) {
|
if (contact == NULL) {
|
||||||
contact = p_contact_new(barejid, name, subscription, NULL, pending_out);
|
contact = p_contact_new(barejid, name, subscription, NULL, pending_out);
|
||||||
autocomplete_add(jid_ac, strdup(barejid));
|
g_hash_table_insert(contacts, strdup(barejid), contact);
|
||||||
|
if (name != NULL) {
|
||||||
autocomplete_add(handle_ac, strdup(name));
|
autocomplete_add(handle_ac, strdup(name));
|
||||||
g_hash_table_insert(handle_to_jid, strdup(name), strdup(barejid));
|
g_hash_table_insert(handle_to_jid, strdup(name), strdup(barejid));
|
||||||
g_hash_table_insert(contacts, strdup(barejid), contact);
|
} else {
|
||||||
|
autocomplete_add(handle_ac, strdup(barejid));
|
||||||
|
g_hash_table_insert(handle_to_jid, strdup(barejid), strdup(barejid));
|
||||||
|
}
|
||||||
|
autocomplete_add(jid_ac, strdup(barejid));
|
||||||
} else {
|
} else {
|
||||||
p_contact_set_subscription(contact, subscription);
|
p_contact_set_subscription(contact, subscription);
|
||||||
p_contact_set_pending_out(contact, pending_out);
|
p_contact_set_pending_out(contact, pending_out);
|
||||||
|
|
||||||
if (p_contact_name(contact) == NULL) {
|
const char * const new_handle = name;
|
||||||
if (name != NULL) {
|
const char * current_handle = NULL;
|
||||||
autocomplete_add(handle_ac, strdup(name));
|
if (p_contact_name(contact) != NULL) {
|
||||||
autocomplete_remove(handle_ac, barejid);
|
current_handle = strdup(p_contact_name(contact));
|
||||||
g_hash_table_remove(handle_to_jid, barejid);
|
|
||||||
g_hash_table_insert(handle_to_jid, strdup(name), strdup(barejid));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (name != NULL) {
|
|
||||||
autocomplete_add(handle_ac, strdup(name));
|
|
||||||
autocomplete_remove(handle_ac, p_contact_name(contact));
|
|
||||||
g_hash_table_remove(handle_to_jid, p_contact_name(contact));
|
|
||||||
g_hash_table_insert(handle_to_jid, strdup(name), strdup(barejid));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name != NULL) {
|
p_contact_set_name(contact, new_handle);
|
||||||
p_contact_set_name(contact, name);
|
|
||||||
|
// current handle exists already
|
||||||
|
if (current_handle != NULL) {
|
||||||
|
autocomplete_remove(handle_ac, current_handle);
|
||||||
|
g_hash_table_remove(handle_to_jid, current_handle);
|
||||||
|
|
||||||
|
if (new_handle != NULL) {
|
||||||
|
autocomplete_add(handle_ac, strdup(new_handle));
|
||||||
|
g_hash_table_insert(handle_to_jid, strdup(new_handle), strdup(barejid));
|
||||||
|
} else {
|
||||||
|
autocomplete_add(handle_ac, strdup(barejid));
|
||||||
|
g_hash_table_insert(handle_to_jid, strdup(barejid), strdup(barejid));
|
||||||
|
}
|
||||||
|
// no current handle
|
||||||
|
} else {
|
||||||
|
if (new_handle != NULL) {
|
||||||
|
autocomplete_remove(handle_ac, barejid);
|
||||||
|
g_hash_table_remove(handle_to_jid, barejid);
|
||||||
|
|
||||||
|
autocomplete_add(handle_ac, strdup(new_handle));
|
||||||
|
g_hash_table_insert(handle_to_jid, strdup(new_handle), strdup(barejid));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user