diff options
author | James Booth <boothj5@gmail.com> | 2012-10-14 22:36:29 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2012-10-14 22:36:29 +0100 |
commit | c0cc8295190e371c115aca71e4e71d7ff6d70f46 (patch) | |
tree | 2603707d4f2ffb8ee08a380d01afc0d9f827cb6e | |
parent | 6ef7b30cd7b3dd709623fe9195d55c360f9b17e8 (diff) | |
download | profani-tty-c0cc8295190e371c115aca71e4e71d7ff6d70f46.tar.gz |
Refactored show history, free'd memory
-rw-r--r-- | src/windows.c | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/src/windows.c b/src/windows.c index 74e51a0f..8ffc5005 100644 --- a/src/windows.c +++ b/src/windows.c @@ -83,6 +83,8 @@ static void _win_handle_switch(const int * const ch); static void _win_handle_page(const int * const ch); static void _win_resize_all(void); static gint _win_get_unread(void); +static void _win_show_history(WINDOW *win, int win_index, + const char * const contact); #ifdef HAVE_LIBNOTIFY static void _win_notify(const char * const message, int timeout, @@ -284,15 +286,7 @@ win_show_incomming_msg(const char * const from, const char * const message) _wins[win_index].unread++; if (prefs_get_chlog() && prefs_get_history()) { - if (!_wins[win_index].history_shown) { - GSList *history = NULL; - history = chat_log_get_previous(jabber_get_jid(), short_from, history); - while (history != NULL) { - wprintw(win, "%s\n", history->data); - history = g_slist_next(history); - } - _wins[win_index].history_shown = 1; - } + _win_show_history(win, win_index, short_from); } _win_show_time(win); @@ -390,15 +384,7 @@ win_show_outgoing_msg(const char * const from, const char * const to, win = _wins[win_index].win; if (prefs_get_chlog() && prefs_get_history()) { - if (!_wins[win_index].history_shown) { - GSList *history = NULL; - history = chat_log_get_previous(jabber_get_jid(), to, history); - while (history != NULL) { - wprintw(win, "%s\n", history->data); - history = g_slist_next(history); - } - _wins[win_index].history_shown = 1; - } + _win_show_history(win, win_index, to); } if (strcmp(p_contact_show(contact), "offline") == 0) { @@ -1097,3 +1083,19 @@ _win_get_unread(void) return result; } +static void +_win_show_history(WINDOW *win, int win_index, const char * const contact) +{ + if (!_wins[win_index].history_shown) { + GSList *history = NULL; + history = chat_log_get_previous(jabber_get_jid(), contact, history); + while (history != NULL) { + wprintw(win, "%s\n", history->data); + history = g_slist_next(history); + } + _wins[win_index].history_shown = 1; + + g_slist_free_full(history, free); + } +} + |