about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/command/command.c56
-rw-r--r--src/ui/console.c36
-rw-r--r--src/ui/ui.h1
-rw-r--r--src/xmpp/presence.c13
-rw-r--r--src/xmpp/xmpp.h1
5 files changed, 86 insertions, 21 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 79e1fdd2..6309ad75 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -276,7 +276,7 @@ static struct cmd_t main_commands[] =
           NULL } } },
 
     { "/roster",
-        _cmd_roster, parse_args_with_freetext, 2, 3,
+        _cmd_roster, parse_args_with_freetext, 0, 3,
         { "/roster nick jid [handle]", "Add or change a contacts handle.",
         { "/roster nick jid [handle]",
           "-------------------------",
@@ -2008,35 +2008,49 @@ _cmd_msg(gchar **args, struct cmd_help_t help)
 static gboolean
 _cmd_roster(gchar **args, struct cmd_help_t help)
 {
+    // show roster
+    if (args[0] == NULL) {
+        GSList *list = roster_get_contacts();
+        cons_show_roster(list);
+        return TRUE;
+    }
+
+    // first arg invalid
     if (strcmp(args[0], "nick") != 0) {
         cons_show("Usage: %s", help.usage);
         return TRUE;
-    } else {
-        char *jid = args[1];
-        char *name = args[2];
-        jabber_conn_status_t conn_status = jabber_get_connection_status();
+    }
 
-        if (conn_status != JABBER_CONNECTED) {
-            cons_show("You are not currently connected.");
-            return TRUE;
-        }
+    if (args[1] == NULL) {
+        cons_show("Usage: %s", help.usage);
+        return TRUE;
+    }
 
-        // contact does not exist
-        PContact contact = roster_get_contact(jid);
-        if (contact == NULL) {
-            cons_show("Contact not found in roster: %s", jid);
-            return TRUE;
-        }
+    char *jid = args[1];
+    char *name = args[2];
+    jabber_conn_status_t conn_status = jabber_get_connection_status();
 
-        roster_change_name(jid, name);
+    if (conn_status != JABBER_CONNECTED) {
+        cons_show("You are not currently connected.");
+        return TRUE;
+    }
 
-        if (name == NULL) {
-            cons_show("Nickname for %s removed.", jid);
-        } else {
-            cons_show("Nickname for %s set to: %s.", jid, name);
-        }
+    // contact does not exist
+    PContact contact = roster_get_contact(jid);
+    if (contact == NULL) {
+        cons_show("Contact not found in roster: %s", jid);
         return TRUE;
     }
+
+    roster_change_name(jid, name);
+
+    if (name == NULL) {
+        cons_show("Nickname for %s removed.", jid);
+    } else {
+        cons_show("Nickname for %s set to: %s.", jid, name);
+    }
+
+    return TRUE;
 }
 
 static gboolean
diff --git a/src/ui/console.c b/src/ui/console.c
index 4e33376a..95c7d9b0 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -1240,6 +1240,42 @@ cons_navigation_help(void)
 }
 
 void
+cons_show_roster(GSList *list)
+{
+    GSList *curr = list;
+    cons_show("");
+    cons_show("Roster:");
+
+    while(curr) {
+        PContact contact = curr->data;
+        GString *title = g_string_new("  ");
+        title = g_string_append(title, p_contact_barejid(contact));
+        if (p_contact_name(contact) != NULL) {
+            title = g_string_append(title, " (");
+            title = g_string_append(title, strdup(p_contact_name(contact)));
+            title = g_string_append(title, ")");
+        }
+        cons_show(title->str);
+        g_string_free(title, TRUE);
+
+        GString *sub = g_string_new("    Subscription : ");
+        sub = g_string_append(sub, p_contact_subscription(contact));
+        if (p_contact_pending_out(contact)) {
+            sub = g_string_append(sub, ", request sent");
+        }
+        if (presence_sub_request_exists(p_contact_barejid(contact))) {
+            sub = g_string_append(sub, ", request received");
+        }
+        cons_show(sub->str);
+        g_string_free(sub, TRUE);
+        curr = g_slist_next(curr);
+    }
+
+    ui_console_dirty();
+    cons_alert();
+}
+
+void
 cons_show_contacts(GSList *list)
 {
     GSList *curr = list;
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 1f37b1f2..be57a0be 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -165,6 +165,7 @@ void cons_show_word(const char * const word);
 void cons_show_error(const char * const cmd, ...);
 void cons_highlight_show(const char * const cmd);
 void cons_show_contacts(GSList * list);
+void cons_show_roster(GSList * list);
 void cons_show_wins(void);
 void cons_show_status(const char * const barejid);
 void cons_show_info(PContact pcontact);
diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c
index 6a7c214f..5aa94c1d 100644
--- a/src/xmpp/presence.c
+++ b/src/xmpp/presence.c
@@ -153,6 +153,19 @@ presence_sub_request_find(char * search_str)
     return autocomplete_complete(sub_requests_ac, search_str);
 }
 
+gboolean
+presence_sub_request_exists(const char * const bare_jid)
+{
+    GSList *requests = autocomplete_get_list(sub_requests_ac);
+    while (requests != NULL) {
+        if (strcmp(requests->data, bare_jid) == 0) {
+            return TRUE;
+        }
+        requests = g_slist_next(requests);
+    }
+    return FALSE;
+}
+
 void
 presence_reset_sub_request_search(void)
 {
diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h
index 70b41d59..9cc33674 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -113,6 +113,7 @@ void presence_change_room_nick(const char * const room, const char * const nick)
 void presence_leave_chat_room(const char * const room_jid);
 void presence_update(resource_presence_t status, const char * const msg,
     int idle);
+gboolean presence_sub_request_exists(const char * const bare_jid);
 
 // iq functions
 void iq_send_software_version(const char * const fulljid);