mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Use resource_presence_t in Resource
This commit is contained in:
parent
e922568770
commit
1a6490a5b7
@ -65,7 +65,8 @@ p_contact_new(const char * const barejid, const char * const name,
|
||||
(GDestroyNotify)resource_destroy);
|
||||
// TODO, priority, last activity
|
||||
if (g_strcmp0(presence, "offline") != 0) {
|
||||
Resource *resource = resource_new("default", presence, status, 0, caps_str);
|
||||
resource_presence_t resource_presence = resource_presence_from_string(presence);
|
||||
Resource *resource = resource_new("default", resource_presence, status, 0, caps_str);
|
||||
g_hash_table_insert(contact->available_resources, strdup(resource->name), resource);
|
||||
}
|
||||
|
||||
@ -130,7 +131,7 @@ p_contact_presence(const PContact contact)
|
||||
return "offline";
|
||||
} else {
|
||||
Resource *resource = g_hash_table_lookup(contact->available_resources, "default");
|
||||
return resource->show;
|
||||
return string_from_resource_presence(resource->presence);
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,17 +181,13 @@ p_contact_set_presence(const PContact contact, const char * const presence)
|
||||
if (g_strcmp0(presence, "offline") == 0) {
|
||||
g_hash_table_remove(contact->available_resources, "default");
|
||||
} else {
|
||||
resource_presence_t resource_presence = resource_presence_from_string(presence);
|
||||
if (g_hash_table_size(contact->available_resources) == 0) {
|
||||
Resource *resource = resource_new("default", presence, NULL, 0, NULL);
|
||||
Resource *resource = resource_new("default", resource_presence, NULL, 0, NULL);
|
||||
g_hash_table_insert(contact->available_resources, strdup(resource->name), resource);
|
||||
} else {
|
||||
Resource *resource = g_hash_table_lookup(contact->available_resources, "default");
|
||||
if (presence != NULL) {
|
||||
FREE_SET_NULL(resource->show);
|
||||
resource->show = strdup(presence);
|
||||
} else {
|
||||
resource->show = NULL;
|
||||
}
|
||||
resource->presence = resource_presence;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,17 +27,13 @@
|
||||
#include <common.h>
|
||||
#include <resource.h>
|
||||
|
||||
Resource * resource_new(const char * const name, const char * const show,
|
||||
Resource * resource_new(const char * const name, resource_presence_t presence,
|
||||
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);
|
||||
if (show == NULL || (strcmp(show, "") == 0))
|
||||
new_resource->show = strdup("online");
|
||||
else
|
||||
new_resource->show = strdup(show);
|
||||
new_resource->presence = presence;
|
||||
if (status != NULL) {
|
||||
new_resource->status = strdup(status);
|
||||
} else {
|
||||
@ -57,7 +53,6 @@ void resource_destroy(Resource *resource)
|
||||
{
|
||||
assert(resource != NULL);
|
||||
FREE_SET_NULL(resource->name);
|
||||
FREE_SET_NULL(resource->show);
|
||||
FREE_SET_NULL(resource->status);
|
||||
FREE_SET_NULL(resource->caps_str);
|
||||
FREE_SET_NULL(resource);
|
||||
|
@ -25,13 +25,13 @@
|
||||
|
||||
typedef struct resource_t {
|
||||
char *name;
|
||||
char *show;
|
||||
resource_presence_t presence;
|
||||
char *status;
|
||||
int priority;
|
||||
char *caps_str;
|
||||
} Resource;
|
||||
|
||||
Resource * resource_new(const char * const name, const char * const show,
|
||||
Resource * resource_new(const char * const name, resource_presence_t presence,
|
||||
const char * const status, const int priority, const char * const caps_str);
|
||||
void resource_destroy(Resource *resource);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user