From 681c3b6be260ecc31c3b62df3f687c69ab9cc2c3 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 14 Mar 2013 22:03:38 +0000 Subject: [PATCH] Show name as well as jid for room list --- src/profanity.c | 10 +--------- src/ui/ui.h | 1 + src/ui/windows.c | 20 ++++++++++++++++++++ src/xmpp/iq.c | 27 +++++++++++++++++++-------- src/xmpp/xmpp.h | 5 +++++ 5 files changed, 46 insertions(+), 17 deletions(-) diff --git a/src/profanity.c b/src/profanity.c index e2e06bab..627a778e 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -404,15 +404,7 @@ prof_handle_version_result(const char * const jid, const char * const presence, void prof_handle_room_list(GSList *rooms, const char *conference_node) { - if ((rooms != NULL) && (g_slist_length(rooms) > 0)) { - cons_show("Chat rooms at %s:", conference_node); - while (rooms != NULL) { - cons_show(" %s", rooms->data); - rooms = g_slist_next(rooms); - } - } else { - cons_show("No chat rooms at %s", conference_node); - } + cons_show_room_list(rooms, conference_node); win_current_page_off(); } diff --git a/src/ui/ui.h b/src/ui/ui.h index 3752fbd7..9c06089b 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -173,6 +173,7 @@ void cons_show_software_version(const char * const jid, const char * const presence, const char * const name, const char * const version, const char * const os); void cons_show_account_list(gchar **accounts); +void cons_show_room_list(GSList *room, const char * const conference_node); // status bar actions void status_bar_refresh(void); diff --git a/src/ui/windows.c b/src/ui/windows.c index d98f1091..33b7ace3 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -1303,6 +1303,26 @@ cons_show_software_version(const char * const jid, const char * const presence, } } +void +cons_show_room_list(GSList *rooms, const char * const conference_node) +{ + if ((rooms != NULL) && (g_slist_length(rooms) > 0)) { + cons_show("Chat rooms at %s:", conference_node); + while (rooms != NULL) { + DiscoItem *room = rooms->data; + _win_show_time(console->win, '-'); + wprintw(console->win, " %s", room->jid); + if (room->name != NULL) { + wprintw(console->win, ", (%s)", room->name); + } + wprintw(console->win, "\n"); + rooms = g_slist_next(rooms); + } + } else { + cons_show("No chat rooms at %s", conference_node); + } +} + void cons_show_status(const char * const contact) { diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index b3053c5a..5e71fa5b 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -492,20 +492,31 @@ _iq_handle_discoitems_result(xmpp_conn_t * const conn, xmpp_stanza_t * const sta log_debug("Recieved diso#items response"); const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *stanza_name = NULL; + const char *item_jid = NULL; + const char *item_name = NULL; if (g_strcmp0(id, "confreq") == 0) { log_debug("Response to query: %s", id); - GSList *rooms = NULL; + GSList *items = NULL; xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); if (query != NULL) { xmpp_stanza_t *child = xmpp_stanza_get_children(query); while (child != NULL) { - const char *name = xmpp_stanza_get_name(child); - if ((name != NULL) && (g_strcmp0(name, STANZA_NAME_ITEM) == 0)) { - const char *jid = xmpp_stanza_get_attribute(child, STANZA_ATTR_JID); - if (jid != NULL) { - rooms = g_slist_append(rooms, strdup(jid)); + stanza_name = xmpp_stanza_get_name(child); + if ((stanza_name != NULL) && (g_strcmp0(stanza_name, STANZA_NAME_ITEM) == 0)) { + item_jid = xmpp_stanza_get_attribute(child, STANZA_ATTR_JID); + if (item_jid != NULL) { + DiscoItem *item = malloc(sizeof(struct disco_item_t)); + item->jid = strdup(item_jid); + item_name = xmpp_stanza_get_attribute(child, STANZA_ATTR_NAME); + if (item_name != NULL) { + item->name = strdup(item_name); + } else { + item->name = NULL; + } + items = g_slist_append(items, item); } } @@ -513,8 +524,8 @@ _iq_handle_discoitems_result(xmpp_conn_t * const conn, xmpp_stanza_t * const sta } } - prof_handle_room_list(rooms, from); - g_slist_free_full(rooms, free); + prof_handle_room_list(items, from); + g_slist_free_full(items, free); } else if ((id != NULL) && (g_strcmp0(id, "discoitemsreq") == 0)) { cons_show("GOT DISO ITEMS RESULT"); } diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index 16e293a4..eb3c3c09 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -57,6 +57,11 @@ typedef struct capabilities_t { GSList *features; } Capabilities; +typedef struct disco_item_t { + char *jid; + char *name; +} DiscoItem; + // connection functions void jabber_init(const int disable_tls); jabber_conn_status_t jabber_connect_with_details(const char * const jid,