From 894360dc813fcce3d22fcc2dc34ec6f5f1926072 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 29 Dec 2014 01:54:09 +0000 Subject: Removed static functions from chat_session --- src/chat_session.c | 236 +++++++++++++++-------------------------------------- src/chat_session.h | 3 +- 2 files changed, 66 insertions(+), 173 deletions(-) diff --git a/src/chat_session.c b/src/chat_session.c index 81240f8f..f615bded 100644 --- a/src/chat_session.c +++ b/src/chat_session.c @@ -57,7 +57,7 @@ typedef enum { typedef struct chat_session_t { char *barejid; char *resource; - gboolean recipient_supports; + gboolean supported; chat_state_t state; GTimer *active_timer; gboolean sent; @@ -65,19 +65,9 @@ typedef struct chat_session_t { static GHashTable *sessions; -static ChatSession* _chat_session_new(const char * const recipient, gboolean recipient_supports); -static gboolean _chat_session_exists(const char * const recipient); +static ChatSession* _chat_session_new(const char * const recipient, gboolean supported); static void _chat_session_set_composing(const char * const recipient); -static void _chat_session_set_sent(const char * const recipient); -static gboolean _chat_session_get_sent(const char * const recipient); -static void _chat_session_end(const char * const recipient); -static gboolean _chat_session_is_inactive(const char * const recipient); static void _chat_session_set_active(const char * const recipient); -static gboolean _chat_session_is_paused(const char * const recipient); -static gboolean _chat_session_is_gone(const char * const recipient); -static void _chat_session_set_gone(const char * const recipient); -static gboolean _chat_session_get_recipient_supports(const char * const recipient); -static void _chat_session_set_recipient_supports(const char * const recipient, gboolean recipient_supports); static void _chat_session_free(ChatSession *session); void @@ -95,11 +85,12 @@ chat_sessions_clear(void) } ChatSession* -_chat_session_new(const char * const barejid, gboolean recipient_supports) +_chat_session_new(const char * const barejid, gboolean supported) { ChatSession *new_session = malloc(sizeof(struct chat_session_t)); new_session->barejid = strdup(barejid); - new_session->recipient_supports = recipient_supports; + new_session->resource = NULL; + new_session->supported = supported; new_session->state = CHAT_STATE_STARTED; new_session->active_timer = g_timer_new(); new_session->sent = FALSE; @@ -107,18 +98,6 @@ _chat_session_new(const char * const barejid, gboolean recipient_supports) return new_session; } -static gboolean -_chat_session_exists(const char * const recipient) -{ - ChatSession *session = g_hash_table_lookup(sessions, recipient); - - if (session != NULL) { - return TRUE; - } else { - return FALSE; - } -} - static void _chat_session_set_composing(const char * const recipient) { @@ -133,46 +112,6 @@ _chat_session_set_composing(const char * const recipient) } } -static void -_chat_session_set_sent(const char * const recipient) -{ - ChatSession *session = g_hash_table_lookup(sessions, recipient); - - if (session != NULL) { - session->sent = TRUE; - } -} - -static gboolean -_chat_session_get_sent(const char * const recipient) -{ - ChatSession *session = g_hash_table_lookup(sessions, recipient); - - if (session == NULL) { - return FALSE; - } else { - return session->sent; - } -} - -static void -_chat_session_end(const char * const recipient) -{ - g_hash_table_remove(sessions, recipient); -} - -static gboolean -_chat_session_is_inactive(const char * const recipient) -{ - ChatSession *session = g_hash_table_lookup(sessions, recipient); - - if (session == NULL) { - return FALSE; - } else { - return (session->state == CHAT_STATE_INACTIVE); - } -} - static void _chat_session_set_active(const char * const recipient) { @@ -185,73 +124,18 @@ _chat_session_set_active(const char * const recipient) } } -static gboolean -_chat_session_is_paused(const char * const recipient) -{ - ChatSession *session = g_hash_table_lookup(sessions, recipient); - - if (session == NULL) { - return FALSE; - } else { - return (session->state == CHAT_STATE_PAUSED); - } -} - -static gboolean -_chat_session_is_gone(const char * const recipient) -{ - ChatSession *session = g_hash_table_lookup(sessions, recipient); - - if (session == NULL) { - return FALSE; - } else { - return (session->state == CHAT_STATE_GONE); - } -} - -static void -_chat_session_set_gone(const char * const recipient) -{ - ChatSession *session = g_hash_table_lookup(sessions, recipient); - - if (session != NULL) { - session->state = CHAT_STATE_GONE; - } -} - -static gboolean -_chat_session_get_recipient_supports(const char * const recipient) -{ - ChatSession *session = g_hash_table_lookup(sessions, recipient); - - if (session == NULL) { - return FALSE; - } else { - return session->recipient_supports; - } -} - -static void -_chat_session_set_recipient_supports(const char * const recipient, gboolean recipient_supports) -{ - ChatSession *session = g_hash_table_lookup(sessions, recipient); - - if (session != NULL) { - session->recipient_supports = recipient_supports; - } -} - gboolean chat_session_on_message_send(const char * const barejid) { gboolean send_state = FALSE; if (prefs_get_boolean(PREF_STATES)) { - if (!_chat_session_exists(barejid)) { - ChatSession *session = _chat_session_new(barejid, TRUE); + ChatSession *session = g_hash_table_lookup(sessions, barejid); + if (!session) { + session = _chat_session_new(barejid, TRUE); g_hash_table_insert(sessions, strdup(barejid), session); } - if (_chat_session_get_recipient_supports(barejid)) { + if (session->supported) { _chat_session_set_active(barejid); send_state = TRUE; } @@ -261,13 +145,14 @@ chat_session_on_message_send(const char * const barejid) } void -chat_session_on_incoming_message(const char * const barejid, gboolean recipient_supports) +chat_session_on_incoming_message(const char * const barejid, gboolean supported) { - if (!_chat_session_exists(barejid)) { - ChatSession *session = _chat_session_new(barejid, recipient_supports); + ChatSession *session = g_hash_table_lookup(sessions, barejid); + if (!session) { + session = _chat_session_new(barejid, supported); g_hash_table_insert(sessions, strdup(barejid), session); } else { - _chat_session_set_recipient_supports(barejid, recipient_supports); + session->supported = supported; } } @@ -275,8 +160,9 @@ void chat_session_on_window_open(const char * const barejid) { if (prefs_get_boolean(PREF_STATES)) { - if (!_chat_session_exists(barejid)) { - ChatSession *session = _chat_session_new(barejid, TRUE); + ChatSession *session = g_hash_table_lookup(sessions, barejid); + if (!session) { + session = _chat_session_new(barejid, TRUE); g_hash_table_insert(sessions, strdup(barejid), session); } } @@ -286,12 +172,13 @@ void chat_session_on_window_close(const char * const barejid) { if (prefs_get_boolean(PREF_STATES)) { + ChatSession *session = g_hash_table_lookup(sessions, barejid); // send chat state before closing - if (_chat_session_get_recipient_supports(barejid)) { - _chat_session_set_gone(barejid); + if (session->supported) { + session->state = CHAT_STATE_GONE; message_send_gone(barejid); - _chat_session_set_sent(barejid); - _chat_session_end(barejid); + session->sent = TRUE; + g_hash_table_remove(sessions, barejid); } } } @@ -299,19 +186,25 @@ chat_session_on_window_close(const char * const barejid) void chat_session_on_cancel(const char * const jid) { - if (prefs_get_boolean(PREF_STATES) && _chat_session_exists(jid)) { - _chat_session_set_recipient_supports(jid, FALSE); + if (prefs_get_boolean(PREF_STATES)) { + ChatSession *session = g_hash_table_lookup(sessions, jid); + if (session) { + session->supported = FALSE; + } } } void chat_session_on_activity(const char * const barejid) { - if (_chat_session_get_recipient_supports(barejid)) { - _chat_session_set_composing(barejid); - if (!_chat_session_get_sent(barejid) || _chat_session_is_paused(barejid)) { - message_send_composing(barejid); - _chat_session_set_sent(barejid); + ChatSession *session = g_hash_table_lookup(sessions, barejid); + if (session) { + if (session->supported) { + _chat_session_set_composing(barejid); + if (!session->sent || session->state == CHAT_STATE_PAUSED) { + message_send_composing(barejid); + session->sent = TRUE; + } } } } @@ -319,43 +212,42 @@ chat_session_on_activity(const char * const barejid) void chat_session_on_inactivity(const char * const barejid) { - if (_chat_session_get_recipient_supports(barejid)) { - ChatSession *session = g_hash_table_lookup(sessions, barejid); - if (session != NULL) { - if (session->active_timer != NULL) { - gdouble elapsed = g_timer_elapsed(session->active_timer, NULL); - - if ((prefs_get_gone() != 0) && (elapsed > (prefs_get_gone() * 60.0))) { - if (session->state != CHAT_STATE_GONE) { - session->sent = FALSE; - } - session->state = CHAT_STATE_GONE; + ChatSession *session = g_hash_table_lookup(sessions, barejid); + if (session && session->supported) { + if (session->active_timer != NULL) { + gdouble elapsed = g_timer_elapsed(session->active_timer, NULL); - } else if (elapsed > INACTIVE_TIMOUT) { - if (session->state != CHAT_STATE_INACTIVE) { - session->sent = FALSE; - } - session->state = CHAT_STATE_INACTIVE; + if ((prefs_get_gone() != 0) && (elapsed > (prefs_get_gone() * 60.0))) { + if (session->state != CHAT_STATE_GONE) { + session->sent = FALSE; + } + session->state = CHAT_STATE_GONE; - } else if (elapsed > PAUSED_TIMOUT) { + } else if (elapsed > INACTIVE_TIMOUT) { + if (session->state != CHAT_STATE_INACTIVE) { + session->sent = FALSE; + } + session->state = CHAT_STATE_INACTIVE; - if (session->state == CHAT_STATE_COMPOSING) { - session->sent = FALSE; - session->state = CHAT_STATE_PAUSED; - } + } else if (elapsed > PAUSED_TIMOUT) { + if (session->state == CHAT_STATE_COMPOSING) { + session->sent = FALSE; + session->state = CHAT_STATE_PAUSED; } } } - if (_chat_session_is_gone(barejid) && !_chat_session_get_sent(barejid)) { - message_send_gone(barejid); - _chat_session_set_sent(barejid); - } else if (_chat_session_is_inactive(barejid) && !_chat_session_get_sent(barejid)) { - message_send_inactive(barejid); - _chat_session_set_sent(barejid); - } else if (prefs_get_boolean(PREF_OUTTYPE) && _chat_session_is_paused(barejid) && !_chat_session_get_sent(barejid)) { - message_send_paused(barejid); - _chat_session_set_sent(barejid); + if (session->sent == FALSE) { + if (session->state == CHAT_STATE_GONE) { + message_send_gone(barejid); + session->sent = TRUE; + } else if (session->state == CHAT_STATE_INACTIVE) { + message_send_inactive(barejid); + session->sent = TRUE; + } else if (session->state == CHAT_STATE_PAUSED && prefs_get_boolean(PREF_OUTTYPE)) { + message_send_paused(barejid); + session->sent = TRUE; + } } } } diff --git a/src/chat_session.h b/src/chat_session.h index a44027a8..d1815f44 100644 --- a/src/chat_session.h +++ b/src/chat_session.h @@ -39,10 +39,11 @@ void chat_sessions_init(void); void chat_sessions_clear(void); + gboolean chat_session_on_message_send(const char * const barejid); void chat_session_on_window_open(const char * const barejid); void chat_session_on_window_close(const char * const barejid); -void chat_session_on_incoming_message(const char * const barejid, gboolean recipient_supports); +void chat_session_on_incoming_message(const char * const barejid, gboolean supported); void chat_session_on_cancel(const char * const jid); void chat_session_on_activity(const char * const barejid); void chat_session_on_inactivity(const char * const recipient); -- cgit 1.4.1-2-gfad0