diff options
author | James Booth <boothj5@gmail.com> | 2012-10-28 21:16:22 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2012-10-28 21:16:22 +0000 |
commit | 4e0a631fee54bd5e4fa37127ecdec84a62a72c3f (patch) | |
tree | 3ddd1e214e8ff1cb2c65dc63f3a05cca420d43d2 /src | |
parent | d13794bf60747323c434ee8b25523bc12c2f540d (diff) | |
download | profani-tty-4e0a631fee54bd5e4fa37127ecdec84a62a72c3f.tar.gz |
Subscription management
Diffstat (limited to 'src')
-rw-r--r-- | src/contact.c | 24 | ||||
-rw-r--r-- | src/contact.h | 1 | ||||
-rw-r--r-- | src/jabber.c | 8 | ||||
-rw-r--r-- | src/windows.c | 74 |
4 files changed, 68 insertions, 39 deletions
diff --git a/src/contact.c b/src/contact.c index d217f4c8..2d58308a 100644 --- a/src/contact.c +++ b/src/contact.c @@ -59,6 +59,11 @@ p_contact_new(const char * const jid, const char * const name, else contact->status = NULL; + if (subscription != NULL) + contact->subscription = strdup(subscription); + else + contact->subscription = NULL; + return contact; } @@ -81,6 +86,11 @@ p_contact_copy(PContact contact) else copy->status = NULL; + if (contact->subscription != NULL) + copy->subscription = strdup(contact->subscription); + else + copy->subscription = NULL; + return copy; } @@ -107,6 +117,11 @@ p_contact_free(PContact contact) contact->status = NULL; } + if (contact->subscription != NULL) { + free(contact->subscription); + contact->subscription = NULL; + } + free(contact); contact = NULL; } @@ -135,6 +150,12 @@ p_contact_status(const PContact contact) return contact->status; } +const char * +p_contact_subscription(const PContact contact) +{ + return contact->subscription; +} + int p_contacts_equal_deep(const PContact c1, const PContact c2) { @@ -142,6 +163,7 @@ p_contacts_equal_deep(const PContact c1, const PContact c2) int name_eq = (g_strcmp0(c1->name, c2->name) == 0); int presence_eq = (g_strcmp0(c1->presence, c2->presence) == 0); int status_eq = (g_strcmp0(c1->status, c2->status) == 0); + int subscription_eq = (g_strcmp0(c1->subscription, c2->subscription) == 0); - return (jid_eq && name_eq && presence_eq && status_eq); + return (jid_eq && name_eq && presence_eq && status_eq && subscription_eq); } diff --git a/src/contact.h b/src/contact.h index 45c9780f..194d867b 100644 --- a/src/contact.h +++ b/src/contact.h @@ -34,6 +34,7 @@ const char * p_contact_jid(PContact contact); 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); int p_contacts_equal_deep(const PContact c1, const PContact c2); #endif diff --git a/src/jabber.c b/src/jabber.c index f9c4f0c7..f1626869 100644 --- a/src/jabber.c +++ b/src/jabber.c @@ -386,14 +386,8 @@ _roster_handler(xmpp_conn_t * const conn, const char *jid = xmpp_stanza_get_attribute(item, "jid"); const char *name = xmpp_stanza_get_attribute(item, "name"); const char *sub = xmpp_stanza_get_attribute(item, "subscription"); + contact_list_add(jid, name, "offline", NULL, sub); - if (sub != NULL) { - if (strcmp(sub, "none") != 0) { - - contact_list_add(jid, name, "offline", NULL, sub); - - } - } item = xmpp_stanza_get_next(item); } /* diff --git a/src/windows.c b/src/windows.c index 276d1eb8..c7e49020 100644 --- a/src/windows.c +++ b/src/windows.c @@ -703,44 +703,56 @@ cons_show_contacts(GSList *list) while(curr) { PContact contact = curr->data; + const char *jid = p_contact_jid(contact); + const char *name = p_contact_name(contact); const char *presence = p_contact_presence(contact); + const char *status = p_contact_status(contact); + const char *sub = p_contact_subscription(contact); - _win_show_time(_cons_win); + if (strcmp(sub, "none") != 0) { + _win_show_time(_cons_win); - if (strcmp(presence, "online") == 0) { - wattron(_cons_win, COLOUR_ONLINE); - } else if (strcmp(presence, "away") == 0) { - wattron(_cons_win, COLOUR_AWAY); - } else if (strcmp(presence, "chat") == 0) { - wattron(_cons_win, COLOUR_CHAT); - } else if (strcmp(presence, "dnd") == 0) { - wattron(_cons_win, COLOUR_DND); - } else if (strcmp(presence, "xa") == 0) { - wattron(_cons_win, COLOUR_XA); - } else { - wattron(_cons_win, COLOUR_OFFLINE); - } + if (strcmp(presence, "online") == 0) { + wattron(_cons_win, COLOUR_ONLINE); + } else if (strcmp(presence, "away") == 0) { + wattron(_cons_win, COLOUR_AWAY); + } else if (strcmp(presence, "chat") == 0) { + wattron(_cons_win, COLOUR_CHAT); + } else if (strcmp(presence, "dnd") == 0) { + wattron(_cons_win, COLOUR_DND); + } else if (strcmp(presence, "xa") == 0) { + wattron(_cons_win, COLOUR_XA); + } else { + wattron(_cons_win, COLOUR_OFFLINE); + } + + wprintw(_cons_win, "%s", jid); - wprintw(_cons_win, "%s", p_contact_jid(contact)); - wprintw(_cons_win, " is %s", presence); + if (name != NULL) { + wprintw(_cons_win, " (%s)", name); + } + + wprintw(_cons_win, " is %s", presence); - if (p_contact_status(contact)) - wprintw(_cons_win, ", \"%s\"", p_contact_status(contact)); + if (status != NULL) { + wprintw(_cons_win, ", \"%s\"", p_contact_status(contact)); + } - wprintw(_cons_win, "\n"); + wprintw(_cons_win, "\n"); - if (strcmp(presence, "online") == 0) { - wattroff(_cons_win, COLOUR_ONLINE); - } else if (strcmp(presence, "away") == 0) { - wattroff(_cons_win, COLOUR_AWAY); - } else if (strcmp(presence, "chat") == 0) { - wattroff(_cons_win, COLOUR_CHAT); - } else if (strcmp(presence, "dnd") == 0) { - wattroff(_cons_win, COLOUR_DND); - } else if (strcmp(presence, "xa") == 0) { - wattroff(_cons_win, COLOUR_XA); - } else { - wattroff(_cons_win, COLOUR_OFFLINE); + if (strcmp(presence, "online") == 0) { + wattroff(_cons_win, COLOUR_ONLINE); + } else if (strcmp(presence, "away") == 0) { + wattroff(_cons_win, COLOUR_AWAY); + } else if (strcmp(presence, "chat") == 0) { + wattroff(_cons_win, COLOUR_CHAT); + } else if (strcmp(presence, "dnd") == 0) { + wattroff(_cons_win, COLOUR_DND); + } else if (strcmp(presence, "xa") == 0) { + wattroff(_cons_win, COLOUR_XA); + } else { + wattroff(_cons_win, COLOUR_OFFLINE); + } } curr = g_slist_next(curr); |