1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Added p_contact_add_resource

This commit is contained in:
James Booth 2013-02-10 18:16:06 +00:00
parent 1a6490a5b7
commit 8c9f916246
5 changed files with 22 additions and 15 deletions

View File

@ -20,6 +20,7 @@
* *
*/ */
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -40,9 +41,7 @@ struct p_contact_t {
PContact PContact
p_contact_new(const char * const barejid, const char * const name, p_contact_new(const char * const barejid, const char * const name,
const char * const presence, const char * const status, const char * const subscription, gboolean pending_out)
const char * const subscription, gboolean pending_out,
const char * const caps_str)
{ {
PContact contact = malloc(sizeof(struct p_contact_t)); PContact contact = malloc(sizeof(struct p_contact_t));
contact->barejid = strdup(barejid); contact->barejid = strdup(barejid);
@ -63,16 +62,19 @@ p_contact_new(const char * const barejid, const char * const name,
contact->available_resources = g_hash_table_new_full(g_str_hash, g_str_equal, free, contact->available_resources = g_hash_table_new_full(g_str_hash, g_str_equal, free,
(GDestroyNotify)resource_destroy); (GDestroyNotify)resource_destroy);
// TODO, priority, last activity
if (g_strcmp0(presence, "offline") != 0) {
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);
}
return contact; return contact;
} }
void
p_contact_add_resource(PContact contact, Resource *resource)
{
assert(contact != NULL);
assert(resource != NULL);
g_hash_table_insert(contact->available_resources, strdup(resource->name), resource);
}
PContact PContact
p_contact_new_subscription(const char * const barejid, p_contact_new_subscription(const char * const barejid,
const char * const subscription, gboolean pending_out) const char * const subscription, gboolean pending_out)

View File

@ -23,14 +23,15 @@
#ifndef CONTACT_H #ifndef CONTACT_H
#define CONTACT_H #define CONTACT_H
#include "resource.h"
typedef struct p_contact_t *PContact; typedef struct p_contact_t *PContact;
PContact p_contact_new(const char * const barejid, const char * const name, PContact p_contact_new(const char * const barejid, const char * const name,
const char * const presence, const char * const status, const char * const subscription, gboolean pending_out);
const char * const subscription, gboolean pending_out,
const char * const caps_str);
PContact p_contact_new_subscription(const char * const barejid, PContact p_contact_new_subscription(const char * const barejid,
const char * const subscription, gboolean pending_out); const char * const subscription, gboolean pending_out);
void p_contact_add_resource(PContact contact, Resource *resource);
void p_contact_free(PContact contact); void p_contact_free(PContact contact);
const char* p_contact_barejid(PContact contact); const char* p_contact_barejid(PContact contact);
const char* p_contact_name(PContact contact); const char* p_contact_name(PContact contact);

View File

@ -70,8 +70,7 @@ contact_list_add(const char * const barejid, const char * const name,
PContact contact = g_hash_table_lookup(contacts, barejid); PContact contact = g_hash_table_lookup(contacts, barejid);
if (contact == NULL) { if (contact == NULL) {
contact = p_contact_new(barejid, name, "offline", NULL, subscription, contact = p_contact_new(barejid, name, subscription, pending_out);
pending_out, NULL);
g_hash_table_insert(contacts, strdup(barejid), contact); g_hash_table_insert(contacts, strdup(barejid), contact);
autocomplete_add(ac, strdup(barejid)); autocomplete_add(ac, strdup(barejid));
added = TRUE; added = TRUE;

View File

@ -220,7 +220,10 @@ muc_add_to_roster(const char * const room, const char * const nick,
(g_strcmp0(p_contact_status(old), status) != 0)) { (g_strcmp0(p_contact_status(old), status) != 0)) {
updated = TRUE; updated = TRUE;
} }
PContact contact = p_contact_new(nick, NULL, show, status, NULL, FALSE, caps_str); PContact contact = p_contact_new(nick, NULL, NULL, FALSE);
resource_presence_t resource_presence = resource_presence_from_string(show);
Resource *resource = resource_new("default", resource_presence, status, 0, caps_str);
p_contact_add_resource(contact, resource);
g_hash_table_replace(chat_room->roster, strdup(nick), contact); g_hash_table_replace(chat_room->roster, strdup(nick), contact);
} }

View File

@ -23,6 +23,8 @@
#ifndef RESOURCE_H #ifndef RESOURCE_H
#define RESOURCE_H #define RESOURCE_H
#include "common.h"
typedef struct resource_t { typedef struct resource_t {
char *name; char *name;
resource_presence_t presence; resource_presence_t presence;