1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-02-02 15:08:15 -05:00

Fix autocomplete clash, fix crash on opening window when recipient not in roster

This commit is contained in:
James Booth 2014-11-22 21:55:33 +00:00
parent 6772935493
commit b819ea3708
2 changed files with 30 additions and 30 deletions

View File

@ -263,7 +263,11 @@ roster_add(const char * const barejid, const char * const name, GSList *groups,
char * char *
roster_barejid_from_name(const char * const name) roster_barejid_from_name(const char * const name)
{ {
return g_hash_table_lookup(name_to_barejid, name); if (name) {
return g_hash_table_lookup(name_to_barejid, name);
} else {
return NULL;
}
} }
GSList * GSList *

View File

@ -176,7 +176,9 @@ _title_bar_draw(void)
waddch(win, ' '); waddch(win, ' ');
mvwprintw(win, 0, 0, " %s", current_title); mvwprintw(win, 0, 0, " %s", current_title);
_show_contact_presence(); if (prefs_get_boolean(PREF_PRESENCE)) {
_show_contact_presence();
}
#ifdef HAVE_LIBOTR #ifdef HAVE_LIBOTR
_show_privacy(); _show_privacy();
@ -324,22 +326,17 @@ _show_contact_presence(void)
{ {
int bracket_attrs = theme_attrs(THEME_TITLE_BRACKET); int bracket_attrs = theme_attrs(THEME_TITLE_BRACKET);
if (prefs_get_boolean(PREF_PRESENCE) && current_recipient) { ProfWin *current = wins_get_current();
char *recipient_jid = NULL; if (current && current->type == WIN_CHAT) {
char *found_contact = roster_contact_autocomplete(current_recipient); theme_item_t presence_colour = THEME_TITLE_OFFLINE;
if (found_contact) { const char *presence = "offline";
recipient_jid = roster_barejid_from_name(current_recipient);
free(found_contact);
} else {
recipient_jid = current_recipient;
}
ProfWin *current = wins_get_by_recipient(recipient_jid);
if (current) {
if (current->type == WIN_CHAT) {
PContact contact = roster_get_contact(recipient_jid);
const char *presence = p_contact_presence(contact);
theme_item_t presence_colour = THEME_TITLE_ONLINE; char *barejid = roster_barejid_from_name(current_recipient);
if (barejid) {
PContact contact = roster_get_contact(barejid);
if (contact) {
presence = p_contact_presence(contact);
presence_colour = THEME_TITLE_ONLINE;
if (g_strcmp0(presence, "offline") == 0) { if (g_strcmp0(presence, "offline") == 0) {
presence_colour = THEME_TITLE_OFFLINE; presence_colour = THEME_TITLE_OFFLINE;
} else if (g_strcmp0(presence, "away") == 0) { } else if (g_strcmp0(presence, "away") == 0) {
@ -351,20 +348,19 @@ _show_contact_presence(void)
} else if (g_strcmp0(presence, "dnd") == 0) { } else if (g_strcmp0(presence, "dnd") == 0) {
presence_colour = THEME_TITLE_DND; presence_colour = THEME_TITLE_DND;
} }
int presence_attrs = theme_attrs(presence_colour);
wprintw(win, " ");
wattron(win, bracket_attrs);
wprintw(win, "[");
wattroff(win, bracket_attrs);
wattron(win, presence_attrs);
wprintw(win, presence);
wattroff(win, presence_attrs);
wattron(win, bracket_attrs);
wprintw(win, "]");
wattroff(win, bracket_attrs);
} }
} }
int presence_attrs = theme_attrs(presence_colour);
wprintw(win, " ");
wattron(win, bracket_attrs);
wprintw(win, "[");
wattroff(win, bracket_attrs);
wattron(win, presence_attrs);
wprintw(win, presence);
wattroff(win, presence_attrs);
wattron(win, bracket_attrs);
wprintw(win, "]");
wattroff(win, bracket_attrs);
} }
} }