1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Added private chat to roster rooms

This commit is contained in:
James Booth 2016-01-24 00:33:24 +00:00
parent 2df622f9fd
commit 67abfaa21e
4 changed files with 95 additions and 1 deletions

View File

@ -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

View File

@ -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);

View File

@ -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)
{

View File

@ -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);