From a9c629dd9e569b1718566a097c14e99695cef8b0 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 27 Jan 2013 22:27:30 +0000 Subject: [PATCH] Set last presence for account --- src/accounts.c | 18 ++++++++++++++++++ src/accounts.h | 2 ++ src/connection.c | 10 +++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/accounts.c b/src/accounts.c index 14851bef..7e21b8fa 100644 --- a/src/accounts.c +++ b/src/accounts.c @@ -300,6 +300,24 @@ accounts_set_resource(const char * const account_name, const char * const value) } } +void +accounts_set_last_presence(const char * const account_name, const char * const value) +{ + if (accounts_account_exists(account_name)) { + g_key_file_set_string(accounts, account_name, "presence.last", value); + _save_accounts(); + } +} + +void +accounts_set_login_presence(const char * const account_name, const char * const value) +{ + if (accounts_account_exists(account_name)) { + g_key_file_set_string(accounts, account_name, "presence.login", value); + _save_accounts(); + } +} + static void _fix_legacy_accounts(const char * const account_name) { diff --git a/src/accounts.h b/src/accounts.h index 7839cee2..42272890 100644 --- a/src/accounts.h +++ b/src/accounts.h @@ -50,5 +50,7 @@ gboolean accounts_account_exists(const char * const account_name); void accounts_set_jid(const char * const account_name, const char * const value); void accounts_set_server(const char * const account_name, const char * const value); void accounts_set_resource(const char * const account_name, const char * const value); +void accounts_set_last_presence(const char * const account_name, const char * const value); +void accounts_set_login_presence(const char * const account_name, const char * const value); #endif diff --git a/src/connection.c b/src/connection.c index 5db6649c..8185c7c8 100644 --- a/src/connection.c +++ b/src/connection.c @@ -402,7 +402,7 @@ jabber_update_presence(jabber_presence_t status, const char * const msg, int idle) { int pri; - char *show; + char *show, *last; // don't send presence when disconnected if (jabber_conn.conn_status != JABBER_CONNECTED) @@ -419,18 +419,23 @@ jabber_update_presence(jabber_presence_t status, const char * const msg, { case PRESENCE_AWAY: show = STANZA_TEXT_AWAY; + last = STANZA_TEXT_AWAY; break; case PRESENCE_DND: show = STANZA_TEXT_DND; + last = STANZA_TEXT_DND; break; case PRESENCE_CHAT: show = STANZA_TEXT_CHAT; + last = STANZA_TEXT_CHAT; break; case PRESENCE_XA: show = STANZA_TEXT_XA; + last = STANZA_TEXT_XA; break; default: // PRESENCE_ONLINE show = NULL; + last = STANZA_TEXT_ONLINE; break; } @@ -496,6 +501,9 @@ jabber_update_presence(jabber_presence_t status, const char * const msg, xmpp_stanza_release(presence); FREE_SET_NULL(sha1); + + // set last presence for account + accounts_set_last_presence(saved_account.name, last); } void