diff options
author | James Booth <boothj5@gmail.com> | 2016-07-24 13:56:11 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2016-07-24 13:56:11 +0100 |
commit | 8d8f2f290d5d78d130d2db7c6fad90af2f031877 (patch) | |
tree | b69e6954acd958546c41f08da8ce459e5edde1e5 /src | |
parent | 7c593c278014760c065a87edf293546794911f58 (diff) | |
download | profani-tty-8d8f2f290d5d78d130d2db7c6fad90af2f031877.tar.gz |
Moved chat state handling code to chat_state.c
Diffstat (limited to 'src')
-rw-r--r-- | src/chat_state.c | 37 | ||||
-rw-r--r-- | src/chat_state.h | 3 | ||||
-rw-r--r-- | src/event/client_events.h | 2 | ||||
-rw-r--r-- | src/profanity.c | 35 | ||||
-rw-r--r-- | src/profanity.h | 5 | ||||
-rw-r--r-- | src/ui/inputwin.c | 5 |
6 files changed, 45 insertions, 42 deletions
diff --git a/src/chat_state.c b/src/chat_state.c index b0e08fd5..cac73817 100644 --- a/src/chat_state.c +++ b/src/chat_state.c @@ -33,11 +33,14 @@ */ #include <stdlib.h> +#include <assert.h> #include <glib.h> #include "chat_state.h" #include "chat_session.h" +#include "window_list.h" +#include "ui/win_types.h" #include "xmpp/xmpp.h" #include "config/preferences.h" @@ -149,6 +152,40 @@ chat_state_gone(const char *const barejid, ChatState *state) } } +void +chat_state_idle(void) +{ + jabber_conn_status_t status = connection_get_status(); + if (status == JABBER_CONNECTED) { + GSList *recipients = wins_get_chat_recipients(); + GSList *curr = recipients; + + while (curr) { + char *barejid = curr->data; + ProfChatWin *chatwin = wins_get_chat(barejid); + chat_state_handle_idle(chatwin->barejid, chatwin->state); + curr = g_slist_next(curr); + } + + if (recipients) { + g_slist_free(recipients); + } + } +} + +void +chat_state_activity(void) +{ + jabber_conn_status_t status = connection_get_status(); + ProfWin *current = wins_get_current(); + + if ((status == JABBER_CONNECTED) && (current->type == WIN_CHAT)) { + ProfChatWin *chatwin = (ProfChatWin*)current; + assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); + chat_state_handle_typing(chatwin->barejid, chatwin->state); + } +} + static void _send_if_supported(const char *const barejid, void (*send_func)(const char *const)) { diff --git a/src/chat_state.h b/src/chat_state.h index c9e8fa58..393598ba 100644 --- a/src/chat_state.h +++ b/src/chat_state.h @@ -53,6 +53,9 @@ typedef struct prof_chat_state_t { ChatState* chat_state_new(void); void chat_state_free(ChatState *state); +void chat_state_idle(void); +void chat_state_activity(void); + void chat_state_handle_idle(const char *const barejid, ChatState *state); void chat_state_handle_typing(const char *const barejid, ChatState *state); void chat_state_active(ChatState *state); diff --git a/src/event/client_events.h b/src/event/client_events.h index ffce00fd..39bb1372 100644 --- a/src/event/client_events.h +++ b/src/event/client_events.h @@ -35,6 +35,8 @@ #ifndef CLIENT_EVENTS_H #define CLIENT_EVENTS_H +#include "xmpp/xmpp.h" + jabber_conn_status_t cl_ev_connect_jid(const char *const jid, const char *const passwd, const char *const altdomain, const int port, const char *const tls_policy); jabber_conn_status_t cl_ev_connect_account(ProfAccount *account); diff --git a/src/profanity.c b/src/profanity.c index 950c28e9..f5540d3a 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -44,7 +44,6 @@ #include <signal.h> #include <stdlib.h> #include <string.h> -#include <assert.h> #include <glib.h> @@ -145,40 +144,6 @@ prof_set_quit(void) force_quit = TRUE; } -void -prof_handle_idle(void) -{ - jabber_conn_status_t status = connection_get_status(); - if (status == JABBER_CONNECTED) { - GSList *recipients = wins_get_chat_recipients(); - GSList *curr = recipients; - - while (curr) { - char *barejid = curr->data; - ProfChatWin *chatwin = wins_get_chat(barejid); - chat_state_handle_idle(chatwin->barejid, chatwin->state); - curr = g_slist_next(curr); - } - - if (recipients) { - g_slist_free(recipients); - } - } -} - -void -prof_handle_activity(void) -{ - jabber_conn_status_t status = connection_get_status(); - ProfWin *current = wins_get_current(); - - if ((status == JABBER_CONNECTED) && (current->type == WIN_CHAT)) { - ProfChatWin *chatwin = (ProfChatWin*)current; - assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); - chat_state_handle_typing(chatwin->barejid, chatwin->state); - } -} - static void _connect_default(const char *const account) { diff --git a/src/profanity.h b/src/profanity.h index ecc4cd13..ef1f2ea1 100644 --- a/src/profanity.h +++ b/src/profanity.h @@ -37,13 +37,8 @@ #include <pthread.h> -#include "resource.h" -#include "xmpp/xmpp.h" - void prof_run(char *log_level, char *account_name); -void prof_handle_idle(void); -void prof_handle_activity(void); gboolean prof_process_input(char *inp); void prof_set_quit(void); diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index e8db673c..10035d37 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -54,6 +54,7 @@ #endif #include "command/cmd_ac.h" +#include "chat_state.h" #include "common.h" #include "config/accounts.h" #include "config/preferences.h" @@ -164,7 +165,7 @@ inp_readline(void) rl_line_buffer[0] != '/' && rl_line_buffer[0] != '\0' && rl_line_buffer[0] != '\n') { - prof_handle_activity(); + chat_state_activity(); } ui_reset_idle_time(); @@ -174,7 +175,7 @@ inp_readline(void) inp_nonblocking(TRUE); } else { inp_nonblocking(FALSE); - prof_handle_idle(); + chat_state_idle(); } if (inp_line) { |