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

Moved sending of initial presence to sv_ev_roster_received

This commit is contained in:
James Booth 2015-12-14 23:53:35 +00:00
parent 1080c8c2ae
commit 482eea4fcf
3 changed files with 35 additions and 29 deletions

View File

@ -48,6 +48,7 @@
#include "window_list.h"
#include "config/tlscerts.h"
#include "profanity.h"
#include "event/client_events.h"
#ifdef HAVE_LIBOTR
#include "otr/otr.h"
@ -100,6 +101,36 @@ sv_ev_roster_received(void)
if (prefs_get_boolean(PREF_ROSTER)) {
ui_show_roster();
}
char *account = jabber_get_account_name();
// send initial presence
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;
if (prefs_get_boolean(PREF_LASTACTIVITY)) {
cl_ev_presence_send(conn_presence, NULL, diff_secs);
} else {
cl_ev_presence_send(conn_presence, NULL, 0);
}
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);
}
}
void

View File

@ -336,35 +336,6 @@ _roster_result_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, voi
sv_ev_roster_received();
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;
if (prefs_get_boolean(PREF_LASTACTIVITY)) {
cl_ev_presence_send(conn_presence, NULL, diff_secs);
} else {
cl_ev_presence_send(conn_presence, NULL, 0);
}
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;
}

View File

@ -195,3 +195,7 @@ void accounts_clear_otr(const char * const account_name) {}
void accounts_clear_pgp_keyid(const char * const account_name) {}
void accounts_clear_script_start(const char * const account_name) {}
void accounts_add_otr_policy(const char * const account_name, const char * const contact_jid, const char * const policy) {}
char* accounts_get_last_activity(const char *const account_name)
{
return NULL;
}