Beispiel #1
0
void
ui_switch_win(const int i)
{
    ui_current_page_off();
    ProfWin *new_current = wins_get_by_num(i);
    if (new_current != NULL) {
        wins_set_current_by_num(i);
        ui_current_page_off();

        new_current->unread = 0;

        if (i == 1) {
            title_bar_title();
            status_bar_active(1);
        } else {
            PContact contact = roster_get_contact(new_current->from);
            if (contact != NULL) {
                if (p_contact_name(contact) != NULL) {
                    title_bar_set_recipient(p_contact_name(contact));
                } else {
                    title_bar_set_recipient(new_current->from);
                }
            } else {
                title_bar_set_recipient(new_current->from);
            }
            title_bar_draw();;
            status_bar_active(i);
        }
        wins_refresh_current();
    }
}
Beispiel #2
0
gboolean
roster_add(const char *const barejid, const char *const name, GSList *groups, const char *const subscription,
    gboolean pending_out)
{
    assert(roster != NULL);

    PContact contact = roster_get_contact(barejid);
    if (contact) {
        return FALSE;
    }

    contact = p_contact_new(barejid, name, groups, subscription, NULL, pending_out);

    // add groups
    GSList *curr_new_group = groups;
    while (curr_new_group) {
        char *new_group = curr_new_group->data;
        if (g_hash_table_contains(roster->group_count, new_group)) {
            int count = GPOINTER_TO_INT(g_hash_table_lookup(roster->group_count, new_group));
            g_hash_table_insert(roster->group_count, strdup(new_group), GINT_TO_POINTER(count + 1));
        } else {
            g_hash_table_insert(roster->group_count, strdup(new_group), GINT_TO_POINTER(1));
            autocomplete_add(roster->groups_ac, new_group);
        }

        curr_new_group = g_slist_next(curr_new_group);
    }

    g_hash_table_insert(roster->contacts, strdup(barejid), contact);
    autocomplete_add(roster->barejid_ac, barejid);
    _add_name_and_barejid(name, barejid);

    return TRUE;
}
Beispiel #3
0
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;
    }
}
Beispiel #4
0
char*
chatwin_get_string(ProfChatWin *chatwin)
{
    assert(chatwin != NULL);

    GString *res = g_string_new("Chat ");

    jabber_conn_status_t conn_status = jabber_get_connection_status();
    if (conn_status == JABBER_CONNECTED) {
        PContact contact = roster_get_contact(chatwin->barejid);
        if (contact == NULL) {
            g_string_append(res, chatwin->barejid);
        } else {
            const char *display_name = p_contact_name_or_jid(contact);
            g_string_append(res, display_name);
            g_string_append_printf(res, " - %s", p_contact_presence(contact));
        }
    } else {
        g_string_append(res, chatwin->barejid);
    }

    if (chatwin->unread > 0) {
        g_string_append_printf(res, ", %d unread", chatwin->unread);
    }

    char *resstr = res->str;
    g_string_free(res, FALSE);

    return resstr;
}
Beispiel #5
0
void
roster_remove(const char *const name, const char *const barejid)
{
    autocomplete_remove(barejid_ac, barejid);
    autocomplete_remove(name_ac, name);
    g_hash_table_remove(name_to_barejid, name);

    // remove each fulljid
    PContact contact = roster_get_contact(barejid);
    if (contact) {
        GList *resources = p_contact_get_available_resources(contact);
        while (resources) {
            GString *fulljid = g_string_new(strdup(barejid));
            g_string_append(fulljid, "/");
            g_string_append(fulljid, resources->data);
            autocomplete_remove(fulljid_ac, fulljid->str);
            g_string_free(fulljid, TRUE);
            resources = g_list_next(resources);
        }
        g_list_free(resources);
    }

    // remove the contact
    g_hash_table_remove(contacts, barejid);
}
Beispiel #6
0
void
roster_update(const char *const barejid, const char *const name, GSList *groups, const char *const subscription,
    gboolean pending_out)
{
    PContact contact = roster_get_contact(barejid);
    assert(contact != NULL);

    p_contact_set_subscription(contact, subscription);
    p_contact_set_pending_out(contact, pending_out);

    const char * const new_name = name;
    const char * current_name = NULL;
    if (p_contact_name(contact)) {
        current_name = strdup(p_contact_name(contact));
    }

    p_contact_set_name(contact, new_name);
    p_contact_set_groups(contact, groups);
    _replace_name(current_name, new_name, barejid);

    // add groups
    while (groups) {
        autocomplete_add(groups_ac, groups->data);
        groups = g_slist_next(groups);
    }
}
Beispiel #7
0
char*
roster_get_msg_display_name(const char *const barejid, const char *const resource)
{
    assert(roster != NULL);

    GString *result = g_string_new("");

    PContact contact = roster_get_contact(barejid);
    if (contact) {
        if (p_contact_name(contact)) {
            g_string_append(result, p_contact_name(contact));
        } else {
            g_string_append(result, barejid);
        }
    } else {
        g_string_append(result, barejid);
    }

    if (resource && prefs_get_boolean(PREF_RESOURCE_MESSAGE)) {
        g_string_append(result, "/");
        g_string_append(result, resource);
    }

    char *result_str = result->str;
    g_string_free(result, FALSE);

    return result_str;
}
Beispiel #8
0
void
ui_recipient_gone(const char * const barejid)
{
    if (barejid == NULL)
        return;

    PContact contact = roster_get_contact(barejid);
    const char * display_usr = NULL;
    if (p_contact_name(contact) != NULL) {
        display_usr = p_contact_name(contact);
    } else {
        display_usr = barejid;
    }

    ProfWin *window = wins_get_by_recipient(barejid);
    if (window != NULL) {
        win_print_time(window, '!');
        wattron(window->win, COLOUR_GONE);
        wprintw(window->win, "<- %s ", display_usr);
        wprintw(window->win, "has left the conversation.");
        wprintw(window->win, "\n");
        wattroff(window->win, COLOUR_GONE);
        if (wins_is_current(window)) {
            wins_refresh_current();
        }
    }
}
Beispiel #9
0
char*
win_get_title(ProfWin *window)
{
    if (window == NULL) {
        return strdup(CONS_WIN_TITLE);
    }
    if (window->type == WIN_CONSOLE) {
        return strdup(CONS_WIN_TITLE);
    }
    if (window->type == WIN_CHAT) {
        ProfChatWin *chatwin = (ProfChatWin*) window;
        assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
        jabber_conn_status_t conn_status = connection_get_status();
        if (conn_status == JABBER_CONNECTED) {
            PContact contact = roster_get_contact(chatwin->barejid);
            if (contact) {
                const char *name = p_contact_name_or_jid(contact);
                return strdup(name);
            } else {
                return strdup(chatwin->barejid);
            }
        } else {
            return strdup(chatwin->barejid);
        }
    }
    if (window->type == WIN_MUC) {
        ProfMucWin *mucwin = (ProfMucWin*) window;
        assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
        return strdup(mucwin->roomjid);
    }
    if (window->type == WIN_MUC_CONFIG) {
        ProfMucConfWin *confwin = (ProfMucConfWin*) window;
        assert(confwin->memcheck == PROFCONFWIN_MEMCHECK);
        GString *title = g_string_new(confwin->roomjid);
        g_string_append(title, " config");
        if (confwin->form->modified) {
            g_string_append(title, " *");
        }
        char *title_str = title->str;
        g_string_free(title, FALSE);
        return title_str;
    }
    if (window->type == WIN_PRIVATE) {
        ProfPrivateWin *privatewin = (ProfPrivateWin*) window;
        assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
        return strdup(privatewin->fulljid);
    }
    if (window->type == WIN_XML) {
        return strdup(XML_WIN_TITLE);
    }
    if (window->type == WIN_PLUGIN) {
        ProfPluginWin *pluginwin = (ProfPluginWin*) window;
        assert(pluginwin->memcheck == PROFPLUGINWIN_MEMCHECK);
        return strdup(pluginwin->tag);
    }

    return NULL;
}
Beispiel #10
0
static int
_version_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
    void * const userdata)
{
    char *id = xmpp_stanza_get_id(stanza);

    if (id != NULL) {
        log_debug("IQ version result handler fired, id: %s.", id);
    } else {
        log_debug("IQ version result handler fired.");
    }

    const char *jid = xmpp_stanza_get_attribute(stanza, "from");

    xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
    if (query == NULL) {
        return 1;
    }

    char *ns = xmpp_stanza_get_ns(query);
    if (g_strcmp0(ns, STANZA_NS_VERSION) != 0) {
        return 1;
    }

    char *name_str = NULL;
    char *version_str = NULL;
    char *os_str = NULL;
    xmpp_stanza_t *name = xmpp_stanza_get_child_by_name(query, "name");
    xmpp_stanza_t *version = xmpp_stanza_get_child_by_name(query, "version");
    xmpp_stanza_t *os = xmpp_stanza_get_child_by_name(query, "os");

    if (name != NULL) {
        name_str = xmpp_stanza_get_text(name);
    }
    if (version != NULL) {
        version_str = xmpp_stanza_get_text(version);
    }
    if (os != NULL) {
        os_str = xmpp_stanza_get_text(os);
    }

    PContact contact;
    Jid *jidp = jid_create(jid);
    if (muc_room_is_active(jidp->barejid)) {
        contact = muc_get_participant(jidp->barejid, jidp->resourcepart);
    } else {
        contact = roster_get_contact(jidp->barejid);
    }

    Resource *resource = p_contact_get_resource(contact, jidp->resourcepart);
    const char *presence = string_from_resource_presence(resource->presence);
    handle_software_version_result(jid, presence, name_str, version_str, os_str);

    jid_destroy(jidp);

    return 1;
}
Beispiel #11
0
static int
cb_is_logged_in(void *opdata, const char *accountname,
    const char *protocol, const char *recipient)
{
    PContact contact = roster_get_contact(recipient);
    if (g_strcmp0(p_contact_presence(contact), "offline") == 0) {
        return 0;
    } else {
        return 1;
    }
}
Beispiel #12
0
void
chatwin_contact_offline(ProfChatWin *chatwin, char *resource, char *status)
{
    assert(chatwin != NULL);

    PContact contact = roster_get_contact(chatwin->barejid);
    char *display_str = p_contact_create_display_string(contact, resource);

    win_show_status_string((ProfWin*)chatwin, display_str, "offline", status, NULL, "--", "offline");

    free(display_str);
}
Beispiel #13
0
void
cons_show_status(const char * const barejid)
{
    PContact pcontact = roster_get_contact(barejid);

    if (pcontact != NULL) {
        win_show_contact(console, pcontact);
    } else {
        cons_show("No such contact \"%s\" in roster.", barejid);
    }
    ui_console_dirty();
    cons_alert();
}
Beispiel #14
0
void
ui_status(void)
{
    char *recipient = ui_current_recipient();
    PContact pcontact = roster_get_contact(recipient);
    ProfWin *current = wins_get_current();

    if (pcontact != NULL) {
        win_show_contact(current, pcontact);
    } else {
        ui_current_print_line("Error getting contact info.");
    }
}
Beispiel #15
0
void
chatwin_contact_online(ProfChatWin *chatwin, Resource *resource, GDateTime *last_activity)
{
    assert(chatwin != NULL);

    const char *show = string_from_resource_presence(resource->presence);
    PContact contact = roster_get_contact(chatwin->barejid);
    char *display_str = p_contact_create_display_string(contact, resource->name);

    win_show_status_string((ProfWin*)chatwin, display_str, show, resource->status, last_activity, "++", "online");

    free(display_str);
}
Beispiel #16
0
void
ui_outgoing_msg(const char * const from, const char * const to,
    const char * const message)
{
    PContact contact = roster_get_contact(to);
    ProfWin *window = wins_get_by_recipient(to);
    int num = 0;

    // create new window
    if (window == NULL) {
        Jid *jid = jid_create(to);

        if (muc_room_is_active(jid)) {
            window = wins_new(to, WIN_PRIVATE);
        } else {
            window = wins_new(to, WIN_CHAT);
        }

        jid_destroy(jid);
        num = wins_get_num(window);

        if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) {
            _win_show_history(window->win, num, to);
        }

        if (contact != NULL) {
            if (strcmp(p_contact_presence(contact), "offline") == 0) {
                const char const *show = p_contact_presence(contact);
                const char const *status = p_contact_status(contact);
                _show_status_string(window, to, show, status, NULL, "--", "offline");
            }
        }

    // use existing window
    } else {
        num = wins_get_num(window);
    }

    win_print_time(window, '-');
    if (strncmp(message, "/me ", 4) == 0) {
        wattron(window->win, COLOUR_ME);
        wprintw(window->win, "*%s ", from);
        wprintw(window->win, "%s", message + 4);
        wprintw(window->win, "\n");
        wattroff(window->win, COLOUR_ME);
    } else {
        _win_show_user(window->win, from, 0);
        _win_show_message(window->win, message);
    }
    ui_switch_win(num);
}
void
handle_contact_offline(char *contact, char *resource, char *status)
{
    gboolean updated = roster_contact_offline(contact, resource, status);

    if (resource != NULL && updated && prefs_get_boolean(PREF_STATUSES)) {
        Jid *jid = jid_create_from_bare_and_resource(contact, resource);
        PContact result = roster_get_contact(contact);
        if (p_contact_subscription(result) != NULL) {
            if (strcmp(p_contact_subscription(result), "none") != 0) {
                ui_contact_offline(jid->fulljid, "offline", status);
                ui_current_page_off();
            }
        }
        jid_destroy(jid);
    }
}
void
handle_contact_online(char *contact, Resource *resource,
    GDateTime *last_activity)
{
    gboolean updated = roster_update_presence(contact, resource, last_activity);

    if (updated && prefs_get_boolean(PREF_STATUSES)) {
        PContact result = roster_get_contact(contact);
        if (p_contact_subscription(result) != NULL) {
            if (strcmp(p_contact_subscription(result), "none") != 0) {
                const char *show = string_from_resource_presence(resource->presence);
                ui_contact_online(contact, resource->name, show, resource->status, last_activity);
                ui_current_page_off();
            }
        }
    }
}
Beispiel #19
0
void
ui_contact_offline(char *barejid, char *resource, char *status)
{
    char *show_console = prefs_get_string(PREF_STATUSES_CONSOLE);
    char *show_chat_win = prefs_get_string(PREF_STATUSES_CHAT);
    Jid *jid = jid_create_from_bare_and_resource(barejid, resource);
    PContact contact = roster_get_contact(barejid);
    if (p_contact_subscription(contact)) {
        if (strcmp(p_contact_subscription(contact), "none") != 0) {

            // show in console if "all"
            if (g_strcmp0(show_console, "all") == 0) {
                cons_show_contact_offline(contact, resource, status);

            // show in console of "online"
            } else if (g_strcmp0(show_console, "online") == 0) {
                cons_show_contact_offline(contact, resource, status);
            }

            // show in chat win if "all"
            if (g_strcmp0(show_chat_win, "all") == 0) {
                ProfChatWin *chatwin = wins_get_chat(barejid);
                if (chatwin) {
                    chatwin_contact_offline(chatwin, resource, status);
                }

            // show in chat win if "online" and presence online
            } else if (g_strcmp0(show_chat_win, "online") == 0) {
                ProfChatWin *chatwin = wins_get_chat(barejid);
                if (chatwin) {
                    chatwin_contact_offline(chatwin, resource, status);
                }
            }
        }
    }

    ProfChatWin *chatwin = wins_get_chat(barejid);
    if (chatwin && chatwin->resource_override && (g_strcmp0(resource, chatwin->resource_override) == 0)) {
        FREE_SET_NULL(chatwin->resource_override);
    }

    prefs_free_string(show_console);
    prefs_free_string(show_chat_win);
    jid_destroy(jid);
}
Beispiel #20
0
void
roster_remove(const char *const name, const char *const barejid)
{
    assert(roster != NULL);

    autocomplete_remove(roster->barejid_ac, barejid);
    autocomplete_remove(roster->name_ac, name);
    g_hash_table_remove(roster->name_to_barejid, name);

    // remove each fulljid
    PContact contact = roster_get_contact(barejid);
    if (contact) {
        GList *resources = p_contact_get_available_resources(contact);
        while (resources) {
            GString *fulljid = g_string_new(strdup(barejid));
            g_string_append(fulljid, "/");
            g_string_append(fulljid, resources->data);
            autocomplete_remove(roster->fulljid_ac, fulljid->str);
            g_string_free(fulljid, TRUE);
            resources = g_list_next(resources);
        }
        g_list_free(resources);

        GSList *groups = p_contact_groups(contact);
        GSList *curr = groups;
        while (curr) {
            gchar *group = curr->data;
            if (g_hash_table_contains(roster->group_count, group)) {
                int count = GPOINTER_TO_INT(g_hash_table_lookup(roster->group_count, group));
                count--;
                if (count < 1) {
                    g_hash_table_remove(roster->group_count, group);
                    autocomplete_remove(roster->groups_ac, group);
                } else {
                    g_hash_table_insert(roster->group_count, strdup(group), GINT_TO_POINTER(count));
                }
            }
            curr = g_slist_next(curr);
        }
    }

    // remove the contact
    g_hash_table_remove(roster->contacts, barejid);
}
Beispiel #21
0
void
cons_show_typing(const char * const barejid)
{
    PContact contact = roster_get_contact(barejid);
    const char * display_usr = NULL;
    if (p_contact_name(contact) != NULL) {
        display_usr = p_contact_name(contact);
    } else {
        display_usr = barejid;
    }

    win_print_time(console, '-');
    wattron(console->win, COLOUR_TYPING);
    wprintw(console->win, "!! %s is typing a message...\n", display_usr);
    wattroff(console->win, COLOUR_TYPING);

    ui_console_dirty();
    cons_alert();
}
Beispiel #22
0
void
chatwin_recipient_gone(ProfChatWin *chatwin)
{
    assert(chatwin != NULL);

    const char *display_usr = NULL;
    PContact contact = roster_get_contact(chatwin->barejid);
    if (contact) {
        if (p_contact_name(contact)) {
            display_usr = p_contact_name(contact);
        } else {
            display_usr = chatwin->barejid;
        }
    } else {
        display_usr = chatwin->barejid;
    }

    win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, THEME_GONE, "", "<- %s has left the conversation.", display_usr);
}
Beispiel #23
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);
        }
    }
}
Beispiel #24
0
gboolean
roster_update_presence(const char *const barejid, Resource *resource, GDateTime *last_activity)
{
    assert(barejid != NULL);
    assert(resource != NULL);

    PContact contact = roster_get_contact(barejid);
    if (contact == NULL) {
        return FALSE;
    }
    if (!_datetimes_equal(p_contact_last_activity(contact), last_activity)) {
        p_contact_set_last_activity(contact, last_activity);
    }
    p_contact_set_presence(contact, resource);
    Jid *jid = jid_create_from_bare_and_resource(barejid, resource->name);
    autocomplete_add(fulljid_ac, jid->fulljid);
    jid_destroy(jid);

    return TRUE;
}
Beispiel #25
0
void
handle_contact_online(char *barejid, Resource *resource,
    GDateTime *last_activity)
{
    gboolean updated = roster_update_presence(barejid, resource, last_activity);

    if (updated) {
        char *show_console = prefs_get_string(PREF_STATUSES_CONSOLE);
        char *show_chat_win = prefs_get_string(PREF_STATUSES_CHAT);
        PContact contact = roster_get_contact(barejid);
        if (p_contact_subscription(contact) != NULL) {
            if (strcmp(p_contact_subscription(contact), "none") != 0) {

                // show in console if "all"
                if (g_strcmp0(show_console, "all") == 0) {
                    cons_show_contact_online(contact, resource, last_activity);

                // show in console of "online" and presence online
                } else if (g_strcmp0(show_console, "online") == 0 &&
                        resource->presence == RESOURCE_ONLINE) {
                    cons_show_contact_online(contact, resource, last_activity);

                }

                // show in chat win if "all"
                if (g_strcmp0(show_chat_win, "all") == 0) {
                    ui_chat_win_contact_online(contact, resource, last_activity);

                // show in char win if "online" and presence online
                } else if (g_strcmp0(show_chat_win, "online") == 0 &&
                        resource->presence == RESOURCE_ONLINE) {
                    ui_chat_win_contact_online(contact, resource, last_activity);
                }
            }
        }
        prefs_free_string(show_console);
        prefs_free_string(show_chat_win);
    }

    ui_roster();
}
Beispiel #26
0
void
ui_contact_online(const char * const barejid, const char * const resource,
    const char * const show, const char * const status, GDateTime *last_activity)
{
    Jid *jid = jid_create_from_bare_and_resource(barejid, resource);
    PContact contact = roster_get_contact(barejid);
    GString *display_str = g_string_new("");

    // use nickname if exists
    if (p_contact_name(contact) != NULL) {
        g_string_append(display_str, p_contact_name(contact));
    } else {
        g_string_append(display_str, barejid);
    }

    // add resource if not default provided by profanity
    if (strcmp(jid->resourcepart, "__prof_default") != 0) {
        g_string_append(display_str, " (");
        g_string_append(display_str, jid->resourcepart);
        g_string_append(display_str, ")");
    }

    ProfWin *console = wins_get_console();
    _show_status_string(console, display_str->str, show, status, last_activity,
        "++", "online");

    ProfWin *window = wins_get_by_recipient(barejid);
    if (window != NULL) {
        _show_status_string(window, display_str->str, show, status,
            last_activity, "++", "online");
    }

    jid_destroy(jid);
    g_string_free(display_str, TRUE);

    if (wins_is_current(console)) {
        wins_refresh_current();
    } else if ((window != NULL) && (wins_is_current(window))) {
        wins_refresh_current();
    }
}
Beispiel #27
0
void
ui_contact_offline(const char * const from, const char * const show,
    const char * const status)
{
    Jid *jidp = jid_create(from);
    PContact contact = roster_get_contact(jidp->barejid);
    GString *display_str = g_string_new("");

    // use nickname if exists
    if (p_contact_name(contact) != NULL) {
        g_string_append(display_str, p_contact_name(contact));
    } else {
        g_string_append(display_str, jidp->barejid);
    }

    // add resource if not default provided by profanity
    if (strcmp(jidp->resourcepart, "__prof_default") != 0) {
        g_string_append(display_str, " (");
        g_string_append(display_str, jidp->resourcepart);
        g_string_append(display_str, ")");
    }

    ProfWin *console = wins_get_console();
    _show_status_string(console, display_str->str, show, status, NULL, "--",
        "offline");

    ProfWin *window = wins_get_by_recipient(jidp->barejid);
    if (window != NULL) {
        _show_status_string(window, display_str->str, show, status, NULL, "--",
            "offline");
    }

    jid_destroy(jidp);
    g_string_free(display_str, TRUE);

    if (wins_is_current(console)) {
        wins_refresh_current();
    } else if ((window != NULL) && (wins_is_current(window))) {
        wins_refresh_current();
    }
}
Beispiel #28
0
void
ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activity)
{
    char *show_console = prefs_get_string(PREF_STATUSES_CONSOLE);
    char *show_chat_win = prefs_get_string(PREF_STATUSES_CHAT);
    PContact contact = roster_get_contact(barejid);

    // show nothing
    if (g_strcmp0(p_contact_subscription(contact), "none") == 0) {
        free(show_console);
        free(show_chat_win);
        return;
    }

    // show in console if "all"
    if (g_strcmp0(show_console, "all") == 0) {
        cons_show_contact_online(contact, resource, last_activity);

    // show in console of "online" and presence online
    } else if (g_strcmp0(show_console, "online") == 0 && resource->presence == RESOURCE_ONLINE) {
        cons_show_contact_online(contact, resource, last_activity);
    }

    // show in chat win if "all"
    if (g_strcmp0(show_chat_win, "all") == 0) {
        ProfChatWin *chatwin = wins_get_chat(barejid);
        if (chatwin) {
            chatwin_contact_online(chatwin, resource, last_activity);
        }

    // show in char win if "online" and presence online
    } else if (g_strcmp0(show_chat_win, "online") == 0 && resource->presence == RESOURCE_ONLINE) {
        ProfChatWin *chatwin = wins_get_chat(barejid);
        if (chatwin) {
            chatwin_contact_online(chatwin, resource, last_activity);
        }
    }

    free(show_console);
    free(show_chat_win);
}
Beispiel #29
0
gboolean
roster_contact_offline(const char *const barejid, const char *const resource, const char *const status)
{
    PContact contact = roster_get_contact(barejid);

    if (contact == NULL) {
        return FALSE;
    }
    if (resource == NULL) {
        return TRUE;
    } else {
        gboolean result = p_contact_remove_resource(contact, resource);
        if (result == TRUE) {
            Jid *jid = jid_create_from_bare_and_resource(barejid, resource);
            autocomplete_remove(fulljid_ac, jid->fulljid);
            jid_destroy(jid);
        }

        return result;
    }
}
Beispiel #30
0
ProfChatWin*
chatwin_new(const char *const barejid)
{
    ProfWin *window = wins_new_chat(barejid);
    ProfChatWin *chatwin = (ProfChatWin *)window;

    if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) {
        _chatwin_history(chatwin, barejid);
    }

    // if the contact is offline, show a message
    PContact contact = roster_get_contact(barejid);
    if (contact) {
        if (strcmp(p_contact_presence(contact), "offline") == 0) {
            const char * const show = p_contact_presence(contact);
            const char * const status = p_contact_status(contact);
            win_show_status_string(window, barejid, show, status, NULL, "--", "offline");
        }
    }

    return chatwin;
}