From baced85767ab1882ca0e2da6580042ec3a9c7d06 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 31 Oct 2012 21:30:58 +0000 Subject: Send when closing chat window --- src/command.c | 16 +++++++++++++++- src/ui.h | 2 +- src/windows.c | 30 +++++++++++------------------- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/command.c b/src/command.c index f8c5b1e9..d4f1756d 100644 --- a/src/command.c +++ b/src/command.c @@ -25,6 +25,7 @@ #include +#include "chat_session.h" #include "command.h" #include "common.h" #include "contact.h" @@ -985,8 +986,21 @@ _cmd_tiny(const char * const inp, struct cmd_help_t help) static gboolean _cmd_close(const char * const inp, struct cmd_help_t help) { - if (!win_close_win()) + if (win_in_chat()) { + char *recipient = win_get_recipient(); + + // send chat state before closing + if (chat_session_get_recipient_supports(recipient)) { + chat_session_gone(recipient); + jabber_send_gone(recipient); + chat_session_end(recipient); + } + + win_close_win(); + + } else { cons_bad_command(inp); + } return TRUE; } diff --git a/src/ui.h b/src/ui.h index 642d2ec5..46fb22bf 100644 --- a/src/ui.h +++ b/src/ui.h @@ -83,7 +83,7 @@ void title_bar_set_typing(gboolean is_typing); void title_bar_draw(void); // main window actions -int win_close_win(void); +void win_close_win(void); int win_in_chat(void); char *win_get_recipient(void); void win_show_typing(const char * const from); diff --git a/src/windows.c b/src/windows.c index 57cebdf5..0d4c0b7c 100644 --- a/src/windows.c +++ b/src/windows.c @@ -171,30 +171,22 @@ gui_resize(const int ch, const char * const input, const int size) dirty = TRUE; } -int +void win_close_win(void) { - if (win_in_chat()) { - // reset the chat win to unused - strcpy(_wins[_curr_prof_win].from, ""); - wclear(_wins[_curr_prof_win].win); - _wins[_curr_prof_win].history_shown = 0; + // reset the chat win to unused + strcpy(_wins[_curr_prof_win].from, ""); + wclear(_wins[_curr_prof_win].win); + _wins[_curr_prof_win].history_shown = 0; - // set it as inactive in the status bar - status_bar_inactive(_curr_prof_win); + // set it as inactive in the status bar + status_bar_inactive(_curr_prof_win); - // go back to console window - _curr_prof_win = 0; - title_bar_title(); - - dirty = TRUE; + // go back to console window + _curr_prof_win = 0; + title_bar_title(); - // success - return 1; - } else { - // didn't close anything - return 0; - } + dirty = TRUE; } int -- cgit 1.4.1-2-gfad0