about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/command/command.c6
-rw-r--r--src/command/commands.c9
-rw-r--r--src/roster_list.c18
-rw-r--r--src/roster_list.h1
4 files changed, 31 insertions, 3 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 415399c5..6c52af2a 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -169,11 +169,12 @@ static struct cmd_t command_defs[] =
 
     { "/roster",
         cmd_roster, parse_args_with_freetext, 0, 3, NULL,
-        { "/roster [show|hide|by|size|add|remove|nick|clearnick] [offline|resource] [percent] [group|presence|none] [jid] [nickname]", "Manage your roster.",
-        { "/roster [show|hide|by|size|add|remove|nick|clearnick] [offline|resource] [percent] [group|presence|none] [jid] [nickname]",
+        { "/roster [online|show|hide|by|size|add|remove|nick|clearnick] [offline|resource] [percent] [group|presence|none] [jid] [nickname]", "Manage your roster.",
+        { "/roster [online|show|hide|by|size|add|remove|nick|clearnick] [offline|resource] [percent] [group|presence|none] [jid] [nickname]",
           "-------------------------------------------------------------------------------------------------------------------------",
           "View, add to, and remove from your roster.",
           "Passing no arguments lists all contacts in your roster.",
+          "online        - Show all online contacts in your roster.",
           "show          - Show the roster panel in the console window.",
           "hide          - Hide the roster panel.",
           "show offline  - Show offline contacts in the roster panel.",
@@ -1252,6 +1253,7 @@ cmd_init(void)
 
     roster_ac = autocomplete_new();
     autocomplete_add(roster_ac, "add");
+    autocomplete_add(roster_ac, "online");
     autocomplete_add(roster_ac, "nick");
     autocomplete_add(roster_ac, "clearnick");
     autocomplete_add(roster_ac, "remove");
diff --git a/src/command/commands.c b/src/command/commands.c
index 081c8f10..fc95f521 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -1358,6 +1358,14 @@ cmd_roster(gchar **args, struct cmd_help_t help)
     if (args[0] == NULL) {
         GSList *list = roster_get_contacts();
         cons_show_roster(list);
+        g_slist_free(list);
+        return TRUE;
+
+    // show roster, only online contacts
+    } else if(g_strcmp0(args[0], "online") == 0){
+        GSList *list = roster_get_contacts_online();
+        cons_show_roster(list);
+        g_slist_free(list);
         return TRUE;
 
     // set roster size
@@ -4056,4 +4064,3 @@ gint _compare_commands(Command *a, Command *b)
 
     return result;
 }
-
diff --git a/src/roster_list.c b/src/roster_list.c
index 941b6321..2d01d205 100644
--- a/src/roster_list.c
+++ b/src/roster_list.c
@@ -307,6 +307,24 @@ roster_get_contacts(void)
     return result;
 }
 
+GSList *
+roster_get_contacts_online(void)
+{
+    GSList *result = NULL;
+    GHashTableIter iter;
+    gpointer key;
+    gpointer value;
+
+    g_hash_table_iter_init(&iter, contacts);
+    while (g_hash_table_iter_next(&iter, &key, &value)) {
+        if(strcmp(p_contact_presence(value), "offline"))
+            result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_contacts);
+    }
+
+    // resturn all contact structs
+    return result;
+}
+
 gboolean
 roster_has_pending_subscriptions(void)
 {
diff --git a/src/roster_list.h b/src/roster_list.h
index 13b0bac7..7743ece6 100644
--- a/src/roster_list.h
+++ b/src/roster_list.h
@@ -57,6 +57,7 @@ gboolean roster_add(const char * const barejid, const char * const name, GSList
     const char * const subscription, gboolean pending_out);
 char * roster_barejid_from_name(const char * const name);
 GSList * roster_get_contacts(void);
+GSList * roster_get_contacts_online(void);
 gboolean roster_has_pending_subscriptions(void);
 char * roster_contact_autocomplete(char *search_str);
 char * roster_fulljid_autocomplete(char *search_str);