void lost_connection_clears_chat_sessions(void **state)
{
    chat_sessions_init();
    chat_session_recipient_active("*****@*****.**", "laptop", FALSE);
    chat_session_recipient_active("*****@*****.**", "mobile", FALSE);
    expect_any_cons_show_error();

    sv_ev_lost_connection();

    ChatSession *session1 = chat_session_get("*****@*****.**");
    ChatSession *session2 = chat_session_get("*****@*****.**");
    assert_null(session1);
    assert_null(session2);
}
void removes_chat_session(void **state)
{
    char *barejid = "*****@*****.**";
    char *resource1 = "laptop";

    chat_session_recipient_active(barejid, resource1, FALSE);
    chat_session_remove(barejid);
    ChatSession *session = chat_session_get(barejid);

    assert_null(session);
}
void creates_chat_session_on_recipient_activity(void **state)
{
    char *barejid = "*****@*****.**";
    char *resource = "tablet";

    chat_session_recipient_active(barejid, resource, FALSE);
    ChatSession *session = chat_session_get(barejid);

    assert_non_null(session);
    assert_string_equal(session->resource, resource);
}
void clears_chat_sessions(void **state)
{
    chat_sessions_init();
    roster_create();
    chat_session_recipient_active("*****@*****.**", "laptop", FALSE);
    chat_session_recipient_active("*****@*****.**", "work", FALSE);

    will_return(connection_get_status, JABBER_CONNECTED);
    will_return(connection_get_fulljid, "*****@*****.**");
    expect_any_cons_show();

    gboolean result = cmd_disconnect(NULL, CMD_DISCONNECT, NULL);

    assert_true(result);

    ChatSession *session1 = chat_session_get("*****@*****.**");
    ChatSession *session2 = chat_session_get("*****@*****.**");
    assert_null(session1);
    assert_null(session2);
}
void replaces_chat_session_on_recipient_activity_with_different_resource(void **state)
{
    char *barejid = "*****@*****.**";
    char *resource1 = "tablet";
    char *resource2 = "mobile";

    chat_session_recipient_active(barejid, resource1, FALSE);
    chat_session_recipient_active(barejid, resource2, FALSE);
    ChatSession *session = chat_session_get(barejid);

    assert_string_equal(session->resource, resource2);
}
Exemple #6
0
static char*
_session_jid(const char *const barejid)
{
    ChatSession *session = chat_session_get(barejid);
    char *jid = NULL;
    if (session) {
        Jid *jidp = jid_create_from_bare_and_resource(session->barejid, session->resource);
        jid = strdup(jidp->fulljid);
        jid_destroy(jidp);
    } else {
        jid = strdup(barejid);
    }

    return jid;
}
Exemple #7
0
static char*
_session_state(const char *const barejid)
{
    ChatSession *session = chat_session_get(barejid);
    char *state = NULL;
    if (session) {
        if (prefs_get_boolean(PREF_STATES) && session->send_states) {
            state = STANZA_NAME_ACTIVE;
        }
    } else {
        if (prefs_get_boolean(PREF_STATES)) {
            state = STANZA_NAME_ACTIVE;
        }
    }

    return state;
}
void handle_offline_removes_chat_session(void **state)
{
    chat_sessions_init();
    char *barejid = "*****@*****.**";
    char *resource = "home";
    roster_init();
    roster_add(barejid, "bob", NULL, "both", FALSE);
    Resource *resourcep = resource_new(resource, RESOURCE_ONLINE, NULL, 10);
    roster_update_presence(barejid, resourcep, NULL);
    chat_session_recipient_active(barejid, resource, FALSE);
    sv_ev_contact_offline(barejid, resource, NULL);
    ChatSession *session = chat_session_get(barejid);

    assert_null(session);

    roster_clear();
    chat_sessions_clear();
}
Exemple #9
0
void
ui_contact_typing(const char *const barejid, const char *const resource)
{
    ProfChatWin *chatwin = wins_get_chat(barejid);
    ProfWin *window = (ProfWin*) chatwin;
    ChatSession *session = chat_session_get(barejid);

    if (prefs_get_boolean(PREF_INTYPE)) {
        // no chat window for user
        if (chatwin == NULL) {
            cons_show_typing(barejid);

        // have chat window but not currently in it
        } else if (!wins_is_current(window)) {
            cons_show_typing(barejid);

        // in chat window with user, no session or session with resource
        } else if (!session || (session && g_strcmp0(session->resource, resource) == 0)) {
            title_bar_set_typing(TRUE);

            int num = wins_get_num(window);
            status_bar_active(num);
       }
    }

    if (prefs_get_boolean(PREF_NOTIFY_TYPING)) {
        gboolean is_current = FALSE;
        if (window) {
            is_current = wins_is_current(window);
        }
        if ( !is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_TYPING_CURRENT)) ) {
            PContact contact = roster_get_contact(barejid);
            char const *display_usr = NULL;
            if (p_contact_name(contact)) {
                display_usr = p_contact_name(contact);
            } else {
                display_usr = barejid;
            }
            notify_typing(display_usr);
        }
    }
}
Exemple #10
0
void
sv_ev_gone(const char *const barejid, const char *const resource)
{
    if (barejid && resource) {
        gboolean show_message = TRUE;

        ProfChatWin *chatwin = wins_get_chat(barejid);
        if (chatwin) {
            ChatSession *session = chat_session_get(barejid);
            if (session && g_strcmp0(session->resource, resource) != 0) {
                show_message = FALSE;
            }
            if (show_message) {
                chatwin_recipient_gone(chatwin);
            }
        }
    }

    if (wins_chat_exists(barejid)) {
        chat_session_recipient_gone(barejid, resource);
    }
}
void handle_offline_removes_chat_session(void **state)
{
    plugins_init();
    roster_create();
    chat_sessions_init();
    char *barejid = "*****@*****.**";
    char *resource = "home";
    roster_add(barejid, "bob", NULL, "both", FALSE);
    Resource *resourcep = resource_new(resource, RESOURCE_ONLINE, NULL, 10);
    roster_update_presence(barejid, resourcep, NULL);
    chat_session_recipient_active(barejid, resource, FALSE);
    ProfConsoleWin *console = malloc(sizeof(ProfConsoleWin));
    will_return(win_create_console, &console->window);
    wins_init();
    sv_ev_contact_offline(barejid, resource, NULL);
    ChatSession *session = chat_session_get(barejid);

    assert_null(session);

    roster_destroy();
    chat_sessions_clear();
    plugins_shutdown();
}
void returns_false_when_chat_session_does_not_exist(void **state)
{
    ChatSession *session = chat_session_get("*****@*****.**");
    assert_null(session);
}
Exemple #13
0
static void
_show_contact_presence(ProfChatWin *chatwin)
{
    int bracket_attrs = theme_attrs(THEME_TITLE_BRACKET);
    char *resource = NULL;

    ChatSession *session = chat_session_get(chatwin->barejid);
    if (chatwin->resource_override) {
        resource = chatwin->resource_override;
    } else if (session && session->resource) {
        resource = session->resource;
    }
    if (resource && prefs_get_boolean(PREF_RESOURCE_TITLE)) {
        wprintw(win, "/");
        wprintw(win, resource);
    }

    if (prefs_get_boolean(PREF_PRESENCE)) {
        theme_item_t presence_colour = THEME_TITLE_OFFLINE;
        const char *presence = "offline";

        jabber_conn_status_t conn_status = connection_get_status();
        if (conn_status == JABBER_CONNECTED) {
            PContact contact = roster_get_contact(chatwin->barejid);
            if (contact) {
                if (resource) {
                    Resource *resourcep = p_contact_get_resource(contact, resource);
                    if (resourcep) {
                        presence = string_from_resource_presence(resourcep->presence);
                    }
                } else {
                    presence = p_contact_presence(contact);
                }
            }
        }

        presence_colour = THEME_TITLE_ONLINE;
        if (g_strcmp0(presence, "offline") == 0) {
            presence_colour = THEME_TITLE_OFFLINE;
        } else if (g_strcmp0(presence, "away") == 0) {
            presence_colour = THEME_TITLE_AWAY;
        } else if (g_strcmp0(presence, "xa") == 0) {
            presence_colour = THEME_TITLE_XA;
        } else if (g_strcmp0(presence, "chat") == 0) {
            presence_colour = THEME_TITLE_CHAT;
        } else if (g_strcmp0(presence, "dnd") == 0) {
            presence_colour = THEME_TITLE_DND;
        }

        int presence_attrs = theme_attrs(presence_colour);
        wprintw(win, " ");
        wattron(win, bracket_attrs);
        wprintw(win, "[");
        wattroff(win, bracket_attrs);
        wattron(win, presence_attrs);
        wprintw(win, presence);
        wattroff(win, presence_attrs);
        wattron(win, bracket_attrs);
        wprintw(win, "]");
        wattroff(win, bracket_attrs);
    }
}