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:
parent
54e225aa53
commit
9593e17c3c
@ -786,11 +786,22 @@ accounts_set_last_activity(const char * const account_name)
|
||||
if (res) {
|
||||
char *timestr = g_time_val_to_iso8601(&nowtv);
|
||||
g_key_file_set_string(accounts, account_name, "last.activity", timestr);
|
||||
free(timestr);
|
||||
_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
|
||||
accounts_set_login_presence(const char * const account_name, const char * const value)
|
||||
{
|
||||
|
@ -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_status(const char * const account_name, const char * const value);
|
||||
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);
|
||||
resource_presence_t accounts_get_login_presence(const char * const account_name);
|
||||
char * accounts_get_last_status(const char * const account_name);
|
||||
|
@ -65,7 +65,7 @@ cl_ev_connect_account(ProfAccount *account)
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@ -78,7 +78,7 @@ cl_ev_presence_send(const resource_presence_t presence_type, const char * const
|
||||
account_free(account);
|
||||
#endif
|
||||
|
||||
presence_send(presence_type, msg, idle, signed_status);
|
||||
presence_send(presence_type, msg, idle_secs, signed_status);
|
||||
|
||||
free(signed_status);
|
||||
}
|
||||
|
@ -38,10 +38,10 @@
|
||||
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);
|
||||
|
||||
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_muc_msg(ProfMucWin *mucwin, const char * const msg);
|
||||
void cl_ev_send_priv_msg(ProfPrivateWin *privwin, const char * const msg);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user