about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-09-25 22:55:44 +0100
committerJames Booth <boothj5@gmail.com>2015-09-25 22:55:44 +0100
commit100db7c36cc40ff740a51d51c2c7887c4d2e138d (patch)
tree91b5f7a7d1e6d05c8b45f78928e596d8378a0d02
parent22ba3db0b27a34f62594adaab4519c854ee72f77 (diff)
downloadprofani-tty-100db7c36cc40ff740a51d51c2c7887c4d2e138d.tar.gz
Set status to what it was before autoaway
-rw-r--r--src/profanity.c12
-rw-r--r--src/ui/core.c7
-rw-r--r--src/ui/ui.h2
-rw-r--r--tests/unittests/ui/stub_ui.c2
4 files changed, 13 insertions, 10 deletions
diff --git a/src/profanity.c b/src/profanity.c
index 1e542420..edc3cf76 100644
--- a/src/profanity.c
+++ b/src/profanity.c
@@ -78,6 +78,8 @@ static void _create_directories(void);
 static void _connect_default(const char * const account);
 
 static gboolean idle = FALSE;
+resource_presence_t autoaway_pre_presence;
+
 static gboolean cont = TRUE;
 
 void
@@ -174,8 +176,10 @@ _check_autoaway()
     unsigned long idle_ms = ui_get_idle_time();
     char *pref_autoaway_mode = prefs_get_string(PREF_AUTOAWAY_MODE);
 
+
     if (!idle) {
         resource_presence_t current_presence = accounts_get_last_presence(jabber_get_account_name());
+        autoaway_pre_presence = current_presence;
         if ((current_presence == RESOURCE_ONLINE) || (current_presence == RESOURCE_CHAT)) {
             if (idle_ms >= prefs_time) {
                 idle = TRUE;
@@ -202,11 +206,11 @@ _check_autoaway()
             // handle check
             if (prefs_get_boolean(PREF_AUTOAWAY_CHECK)) {
                 if (strcmp(pref_autoaway_mode, "away") == 0) {
-                    cl_ev_presence_send(RESOURCE_ONLINE, NULL, 0);
-                    ui_end_auto_away();
+                    cl_ev_presence_send(autoaway_pre_presence, NULL, 0);
+                    ui_end_auto_away(autoaway_pre_presence);
                 } else if (strcmp(pref_autoaway_mode, "idle") == 0) {
-                    cl_ev_presence_send(RESOURCE_ONLINE, NULL, 0);
-                    ui_titlebar_presence(CONTACT_ONLINE);
+                    cl_ev_presence_send(autoaway_pre_presence, NULL, 0);
+                    ui_titlebar_presence(contact_presence_from_resource_presence(autoaway_pre_presence));
                 }
             }
         }
diff --git a/src/ui/core.c b/src/ui/core.c
index 9f7ffcd7..3950ecea 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -574,12 +574,11 @@ ui_auto_away(void)
 }
 
 void
-ui_end_auto_away(void)
+ui_end_auto_away(resource_presence_t presence)
 {
-    int pri =
-        accounts_get_priority_for_presence_type(jabber_get_account_name(), RESOURCE_ONLINE);
+    int pri = accounts_get_priority_for_presence_type(jabber_get_account_name(), presence);
     cons_show("No longer idle, status set to online (priority %d).", pri);
-    title_bar_set_presence(CONTACT_ONLINE);
+    title_bar_set_presence(contact_presence_from_resource_presence(presence));
 }
 
 void
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 07cccd20..fd3caf70 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -226,7 +226,7 @@ void ui_subwin_page_down(void);
 void ui_clear_win(ProfWin *window);
 
 void ui_auto_away(void);
-void ui_end_auto_away(void);
+void ui_end_auto_away(resource_presence_t presence);
 void ui_titlebar_presence(contact_presence_t presence);
 void ui_handle_login_account_success(ProfAccount *account);
 void ui_update_presence(const resource_presence_t resource_presence,
diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c
index 032564fd..c22265b7 100644
--- a/tests/unittests/ui/stub_ui.c
+++ b/tests/unittests/ui/stub_ui.c
@@ -316,7 +316,7 @@ gboolean ui_swap_wins(int source_win, int target_win)
 }
 
 void ui_auto_away(void) {}
-void ui_end_auto_away(void) {}
+void ui_end_auto_away(resource_presence_t presence) {}
 void ui_titlebar_presence(contact_presence_t presence) {}
 void ui_handle_login_account_success(ProfAccount *account) {}
 void ui_update_presence(const resource_presence_t resource_presence,