about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2020-01-23 19:52:41 +0100
committerMichael Vetter <jubalh@iodoru.org>2020-01-23 19:52:41 +0100
commit6567936406918275a4078020aef8fd2d57fe1793 (patch)
tree1a53994b53c94ffc8e77c37aaf4175d6717adb76 /src
parentff574371557d629d0f0a1b6613788453019d3621 (diff)
downloadprofani-tty-6567936406918275a4078020aef8fd2d57fe1793.tar.gz
Refactor rosterwin_roster()
Use helper function for duplicate code.
Diffstat (limited to 'src')
-rw-r--r--src/ui/rosterwin.c35
1 files changed, 17 insertions, 18 deletions
diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c
index 02bed821..d0cb8b29 100644
--- a/src/ui/rosterwin.c
+++ b/src/ui/rosterwin.c
@@ -68,6 +68,7 @@ static void _rosterwin_rooms(ProfLayoutSplit *layout, char *title, GList *rooms)
 static void _rosterwin_rooms_by_service(ProfLayoutSplit *layout);
 static void _rosterwin_rooms_header(ProfLayoutSplit *layout, GList *rooms, char *title);
 static void _rosterwin_room(ProfLayoutSplit *layout, ProfMucWin *mucwin);
+static void _rosterwin_print_rooms(ProfLayoutSplit *layout);
 
 static void _rosterwin_private_chats(ProfLayoutSplit *layout, GList *orphaned_privchats);
 static void _rosterwin_private_header(ProfLayoutSplit *layout, GList *privs);
@@ -97,15 +98,7 @@ rosterwin_roster(void)
 
     char *roomspos = prefs_get_string(PREF_ROSTER_ROOMS_POS);
     if (prefs_get_boolean(PREF_ROSTER_ROOMS) && (g_strcmp0(roomspos, "first") == 0)) {
-        char *roomsbypref = prefs_get_string(PREF_ROSTER_ROOMS_BY);
-        if (g_strcmp0(roomsbypref, "service") == 0) {
-            _rosterwin_rooms_by_service(layout);
-        } else {
-            GList *rooms = muc_rooms();
-            _rosterwin_rooms(layout, "Rooms", rooms);
-            g_list_free(rooms);
-        }
-        prefs_free_string(roomsbypref);
+        _rosterwin_print_rooms(layout);
 
         GList *orphaned_privchats = NULL;
         GList *privchats = wins_get_private_chats(NULL);
@@ -158,15 +151,7 @@ rosterwin_roster(void)
     }
 
     if (prefs_get_boolean(PREF_ROSTER_ROOMS) && (g_strcmp0(roomspos, "last") == 0)) {
-        char *roomsbypref = prefs_get_string(PREF_ROSTER_ROOMS_BY);
-        if (g_strcmp0(roomsbypref, "service") == 0) {
-            _rosterwin_rooms_by_service(layout);
-        } else {
-            GList *rooms = muc_rooms();
-            _rosterwin_rooms(layout, "Rooms", rooms);
-            g_list_free(rooms);
-        }
-        prefs_free_string(roomsbypref);
+        _rosterwin_print_rooms(layout);
 
         GList *orphaned_privchats = NULL;
         GList *privchats = wins_get_private_chats(NULL);
@@ -902,6 +887,20 @@ _rosterwin_room(ProfLayoutSplit *layout, ProfMucWin *mucwin)
 }
 
 static void
+_rosterwin_print_rooms(ProfLayoutSplit *layout)
+{
+    char *roomsbypref = prefs_get_string(PREF_ROSTER_ROOMS_BY);
+    if (g_strcmp0(roomsbypref, "service") == 0) {
+        _rosterwin_rooms_by_service(layout);
+    } else {
+        GList *rooms = muc_rooms();
+        _rosterwin_rooms(layout, "Rooms", rooms);
+        g_list_free(rooms);
+    }
+    prefs_free_string(roomsbypref);
+}
+
+static void
 _rosterwin_private_chats(ProfLayoutSplit *layout, GList *orphaned_privchats)
 {
     GList *privs = NULL;