about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-01-11 23:25:50 +0000
committerJames Booth <boothj5@gmail.com>2015-01-11 23:25:50 +0000
commitf2728096ea561b97631c8fb8d937552d6219818d (patch)
treebf7b5f429333c354876b6d159ba901c082e4524e /src
parent51bd4ed375229d66d1c6957413c724403202ca38 (diff)
downloadprofani-tty-f2728096ea561b97631c8fb8d937552d6219818d.tar.gz
Use /gone preference
Diffstat (limited to 'src')
-rw-r--r--src/chat_state.c39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/chat_state.c b/src/chat_state.c
index 6b3434d3..99a83f43 100644
--- a/src/chat_state.c
+++ b/src/chat_state.c
@@ -42,8 +42,7 @@
 #include "config/preferences.h"
 
 #define PAUSED_TIMEOUT 10.0
-#define INACTIVE_TIMEOUT 10.0
-#define GONE_TIMEOUT 10.0
+#define INACTIVE_TIMEOUT 30.0
 
 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
 chat_state_handle_idle(const char * const barejid, ChatState *state)
 {
+    gdouble elapsed = g_timer_elapsed(state->timer, NULL);
+
     // 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;
         g_timer_start(state->timer);
         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
-    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;
         g_timer_start(state->timer);
         if (prefs_get_boolean(PREF_STATES)) {
@@ -91,26 +92,28 @@ chat_state_handle_idle(const char * const barejid, ChatState *state)
     }
 
     // INACTIVE -> GONE
-    if (state->type == CHAT_STATE_INACTIVE && g_timer_elapsed(state->timer, NULL) > GONE_TIMEOUT) {
-        ChatSession *session = chat_session_get(barejid);
-        if (session) {
-            // never move to GONE when resource override
-            if (!session->resource_override) {
+    if (state->type == CHAT_STATE_INACTIVE) {
+        if (prefs_get_gone() != 0 && (elapsed > (prefs_get_gone() * 60.0))) {
+            ChatSession *session = chat_session_get(barejid);
+            if (session) {
+                // never move to GONE when resource override
+                if (!session->resource_override) {
+                    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)) {
-                    _send_if_supported(barejid, message_send_gone);
+                    message_send_gone(barejid);
                 }
-                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);
-            }
-            state->type = CHAT_STATE_GONE;
-            g_timer_start(state->timer);
+            return;
         }
-        return;
     }
 }