static int cb_is_logged_in(void *opdata, const char *accountname, const char *protocol, const char *recipient) { jabber_conn_status_t conn_status = jabber_get_connection_status(); if (conn_status != JABBER_CONNECTED) { return PRESENCE_OFFLINE; } PContact contact = roster_get_contact(recipient); // not in roster if (contact == NULL) { return PRESENCE_ONLINE; } // not subscribed if (p_contact_subscribed(contact) == FALSE) { return PRESENCE_ONLINE; } // subscribed if (g_strcmp0(p_contact_presence(contact), "offline") == 0) { return PRESENCE_OFFLINE; } else { return PRESENCE_ONLINE; } }
void contact_not_subscribed_when_no_subscription_value(void **state) { PContact contact = p_contact_new("*****@*****.**", "bob", NULL, NULL, "is offline", FALSE); gboolean result = p_contact_subscribed(contact); assert_false(result); p_contact_free(contact); }
void contact_subscribed_when_both(void **state) { PContact contact = p_contact_new("*****@*****.**", "bob", NULL, "both", "is offline", FALSE); gboolean result = p_contact_subscribed(contact); assert_true(result); p_contact_free(contact); }
void _show_roster_contacts(GSList *list, gboolean show_groups) { GSList *curr = list; while(curr) { PContact contact = curr->data; GString *title = g_string_new(" "); title = g_string_append(title, p_contact_barejid(contact)); if (p_contact_name(contact) != NULL) { title = g_string_append(title, " ("); title = g_string_append(title, p_contact_name(contact)); title = g_string_append(title, ")"); } const char *presence = p_contact_presence(contact); win_print_time(console, '-'); if (p_contact_subscribed(contact)) { win_presence_colour_on(console, presence); wprintw(console->win, "%s\n", title->str); win_presence_colour_off(console, presence); } else { win_presence_colour_on(console, "offline"); wprintw(console->win, "%s\n", title->str); win_presence_colour_off(console, "offline"); } g_string_free(title, TRUE); win_print_time(console, '-'); wprintw(console->win, " Subscription : "); GString *sub = g_string_new(""); sub = g_string_append(sub, p_contact_subscription(contact)); if (p_contact_pending_out(contact)) { sub = g_string_append(sub, ", request sent"); } if (presence_sub_request_exists(p_contact_barejid(contact))) { sub = g_string_append(sub, ", request received"); } if (p_contact_subscribed(contact)) { wattron(console->win, COLOUR_SUBSCRIBED); } else { wattron(console->win, COLOUR_UNSUBSCRIBED); } wprintw(console->win, "%s\n", sub->str); if (p_contact_subscribed(contact)) { wattroff(console->win, COLOUR_SUBSCRIBED); } else { wattroff(console->win, COLOUR_UNSUBSCRIBED); } g_string_free(sub, TRUE); if (show_groups) { GSList *groups = p_contact_groups(contact); if (groups != NULL) { GString *groups_str = g_string_new(" Groups : "); while (groups != NULL) { g_string_append(groups_str, groups->data); if (g_slist_next(groups) != NULL) { g_string_append(groups_str, ", "); } groups = g_slist_next(groups); } cons_show(groups_str->str); g_string_free(groups_str, TRUE); } } curr = g_slist_next(curr); } }