about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/event/server_events.c1
-rw-r--r--src/ui/rosterwin.c69
-rw-r--r--src/window_list.c25
-rw-r--r--src/window_list.h1
4 files changed, 95 insertions, 1 deletions
diff --git a/src/event/server_events.c b/src/event/server_events.c
index 872dc74b..faeb1bfe 100644
--- a/src/event/server_events.c
+++ b/src/event/server_events.c
@@ -315,6 +315,7 @@ sv_ev_incoming_private_message(const char *const fulljid, char *message)
         privatewin = (ProfPrivateWin*)window;
     }
     privwin_incoming_msg(privatewin, message, NULL);
+    rosterwin_roster();
 }
 
 void
diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c
index 86472d48..ec19b56f 100644
--- a/src/ui/rosterwin.c
+++ b/src/ui/rosterwin.c
@@ -519,6 +519,73 @@ _rosterwin_room(ProfLayoutSplit *layout, ProfMucWin *mucwin)
     } else {
         wattroff(layout->subwin, theme_attrs(THEME_ROSTER_ROOM));
     }
+
+    // TODO if show private chat with room
+    GList *privs = wins_get_private_chats(mucwin->roomjid);
+    GList *curr = privs;
+    while (curr) {
+        ProfPrivateWin *privwin = curr->data;
+        win_sub_newline_lazy(layout->subwin);
+
+        GString *privmsg = g_string_new(" ");
+        indent = prefs_get_roster_contact_indent();
+        current_indent = 0;
+        if (indent > 0) {
+            current_indent += indent;
+            while (indent > 0) {
+                g_string_append(privmsg, " ");
+                indent--;
+            }
+        }
+
+        // TODO add preference
+        indent = prefs_get_roster_resource_indent();
+        if (indent > 0) {
+            current_indent += indent;
+            while (indent > 0) {
+                g_string_append(privmsg, " ");
+                indent--;
+            }
+        }
+
+        // TODO add preference
+        unreadpos = prefs_get_string(PREF_ROSTER_ROOMS_UNREAD);
+        if ((g_strcmp0(unreadpos, "before") == 0) && privwin->unread > 0) {
+            g_string_append_printf(privmsg, "(%d) ", privwin->unread);
+        }
+
+        // TODO add preference
+        ch = '/';
+        if (ch) {
+            g_string_append_printf(privmsg, "%c", ch);
+        }
+
+        g_string_append(privmsg, privwin->fulljid + strlen(mucwin->roomjid) + 1);
+
+        if ((g_strcmp0(unreadpos, "after") == 0) && privwin->unread > 0) {
+            g_string_append_printf(privmsg, " (%d)", privwin->unread);
+        }
+        prefs_free_string(unreadpos);
+
+        if (privwin->unread > 0) {
+            wattron(layout->subwin, theme_attrs(THEME_ROSTER_ROOM_UNREAD));
+        } else {
+            wattron(layout->subwin, theme_attrs(THEME_ROSTER_ROOM));
+        }
+
+        win_sub_print(layout->subwin, privmsg->str, FALSE, wrap, current_indent);
+
+        if (mucwin->unread > 0) {
+            wattroff(layout->subwin, theme_attrs(THEME_ROSTER_ROOM_UNREAD));
+        } else {
+            wattroff(layout->subwin, theme_attrs(THEME_ROSTER_ROOM));
+        }
+
+        g_string_free(privmsg, TRUE);
+        curr = g_list_next(curr);
+    }
+
+    g_list_free(privs);
 }
 
 static int
@@ -560,7 +627,7 @@ _rosterwin_rooms(ProfLayoutSplit *layout, gboolean newline)
     }
     g_list_free(rooms);
 
-    // if this group has contacts, or if we want to show empty groups
+    // if there are active rooms, or if we want to show empty groups
     if (rooms_sorted || prefs_get_boolean(PREF_ROSTER_EMPTY)) {
         if (newline) {
             win_sub_newline_lazy(layout->subwin);
diff --git a/src/window_list.c b/src/window_list.c
index 5147db84..cd6724ac 100644
--- a/src/window_list.c
+++ b/src/window_list.c
@@ -172,6 +172,31 @@ wins_get_private(const char *const fulljid)
     return NULL;
 }
 
+GList*
+wins_get_private_chats(const char *const roomjid)
+{
+    GList *result = NULL;
+    GString *prefix = g_string_new(roomjid);
+    g_string_append(prefix, "/");
+    GList *values = g_hash_table_get_values(windows);
+    GList *curr = values;
+
+    while (curr) {
+        ProfWin *window = curr->data;
+        if (window->type == WIN_PRIVATE) {
+            ProfPrivateWin *privatewin = (ProfPrivateWin*)window;
+            if (g_str_has_prefix(privatewin->fulljid, prefix->str)) {
+                result = g_list_append(result, privatewin);
+            }
+        }
+        curr = g_list_next(curr);
+    }
+
+    g_list_free(values);
+    g_string_free(prefix, TRUE);
+    return result;
+}
+
 ProfWin*
 wins_get_current(void)
 {
diff --git a/src/window_list.h b/src/window_list.h
index c2af5b39..0d20d714 100644
--- a/src/window_list.h
+++ b/src/window_list.h
@@ -46,6 +46,7 @@ ProfWin* wins_new_muc_config(const char *const roomjid, DataForm *form);
 ProfWin* wins_new_private(const char *const fulljid);
 
 gboolean wins_chat_exists(const char *const barejid);
+GList* wins_get_private_chats(const char *const roomjid);
 
 ProfWin* wins_get_console(void);
 ProfChatWin* wins_get_chat(const char *const barejid);