diff --git a/src/config/accounts.c b/src/config/accounts.c index a827392b..d43cc3a3 100644 --- a/src/config/accounts.c +++ b/src/config/accounts.c @@ -761,6 +761,23 @@ accounts_set_last_presence(const char * const account_name, const char * const v } } +void +accounts_set_last_activity(const char * const account_name) +{ + if (accounts_account_exists(account_name)) { + GDateTime *nowdt = g_date_time_new_now_utc(); + GTimeVal nowtv; + gboolean res = g_date_time_to_timeval(nowdt, &nowtv); + g_date_time_unref(nowdt); + + if (res) { + char *timestr = g_time_val_to_iso8601(&nowtv); + g_key_file_set_string(accounts, account_name, "last.activity", timestr); + _save_accounts(); + } + } +} + void accounts_set_login_presence(const char * const account_name, const char * const value) { diff --git a/src/config/accounts.h b/src/config/accounts.h index eb981cb8..65106365 100644 --- a/src/config/accounts.h +++ b/src/config/accounts.h @@ -66,6 +66,7 @@ void accounts_set_muc_service(const char * const account_name, const char * cons void accounts_set_muc_nick(const char * const account_name, const char * const value); void accounts_set_otr_policy(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_last_activity(const char * const account_name); void accounts_set_login_presence(const char * const account_name, const char * const value); resource_presence_t accounts_get_login_presence(const char * const account_name); resource_presence_t accounts_get_last_presence(const char * const account_name); diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index 768a4476..abc08732 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -200,6 +200,7 @@ jabber_disconnect(void) // if connected, send end stream and wait for response if (jabber_conn.conn_status == JABBER_CONNECTED) { log_info("Closing connection"); + accounts_set_last_activity(jabber_get_account_name()); jabber_conn.conn_status = JABBER_DISCONNECTING; xmpp_disconnect(jabber_conn.conn); diff --git a/tests/unittests/config/stub_accounts.c b/tests/unittests/config/stub_accounts.c index c046be86..89b6dfc2 100644 --- a/tests/unittests/config/stub_accounts.c +++ b/tests/unittests/config/stub_accounts.c @@ -122,6 +122,7 @@ void accounts_set_otr_policy(const char * const account_name, const char * const } void accounts_set_last_presence(const char * const account_name, const char * const value) {} +void accounts_set_last_activity(const char * const account_name) {} void accounts_set_pgp_keyid(const char * const account_name, const char * const value) {} void accounts_set_login_presence(const char * const account_name, const char * const value)