static int _roster_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); if (g_strcmp0(id, "roster") != 0) { return 1; } // handle initial roster response xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); xmpp_stanza_t *item = xmpp_stanza_get_children(query); while (item) { const char *barejid = xmpp_stanza_get_attribute(item, STANZA_ATTR_JID); gchar *barejid_lower = g_utf8_strdown(barejid, -1); const char *name = xmpp_stanza_get_attribute(item, STANZA_ATTR_NAME); const char *sub = xmpp_stanza_get_attribute(item, STANZA_ATTR_SUBSCRIPTION); // do not set nickname to empty string, set to NULL instead if (name && (strlen(name) == 0)) name = NULL; gboolean pending_out = FALSE; const char *ask = xmpp_stanza_get_attribute(item, STANZA_ATTR_ASK); if (g_strcmp0(ask, "subscribe") == 0) { pending_out = TRUE; } GSList *groups = _get_groups_from_item(item); gboolean added = roster_add(barejid_lower, name, groups, sub, pending_out); if (!added) { log_warning("Attempt to add contact twice: %s", barejid_lower); } g_free(barejid_lower); item = xmpp_stanza_get_next(item); } 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); return 1; }
static int _roster_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); if (g_strcmp0(id, "roster") != 0) { return 1; } // handle initial roster response xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); xmpp_stanza_t *item = xmpp_stanza_get_children(query); while (item) { const char *barejid = xmpp_stanza_get_attribute(item, STANZA_ATTR_JID); gchar *barejid_lower = g_utf8_strdown(barejid, -1); const char *name = xmpp_stanza_get_attribute(item, STANZA_ATTR_NAME); const char *sub = xmpp_stanza_get_attribute(item, STANZA_ATTR_SUBSCRIPTION); // do not set nickname to empty string, set to NULL instead if (name && (strlen(name) == 0)) name = NULL; gboolean pending_out = FALSE; const char *ask = xmpp_stanza_get_attribute(item, STANZA_ATTR_ASK); if (g_strcmp0(ask, "subscribe") == 0) { pending_out = TRUE; } GSList *groups = _get_groups_from_item(item); gboolean added = roster_add(barejid_lower, name, groups, sub, pending_out); if (!added) { log_warning("Attempt to add contact twice: %s", barejid_lower); } g_free(barejid_lower); item = xmpp_stanza_get_next(item); } 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; 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; }