From 08c1e62e3ca899100758a760452758efab497de6 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 31 Jan 2016 23:08:14 +0000 Subject: [PATCH] Colour private chats by presence in roster panel --- src/event/server_events.c | 7 ++++++ src/ui/rosterwin.c | 50 ++++++++++++++++++++++++--------------- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/event/server_events.c b/src/event/server_events.c index 57416496..105c7d72 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -666,6 +666,7 @@ sv_ev_room_occupant_offline(const char *const room, const char *const nick, } prefs_free_string(muc_status_pref); occupantswin_occupants(room); + rosterwin_roster(); } void @@ -678,6 +679,7 @@ sv_ev_room_occupent_kicked(const char *const room, const char *const nick, const mucwin_occupant_kicked(mucwin, nick, actor, reason); } occupantswin_occupants(room); + rosterwin_roster(); } void @@ -690,6 +692,7 @@ sv_ev_room_occupent_banned(const char *const room, const char *const nick, const mucwin_occupant_banned(mucwin, nick, actor, reason); } occupantswin_occupants(room); + rosterwin_roster(); } void @@ -825,6 +828,7 @@ sv_ev_muc_occupant_online(const char *const room, const char *const nick, const } free(old_nick); occupantswin_occupants(room); + rosterwin_roster(); return; } @@ -837,6 +841,7 @@ sv_ev_muc_occupant_online(const char *const room, const char *const nick, const } prefs_free_string(muc_status_pref); occupantswin_occupants(room); + rosterwin_roster(); return; } @@ -869,6 +874,8 @@ sv_ev_muc_occupant_online(const char *const room, const char *const nick, const } occupantswin_occupants(room); } + + rosterwin_roster(); } int diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index 905000ff..6b63a13e 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -661,26 +661,31 @@ _rosterwin_room(ProfLayoutSplit *layout, ProfMucWin *mucwin) g_string_append_printf(privmsg, "%c", ch); } - g_string_append(privmsg, privwin->fulljid + strlen(mucwin->roomjid) + 1); + char *nick = privwin->fulljid + strlen(mucwin->roomjid) + 1; + g_string_append(privmsg, nick); 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)); + const char *presence = "offline"; + + Occupant *occupant = muc_roster_item(mucwin->roomjid, nick); + if (occupant) { + presence = string_from_resource_presence(occupant->presence); } + theme_item_t colour; + if (privwin->unread > 0) { + colour = _get_roster_theme(ROSTER_CONTACT_UNREAD, presence); + } else { + colour = _get_roster_theme(ROSTER_CONTACT_ACTIVE, presence); + } + + wattron(layout->subwin, theme_attrs(colour)); win_sub_print(layout->subwin, privmsg->str, FALSE, wrap, current_indent); - - if (privwin->unread > 0) { - wattroff(layout->subwin, theme_attrs(THEME_ROSTER_ROOM_UNREAD)); - } else { - wattroff(layout->subwin, theme_attrs(THEME_ROSTER_ROOM)); - } + wattroff(layout->subwin, theme_attrs(colour)); g_string_free(privmsg, TRUE); curr = g_list_next(curr); @@ -744,20 +749,27 @@ _rosterwin_private_chats(ProfLayoutSplit *layout, GList *orphaned_privchats) } prefs_free_string(unreadpos); + Jid *jidp = jid_create(privwin->fulljid); + Occupant *occupant = muc_roster_item(jidp->barejid, jidp->resourcepart); + jid_destroy(jidp); + + const char *presence = "offline"; + if (occupant) { + presence = string_from_resource_presence(occupant->presence); + } + + theme_item_t colour; if (privwin->unread > 0) { - wattron(layout->subwin, theme_attrs(THEME_ROSTER_ROOM_UNREAD)); + colour = _get_roster_theme(ROSTER_CONTACT_UNREAD, presence); } else { - wattron(layout->subwin, theme_attrs(THEME_ROSTER_ROOM)); + colour = _get_roster_theme(ROSTER_CONTACT_ACTIVE, presence); } gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP); - win_sub_print(layout->subwin, privmsg->str, FALSE, wrap, current_indent); - if (privwin->unread > 0) { - wattroff(layout->subwin, theme_attrs(THEME_ROSTER_ROOM_UNREAD)); - } else { - wattroff(layout->subwin, theme_attrs(THEME_ROSTER_ROOM)); - } + wattron(layout->subwin, theme_attrs(colour)); + win_sub_print(layout->subwin, privmsg->str, FALSE, wrap, current_indent); + wattroff(layout->subwin, theme_attrs(colour)); g_string_free(privmsg, TRUE); curr = g_list_next(curr);