mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
Added default resource to contact
This commit is contained in:
parent
835906bada
commit
84a6ac1949
@ -26,18 +26,16 @@
|
|||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
#include "contact.h"
|
#include "contact.h"
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "resource.h"
|
||||||
|
|
||||||
struct p_contact_t {
|
struct p_contact_t {
|
||||||
char *barejid;
|
char *barejid;
|
||||||
char *name;
|
char *name;
|
||||||
char *presence;
|
|
||||||
char *status;
|
|
||||||
char *subscription;
|
char *subscription;
|
||||||
char *caps_str;
|
|
||||||
gboolean pending_out;
|
gboolean pending_out;
|
||||||
GDateTime *last_activity;
|
GDateTime *last_activity;
|
||||||
|
GHashTable *resources;
|
||||||
};
|
};
|
||||||
|
|
||||||
PContact
|
PContact
|
||||||
@ -55,29 +53,20 @@ p_contact_new(const char * const barejid, const char * const name,
|
|||||||
contact->name = NULL;
|
contact->name = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (presence == NULL || (strcmp(presence, "") == 0))
|
|
||||||
contact->presence = strdup("online");
|
|
||||||
else
|
|
||||||
contact->presence = strdup(presence);
|
|
||||||
|
|
||||||
if (status != NULL)
|
|
||||||
contact->status = strdup(status);
|
|
||||||
else
|
|
||||||
contact->status = NULL;
|
|
||||||
|
|
||||||
if (subscription != NULL)
|
if (subscription != NULL)
|
||||||
contact->subscription = strdup(subscription);
|
contact->subscription = strdup(subscription);
|
||||||
else
|
else
|
||||||
contact->subscription = strdup("none");
|
contact->subscription = strdup("none");
|
||||||
|
|
||||||
if (caps_str != NULL)
|
|
||||||
contact->caps_str = strdup(caps_str);
|
|
||||||
else
|
|
||||||
contact->caps_str = NULL;
|
|
||||||
|
|
||||||
contact->pending_out = pending_out;
|
contact->pending_out = pending_out;
|
||||||
contact->last_activity = NULL;
|
contact->last_activity = NULL;
|
||||||
|
|
||||||
|
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, resource->name, resource);
|
||||||
|
|
||||||
return contact;
|
return contact;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,15 +75,14 @@ p_contact_free(PContact contact)
|
|||||||
{
|
{
|
||||||
FREE_SET_NULL(contact->barejid);
|
FREE_SET_NULL(contact->barejid);
|
||||||
FREE_SET_NULL(contact->name);
|
FREE_SET_NULL(contact->name);
|
||||||
FREE_SET_NULL(contact->presence);
|
|
||||||
FREE_SET_NULL(contact->status);
|
|
||||||
FREE_SET_NULL(contact->subscription);
|
FREE_SET_NULL(contact->subscription);
|
||||||
FREE_SET_NULL(contact->caps_str);
|
|
||||||
|
|
||||||
if (contact->last_activity != NULL) {
|
if (contact->last_activity != NULL) {
|
||||||
g_date_time_unref(contact->last_activity);
|
g_date_time_unref(contact->last_activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_hash_table_destroy(contact->resources);
|
||||||
|
|
||||||
FREE_SET_NULL(contact);
|
FREE_SET_NULL(contact);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,13 +101,15 @@ p_contact_name(const PContact contact)
|
|||||||
const char *
|
const char *
|
||||||
p_contact_presence(const PContact contact)
|
p_contact_presence(const PContact contact)
|
||||||
{
|
{
|
||||||
return contact->presence;
|
Resource *resource = g_hash_table_lookup(contact->resources, "default");
|
||||||
|
return resource->show;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
p_contact_status(const PContact contact)
|
p_contact_status(const PContact contact)
|
||||||
{
|
{
|
||||||
return contact->status;
|
Resource *resource = g_hash_table_lookup(contact->resources, "default");
|
||||||
|
return resource->status;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
@ -143,24 +133,27 @@ p_contact_last_activity(const PContact contact)
|
|||||||
const char *
|
const char *
|
||||||
p_contact_caps_str(const PContact contact)
|
p_contact_caps_str(const PContact contact)
|
||||||
{
|
{
|
||||||
return contact->caps_str;
|
Resource *resource = g_hash_table_lookup(contact->resources, "default");
|
||||||
|
return resource->caps_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
p_contact_set_presence(const PContact contact, const char * const presence)
|
p_contact_set_presence(const PContact contact, const char * const presence)
|
||||||
{
|
{
|
||||||
FREE_SET_NULL(contact->presence);
|
Resource *resource = g_hash_table_lookup(contact->resources, "default");
|
||||||
|
FREE_SET_NULL(resource->show);
|
||||||
if (presence != NULL) {
|
if (presence != NULL) {
|
||||||
contact->presence = strdup(presence);
|
resource->show = strdup(presence);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
p_contact_set_status(const PContact contact, const char * const status)
|
p_contact_set_status(const PContact contact, const char * const status)
|
||||||
{
|
{
|
||||||
FREE_SET_NULL(contact->status);
|
Resource *resource = g_hash_table_lookup(contact->resources, "default");
|
||||||
|
FREE_SET_NULL(resource->status);
|
||||||
if (status != NULL) {
|
if (status != NULL) {
|
||||||
contact->status = strdup(status);
|
resource->status = strdup(status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,8 +188,9 @@ p_contact_set_last_activity(const PContact contact, GDateTime *last_activity)
|
|||||||
void
|
void
|
||||||
p_contact_set_caps_str(const PContact contact, const char * const caps_str)
|
p_contact_set_caps_str(const PContact contact, const char * const caps_str)
|
||||||
{
|
{
|
||||||
FREE_SET_NULL(contact->caps_str);
|
Resource *resource = g_hash_table_lookup(contact->resources, "default");
|
||||||
|
FREE_SET_NULL(resource->caps_str);
|
||||||
if (caps_str != NULL) {
|
if (caps_str != NULL) {
|
||||||
contact->caps_str = strdup(caps_str);
|
resource->caps_str = strdup(caps_str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,9 @@ Resource * resource_new(const char * const name, const char * const show,
|
|||||||
assert(show != NULL);
|
assert(show != NULL);
|
||||||
Resource *new_resource = malloc(sizeof(struct resource_t));
|
Resource *new_resource = malloc(sizeof(struct resource_t));
|
||||||
new_resource->name = strdup(name);
|
new_resource->name = strdup(name);
|
||||||
|
if (show == NULL || (strcmp(show, "") == 0))
|
||||||
|
new_resource->show = strdup("online");
|
||||||
|
else
|
||||||
new_resource->show = strdup(show);
|
new_resource->show = strdup(show);
|
||||||
if (status != NULL) {
|
if (status != NULL) {
|
||||||
new_resource->status = strdup(status);
|
new_resource->status = strdup(status);
|
||||||
|
Loading…
Reference in New Issue
Block a user