1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Include last activity in initial presence

This commit is contained in:
James Booth 2015-09-27 23:53:06 +01:00
parent 54e225aa53
commit 9593e17c3c
5 changed files with 40 additions and 6 deletions

View File

@ -786,11 +786,22 @@ accounts_set_last_activity(const char * const account_name)
if (res) { if (res) {
char *timestr = g_time_val_to_iso8601(&nowtv); char *timestr = g_time_val_to_iso8601(&nowtv);
g_key_file_set_string(accounts, account_name, "last.activity", timestr); g_key_file_set_string(accounts, account_name, "last.activity", timestr);
free(timestr);
_save_accounts(); _save_accounts();
} }
} }
} }
char *
accounts_get_last_activity(const char * const account_name)
{
if (accounts_account_exists(account_name)) {
return g_key_file_get_string(accounts, account_name, "last.activity", NULL);
} else {
return NULL;
}
}
void void
accounts_set_login_presence(const char * const account_name, const char * const value) accounts_set_login_presence(const char * const account_name, const char * const value)
{ {

View File

@ -68,6 +68,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_presence(const char * const account_name, const char * const value);
void accounts_set_last_status(const char * const account_name, const char * const value); void accounts_set_last_status(const char * const account_name, const char * const value);
void accounts_set_last_activity(const char * const account_name); void accounts_set_last_activity(const char * const account_name);
char * accounts_get_last_activity(const char * const account_name);
void accounts_set_login_presence(const char * const account_name, const char * const value); 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_login_presence(const char * const account_name);
char * accounts_get_last_status(const char * const account_name); char * accounts_get_last_status(const char * const account_name);

View File

@ -65,7 +65,7 @@ cl_ev_connect_account(ProfAccount *account)
} }
void void
cl_ev_presence_send(const resource_presence_t presence_type, const char * const msg, const int idle) cl_ev_presence_send(const resource_presence_t presence_type, const char * const msg, const int idle_secs)
{ {
char *signed_status = NULL; char *signed_status = NULL;
@ -78,7 +78,7 @@ cl_ev_presence_send(const resource_presence_t presence_type, const char * const
account_free(account); account_free(account);
#endif #endif
presence_send(presence_type, msg, idle, signed_status); presence_send(presence_type, msg, idle_secs, signed_status);
free(signed_status); free(signed_status);
} }

View File

@ -38,7 +38,7 @@
jabber_conn_status_t cl_ev_connect_jid(const char * const jid, const char * const passwd, const char * const altdomain, const int port); jabber_conn_status_t cl_ev_connect_jid(const char * const jid, const char * const passwd, const char * const altdomain, const int port);
jabber_conn_status_t cl_ev_connect_account(ProfAccount *account); jabber_conn_status_t cl_ev_connect_account(ProfAccount *account);
void cl_ev_presence_send(const resource_presence_t presence_type, const char * const msg, const int idle); void cl_ev_presence_send(const resource_presence_t presence_type, const char * const msg, const int idle_secs);
void cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg); void cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg);
void cl_ev_send_muc_msg(ProfMucWin *mucwin, const char * const msg); void cl_ev_send_muc_msg(ProfMucWin *mucwin, const char * const msg);

View File

@ -342,8 +342,30 @@ _roster_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, v
sv_ev_roster_received(); sv_ev_roster_received();
resource_presence_t conn_presence = accounts_get_login_presence(jabber_get_account_name()); 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); 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; return 1;
} }