1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-01-03 14:57:42 -05:00

Use /gone preference

This commit is contained in:
James Booth 2015-01-11 23:25:50 +00:00
parent 51bd4ed375
commit f2728096ea

View File

@ -42,8 +42,7 @@
#include "config/preferences.h" #include "config/preferences.h"
#define PAUSED_TIMEOUT 10.0 #define PAUSED_TIMEOUT 10.0
#define INACTIVE_TIMEOUT 10.0 #define INACTIVE_TIMEOUT 30.0
#define GONE_TIMEOUT 10.0
static void _send_if_supported(const char * const barejid, void(*send_func)(const char * const)); static void _send_if_supported(const char * const barejid, void(*send_func)(const char * const));
@ -69,8 +68,10 @@ chat_state_free(ChatState *state)
void void
chat_state_handle_idle(const char * const barejid, ChatState *state) chat_state_handle_idle(const char * const barejid, ChatState *state)
{ {
gdouble elapsed = g_timer_elapsed(state->timer, NULL);
// TYPING -> PAUSED // TYPING -> PAUSED
if (state->type == CHAT_STATE_COMPOSING && g_timer_elapsed(state->timer, NULL) > PAUSED_TIMEOUT) { if (state->type == CHAT_STATE_COMPOSING && elapsed > PAUSED_TIMEOUT) {
state->type = CHAT_STATE_PAUSED; state->type = CHAT_STATE_PAUSED;
g_timer_start(state->timer); g_timer_start(state->timer);
if (prefs_get_boolean(PREF_STATES) && prefs_get_boolean(PREF_OUTTYPE)) { if (prefs_get_boolean(PREF_STATES) && prefs_get_boolean(PREF_OUTTYPE)) {
@ -80,7 +81,7 @@ chat_state_handle_idle(const char * const barejid, ChatState *state)
} }
// PAUSED|ACTIVE -> INACTIVE // PAUSED|ACTIVE -> INACTIVE
if ((state->type == CHAT_STATE_PAUSED || state->type == CHAT_STATE_ACTIVE) && g_timer_elapsed(state->timer, NULL) > INACTIVE_TIMEOUT) { if ((state->type == CHAT_STATE_PAUSED || state->type == CHAT_STATE_ACTIVE) && elapsed > INACTIVE_TIMEOUT) {
state->type = CHAT_STATE_INACTIVE; state->type = CHAT_STATE_INACTIVE;
g_timer_start(state->timer); g_timer_start(state->timer);
if (prefs_get_boolean(PREF_STATES)) { if (prefs_get_boolean(PREF_STATES)) {
@ -91,26 +92,28 @@ chat_state_handle_idle(const char * const barejid, ChatState *state)
} }
// INACTIVE -> GONE // INACTIVE -> GONE
if (state->type == CHAT_STATE_INACTIVE && g_timer_elapsed(state->timer, NULL) > GONE_TIMEOUT) { if (state->type == CHAT_STATE_INACTIVE) {
ChatSession *session = chat_session_get(barejid); if (prefs_get_gone() != 0 && (elapsed > (prefs_get_gone() * 60.0))) {
if (session) { ChatSession *session = chat_session_get(barejid);
// never move to GONE when resource override if (session) {
if (!session->resource_override) { // never move to GONE when resource override
if (prefs_get_boolean(PREF_STATES)) { if (!session->resource_override) {
_send_if_supported(barejid, message_send_gone); if (prefs_get_boolean(PREF_STATES)) {
_send_if_supported(barejid, message_send_gone);
}
chat_session_remove(barejid);
state->type = CHAT_STATE_GONE;
g_timer_start(state->timer);
}
} else {
if (prefs_get_boolean(PREF_STATES)) {
message_send_gone(barejid);
} }
chat_session_remove(barejid);
state->type = CHAT_STATE_GONE; state->type = CHAT_STATE_GONE;
g_timer_start(state->timer); g_timer_start(state->timer);
} }
} else { return;
if (prefs_get_boolean(PREF_STATES)) {
message_send_gone(barejid);
}
state->type = CHAT_STATE_GONE;
g_timer_start(state->timer);
} }
return;
} }
} }