From b484411ea8d94349c2879f09f48d907dbdaf72c9 Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 25 Sep 2015 00:26:58 +0100 Subject: [PATCH 1/3] Save last activity to account on disconnect --- src/command/commands.c | 1 + src/config/accounts.c | 17 +++++++++++++++++ src/config/accounts.h | 1 + src/xmpp/connection.c | 1 + tests/unittests/config/stub_accounts.c | 1 + tests/unittests/test_cmd_disconnect.c | 1 + 6 files changed, 22 insertions(+) diff --git a/src/command/commands.c b/src/command/commands.c index 3f695cc1..5ddfa07e 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -777,6 +777,7 @@ cmd_disconnect(ProfWin *window, const char * const command, gchar **args) if (jabber_get_connection_status() == JABBER_CONNECTED) { char *jid = strdup(jabber_get_fulljid()); cons_show("%s logged out successfully.", jid); + accounts_set_last_activity(jabber_get_account_name()); jabber_disconnect(); roster_clear(); muc_invites_clear(); 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) diff --git a/tests/unittests/test_cmd_disconnect.c b/tests/unittests/test_cmd_disconnect.c index 7ea5b53a..c6c9f611 100644 --- a/tests/unittests/test_cmd_disconnect.c +++ b/tests/unittests/test_cmd_disconnect.c @@ -22,6 +22,7 @@ void clears_chat_sessions(void **state) chat_session_recipient_active("mike@server.org", "work", FALSE); will_return(jabber_get_connection_status, JABBER_CONNECTED); + will_return(jabber_get_account_name, "someaccount"); will_return(jabber_get_fulljid, "myjid@myserver.com"); expect_any_cons_show(); From a5c671002407220562d88ea5674a46d77ceb8022 Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 25 Sep 2015 00:35:08 +0100 Subject: [PATCH 2/3] Removed redundant last activity setter --- src/command/commands.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/command/commands.c b/src/command/commands.c index 5ddfa07e..3f695cc1 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -777,7 +777,6 @@ cmd_disconnect(ProfWin *window, const char * const command, gchar **args) if (jabber_get_connection_status() == JABBER_CONNECTED) { char *jid = strdup(jabber_get_fulljid()); cons_show("%s logged out successfully.", jid); - accounts_set_last_activity(jabber_get_account_name()); jabber_disconnect(); roster_clear(); muc_invites_clear(); From c5178747fdbf9a9d5b8facc03f12bc5a1a38860e Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 25 Sep 2015 00:36:20 +0100 Subject: [PATCH 3/3] Fixed test --- tests/unittests/test_cmd_disconnect.c | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unittests/test_cmd_disconnect.c b/tests/unittests/test_cmd_disconnect.c index c6c9f611..7ea5b53a 100644 --- a/tests/unittests/test_cmd_disconnect.c +++ b/tests/unittests/test_cmd_disconnect.c @@ -22,7 +22,6 @@ void clears_chat_sessions(void **state) chat_session_recipient_active("mike@server.org", "work", FALSE); will_return(jabber_get_connection_status, JABBER_CONNECTED); - will_return(jabber_get_account_name, "someaccount"); will_return(jabber_get_fulljid, "myjid@myserver.com"); expect_any_cons_show();