Only create contacts resource when online
This commit is contained in:
@@ -64,8 +64,10 @@ p_contact_new(const char * const barejid, const char * const name,
|
||||
contact->resources = g_hash_table_new_full(g_str_hash, g_str_equal, free,
|
||||
(GDestroyNotify)resource_destroy);
|
||||
// TODO, priority, last activity
|
||||
Resource *resource = resource_new("default", presence, status, 0, caps_str);
|
||||
g_hash_table_insert(contact->resources, strdup(resource->name), resource);
|
||||
if (g_strcmp0(presence, "offline") != 0) {
|
||||
Resource *resource = resource_new("default", presence, status, 0, caps_str);
|
||||
g_hash_table_insert(contact->resources, strdup(resource->name), resource);
|
||||
}
|
||||
|
||||
return contact;
|
||||
}
|
||||
@@ -127,15 +129,23 @@ p_contact_name(const PContact contact)
|
||||
const char *
|
||||
p_contact_presence(const PContact contact)
|
||||
{
|
||||
Resource *resource = g_hash_table_lookup(contact->resources, "default");
|
||||
return resource->show;
|
||||
if (g_hash_table_size(contact->resources) == 0) {
|
||||
return "offline";
|
||||
} else {
|
||||
Resource *resource = g_hash_table_lookup(contact->resources, "default");
|
||||
return resource->show;
|
||||
}
|
||||
}
|
||||
|
||||
const char *
|
||||
p_contact_status(const PContact contact)
|
||||
{
|
||||
Resource *resource = g_hash_table_lookup(contact->resources, "default");
|
||||
return resource->status;
|
||||
if (g_hash_table_size(contact->resources) == 0) {
|
||||
return NULL;
|
||||
} else {
|
||||
Resource *resource = g_hash_table_lookup(contact->resources, "default");
|
||||
return resource->status;
|
||||
}
|
||||
}
|
||||
|
||||
const char *
|
||||
@@ -159,17 +169,32 @@ p_contact_last_activity(const PContact contact)
|
||||
const char *
|
||||
p_contact_caps_str(const PContact contact)
|
||||
{
|
||||
Resource *resource = g_hash_table_lookup(contact->resources, "default");
|
||||
return resource->caps_str;
|
||||
if (g_hash_table_size(contact->resources) == 0) {
|
||||
return NULL;
|
||||
} else {
|
||||
Resource *resource = g_hash_table_lookup(contact->resources, "default");
|
||||
return resource->caps_str;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
p_contact_set_presence(const PContact contact, const char * const presence)
|
||||
{
|
||||
Resource *resource = g_hash_table_lookup(contact->resources, "default");
|
||||
FREE_SET_NULL(resource->show);
|
||||
if (presence != NULL) {
|
||||
resource->show = strdup(presence);
|
||||
if (g_strcmp0(presence, "offline") == 0) {
|
||||
g_hash_table_remove(contact->resources, "default");
|
||||
} else {
|
||||
if (g_hash_table_size(contact->resources) == 0) {
|
||||
Resource *resource = resource_new("default", presence, NULL, 0, NULL);
|
||||
g_hash_table_insert(contact->resources, strdup(resource->name), resource);
|
||||
} else {
|
||||
Resource *resource = g_hash_table_lookup(contact->resources, "default");
|
||||
if (presence != NULL) {
|
||||
FREE_SET_NULL(resource->show);
|
||||
resource->show = strdup(presence);
|
||||
} else {
|
||||
resource->show = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -64,14 +64,13 @@ contact_list_reset_search_attempts(void)
|
||||
|
||||
gboolean
|
||||
contact_list_add(const char * const barejid, const char * const name,
|
||||
const char * const presence, const char * const status,
|
||||
const char * const subscription, gboolean pending_out)
|
||||
{
|
||||
gboolean added = FALSE;
|
||||
PContact contact = g_hash_table_lookup(contacts, barejid);
|
||||
|
||||
if (contact == NULL) {
|
||||
contact = p_contact_new(barejid, name, presence, status, subscription,
|
||||
contact = p_contact_new(barejid, name, "offline", NULL, subscription,
|
||||
pending_out, NULL);
|
||||
g_hash_table_insert(contacts, strdup(barejid), contact);
|
||||
autocomplete_add(ac, strdup(barejid));
|
||||
|
||||
@@ -33,7 +33,6 @@ void contact_list_free(void);
|
||||
void contact_list_reset_search_attempts(void);
|
||||
void contact_list_remove(const char * const barejid);
|
||||
gboolean contact_list_add(const char * const barejid, const char * const name,
|
||||
const char * const presence, const char * const status,
|
||||
const char * const subscription, gboolean pending_out);
|
||||
gboolean contact_list_update_contact(const char * const barejid, const char * const presence,
|
||||
const char * const status, GDateTime *last_activity, const char * const caps_str);
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
Resource * resource_new(const char * const name, const char * const show,
|
||||
const char * const status, const int priority, const char * const caps_str)
|
||||
{
|
||||
assert(g_strcmp0(show, "offline") != 0);
|
||||
assert(name != NULL);
|
||||
Resource *new_resource = malloc(sizeof(struct resource_t));
|
||||
new_resource->name = strdup(name);
|
||||
|
||||
@@ -144,8 +144,7 @@ _iq_handle_roster_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
pending_out = TRUE;
|
||||
}
|
||||
|
||||
gboolean added = contact_list_add(barejid, name, "offline", NULL, sub,
|
||||
pending_out);
|
||||
gboolean added = contact_list_add(barejid, name, sub, pending_out);
|
||||
|
||||
if (!added) {
|
||||
log_warning("Attempt to add contact twice: %s", barejid);
|
||||
|
||||
Reference in New Issue
Block a user