1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Fixed invalid state transition from <active/> to <paused/>

This commit is contained in:
James Booth 2012-10-31 23:41:30 +00:00
parent 5792cd597d
commit 270ac03558
4 changed files with 60 additions and 37 deletions

View File

@ -29,11 +29,11 @@
#include "log.h"
#define PAUSED_TIMOUT 10.0
#define INACTIVE_TIMOUT 120.0
#define GONE_TIMOUT 600.0
#define INACTIVE_TIMOUT 20.0
#define GONE_TIMOUT 30.0
//#define INACTIVE_TIMOUT 120.0
//#define GONE_TIMOUT 600.0
static ChatSession _chat_session_new(const char * const recipient,
gboolean recipient_supports);
static void _chat_session_free(ChatSession session);
typedef enum {
@ -68,6 +68,18 @@ chat_sessions_clear(void)
g_hash_table_remove_all(sessions);
}
void
chat_session_start(const char * const recipient, gboolean recipient_supports)
{
ChatSession new_session = malloc(sizeof(struct chat_session_t));
new_session->recipient = strdup(recipient);
new_session->recipient_supports = recipient_supports;
new_session->state = CHAT_STATE_STARTED;
new_session->active_timer = g_timer_new();
new_session->sent = FALSE;
g_hash_table_insert(sessions, strdup(recipient), new_session);
}
gboolean
chat_session_exists(const char * const recipient)
{
@ -80,13 +92,6 @@ chat_session_exists(const char * const recipient)
}
}
void
chat_session_start(const char * const recipient, gboolean recipient_supports)
{
ChatSession session = _chat_session_new(recipient, recipient_supports);
g_hash_table_insert(sessions, strdup(recipient), session);
}
void
chat_session_set_composing(const char * const recipient)
{
@ -119,13 +124,17 @@ chat_session_no_activity(const char * const recipient)
session->sent = FALSE;
}
session->state = CHAT_STATE_GONE;
} else if (elapsed > INACTIVE_TIMOUT) {
if (session->state != CHAT_STATE_INACTIVE) {
session->sent = FALSE;
}
session->state = CHAT_STATE_INACTIVE;
} else if (elapsed > PAUSED_TIMOUT) {
if (session->state != CHAT_STATE_PAUSED) {
if ((session->state != CHAT_STATE_PAUSED) &&
(session->state != CHAT_STATE_ACTIVE)) {
session->sent = FALSE;
}
session->state = CHAT_STATE_PAUSED;
@ -166,7 +175,7 @@ chat_session_end(const char * const recipient)
}
gboolean
chat_session_inactive(const char * const recipient)
chat_session_is_inactive(const char * const recipient)
{
ChatSession session = g_hash_table_lookup(sessions, recipient);
@ -178,6 +187,19 @@ chat_session_inactive(const char * const recipient)
}
}
gboolean
chat_session_is_active(const char * const recipient)
{
ChatSession session = g_hash_table_lookup(sessions, recipient);
if (session == NULL) {
log_error("No chat session found for %s.", recipient);
return FALSE;
} else {
return (session->state == CHAT_STATE_ACTIVE);
}
}
void
chat_session_set_active(const char * const recipient)
{
@ -187,12 +209,12 @@ chat_session_set_active(const char * const recipient)
log_error("No chat session found for %s.", recipient);
} else {
session->state = CHAT_STATE_ACTIVE;
session->sent = FALSE;
session->sent = TRUE;
}
}
gboolean
chat_session_paused(const char * const recipient)
chat_session_is_paused(const char * const recipient)
{
ChatSession session = g_hash_table_lookup(sessions, recipient);
@ -205,7 +227,7 @@ chat_session_paused(const char * const recipient)
}
gboolean
chat_session_gone(const char * const recipient)
chat_session_is_gone(const char * const recipient)
{
ChatSession session = g_hash_table_lookup(sessions, recipient);
@ -217,6 +239,18 @@ chat_session_gone(const char * const recipient)
}
}
void
chat_session_set_gone(const char * const recipient)
{
ChatSession session = g_hash_table_lookup(sessions, recipient);
if (session == NULL) {
log_error("No chat session found for %s.", recipient);
} else {
session->state = CHAT_STATE_GONE;
}
}
gboolean
chat_session_get_recipient_supports(const char * const recipient)
{
@ -243,19 +277,6 @@ chat_session_set_recipient_supports(const char * const recipient,
}
}
static ChatSession
_chat_session_new(const char * const recipient, gboolean recipient_supports)
{
ChatSession new_session = malloc(sizeof(struct chat_session_t));
new_session->recipient = strdup(recipient);
new_session->recipient_supports = recipient_supports;
new_session->state = CHAT_STATE_STARTED;
new_session->active_timer = g_timer_new();
new_session->sent = FALSE;
return new_session;
}
static void
_chat_session_free(ChatSession session)
{

View File

@ -39,10 +39,12 @@ void chat_session_set_recipient_supports(const char * const recipient,
void chat_session_set_composing(const char * const recipient);
void chat_session_no_activity(const char * const recipient);
gboolean chat_session_inactive(const char * const recipient);
gboolean chat_session_is_inactive(const char * const recipient);
gboolean chat_session_is_active(const char * const recipient);
void chat_session_set_active(const char * const recipient);
gboolean chat_session_paused(const char * const recipient);
gboolean chat_session_gone(const char * const recipient);
gboolean chat_session_is_paused(const char * const recipient);
gboolean chat_session_is_gone(const char * const recipient);
void chat_session_set_gone(const char * const recipient);
void chat_session_set_sent(const char * const recipient);
gboolean chat_session_get_sent(const char * const recipient);

View File

@ -1015,7 +1015,7 @@ _cmd_close(const char * const inp, struct cmd_help_t help)
// send <gone/> chat state before closing
if (chat_session_get_recipient_supports(recipient)) {
chat_session_gone(recipient);
chat_session_set_gone(recipient);
jabber_send_gone(recipient);
chat_session_end(recipient);
}

View File

@ -146,13 +146,13 @@ inp_get_char(int *ch, char *input, int *size)
char *recipient = win_get_recipient();
chat_session_no_activity(recipient);
if (chat_session_gone(recipient) &&
if (chat_session_is_gone(recipient) &&
!chat_session_get_sent(recipient)) {
jabber_send_gone(recipient);
} else if (chat_session_inactive(recipient) &&
} else if (chat_session_is_inactive(recipient) &&
!chat_session_get_sent(recipient)) {
jabber_send_inactive(recipient);
} else if (chat_session_paused(recipient) &&
} else if (chat_session_is_paused(recipient) &&
!chat_session_get_sent(recipient)) {
jabber_send_paused(recipient);
}
@ -165,7 +165,7 @@ inp_get_char(int *ch, char *input, int *size)
char *recipient = win_get_recipient();
chat_session_set_composing(recipient);
if (!chat_session_get_sent(recipient) ||
chat_session_paused(recipient)) {
chat_session_is_paused(recipient)) {
jabber_send_composing(recipient);
}
}