about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-11-13 00:22:22 +0000
committerJames Booth <boothj5@gmail.com>2014-11-13 00:22:22 +0000
commit4e429fe7889c5dc35a51dc44d26dabd50d447bd1 (patch)
treef177386b3b89959dc4afa6a22fed08b02a206a0f
parent15d0f679f6a2b56fe58837a4257ea90df92d14e4 (diff)
downloadprofani-tty-4e429fe7889c5dc35a51dc44d26dabd50d447bd1.tar.gz
Implemented /roster by group
-rw-r--r--src/roster_list.c20
-rw-r--r--src/roster_list.h1
-rw-r--r--src/server_events.c8
-rw-r--r--src/server_events.h2
-rw-r--r--src/ui/core.c59
-rw-r--r--src/xmpp/roster.c2
6 files changed, 90 insertions, 2 deletions
diff --git a/src/roster_list.c b/src/roster_list.c
index c5c47862..0451d43f 100644
--- a/src/roster_list.c
+++ b/src/roster_list.c
@@ -333,6 +333,26 @@ roster_find_resource(char *search_str)
 }
 
 GSList *
+roster_get_nogroup(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)) {
+        GSList *groups = p_contact_groups(value);
+        if (groups == NULL) {
+            result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_contacts);
+        }
+    }
+
+    // resturn all contact structs
+    return result;
+}
+
+GSList *
 roster_get_group(const char * const group)
 {
     GSList *result = NULL;
diff --git a/src/roster_list.h b/src/roster_list.h
index 0c6861ad..280dbe1c 100644
--- a/src/roster_list.h
+++ b/src/roster_list.h
@@ -65,5 +65,6 @@ GSList * roster_get_groups(void);
 char * roster_find_group(char *search_str);
 char * roster_find_jid(char *search_str);
 GSList * roster_get_contacts_by_presence(const char * const presence);
+GSList * roster_get_nogroup(void);
 
 #endif
diff --git a/src/server_events.c b/src/server_events.c
index 0de5e713..ecc78915 100644
--- a/src/server_events.c
+++ b/src/server_events.c
@@ -629,6 +629,14 @@ handle_roster_add(const char * const barejid, const char * const name)
 }
 
 void
+handle_roster_update(const char * const barejid, const char * const name,
+    GSList *groups, const char * const subscription, gboolean pending_out)
+{
+    roster_update(barejid, name, groups, subscription, pending_out);
+    ui_roster();
+}
+
+void
 handle_autoping_cancel(void)
 {
     prefs_set_autoping(0);
diff --git a/src/server_events.h b/src/server_events.h
index 1155b9d1..ec83a50c 100644
--- a/src/server_events.h
+++ b/src/server_events.h
@@ -114,5 +114,7 @@ void handle_muc_self_online(const char * const room, const char * const nick, gb
 void handle_muc_occupant_online(const char * const room, const char * const nick, const char * const jid,
     const char * const role, const char * const affiliation, const char * const actor, const char * const reason,
     const char * const show_str, const char * const status_str);
+void handle_roster_update(const char * const barejid, const char * const name,
+    GSList *groups, const char * const subscription, gboolean pending_out);
 
 #endif
diff --git a/src/ui/core.c b/src/ui/core.c
index f8062b1f..a9b7b4c9 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -402,36 +402,42 @@ _ui_roster_add(const char * const barejid, const char * const name)
     } else {
         cons_show("Roster item added: %s", barejid);
     }
+    ui_roster();
 }
 
 static void
 _ui_roster_remove(const char * const barejid)
 {
     cons_show("Roster item removed: %s", barejid);
+    ui_roster();
 }
 
 static void
 _ui_contact_already_in_group(const char * const contact, const char * const group)
 {
     cons_show("%s already in group %s", contact, group);
+    ui_roster();
 }
 
 static void
 _ui_contact_not_in_group(const char * const contact, const char * const group)
 {
     cons_show("%s is not currently in group %s", contact, group);
+    ui_roster();
 }
 
 static void
 _ui_group_added(const char * const contact, const char * const group)
 {
     cons_show("%s added to group %s", contact, group);
+    ui_roster();
 }
 
 static void
 _ui_group_removed(const char * const contact, const char * const group)
 {
     cons_show("%s removed from group %s", contact, group);
+    ui_roster();
 }
 
 static void
@@ -577,6 +583,7 @@ _ui_disconnected(void)
     title_bar_set_presence(CONTACT_OFFLINE);
     status_bar_clear_message();
     status_bar_update_virtual();
+    ui_hide_roster();
 }
 
 static void
@@ -2864,10 +2871,10 @@ static void
 _ui_roster_contacts_by_presence(const char * const presence, char *title)
 {
     ProfWin *window = wins_get_console();
-    GSList *contacts = roster_get_contacts_by_presence(presence);
     wattron(window->subwin, COLOUR_ROOMINFO);
     win_printline_nowrap(window->subwin, title);
     wattroff(window->subwin, COLOUR_ROOMINFO);
+    GSList *contacts = roster_get_contacts_by_presence(presence);
     if (contacts) {
         GSList *curr_contact = contacts;
         while (curr_contact) {
@@ -2880,6 +2887,47 @@ _ui_roster_contacts_by_presence(const char * const presence, char *title)
 }
 
 static void
+_ui_roster_contacts_by_group(char *group)
+{
+    ProfWin *window = wins_get_console();
+    wattron(window->subwin, COLOUR_ROOMINFO);
+    GString *title = g_string_new(" -");
+    g_string_append(title, group);
+    win_printline_nowrap(window->subwin, title->str);
+    g_string_free(title, TRUE);
+    wattroff(window->subwin, COLOUR_ROOMINFO);
+    GSList *contacts = roster_get_group(group);
+    if (contacts) {
+        GSList *curr_contact = contacts;
+        while (curr_contact) {
+            PContact contact = curr_contact->data;
+            _ui_roster_contact(contact);
+            curr_contact = g_slist_next(curr_contact);
+        }
+    }
+    g_slist_free(contacts);
+}
+
+static void
+_ui_roster_contacts_by_no_group(void)
+{
+    ProfWin *window = wins_get_console();
+    GSList *contacts = roster_get_nogroup();
+    if (contacts) {
+        wattron(window->subwin, COLOUR_ROOMINFO);
+        win_printline_nowrap(window->subwin, " -no group");
+        wattroff(window->subwin, COLOUR_ROOMINFO);
+        GSList *curr_contact = contacts;
+        while (curr_contact) {
+            PContact contact = curr_contact->data;
+            _ui_roster_contact(contact);
+            curr_contact = g_slist_next(curr_contact);
+        }
+    }
+    g_slist_free(contacts);
+}
+
+static void
 _ui_roster(void)
 {
     ProfWin *window = wins_get_console();
@@ -2894,6 +2942,15 @@ _ui_roster(void)
             if (prefs_get_boolean(PREF_ROSTER_OFFLINE)) {
                 _ui_roster_contacts_by_presence("offline", " -Offline");
             }
+        } else if (g_strcmp0(prefs_get_string(PREF_ROSTER_BY), "group") == 0) {
+            werase(window->subwin);
+            GSList *groups = roster_get_groups();
+            GSList *curr_group = groups;
+            while (curr_group) {
+                _ui_roster_contacts_by_group(curr_group->data);
+                curr_group = g_slist_next(curr_group);
+            }
+            _ui_roster_contacts_by_no_group();
         } else {
             GSList *contacts = roster_get_contacts();
             if (contacts) {
diff --git a/src/xmpp/roster.c b/src/xmpp/roster.c
index 5f9fa6f9..d269e995 100644
--- a/src/xmpp/roster.c
+++ b/src/xmpp/roster.c
@@ -280,7 +280,7 @@ _roster_set_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
                 handle_roster_add(barejid, name);
             }
         } else {
-            roster_update(barejid, name, groups, sub, pending_out);
+            handle_roster_update(barejid, name, groups, sub, pending_out);
         }
     }