diff options
author | James Booth <boothj5@gmail.com> | 2015-09-27 23:53:06 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2015-09-27 23:53:06 +0100 |
commit | 9593e17c3c414a4a78ec73bfee8464a78fa28dc1 (patch) | |
tree | a5800372fd853b195050b870156aa65b2bf4c5b3 /src/xmpp/roster.c | |
parent | 54e225aa5330b7a3c20bda38264e5ad0cfdfcdc5 (diff) | |
download | profani-tty-9593e17c3c414a4a78ec73bfee8464a78fa28dc1.tar.gz |
Include last activity in initial presence
Diffstat (limited to 'src/xmpp/roster.c')
-rw-r--r-- | src/xmpp/roster.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/xmpp/roster.c b/src/xmpp/roster.c index 55695d75..020f01f6 100644 --- a/src/xmpp/roster.c +++ b/src/xmpp/roster.c @@ -342,8 +342,30 @@ _roster_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, v sv_ev_roster_received(); - resource_presence_t conn_presence = accounts_get_login_presence(jabber_get_account_name()); - cl_ev_presence_send(conn_presence, NULL, 0); + char *account = jabber_get_account_name(); + resource_presence_t conn_presence = accounts_get_login_presence(account); + + char *last_activity_str = accounts_get_last_activity(account); + if (last_activity_str) { + GDateTime *nowdt = g_date_time_new_now_utc(); + + GTimeVal lasttv; + gboolean res = g_time_val_from_iso8601(last_activity_str, &lasttv); + if (res) { + GDateTime *lastdt = g_date_time_new_from_timeval_utc(&lasttv); + GTimeSpan diff_micros = g_date_time_difference(nowdt, lastdt); + int diff_secs = (diff_micros / 1000) / 1000; + cl_ev_presence_send(conn_presence, NULL, diff_secs); + g_date_time_unref(lastdt); + } else { + cl_ev_presence_send(conn_presence, NULL, 0); + } + + free(last_activity_str); + g_date_time_unref(nowdt); + } else { + cl_ev_presence_send(conn_presence, NULL, 0); + } return 1; } |