mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Split contact add and update presence
This commit is contained in:
parent
dbb7445324
commit
a0eda4207c
@ -156,6 +156,36 @@ p_contact_subscription(const PContact contact)
|
||||
return contact->subscription;
|
||||
}
|
||||
|
||||
void
|
||||
p_contact_set_presence(const PContact contact, const char * const presence)
|
||||
{
|
||||
if (contact->presence != NULL) {
|
||||
free(contact->presence);
|
||||
contact->presence = NULL;
|
||||
}
|
||||
|
||||
if (presence == NULL) {
|
||||
contact->presence = NULL;
|
||||
} else {
|
||||
contact->presence = strdup(presence);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
p_contact_set_status(const PContact contact, const char * const status)
|
||||
{
|
||||
if (contact->status != NULL) {
|
||||
free(contact->status);
|
||||
contact->status = NULL;
|
||||
}
|
||||
|
||||
if (status == NULL) {
|
||||
contact->status = NULL;
|
||||
} else {
|
||||
contact->status = strdup(status);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
p_contacts_equal_deep(const PContact c1, const PContact c2)
|
||||
{
|
||||
|
@ -35,6 +35,8 @@ const char * p_contact_name(PContact contact);
|
||||
const char * p_contact_presence(PContact contact);
|
||||
const char * p_contact_status(PContact contact);
|
||||
const char * p_contact_subscription(const PContact contact);
|
||||
void p_contact_set_presence(const PContact contact, const char * const presence);
|
||||
void p_contact_set_status(const PContact contact, const char * const status);
|
||||
int p_contacts_equal_deep(const PContact c1, const PContact c2);
|
||||
|
||||
#endif
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <glib.h>
|
||||
|
||||
#include "contact.h"
|
||||
#include "log.h"
|
||||
#include "prof_autocomplete.h"
|
||||
|
||||
static PAutocomplete ac;
|
||||
@ -60,58 +61,41 @@ contact_list_add(const char * const jid, const char * const name,
|
||||
{
|
||||
PContact contact = g_hash_table_lookup(contacts, jid);
|
||||
|
||||
// contact not yet in list
|
||||
if (contact == NULL) {
|
||||
contact = p_contact_new(jid, name, presence, status, subscription);
|
||||
g_hash_table_insert(contacts, strdup(jid), contact);
|
||||
|
||||
// contact already exists, update non NULL arguments
|
||||
} else {
|
||||
char *new_name = NULL;
|
||||
if (name != NULL) {
|
||||
new_name = strdup(name);
|
||||
} else {
|
||||
if (p_contact_name(contact) != NULL) {
|
||||
new_name = strdup(p_contact_name(contact));
|
||||
}
|
||||
}
|
||||
|
||||
char *new_presence = NULL;
|
||||
if (presence != NULL) {
|
||||
new_presence = strdup(presence);
|
||||
} else {
|
||||
if (p_contact_presence(contact) != NULL) {
|
||||
new_presence = strdup(p_contact_presence(contact));
|
||||
}
|
||||
}
|
||||
|
||||
char *new_status = NULL;
|
||||
if (status != NULL) {
|
||||
new_status = strdup(status);
|
||||
} else {
|
||||
if (p_contact_status(contact) != NULL) {
|
||||
new_status = strdup(p_contact_status(contact));
|
||||
}
|
||||
}
|
||||
|
||||
char *new_subscription = NULL;
|
||||
if (subscription != NULL) {
|
||||
new_subscription = strdup(subscription);
|
||||
} else {
|
||||
if (p_contact_subscription(contact) != NULL) {
|
||||
new_subscription = strdup(p_contact_subscription(contact));
|
||||
}
|
||||
}
|
||||
|
||||
PContact new_contact = p_contact_new(jid, new_name, new_presence,
|
||||
new_status, new_subscription);
|
||||
|
||||
g_hash_table_replace(contacts, strdup(jid), new_contact);
|
||||
log_warning("Duplicate roster entry: %s", jid);
|
||||
}
|
||||
|
||||
p_autocomplete_add(ac, strdup(jid));
|
||||
}
|
||||
|
||||
gboolean
|
||||
contact_list_update_contact(const char * const jid, const char * const presence,
|
||||
const char * const status)
|
||||
{
|
||||
gboolean changed = FALSE;
|
||||
PContact contact = g_hash_table_lookup(contacts, jid);
|
||||
|
||||
if (contact == NULL) {
|
||||
log_warning("Contact not in list: %s", jid);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (g_strcmp0(p_contact_presence(contact), presence) != 0) {
|
||||
p_contact_set_presence(contact, presence);
|
||||
changed = TRUE;
|
||||
}
|
||||
|
||||
if (g_strcmp0(p_contact_status(contact), status) != 0) {
|
||||
p_contact_set_status(contact, status);
|
||||
changed = TRUE;
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
GSList *
|
||||
get_contact_list(void)
|
||||
{
|
||||
|
@ -33,6 +33,8 @@ void contact_list_reset_search_attempts(void);
|
||||
void contact_list_add(const char * const jid, const char * const name,
|
||||
const char * const presence, const char * const status,
|
||||
const char * const subscription);
|
||||
gboolean contact_list_update_contact(const char * const jid, const char * const presence,
|
||||
const char * const status);
|
||||
GSList * get_contact_list(void);
|
||||
char * contact_list_find_contact(char *search_str);
|
||||
PContact contact_list_get_contact(const char const *jid);
|
||||
|
@ -165,7 +165,9 @@ prof_handle_failed_login(void)
|
||||
void
|
||||
prof_handle_contact_online(char *contact, char *show, char *status)
|
||||
{
|
||||
contact_list_add(contact, NULL, show, status, NULL);
|
||||
gboolean updated = contact_list_update_contact(contact, show, status);
|
||||
|
||||
if (updated) {
|
||||
PContact result = contact_list_get_contact(contact);
|
||||
if (p_contact_subscription(result) != NULL) {
|
||||
if (strcmp(p_contact_subscription(result), "none") != 0) {
|
||||
@ -174,11 +176,14 @@ prof_handle_contact_online(char *contact, char *show, char *status)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_contact_offline(char *contact, char *show, char *status)
|
||||
{
|
||||
contact_list_add(contact, NULL, "offline", status, NULL);
|
||||
gboolean updated = contact_list_update_contact(contact, "offline", status);
|
||||
|
||||
if (updated) {
|
||||
PContact result = contact_list_get_contact(contact);
|
||||
if (p_contact_subscription(result) != NULL) {
|
||||
if (strcmp(p_contact_subscription(result), "none") != 0) {
|
||||
@ -187,6 +192,7 @@ prof_handle_contact_offline(char *contact, char *show, char *status)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_create_config_directory(void)
|
||||
|
Loading…
Reference in New Issue
Block a user