about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/command.c15
-rw-r--r--src/jabber.c16
-rw-r--r--src/jabber.h3
-rw-r--r--src/preferences.c6
-rw-r--r--src/profanity.c20
-rw-r--r--src/stanza.h2
6 files changed, 46 insertions, 16 deletions
diff --git a/src/command.c b/src/command.c
index f46fe6d3..94d5ce7b 100644
--- a/src/command.c
+++ b/src/command.c
@@ -546,7 +546,7 @@ static struct cmd_t setting_commands[] =
           "          away - Sends an away presence.",
           "          off - Disabled (default).",
           "time    : Number of minutes before the presence change is sent, the default is 15.",
-          "message : Optional message to send with the presence change.",
+          "message : Optional message to send with the presence change, use no value to clear.",
           "check   : on|off, when enabled, checks for activity and sends online presence, default is 'on'.",
           "",
           "Example: /autoaway mode idle",
@@ -1765,8 +1765,13 @@ _cmd_set_autoaway(gchar **args, struct cmd_help_t help)
     }
 
     if (strcmp(setting, "message") == 0) {
-        prefs_set_autoaway_message(value);
-        cons_show("Auto away message set to: \"%s\".", value);
+        if (strcmp(value, "off") == 0) {
+            prefs_set_autoaway_message(NULL);
+            cons_show("Auto away message cleared.");
+        } else {
+            prefs_set_autoaway_message(value);
+            cons_show("Auto away message set to: \"%s\".", value);
+        }
 
         return TRUE;
     }
@@ -1789,7 +1794,7 @@ _cmd_set_priority(gchar **args, struct cmd_help_t help)
         char *status = jabber_get_status();
         prefs_set_priority((int)intval);
         // update presence with new priority
-        jabber_update_presence(jabber_get_presence(), status);
+        jabber_update_presence(jabber_get_presence(), status, 0);
         if (status != NULL)
             free(status);
         cons_show("Priority set to %d.", intval);
@@ -1899,7 +1904,7 @@ _update_presence(const jabber_presence_t presence,
     if (conn_status != JABBER_CONNECTED) {
         cons_show("You are not currently connected.");
     } else {
-        jabber_update_presence(presence, msg);
+        jabber_update_presence(presence, msg, 0);
         title_bar_set_status(presence);
         if (msg != NULL) {
             cons_show("Status set to %s, \"%s\"", show, msg);
diff --git a/src/jabber.c b/src/jabber.c
index 654db520..93234f8a 100644
--- a/src/jabber.c
+++ b/src/jabber.c
@@ -324,7 +324,8 @@ jabber_leave_chat_room(const char * const room_jid)
 }
 
 void
-jabber_update_presence(jabber_presence_t status, const char * const msg)
+jabber_update_presence(jabber_presence_t status, const char * const msg,
+    int idle)
 {
     int pri;
     char *show;
@@ -379,6 +380,17 @@ jabber_update_presence(jabber_presence_t status, const char * const msg)
         xmpp_stanza_add_child(priority, value);
         xmpp_stanza_add_child(presence, priority);
     }
+
+    if (idle > 0) {
+        xmpp_stanza_t *query = xmpp_stanza_new(jabber_conn.ctx);
+        xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
+        xmpp_stanza_set_ns(query, STANZA_NS_LASTACTIVITY);
+        char idle_str[10];
+        snprintf(idle_str, sizeof(idle_str), "%d", idle);
+        xmpp_stanza_set_attribute(query, STANZA_ATTR_SECONDS, idle_str);
+        xmpp_stanza_add_child(presence, query);
+    }
+
     xmpp_send(jabber_conn.conn, presence);
 
     // send presence for each room
@@ -891,7 +903,7 @@ _roster_handler(xmpp_conn_t * const conn,
          *       presence rather than PRESENCE_ONLINE. It will be helpful
          *       when I set dnd status and reconnect for some reason */
         // send initial presence
-        jabber_update_presence(PRESENCE_ONLINE, NULL);
+        jabber_update_presence(PRESENCE_ONLINE, NULL, 0);
     }
 
     return 1;
diff --git a/src/jabber.h b/src/jabber.h
index 0ccd12f7..aad6a61d 100644
--- a/src/jabber.h
+++ b/src/jabber.h
@@ -62,7 +62,8 @@ void jabber_send_inactive(const char * const recipient);
 void jabber_send_composing(const char * const recipient);
 void jabber_send_paused(const char * const recipient);
 void jabber_send_gone(const char * const recipient);
-void jabber_update_presence(jabber_presence_t status, const char * const msg);
+void jabber_update_presence(jabber_presence_t status, const char * const msg,
+    int idle);
 const char * jabber_get_jid(void);
 jabber_conn_status_t jabber_get_connection_status(void);
 int jabber_get_priority(void);
diff --git a/src/preferences.c b/src/preferences.c
index eb7f438b..8b36f059 100644
--- a/src/preferences.c
+++ b/src/preferences.c
@@ -389,7 +389,11 @@ prefs_get_autoaway_message(void)
 void
 prefs_set_autoaway_message(gchar *value)
 {
-    g_key_file_set_string(prefs, "autoaway", "message", value);
+    if (value == NULL) {
+        g_key_file_remove_key(prefs, "autoaway", "message", NULL);
+    } else {
+        g_key_file_set_string(prefs, "autoaway", "message", value);
+    }
     _save_prefs();
 }
 
diff --git a/src/profanity.c b/src/profanity.c
index 27fea803..75df9f8e 100644
--- a/src/profanity.c
+++ b/src/profanity.c
@@ -452,8 +452,10 @@ _handle_idle_time()
     if (!idle) {
         if (idle_ms >= prefs_time) {
             idle = TRUE;
+
+            // handle away mode
             if (strcmp(prefs_get_autoaway_mode(), "away") == 0) {
-                jabber_update_presence(PRESENCE_AWAY, prefs_get_autoaway_message());
+                jabber_update_presence(PRESENCE_AWAY, prefs_get_autoaway_message(), 0);
                 if (prefs_get_autoaway_message() != NULL) {
                     cons_show("Idle for %d minutes, status set to away, \"%s\".",
                         prefs_get_autoaway_time(), prefs_get_autoaway_message());
@@ -465,24 +467,28 @@ _handle_idle_time()
                     title_bar_set_status(PRESENCE_AWAY);
                     win_current_page_off();
                 }
+
+            // handle idle mode
             } else if (strcmp(prefs_get_autoaway_mode(), "idle") == 0) {
-                cons_show("IDLE");
-                win_current_page_off();
+                jabber_update_presence(PRESENCE_ONLINE,
+                    prefs_get_autoaway_message(), idle_ms / 1000);
             }
         }
 
     } else {
         if (idle_ms < prefs_time) {
             idle = FALSE;
+
+            // handle check
             if (prefs_get_autoaway_check()) {
                 if (strcmp(prefs_get_autoaway_mode(), "away") == 0) {
-                    jabber_update_presence(PRESENCE_ONLINE, NULL);
-                    cons_show("Auto presence online.");
+                    jabber_update_presence(PRESENCE_ONLINE, NULL, 0);
+                    cons_show("No longer idle, status set to online.");
                     title_bar_set_status(PRESENCE_ONLINE);
                     win_current_page_off();
                 } else if (strcmp(prefs_get_autoaway_mode(), "idle") == 0) {
-                    cons_show("BACK");
-                    win_current_page_off();
+                    jabber_update_presence(PRESENCE_ONLINE, NULL, 0);
+                    title_bar_set_status(PRESENCE_ONLINE);
                 }
             }
         }
diff --git a/src/stanza.h b/src/stanza.h
index d31ff519..7d380e8c 100644
--- a/src/stanza.h
+++ b/src/stanza.h
@@ -71,6 +71,7 @@
 #define STANZA_ATTR_NICK "nick"
 #define STANZA_ATTR_ASK "ask"
 #define STANZA_ATTR_ID "id"
+#define STANZA_ATTR_SECONDS "seconds"
 
 #define STANZA_TEXT_AWAY "away"
 #define STANZA_TEXT_DND "dnd"
@@ -82,6 +83,7 @@
 #define STANZA_NS_MUC "http://jabber.org/protocol/muc"
 #define STANZA_NS_MUC_USER "http://jabber.org/protocol/muc#user"
 #define STANZA_NS_PING "urn:xmpp:ping"
+#define STANZA_NS_LASTACTIVITY "jabber:iq:last"
 
 xmpp_stanza_t* stanza_create_chat_state(xmpp_ctx_t *ctx,
     const char * const recipient, const char * const state);